Skip to content

Commit 58aea05

Browse files
authored
Merge branch 'main' into feature/runtime-tools
2 parents e8a0380 + d28a1a6 commit 58aea05

File tree

19 files changed

+253
-37
lines changed

19 files changed

+253
-37
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ repos:
77
- id: prettier
88
types_or: [yaml, json5]
99

10+
- repo: https://github.com/igorshubovych/markdownlint-cli
11+
rev: v0.45.0
12+
hooks:
13+
- id: markdownlint
14+
args:
15+
[
16+
"--fix",
17+
"--config",
18+
"pyproject.toml",
19+
"--configPointer",
20+
"/tool/markdown/lint",
21+
]
22+
types: [markdown]
23+
1024
- repo: local
1125
hooks:
1226
- id: ruff-format

CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ This document contains critical information about working with this codebase. Fo
2626
- Bug fixes require regression tests
2727

2828
- For commits fixing bugs or adding features based on user reports add:
29+
2930
```bash
3031
git commit --trailer "Reported-by:<name>"
3132
```
33+
3234
Where `<name>` is the name of the user.
3335

3436
- For commits related to a Github issue, add
37+
3538
```bash
3639
git commit --trailer "Github-Issue:#<number>"
3740
```
41+
3842
- NEVER ever mention a `co-authored-by` or similar aspects. In particular, never
3943
mention the tool used to create the commit message or PR.
4044

CODE_OF_CONDUCT.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ representative at an online or offline event.
6060

6161
Instances of abusive, harassing, or otherwise unacceptable behavior may be
6262
reported to the community leaders responsible for enforcement at
63-
mcp-coc@anthropic.com.
63+
<mcp-coc@anthropic.com>.
6464
All complaints will be reviewed and investigated promptly and fairly.
6565

6666
All community leaders are obligated to respect the privacy and security of the
@@ -116,13 +116,13 @@ the community.
116116

117117
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118118
version 2.0, available at
119-
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
119+
<https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>.
120120

121121
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122122
enforcement ladder](https://github.com/mozilla/diversity).
123123

124124
[homepage]: https://www.contributor-covenant.org
125125

126126
For answers to common questions about this code of conduct, see the FAQ at
127-
https://www.contributor-covenant.org/faq. Translations are available at
128-
https://www.contributor-covenant.org/translations.
127+
<https://www.contributor-covenant.org/faq>. Translations are available at
128+
<https://www.contributor-covenant.org/translations>.

CONTRIBUTING.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Thank you for your interest in contributing to the MCP Python SDK! This document
99
3. Fork the repository
1010
4. Clone your fork: `git clone https://github.com/YOUR-USERNAME/python-sdk.git`
1111
5. Install dependencies:
12+
1213
```bash
1314
uv sync --frozen --all-extras --dev
1415
```
@@ -25,22 +26,26 @@ uv sync --frozen --all-extras --dev
2526
3. Make your changes
2627

2728
4. Ensure tests pass:
28-
```bash
29+
30+
```bash
2931
uv run pytest
3032
```
3133

3234
5. Run type checking:
35+
3336
```bash
3437
uv run pyright
3538
```
3639

3740
6. Run linting:
41+
3842
```bash
3943
uv run ruff check .
4044
uv run ruff format .
4145
```
4246

4347
7. Update README snippets if you modified example code:
48+
4449
```bash
4550
uv run scripts/update_readme_snippets.py
4651
```

README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ If you haven't created a uv-managed project yet, create one:
9696
```
9797

9898
Alternatively, for projects using pip for dependencies:
99+
99100
```bash
100101
pip install "mcp[cli]"
101102
```
@@ -135,11 +136,13 @@ def get_greeting(name: str) -> str:
135136
```
136137

137138
You can install this server in [Claude Desktop](https://claude.ai/download) and interact with it right away by running:
139+
138140
```bash
139141
uv run mcp install server.py
140142
```
141143

142144
Alternatively, you can test it with the MCP Inspector:
145+
143146
```bash
144147
uv run mcp dev server.py
145148
```
@@ -202,7 +205,7 @@ mcp = FastMCP("My App", lifespan=app_lifespan)
202205
def query_db() -> str:
203206
"""Tool that uses initialized resources"""
204207
ctx = mcp.get_context()
205-
db = ctx.request_context.lifespan_context["db"]
208+
db = ctx.request_context.lifespan_context.db
206209
return db.query()
207210
```
208211

@@ -233,6 +236,7 @@ def get_settings() -> str:
233236
"debug": false
234237
}"""
235238
```
239+
236240
_Full example: [examples/snippets/servers/basic_resource.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/basic_resource.py)_
237241
<!-- /snippet-source -->
238242

@@ -259,15 +263,17 @@ def get_weather(city: str, unit: str = "celsius") -> str:
259263
# This would normally call a weather API
260264
return f"Weather in {city}: 22degrees{unit[0].upper()}"
261265
```
266+
262267
_Full example: [examples/snippets/servers/basic_tool.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/basic_tool.py)_
263268
<!-- /snippet-source -->
264269

265270
#### Structured Output
266271

267272
Tools will return structured results by default, if their return type
268-
annotation is compatible. Otherwise, they will return unstructured results.
273+
annotation is compatible. Otherwise, they will return unstructured results.
269274

270275
Structured output supports these return types:
276+
271277
- Pydantic models (BaseModel subclasses)
272278
- TypedDicts
273279
- Dataclasses and other classes with type hints
@@ -279,17 +285,17 @@ Classes without type hints cannot be serialized for structured output. Only
279285
classes with properly annotated attributes will be converted to Pydantic models
280286
for schema generation and validation.
281287

282-
Structured results are automatically validated against the output schema
283-
generated from the annotation. This ensures the tool returns well-typed,
288+
Structured results are automatically validated against the output schema
289+
generated from the annotation. This ensures the tool returns well-typed,
284290
validated data that clients can easily process.
285291

286292
**Note:** For backward compatibility, unstructured results are also
287-
returned. Unstructured results are provided for backward compatibility
293+
returned. Unstructured results are provided for backward compatibility
288294
with previous versions of the MCP specification, and are quirks-compatible
289295
with previous versions of FastMCP in the current version of the SDK.
290296

291-
**Note:** In cases where a tool function's return type annotation
292-
causes the tool to be classified as structured _and this is undesirable_,
297+
**Note:** In cases where a tool function's return type annotation
298+
causes the tool to be classified as structured _and this is undesirable_,
293299
the classification can be suppressed by passing `structured_output=False`
294300
to the `@tool` decorator.
295301

@@ -446,6 +452,7 @@ def debug_error(error: str) -> list[base.Message]:
446452
base.AssistantMessage("I'll help debug that. What have you tried so far?"),
447453
]
448454
```
455+
449456
_Full example: [examples/snippets/servers/basic_prompt.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/basic_prompt.py)_
450457
<!-- /snippet-source -->
451458

@@ -495,6 +502,7 @@ async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str
495502

496503
return f"Task '{task_name}' completed"
497504
```
505+
498506
_Full example: [examples/snippets/servers/tool_progress.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/tool_progress.py)_
499507
<!-- /snippet-source -->
500508

@@ -503,6 +511,7 @@ _Full example: [examples/snippets/servers/tool_progress.py](https://github.com/m
503511
MCP supports providing completion suggestions for prompt arguments and resource template parameters. With the context parameter, servers can provide completions based on previously resolved values:
504512

505513
Client usage:
514+
506515
```python
507516
from mcp.client.session import ClientSession
508517
from mcp.types import ResourceTemplateReference
@@ -581,6 +590,7 @@ async def handle_completion(
581590

582591
return None
583592
```
593+
584594
_Full example: [examples/snippets/servers/completion.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/completion.py)_
585595
<!-- /snippet-source -->
586596
### Elicitation
@@ -631,10 +641,12 @@ async def book_table(
631641
# Date available
632642
return f"[SUCCESS] Booked for {date} at {time}"
633643
```
644+
634645
_Full example: [examples/snippets/servers/elicitation.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/elicitation.py)_
635646
<!-- /snippet-source -->
636647

637648
The `elicit()` method returns an `ElicitationResult` with:
649+
638650
- `action`: "accept", "decline", or "cancel"
639651
- `data`: The validated response (only when accepted)
640652
- `validation_error`: Any validation error message
@@ -670,6 +682,7 @@ async def generate_poem(topic: str, ctx: Context) -> str:
670682
return result.content.text
671683
return str(result.content)
672684
```
685+
673686
_Full example: [examples/snippets/servers/sampling.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/sampling.py)_
674687
<!-- /snippet-source -->
675688

@@ -698,6 +711,7 @@ async def process_data(data: str, ctx: Context) -> str:
698711

699712
return f"Processed: {data}"
700713
```
714+
701715
_Full example: [examples/snippets/servers/notifications.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/notifications.py)_
702716
<!-- /snippet-source -->
703717

@@ -736,6 +750,7 @@ mcp = FastMCP(
736750
For a complete example with separate Authorization Server and Resource Server implementations, see [`examples/servers/simple-auth/`](examples/servers/simple-auth/).
737751

738752
**Architecture:**
753+
739754
- **Authorization Server (AS)**: Handles OAuth flows, user authentication, and token issuance
740755
- **Resource Server (RS)**: Your MCP server that validates tokens and serves protected resources
741756
- **Client**: Discovers AS through RFC 9728, obtains tokens, and uses them with the MCP server
@@ -787,6 +802,7 @@ if __name__ == "__main__":
787802
```
788803

789804
Run it with:
805+
790806
```bash
791807
python server.py
792808
# or
@@ -866,10 +882,12 @@ app.mount("/math", math.mcp.streamable_http_app())
866882
```
867883

868884
For low level server with Streamable HTTP implementations, see:
885+
869886
- Stateful server: [`examples/servers/simple-streamablehttp/`](examples/servers/simple-streamablehttp/)
870887
- Stateless server: [`examples/servers/simple-streamablehttp-stateless/`](examples/servers/simple-streamablehttp-stateless/)
871888

872889
The streamable HTTP transport supports:
890+
873891
- Stateful and stateless operation modes
874892
- Resumability with event stores
875893
- JSON or SSE response formats
@@ -1042,6 +1060,7 @@ async def query_db(name: str, arguments: dict) -> list:
10421060
```
10431061

10441062
The lifespan API provides:
1063+
10451064
- A way to initialize resources when the server starts and clean them up when it stops
10461065
- Access to initialized resources through the request context in handlers
10471066
- Type-safe context passing between lifespan and request handlers
@@ -1168,6 +1187,7 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
11681187
```
11691188

11701189
Tools can return data in three ways:
1190+
11711191
1. **Content only**: Return a list of content blocks (default behavior before spec revision 2025-06-18)
11721192
2. **Structured data only**: Return a dictionary that will be serialized to JSON (Introduced in spec revision 2025-06-18)
11731193
3. **Both**: Return a tuple of (content, structured_data) preferred option to use for backwards compatibility
@@ -1293,6 +1313,7 @@ async def display_resources(session: ClientSession):
12931313
```
12941314

12951315
The `get_display_name()` function implements the proper precedence rules for displaying names:
1316+
12961317
- For tools: `title` > `annotations.title` > `name`
12971318
- For other objects: `title` > `name`
12981319

@@ -1351,7 +1372,6 @@ async def main():
13511372

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

1354-
13551375
### MCP Primitives
13561376

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

SECURITY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Security Policy
2+
23
Thank you for helping us keep the SDKs and systems they interact with secure.
34

45
## Reporting Security Issues

examples/clients/simple-auth-client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The client will open your browser for authentication. After completing OAuth, yo
4747

4848
## Example
4949

50-
```
50+
```markdown
5151
🔐 Simple MCP Auth Client
5252
Connecting to: http://localhost:3001
5353

examples/clients/simple-chatbot/README.MD

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ This example demonstrates how to integrate the Model Context Protocol (MCP) into
2525
```plaintext
2626
LLM_API_KEY=your_api_key_here
2727
```
28+
2829
**Note:** The current implementation is configured to use the Groq API endpoint (`https://api.groq.com/openai/v1/chat/completions`) with the `llama-3.2-90b-vision-preview` model. If you plan to use a different LLM provider, you'll need to modify the `LLMClient` class in `main.py` to use the appropriate endpoint URL and model parameters.
2930

3031
3. **Configure servers:**
3132

32-
The `servers_config.json` follows the same structure as Claude Desktop, allowing for easy integration of multiple servers.
33+
The `servers_config.json` follows the same structure as Claude Desktop, allowing for easy integration of multiple servers.
3334
Here's an example:
3435

3536
```json
@@ -46,9 +47,11 @@ This example demonstrates how to integrate the Model Context Protocol (MCP) into
4647
}
4748
}
4849
```
50+
4951
Environment variables are supported as well. Pass them as you would with the Claude Desktop App.
5052

5153
Example:
54+
5255
```json
5356
{
5457
"mcpServers": {
@@ -72,7 +75,7 @@ This example demonstrates how to integrate the Model Context Protocol (MCP) into
7275
```
7376

7477
2. **Interact with the assistant:**
75-
78+
7679
The assistant will automatically detect available tools and can respond to queries based on the tools provided by the configured servers.
7780

7881
3. **Exit the session:**
@@ -86,6 +89,7 @@ This example demonstrates how to integrate the Model Context Protocol (MCP) into
8689
- **Server Integration**: Supports any MCP-compatible server, tested with various server implementations including Uvicorn and Node.js.
8790

8891
### Class Structure
92+
8993
- **Configuration**: Manages environment variables and server configurations
9094
- **Server**: Handles MCP server initialization, tool discovery, and execution
9195
- **Tool**: Represents individual tools with their properties and formatting
@@ -107,5 +111,3 @@ This example demonstrates how to integrate the Model Context Protocol (MCP) into
107111
- If it's a direct response → return to user
108112
- Tool results are sent back to LLM for interpretation
109113
- Final response is presented to user
110-
111-

0 commit comments

Comments
 (0)