-
Notifications
You must be signed in to change notification settings - Fork 2.8k
docs(instructions): #1516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stvnksslr
wants to merge
4
commits into
modelcontextprotocol:main
Choose a base branch
from
stvnksslr:feat/instructions-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
docs(instructions): #1516
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c0d662e
docs(instructions): contributes to some of the questions in issue #14…
stvnksslr d079d2c
Merge branch 'main' into feat/instructions-docs
stvnksslr fca00d1
Merge branch 'main' into feat/instructions-docs
stvnksslr fee2fd1
Update docs/concepts.md
stvnksslr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """ | ||
| Example showing how to use server instructions to guide tool usage. | ||
|
|
||
| The instructions field helps clients understand how to use your tools | ||
| together, effectively providing tool grouping/bundling/namespacing. | ||
|
|
||
| cd to the `examples/snippets` directory and run: | ||
| uv run server server_instructions stdio | ||
| """ | ||
|
|
||
| from typing import Any | ||
|
|
||
| from mcp.server.fastmcp import FastMCP | ||
|
|
||
| # Create server with instructions | ||
| mcp = FastMCP( | ||
| name="Multi-Domain Server", | ||
| instructions="""This server provides tools across multiple domains: | ||
|
|
||
| ## Weather Tools | ||
| - get_weather: Get current weather for a location | ||
| - get_forecast: Get weather forecast | ||
|
|
||
| These tools work together - use get_weather for current conditions, | ||
| then get_forecast for future planning. | ||
|
|
||
| ## Calendar Tools | ||
| - create_event: Schedule a new calendar event | ||
| - list_events: View upcoming events | ||
|
|
||
| Use list_events first to check availability before create_event. | ||
|
|
||
| ## Best Practices | ||
| - Always check weather before scheduling outdoor events | ||
| - Use get_forecast to plan events 2-7 days ahead | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| # Define the tools mentioned in instructions | ||
| @mcp.tool() | ||
| def get_weather(location: str) -> dict[str, Any]: | ||
| """Get current weather for a location""" | ||
| return {"location": location, "temperature": 72, "condition": "sunny", "humidity": 45} | ||
|
|
||
|
|
||
| @mcp.tool() | ||
| def get_forecast(location: str, days: int = 5) -> list[dict[str, Any]]: | ||
| """Get weather forecast for upcoming days""" | ||
| return [{"day": i, "high": 70 + i, "low": 50 + i, "condition": "partly cloudy"} for i in range(days)] | ||
|
|
||
|
|
||
| @mcp.tool() | ||
| def create_event(title: str, date: str, time: str) -> dict[str, Any]: | ||
| """Schedule a new calendar event""" | ||
| return {"id": "evt_123", "title": title, "date": date, "time": time, "status": "created"} | ||
|
|
||
|
|
||
| @mcp.tool() | ||
| def list_events(start_date: str, end_date: str) -> list[dict[str, Any]]: | ||
| """View upcoming events in date range""" | ||
| return [ | ||
| {"title": "Team Meeting", "date": start_date, "time": "10:00"}, | ||
| {"title": "Lunch with Client", "date": start_date, "time": "12:00"}, | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.