Skip to content

Commit 05dea67

Browse files
committed
Update README.md
1 parent 34c71ba commit 05dea67

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

README.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ async def fetch_weather(city: str) -> str:
250250

251251
#### Output Schemas
252252

253-
Tools automatically generate JSON Schema definitions for their return types, helping LLMs understand the structure of the data they'll receive:
253+
Tools automatically generate JSON Schema definitions for their return types, helping LLMs understand the structure of the data they'll receive. FastMCP also enhances these schemas with semantic metadata that enables intelligent UI rendering and data formatting.
254+
255+
##### Basic Schema Generation
254256

255257
```python
256258
from pydantic import BaseModel
@@ -309,7 +311,7 @@ class WeatherForecast(BaseModel):
309311
@mcp.tool()
310312
def get_weather_forecast(city: str) -> WeatherForecast:
311313
"""Get detailed weather forecast for a city"""
312-
# In a real implementation, this would fetch actual forecast data
314+
# In a real implementation, this would fetch actual weather data
313315
return WeatherForecast(
314316
current=WeatherData(
315317
temperature=72.5,
@@ -324,6 +326,66 @@ def get_weather_forecast(city: str) -> WeatherForecast:
324326
)
325327
```
326328

329+
##### Semantic Metadata Enhancement
330+
331+
FastMCP automatically enhances output schemas with semantic metadata by analyzing field names and types. This helps client applications provide intelligent UI rendering and formatting:
332+
333+
```python
334+
from pydantic import BaseModel
335+
from mcp.server.fastmcp import FastMCP
336+
337+
mcp = FastMCP("Enhanced Schema Demo")
338+
339+
340+
class UserProfile(BaseModel):
341+
email: str # Automatically detected as semantic_type: "email"
342+
profile_url: str # Automatically detected as semantic_type: "url"
343+
avatar_image: str # Automatically detected as semantic_type: "image_url"
344+
created_date: str # Automatically detected as semantic_type: "datetime"
345+
account_balance: float # Automatically detected as semantic_type: "currency"
346+
completion_percentage: (
347+
float # Automatically detected as semantic_type: "percentage"
348+
)
349+
primary_color: str # Automatically detected as semantic_type: "color"
350+
351+
352+
@mcp.tool()
353+
def get_user_profile(user_id: str) -> UserProfile:
354+
"""Get user profile with semantic field types"""
355+
return UserProfile(
356+
email="user@example.com",
357+
profile_url="https://example.com/users/12345",
358+
avatar_image="https://example.com/avatars/user.jpg",
359+
created_date="2023-06-15T10:30:00Z",
360+
account_balance=150.75,
361+
completion_percentage=85.5,
362+
primary_color="#3498db",
363+
)
364+
```
365+
366+
**Supported Semantic Types:**
367+
368+
- `email` - Email addresses
369+
- `url`, `link` - Web URLs and links
370+
- `image_url`, `audio_url`, `video_url` - Media URLs
371+
- `datetime` - Date and time fields (with subtypes like `date`, `time`, `timestamp`)
372+
- `currency`, `money` - Monetary values
373+
- `percentage` - Percentage values
374+
- `color` - Color codes and values
375+
- `phone` - Phone numbers
376+
- `status` - Status indicators
377+
- `media_format` - File format detection for audio/video/image files
378+
379+
**Benefits for Client Applications:**
380+
381+
- Email fields can display mail icons and validation
382+
- URLs become clickable links with preview capabilities
383+
- Date fields get appropriate date pickers and formatting
384+
- Currency fields show proper monetary formatting
385+
- Media URLs can display thumbnails or players
386+
- Status fields can show colored indicators
387+
- Percentage fields can render as progress bars
388+
327389
### Prompts
328390

329391
Prompts are reusable templates that help LLMs interact with your server effectively:
@@ -929,7 +991,6 @@ async def main():
929991

930992
For a complete working example, see [`examples/clients/simple-auth-client/`](examples/clients/simple-auth-client/).
931993

932-
933994
### MCP Primitives
934995

935996
The MCP protocol defines three core primitives that servers can implement:

0 commit comments

Comments
 (0)