Adding description field to the FastMCP get_prompt method (#614)

Co-authored-by: ihrpr <inna@anthropic.com>
This commit is contained in:
Megan Dsouza 2025-07-09 15:50:38 -04:00 • committed by GitHub
commit f55831ee79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -982,6 +982,46 @@ class TestServerPrompts:
assert isinstance(content, TextContent)
assert content.text == "Hello, World!"
@pytest.mark.anyio
async def test_get_prompt_with_description(self):
"""Test getting a prompt through MCP protocol."""
mcp = FastMCP()
@mcp.prompt(description="Test prompt description")
def fn(name: str) -> str:
return f"Hello, {name}!"
async with client_session(mcp._mcp_server) as client:
result = await client.get_prompt("fn", {"name": "World"})
assert result.description == "Test prompt description"
@pytest.mark.anyio
async def test_get_prompt_without_description(self):
"""Test getting a prompt without description returns empty string."""
mcp = FastMCP()
@mcp.prompt()
def fn(name: str) -> str:
return f"Hello, {name}!"
async with client_session(mcp._mcp_server) as client:
result = await client.get_prompt("fn", {"name": "World"})
assert result.description == ""
@pytest.mark.anyio
async def test_get_prompt_with_docstring_description(self):
"""Test prompt uses docstring as description when not explicitly provided."""
mcp = FastMCP()
@mcp.prompt()
def fn(name: str) -> str:
"""This is the function docstring."""
return f"Hello, {name}!"
async with client_session(mcp._mcp_server) as client:
result = await client.get_prompt("fn", {"name": "World"})
assert result.description == "This is the function docstring."
@pytest.mark.anyio
async def test_get_prompt_with_resource(self):
"""Test getting a prompt that returns resource content."""