Skip to content

Commit 45917a3

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 455c5c2 commit 45917a3

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
@@ -209,13 +209,13 @@ from mcp.server.fastmcp import FastMCP
209209
mcp = FastMCP("My App")
210210

211211

212-
@mcp.resource("config://app")
212+
@mcp.resource("config://app", title="Application Configuration")
213213
def get_config() -> str:
214214
"""Static configuration data"""
215215
return "App configuration here"
216216

217217

218-
@mcp.resource("users://{user_id}/profile")
218+
@mcp.resource("users://{user_id}/profile", title="User Profile")
219219
def get_user_profile(user_id: str) -> str:
220220
"""Dynamic user data"""
221221
return f"Profile data for user {user_id}"
@@ -232,13 +232,13 @@ from mcp.server.fastmcp import FastMCP
232232
mcp = FastMCP("My App")
233233

234234

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

240240

241-
@mcp.tool()
241+
@mcp.tool(title="Weather Fetcher")
242242
async def fetch_weather(city: str) -> str:
243243
"""Fetch current weather for a city"""
244244
async with httpx.AsyncClient() as client:
@@ -257,12 +257,12 @@ from mcp.server.fastmcp.prompts import base
257257
mcp = FastMCP("My App")
258258

259259

260-
@mcp.prompt()
260+
@mcp.prompt(title="Code Review")
261261
def review_code(code: str) -> str:
262262
return f"Please review this code:\n\n{code}"
263263

264264

265-
@mcp.prompt()
265+
@mcp.prompt(title="Debug Assistant")
266266
def debug_error(error: str) -> list[base.Message]:
267267
return [
268268
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)