Skip to content

Commit b66c675

Browse files
committed
feat: add example and test for parameter descriptions in FastMCP tools
1 parent a77aaa7 commit b66c675

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
FastMCP Example showing parameter descriptions
3+
"""
4+
5+
from pydantic import Field
6+
7+
from mcp.server.fastmcp import FastMCP
8+
9+
# Create server
10+
mcp = FastMCP("Parameter Descriptions Server")
11+
12+
13+
@mcp.tool()
14+
def greet_user(
15+
name: str = Field(description="The name of the person to greet"),
16+
title: str = Field(description="Optional title like Mr/Ms/Dr", default=""),
17+
times: int = Field(description="Number of times to repeat the greeting", default=1),
18+
) -> str:
19+
"""Greet a user with optional title and repetition"""
20+
greeting = f"Hello {title + ' ' if title else ''}{name}!"
21+
return "\n".join([greeting] * times)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Test that parameter descriptions are properly exposed through list_tools"""
2+
3+
import pytest
4+
from pydantic import Field
5+
6+
from mcp.server.fastmcp import FastMCP
7+
8+
9+
@pytest.mark.asyncio
10+
async def test_parameter_descriptions():
11+
mcp = FastMCP("Test Server")
12+
13+
@mcp.tool()
14+
def greet(
15+
name: str = Field(description="The name to greet"),
16+
title: str = Field(description="Optional title", default=""),
17+
) -> str:
18+
"""A greeting tool"""
19+
return f"Hello {title} {name}"
20+
21+
tools = await mcp.list_tools()
22+
assert len(tools) == 1
23+
tool = tools[0]
24+
25+
# Check that parameter descriptions are present in the schema
26+
properties = tool.inputSchema["properties"]
27+
assert "name" in properties
28+
assert properties["name"]["description"] == "The name to greet"
29+
assert "title" in properties
30+
assert properties["title"]["description"] == "Optional title"

0 commit comments

Comments
 (0)