Skip to content

Commit 7a9aad9

Browse files
committed
Adding description field to the FastMCP get_prompt method
Issue: #602
1 parent ec62372 commit 7a9aad9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,13 @@ async def get_prompt(
531531
) -> GetPromptResult:
532532
"""Get a prompt by name with arguments."""
533533
try:
534+
prompt = self._prompt_manager.get_prompt(name)
534535
messages = await self._prompt_manager.render_prompt(name, arguments)
535536

536-
return GetPromptResult(messages=pydantic_core.to_jsonable_python(messages))
537+
return GetPromptResult(
538+
description=getattr(prompt, "description", None),
539+
messages=pydantic_core.to_jsonable_python(messages),
540+
)
537541
except Exception as e:
538542
logger.error(f"Error getting prompt {name}: {e}")
539543
raise ValueError(str(e))

tests/server/fastmcp/test_server.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,19 @@ def fn(name: str) -> str:
696696
assert isinstance(content, TextContent)
697697
assert content.text == "Hello, World!"
698698

699+
@pytest.mark.anyio
700+
async def test_get_prompt_with_description(self):
701+
"""Test getting a prompt through MCP protocol."""
702+
mcp = FastMCP()
703+
704+
@mcp.prompt(description="Test prompt description")
705+
def fn(name: str) -> str:
706+
return f"Hello, {name}!"
707+
708+
async with client_session(mcp._mcp_server) as client:
709+
result = await client.get_prompt("fn", {"name": "World"})
710+
assert result.description == "Test prompt description"
711+
699712
@pytest.mark.anyio
700713
async def test_get_prompt_with_resource(self):
701714
"""Test getting a prompt that returns resource content."""

0 commit comments

Comments
 (0)