Skip to content

Commit f7f1787

Browse files
committed
docs: add server instructions example
1 parent 161834d commit f7f1787

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

README.v2.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- [Logging and Notifications](#logging-and-notifications)
4949
- [Authentication](#authentication)
5050
- [MCPServer Properties](#mcpserver-properties)
51+
- [Server Instructions](#server-instructions)
5152
- [Session Properties and Methods](#session-properties-and-methods)
5253
- [Request Context Properties](#request-context-properties)
5354
- [Running Your Server](#running-your-server)
@@ -1088,6 +1089,42 @@ def server_info(ctx: Context) -> dict:
10881089
}
10891090
```
10901091

1092+
### Server Instructions
1093+
1094+
Server instructions are sent to clients during initialization and are useful for describing how related tools should be used together. They can provide workflow hints, domain context, or guardrails that apply across the server's tools without repeating the same guidance in every tool description.
1095+
1096+
For example, instructions can describe a preferred order for tools in a workflow:
1097+
1098+
<!-- snippet-source examples/snippets/servers/instructions.py -->
1099+
```python
1100+
from mcp.server.mcpserver import MCPServer
1101+
1102+
mcp = MCPServer(
1103+
name="Workflow Assistant",
1104+
instructions=(
1105+
"Use the project tools together: call get_project_status first, "
1106+
"then use create_task only for missing or blocked work."
1107+
),
1108+
)
1109+
1110+
1111+
@mcp.tool()
1112+
def get_project_status(project_id: str) -> str:
1113+
"""Summarize current project status."""
1114+
return f"Project {project_id} is on track."
1115+
1116+
1117+
@mcp.tool()
1118+
def create_task(project_id: str, title: str) -> str:
1119+
"""Create a follow-up task for the project."""
1120+
return f"Created task '{title}' for project {project_id}."
1121+
```
1122+
1123+
_Full example: [examples/snippets/servers/instructions.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/instructions.py)_
1124+
<!-- /snippet-source -->
1125+
1126+
Clients can read the same value from `InitializeResult.instructions` after connecting. Inside tools, the server can access it as `ctx.mcp_server.instructions`.
1127+
10911128
### Session Properties and Methods
10921129

10931130
The session object accessible via `ctx.session` provides advanced control over client communication:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from mcp.server.mcpserver import MCPServer
2+
3+
mcp = MCPServer(
4+
name="Workflow Assistant",
5+
instructions=(
6+
"Use the project tools together: call get_project_status first, "
7+
"then use create_task only for missing or blocked work."
8+
),
9+
)
10+
11+
12+
@mcp.tool()
13+
def get_project_status(project_id: str) -> str:
14+
"""Summarize current project status."""
15+
return f"Project {project_id} is on track."
16+
17+
18+
@mcp.tool()
19+
def create_task(project_id: str, title: str) -> str:
20+
"""Create a follow-up task for the project."""
21+
return f"Created task '{title}' for project {project_id}."

0 commit comments

Comments
 (0)