Adding description field to the FastMCP get_prompt method (#614)
Co-authored-by: ihrpr <inna@anthropic.com>
This commit is contained in:
parent
7b1078b515
commit
f55831ee79
1 changed files with 49 additions and 2 deletions
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue