Skip to content

Commit f85dc16

Browse files
authored
Merge branch 'main' into subprocess_kill_win32
2 parents b3e3aee + 6353dd1 commit f85dc16

File tree

32 files changed

+1547
-56
lines changed

32 files changed

+1547
-56
lines changed

.github/workflows/shared.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ jobs:
3737
run: uv run --no-sync pyright
3838

3939
test:
40-
runs-on: ubuntu-latest
40+
runs-on: ${{ matrix.os }}
4141
strategy:
4242
matrix:
4343
python-version: ["3.10", "3.11", "3.12", "3.13"]
44+
os: [ubuntu-latest, windows-latest]
4445

4546
steps:
4647
- uses: actions/checkout@v4
@@ -55,3 +56,4 @@ jobs:
5556

5657
- name: Run pytest
5758
run: uv run --no-sync pytest
59+
continue-on-error: true

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ python server.py
387387
mcp run server.py
388388
```
389389

390+
Note that `mcp run` or `mcp dev` only supports server using FastMCP and not the low-level server variant.
391+
390392
### Streamable HTTP Transport
391393

392394
> **Note**: Streamable HTTP transport is superseding SSE transport for production deployments.
@@ -400,6 +402,9 @@ mcp = FastMCP("StatefulServer")
400402
# Stateless server (no session persistence)
401403
mcp = FastMCP("StatelessServer", stateless_http=True)
402404

405+
# Stateless server (no session persistence, no sse stream with supported client)
406+
mcp = FastMCP("StatelessServer", stateless_http=True, json_response=True)
407+
403408
# Run server with streamable_http transport
404409
mcp.run(transport="streamable-http")
405410
```
@@ -432,15 +437,22 @@ def add_two(n: int) -> int:
432437

433438
```python
434439
# main.py
440+
import contextlib
435441
from fastapi import FastAPI
436442
from mcp.echo import echo
437443
from mcp.math import math
438444

439445

440-
app = FastAPI()
446+
# Create a combined lifespan to manage both session managers
447+
@contextlib.asynccontextmanager
448+
async def lifespan(app: FastAPI):
449+
async with contextlib.AsyncExitStack() as stack:
450+
await stack.enter_async_context(echo.mcp.session_manager.run())
451+
await stack.enter_async_context(math.mcp.session_manager.run())
452+
yield
441453

442-
# Use the session manager's lifespan
443-
app = FastAPI(lifespan=lambda app: echo.mcp.session_manager.run())
454+
455+
app = FastAPI(lifespan=lifespan)
444456
app.mount("/echo", echo.mcp.streamable_http_app())
445457
app.mount("/math", math.mcp.streamable_http_app())
446458
```
@@ -694,6 +706,8 @@ if __name__ == "__main__":
694706
asyncio.run(run())
695707
```
696708

709+
Caution: The `mcp run` and `mcp dev` tool doesn't support low-level server.
710+
697711
### Writing MCP Clients
698712

699713
The SDK provides a high-level client interface for connecting to MCP servers using various [transports](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports):

examples/clients/simple-chatbot/README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This example demonstrates how to integrate the Model Context Protocol (MCP) into
2525
```plaintext
2626
LLM_API_KEY=your_api_key_here
2727
```
28+
**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.
2829

2930
3. **Configure servers:**
3031

examples/servers/simple-auth/mcp_simple_auth/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
from mcp_simple_auth.server import main
66

7-
sys.exit(main())
7+
sys.exit(main()) # type: ignore[call-arg]

examples/servers/simple-prompt/mcp_simple_prompt/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from .server import main
44

5-
sys.exit(main())
5+
sys.exit(main()) # type: ignore[call-arg]

examples/servers/simple-resource/mcp_simple_resource/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from .server import main
44

5-
sys.exit(main())
5+
sys.exit(main()) # type: ignore[call-arg]

examples/servers/simple-resource/mcp_simple_resource/server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import click
33
import mcp.types as types
44
from mcp.server.lowlevel import Server
5-
from pydantic import FileUrl
5+
from pydantic import AnyUrl
66

77
SAMPLE_RESOURCES = {
88
"greeting": "Hello! This is a sample text resource.",
@@ -26,7 +26,7 @@ def main(port: int, transport: str) -> int:
2626
async def list_resources() -> list[types.Resource]:
2727
return [
2828
types.Resource(
29-
uri=FileUrl(f"file:///{name}.txt"),
29+
uri=AnyUrl(f"file:///{name}.txt"),
3030
name=name,
3131
description=f"A sample text resource named {name}",
3232
mimeType="text/plain",
@@ -35,7 +35,9 @@ async def list_resources() -> list[types.Resource]:
3535
]
3636

3737
@app.read_resource()
38-
async def read_resource(uri: FileUrl) -> str | bytes:
38+
async def read_resource(uri: AnyUrl) -> str | bytes:
39+
if uri.path is None:
40+
raise ValueError(f"Invalid resource path: {uri}")
3941
name = uri.path.replace(".txt", "").lstrip("/")
4042

4143
if name not in SAMPLE_RESOURCES:
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from .server import main
22

33
if __name__ == "__main__":
4-
main()
4+
# Click will handle CLI arguments
5+
import sys
6+
7+
sys.exit(main()) # type: ignore[call-arg]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .server import main
22

33
if __name__ == "__main__":
4-
main()
4+
main() # type: ignore[call-arg]

examples/servers/simple-tool/mcp_simple_tool/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from .server import main
44

5-
sys.exit(main())
5+
sys.exit(main()) # type: ignore[call-arg]

0 commit comments

Comments
 (0)