Skip to content

Commit d1d0f7d

Browse files
docs: add title field examples to documentation and example servers
Update README and example servers to demonstrate the new title field feature for better human-readable display names. - Add title parameter to decorator examples in README - Update simple-tool example with "Website Fetcher" title - Update simple-resource example with resource-specific titles - Update simple-prompt example with "Simple Assistant Prompt" title 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c386fea commit d1d0f7d

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ from mcp.server.fastmcp import FastMCP
212212
mcp = FastMCP("My App")
213213

214214

215-
@mcp.resource("config://app")
215+
@mcp.resource("config://app", title="Application Configuration")
216216
def get_config() -> str:
217217
"""Static configuration data"""
218218
return "App configuration here"
219219

220220

221-
@mcp.resource("users://{user_id}/profile")
221+
@mcp.resource("users://{user_id}/profile", title="User Profile")
222222
def get_user_profile(user_id: str) -> str:
223223
"""Dynamic user data"""
224224
return f"Profile data for user {user_id}"
@@ -235,13 +235,13 @@ from mcp.server.fastmcp import FastMCP
235235
mcp = FastMCP("My App")
236236

237237

238-
@mcp.tool()
238+
@mcp.tool(title="BMI Calculator")
239239
def calculate_bmi(weight_kg: float, height_m: float) -> float:
240240
"""Calculate BMI given weight in kg and height in meters"""
241241
return weight_kg / (height_m**2)
242242

243243

244-
@mcp.tool()
244+
@mcp.tool(title="Weather Fetcher")
245245
async def fetch_weather(city: str) -> str:
246246
"""Fetch current weather for a city"""
247247
async with httpx.AsyncClient() as client:
@@ -260,12 +260,12 @@ from mcp.server.fastmcp.prompts import base
260260
mcp = FastMCP("My App")
261261

262262

263-
@mcp.prompt()
263+
@mcp.prompt(title="Code Review")
264264
def review_code(code: str) -> str:
265265
return f"Please review this code:\n\n{code}"
266266

267267

268-
@mcp.prompt()
268+
@mcp.prompt(title="Debug Assistant")
269269
def debug_error(error: str) -> list[base.Message]:
270270
return [
271271
base.UserMessage("I'm seeing this error:"),

examples/servers/simple-prompt/mcp_simple_prompt/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async def list_prompts() -> list[types.Prompt]:
5353
return [
5454
types.Prompt(
5555
name="simple",
56+
title="Simple Assistant Prompt",
5657
description="A simple prompt that can take optional context and topic "
5758
"arguments",
5859
arguments=[

examples/servers/simple-resource/mcp_simple_resource/server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"about": "This is the simple-resource MCP server implementation.",
1111
}
1212

13+
RESOURCE_TITLES = {
14+
"greeting": "Welcome Message",
15+
"help": "Help Documentation",
16+
"about": "About This Server",
17+
}
18+
1319

1420
@click.command()
1521
@click.option("--port", default=8000, help="Port to listen on for SSE")
@@ -28,6 +34,7 @@ async def list_resources() -> list[types.Resource]:
2834
types.Resource(
2935
uri=FileUrl(f"file:///{name}.txt"),
3036
name=name,
37+
title=RESOURCE_TITLES.get(name),
3138
description=f"A sample text resource named {name}",
3239
mimeType="text/plain",
3340
)

examples/servers/simple-tool/mcp_simple_tool/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ async def list_tools() -> list[types.Tool]:
4141
return [
4242
types.Tool(
4343
name="fetch",
44+
title="Website Fetcher",
4445
description="Fetches a website and returns its content",
4546
inputSchema={
4647
"type": "object",

0 commit comments

Comments
 (0)