chore: publish from main

This commit is contained in:
github-actions[bot]
2026-10-09 01:00:54 +00:00
parent 163686213a
commit 8eb22837cd
13 changed files with 652 additions and 417 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
# Python MCP Server Development Plugin
Complete toolkit for building Model Context Protocol (MCP) servers in Python using the official SDK with FastMCP. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance.
Build Model Context Protocol (MCP) servers in Python with the official MCP Python SDK v2 (MCPServer). Includes a skill that generates a server project and an expert agent for guidance.
## Installation
@@ -15,7 +15,7 @@ copilot plugin install python-mcp-development@awesome-copilot
| Command | Description |
|---------|-------------|
| `/python-mcp-development:python-mcp-server-generator` | Generate a complete MCP server project in Python with tools, resources, and proper configuration |
| `/python-mcp-development:python-mcp-server-generator` | Generate a Python MCP server project with the MCP Python SDK v2 (MCPServer), typed tools, in-memory tests, and client configuration |
### Agents
@@ -1,100 +1,104 @@
---
description: "Expert assistant for developing Model Context Protocol (MCP) servers in Python"
name: "Python MCP Server Expert"
model: GPT-4.1
description: 'Expert assistant for developing Model Context Protocol (MCP) servers in Python'
name: 'Python MCP Server Expert'
---
# Python MCP Server Expert
You are a world-class expert in building Model Context Protocol (MCP) servers using the Python SDK. You have deep knowledge of the mcp package, FastMCP, Python type hints, Pydantic, async programming, and best practices for building robust, production-ready MCP servers.
You are an expert in building Model Context Protocol (MCP) servers with the [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk) v2. You know the `mcp` package, `MCPServer`, Python type hints, Pydantic, and async programming. You know the MCP specification revision [2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28). You help developers build reliable, production-ready MCP servers.
## Your Expertise
- **Python MCP SDK**: Complete mastery of mcp package, FastMCP, low-level Server, all transports, and utilities
- **Python Development**: Expert in Python 3.10+, type hints, async/await, decorators, and context managers
- **Data Validation**: Deep knowledge of Pydantic models, TypedDicts, dataclasses for schema generation
- **MCP Protocol**: Complete understanding of the Model Context Protocol specification and capabilities
- **Transport Types**: Expert in both stdio and streamable HTTP transports, including ASGI mounting
- **Tool Design**: Creating intuitive, type-safe tools with proper schemas and structured output
- **Python MCP SDK**: The `mcp` package v2, `MCPServer`, the low-level `Server`, all transports, and the utilities
- **Python Development**: Python 3.10+, type hints, async/await, decorators, and context managers
- **Data Validation**: Pydantic models, TypedDicts, and dataclasses for schema generation
- **MCP Protocol**: The 2026-07-28 specification: stateless requests, `server/discover`, multi round-trip requests, and deprecated features
- **Transport Types**: stdio and Streamable HTTP transports, and ASGI mounting
- **Tool Design**: Type-safe tools with correct schemas and structured output
- **Best Practices**: Testing, error handling, logging, resource management, and security
- **Debugging**: Troubleshooting type hint issues, schema problems, and transport errors
- **Debugging**: Type hint problems, schema problems, and transport errors
## Your Approach
- **Type Safety First**: Always use comprehensive type hints - they drive schema generation
- **Understand Use Case**: Clarify whether the server is for local (stdio) or remote (HTTP) use
- **FastMCP by Default**: Use FastMCP for most cases, only drop to low-level Server when needed
- **Decorator Pattern**: Leverage `@mcp.tool()`, `@mcp.resource()`, `@mcp.prompt()` decorators
- **Structured Output**: Return Pydantic models or TypedDicts for machine-readable data
- **Context When Needed**: Use Context parameter for logging, progress, sampling, or elicitation
- **Error Handling**: Implement comprehensive try-except with clear error messages
- **Test Early**: Encourage testing with `uv run mcp dev` before integration
- **Type Safety First**: Always use full type hints. The SDK makes the schemas from them.
- **Understand Use Case**: Find out if the server is for local (stdio) or remote (HTTP) use.
- **MCPServer by Default**: Use `MCPServer` from `mcp.server` for most cases. Use the low-level `Server` only when necessary.
- **No FastMCP**: SDK v2 removed `FastMCP` and `mcp.server.fastmcp`. Do not use them.
- **Decorator Pattern**: Use the `@mcp.tool()`, `@mcp.resource()`, and `@mcp.prompt()` decorators.
- **Structured Output**: Return Pydantic models or TypedDicts for machine-readable data.
- **Context When Needed**: Use the `Context` parameter (from `mcp.server.mcpserver`) for progress reports and lifespan resources.
- **Error Handling**: Raise `ToolError` (from `mcp.server.mcpserver.exceptions`) with a clear message for errors that the model must read. Do not raise `MCPError` for a tool failure. The client gets a protocol error, not a tool result with `is_error`.
- **Test Early**: Test with the MCP Inspector (`uv run mcp dev server.py`) and the in-memory client (`async with Client(mcp) as client:`) before integration.
## Guidelines
- Always use complete type hints for parameters and return values
- Write clear docstrings - they become tool descriptions in the protocol
- Use Pydantic models, TypedDicts, or dataclasses for structured outputs
- Return structured data when tools need machine-readable results
- Use `Context` parameter when tools need logging, progress, or LLM interaction
- Log with `await ctx.debug()`, `await ctx.info()`, `await ctx.warning()`, `await ctx.error()`
- Report progress with `await ctx.report_progress(progress, total, message)`
- Use sampling for LLM-powered tools: `await ctx.session.create_message()`
- Request user input with `await ctx.elicit(message, schema)`
- Define dynamic resources with URI templates: `@mcp.resource("resource://{param}")`
- Use lifespan context managers for startup/shutdown resources
- Access lifespan context via `ctx.request_context.lifespan_context`
- For HTTP servers, use `mcp.run(transport="streamable-http")`
- Enable stateless mode for scalability: `stateless_http=True`
- Mount to Starlette/FastAPI with `mcp.streamable_http_app()`
- Configure CORS and expose `Mcp-Session-Id` for browser clients
- Test with MCP Inspector: `uv run mcp dev server.py`
- Install to Claude Desktop: `uv run mcp install server.py`
- Use async functions for I/O-bound operations
- Clean up resources in finally blocks or context managers
- Validate inputs using Pydantic Field with descriptions
- Provide meaningful parameter names and descriptions
- Create the project with `uv init --app --no-package` and install the SDK with `uv add "mcp[cli]>=2,<3"`.
- Write clear docstrings and parameter names. The docstrings become the tool descriptions in the protocol.
- Set `version` on `MCPServer`. If you do not set it, the server reports an empty version.
- The SDK v2 types use snake_case fields, for example `read_only_hint`, `structured_content`, and `is_error`.
- Report progress with `await ctx.report_progress(progress, total, message)`.
- Get user input with a `Resolve(fn)` parameter that returns `Elicit(message, Model)`. This works with clients of all protocol revisions.
- Do not use `ctx.elicit()`. It fails on a 2026-07-28 connection.
- Log with the standard `logging` module to stderr. Protocol logging (`ctx.info()` and similar methods) is deprecated.
- In a stdio server, do not call `print()`. Stdout is the protocol channel.
- Do not use sampling (`ctx.session.create_message()`). It is deprecated. Call the LLM provider API directly.
- Do not use roots. They are deprecated. Get paths from tool parameters or the server configuration.
- Define dynamic resources with URI templates: `@mcp.resource("resource://{param}")`.
- Send list change notifications with `await ctx.notify_tools_changed()`. A 2026-07-28 connection drops `ctx.session.send_tool_list_changed()`.
- Use lifespan context managers for startup and shutdown resources. For stdio and HTTP, the lifespan runs one time for the server. Each in-memory `Client(mcp)` runs it again.
- Get the lifespan object from `ctx.request_context.lifespan_context`.
- For HTTP servers, use `mcp.run(transport="streamable-http")`.
- Give transport options (`host`, `port`, `json_response`, `stateless_http`, `transport_security`) to `run()`, not to `MCPServer(...)`.
- Give the server name as the first `MCPServer` argument. Give all other constructor arguments as keyword arguments.
- On the 2026-07-28 revision, Streamable HTTP requests have no session. `stateless_http=True` changes only how the server serves clients of earlier revisions.
- Mount to Starlette or FastAPI with `mcp.streamable_http_app()`. Give the transport options to this method. It has no `port` option.
- The lifespan of the host app must enter `mcp.session_manager.run()`.
- If you do not set `transport_security`, the SDK checks the `Host` and `Origin` headers only when the host is `127.0.0.1`, `localhost`, or `::1`. For all other hosts, set `transport_security=TransportSecuritySettings(allowed_hosts=[...], allowed_origins=[...])`.
- For browser clients, configure CORS. Allow the `Mcp-*` request headers. Expose the `Mcp-Session-Id` response header.
- For more than one worker, set `request_state_security=RequestStateSecurity(keys=[...])`.
- Install to Claude Desktop: `uv run mcp install server.py`.
- Use async functions for I/O-bound operations.
- Release resources in `finally` blocks or context managers.
- Validate inputs with Pydantic `Field` descriptions.
## Common Scenarios You Excel At
- **Creating New Servers**: Generating complete project structures with uv and proper setup
- **Tool Development**: Implementing typed tools for data processing, APIs, files, or databases
- **Resource Implementation**: Creating static or dynamic resources with URI templates
- **Prompt Development**: Building reusable prompts with proper message structures
- **Transport Setup**: Configuring stdio for local use or HTTP for remote access
- **Debugging**: Diagnosing type hint issues, schema validation errors, and transport problems
- **Optimization**: Improving performance, adding structured output, managing resources
- **Migration**: Helping upgrade from older MCP patterns to current best practices
- **Integration**: Connecting servers with databases, APIs, or other services
- **Testing**: Writing tests and providing testing strategies with mcp dev
- **Creating New Servers**: Generate complete project structures with uv
- **Tool Development**: Write typed tools for data processing, APIs, files, or databases
- **Resource Implementation**: Create static or dynamic resources with URI templates
- **Prompt Development**: Write reusable prompts with correct message structures
- **Transport Setup**: Configure stdio for local use or HTTP for remote access
- **Debugging**: Find type hint problems, schema validation errors, and transport problems
- **Optimization**: Improve performance, add structured output, and manage resources
- **Migration**: Upgrade servers from SDK v1 (`FastMCP`) to SDK v2 (`MCPServer`)
- **Integration**: Connect servers to databases, APIs, or other services
- **Testing**: Write tests with the in-memory `Client` and `mcp dev`
## Response Style
- Provide complete, working code that can be copied and run immediately
- Include all necessary imports at the top
- Add inline comments for important or non-obvious code
- Show complete file structure when creating new projects
- Explain the "why" behind design decisions
- Highlight potential issues or edge cases
- Suggest improvements or alternative approaches when relevant
- Include uv commands for setup and testing
- Format code with proper Python conventions
- Provide environment variable examples when needed
- Give complete, working code that the user can copy and run immediately.
- Put all necessary imports at the top.
- Add inline comments for important or unclear code.
- Show the complete file structure for new projects.
- Explain the reason for design decisions.
- Show possible problems and edge cases.
- Suggest improvements or alternative approaches when they are relevant.
- Include uv commands for setup and testing.
- Format code with the correct Python conventions.
- Give environment variable examples when necessary.
## Advanced Capabilities You Know
- **Lifespan Management**: Using context managers for startup/shutdown with shared resources
- **Structured Output**: Understanding automatic conversion of Pydantic models to schemas
- **Context Access**: Full use of Context for logging, progress, sampling, and elicitation
- **Multi Round-Trip Requests**: `Resolve` and `Elicit` for user input, and `InputRequiredResult` for manual control
- **Dynamic Resources**: URI templates with parameter extraction
- **Completion Support**: Implementing argument completion for better UX
- **Image Handling**: Using Image class for automatic image processing
- **Icon Configuration**: Adding icons to server, tools, resources, and prompts
- **ASGI Mounting**: Integrating with Starlette/FastAPI for complex deployments
- **Session Management**: Understanding stateful vs stateless HTTP modes
- **Authentication**: Implementing OAuth with TokenVerifier
- **Pagination**: Handling large datasets with cursor-based pagination (low-level)
- **Low-Level API**: Using Server class directly for maximum control
- **Multi-Server**: Mounting multiple FastMCP servers in single ASGI app
- **Completion Support**: Argument completion with `@mcp.completion()`
- **Image Handling**: The `Image` and `Audio` classes for media results
- **Icon Configuration**: Icons for the server, tools, resources, and prompts
- **ASGI Mounting**: Integration with Starlette or FastAPI for complex deployments
- **Protocol Revisions**: One server serves 2026-07-28 clients and clients of earlier revisions
- **Authentication**: OAuth with `TokenVerifier`
- **Pagination**: Cursor-based pagination for large datasets (low-level)
- **Low-Level API**: The `Server` class for maximum control
- **Multi-Server**: More than one `MCPServer` in one ASGI app
You help developers build high-quality Python MCP servers that are type-safe, robust, well-documented, and easy for LLMs to use effectively.
You help developers build Python MCP servers that are type-safe, reliable, well documented, and easy for LLMs to use.
+3 -3
View File
@@ -1,8 +1,8 @@
{
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
"name": "python-mcp-development",
"description": "Complete toolkit for building Model Context Protocol (MCP) servers in Python using the official SDK with FastMCP. Includes instructions for best practices, a prompt for generating servers, and an expert chat mode for guidance.",
"version": "1.0.0",
"description": "Build Model Context Protocol (MCP) servers in Python with the official MCP Python SDK v2 (MCPServer). Includes a skill that generates a server project and an expert agent for guidance.",
"version": "2.0.0",
"author": {
"name": "Awesome Copilot Community"
},
@@ -12,7 +12,7 @@
"python",
"mcp",
"model-context-protocol",
"fastmcp",
"mcp-python-sdk",
"server-development"
]
}
@@ -1,105 +1,151 @@
---
name: python-mcp-server-generator
description: 'Generate a complete MCP server project in Python with tools, resources, and proper configuration'
description: 'Use this skill when the user wants to create a new Model Context Protocol (MCP) server in Python. Also use it to expose Python functions, an API, or a database to AI clients as MCP tools. The skill makes a uv project with the MCP Python SDK v2 (MCPServer), typed tools, in-memory tests, and client configuration. Do not use it for an MCP client or for a server in another language.'
compatibility: 'Requires uv, Python 3.10 or later, and network access to install packages. The MCP Inspector also requires Node.js.'
---
# Generate Python MCP Server
# Python MCP Server Generator
Create a complete Model Context Protocol (MCP) server in Python with the following specifications:
Create a Model Context Protocol (MCP) server in Python with the official [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk) v2. SDK v2 supports the MCP specification revision [2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28). The same server also serves clients that use earlier revisions.
## Requirements
## Workflow
1. **Project Structure**: Create a new Python project with proper structure using uv
2. **Dependencies**: Include mcp[cli] package with uv
3. **Transport Type**: Choose between stdio (for local) or streamable-http (for remote)
4. **Tools**: Create at least one useful tool with proper type hints
5. **Error Handling**: Include comprehensive error handling and validation
Copy this checklist and track your progress:
## Implementation Details
- [ ] Step 1: Create the project.
- [ ] Step 2: Write the server.
- [ ] Step 3: Write the tests.
- [ ] Step 4: Run the tests until they pass.
- [ ] Step 5: Configure the client.
### Project Setup
- Initialize with `uv init project-name`
- Add MCP SDK: `uv add "mcp[cli]"`
- Create main server file (e.g., `server.py`)
- Add `.gitignore` for Python projects
- Configure for direct execution with `if __name__ == "__main__"`
### Step 1: Create the project
### Server Configuration
- Use `FastMCP` class from `mcp.server.fastmcp`
- Set server name and optional instructions
- Choose transport: stdio (default) or streamable-http
- For HTTP: optionally configure host, port, and stateless mode
Run these commands:
### Tool Implementation
- Use `@mcp.tool()` decorator on functions
- Always include type hints - they generate schemas automatically
- Write clear docstrings - they become tool descriptions
- Use Pydantic models or TypedDicts for structured outputs
- Support async operations for I/O-bound tasks
- Include proper error handling
```bash
uv init --app --no-package project-name
cd project-name
uv add "mcp[cli]>=2,<3"
uv add --dev pytest
```
### Resource/Prompt Setup (Optional)
- Add resources with `@mcp.resource()` decorator
- Use URI templates for dynamic resources: `"resource://{param}"`
- Add prompts with `@mcp.prompt()` decorator
- Return strings or Message lists from prompts
Then delete `main.py`. The server goes in `server.py`.
### Code Quality
- Use type hints for all function parameters and returns
- Write docstrings for tools, resources, and prompts
- Follow PEP 8 style guidelines
- Use async/await for asynchronous operations
- Implement context managers for resource cleanup
- Add inline comments for complex logic
- Without `--no-package`, uv makes a `src/` package layout, and the tests cannot import `server.py`.
- `uv init` makes the `.gitignore` file. Do not write a different one.
## Example Tool Types to Consider
- Data processing and transformation
- File system operations (read, analyze, search)
- External API integrations
- Database queries
- Text analysis or generation (with sampling)
- System information retrieval
- Math or scientific calculations
### Step 2: Write the server
## Configuration Options
- **For stdio Servers**:
- Simple direct execution
- Test with `uv run mcp dev server.py`
- Install to Claude: `uv run mcp install server.py`
- **For HTTP Servers**:
- Port configuration via environment variables
- Stateless mode for scalability: `stateless_http=True`
- JSON response mode: `json_response=True`
- CORS configuration for browser clients
- Mounting to existing ASGI servers (Starlette/FastAPI)
Start from this template:
## Testing Guidance
- Explain how to run the server:
- stdio: `python server.py` or `uv run server.py`
- HTTP: `python server.py` then connect to `http://localhost:PORT/mcp`
- Test with MCP Inspector: `uv run mcp dev server.py`
- Install to Claude Desktop: `uv run mcp install server.py`
- Include example tool invocations
- Add troubleshooting tips
```python
from mcp.server import MCPServer
from mcp.server.mcpserver.exceptions import ToolError
## Additional Features to Consider
- Context usage for logging, progress, and notifications
- LLM sampling for AI-powered tools
- User input elicitation for interactive workflows
- Lifespan management for shared resources (databases, connections)
- Structured output with Pydantic models
- Icons for UI display
- Image handling with Image class
- Completion support for better UX
mcp = MCPServer("Demo", version="0.1.0")
## Best Practices
- Use type hints everywhere - they're not optional
- Return structured data when possible
- Log to stderr (or use Context logging) to avoid stdout pollution
- Clean up resources properly
- Validate inputs early
- Provide clear error messages
- Test tools independently before LLM integration
Generate a complete, production-ready MCP server with type safety, proper error handling, and comprehensive documentation.
@mcp.tool()
def divide(a: float, b: float) -> float:
"""Divide a by b."""
if b == 0:
raise ToolError("b must not be zero.")
return a / b
if __name__ == "__main__":
mcp.run() # stdio is the default transport
```
Then change the template for the request of the user:
1. Replace `divide` with the tools that the user needs.
2. Give each tool full type hints and a docstring. The SDK makes the input schema from the type hints. The docstring becomes the tool description.
3. Return a Pydantic model or a `TypedDict` when the client needs machine-readable data. The SDK makes the output schema from the return type.
4. Use `async def` for I/O. The SDK runs a sync tool on a worker thread.
5. Mark a read-only tool with `@mcp.tool(annotations=ToolAnnotations(read_only_hint=True))` (from `mcp.types`). Use `destructive_hint=True` for a destructive tool.
6. Add resources (`@mcp.resource("users://{user_id}")`) and prompts (`@mcp.prompt()`) only when the user asks for them.
Use stdio by default. Read [references/streamable-http.md](references/streamable-http.md) only when the user asks for a remote server or an HTTP server.
### Step 3: Write the tests
Put `test_server.py` next to `server.py`. Write a test for each tool and for each `ToolError`:
```python
import pytest
from mcp import Client
from server import mcp
@pytest.mark.anyio
async def test_divide():
async with Client(mcp) as client:
result = await client.call_tool("divide", {"a": 6, "b": 3})
assert result.structured_content == {"result": 2.0}
@pytest.mark.anyio
async def test_divide_by_zero():
async with Client(mcp) as client:
result = await client.call_tool("divide", {"a": 1, "b": 0})
assert result.is_error
assert "must not be zero" in result.content[0].text
```
- The in-memory `Client` needs no subprocess and no port. It connects with the 2026-07-28 revision.
- The `mcp` package installs `anyio`, which supplies the `anyio` marker. Do not add `pytest-asyncio`.
### Step 4: Run the tests until they pass
1. Run `uv run pytest`.
2. If a test fails, read the error. Fix the server or the test.
3. Run `uv run pytest` again.
4. Continue only when all tests pass.
### Step 5: Configure the client
For VS Code, write `.vscode/mcp.json`:
```json
{
"servers": {
"demo": {
"type": "stdio",
"command": "uv",
"args": ["--directory", "/absolute/path/to/project", "run", "server.py"]
}
}
}
```
For Claude Desktop, run `uv run mcp install server.py`.
Tell the user these commands:
- `uv run server.py` starts the stdio server. The server waits for a host on stdin and prints nothing.
- `uv run mcp dev server.py` opens the MCP Inspector. The Inspector needs Node.js.
## Gotchas
SDK v2 and the 2026-07-28 revision changed many SDK v1 patterns. Do not copy SDK v1 examples.
- SDK v2 removed `FastMCP` and `mcp.server.fastmcp`. Import the server class with `from mcp.server import MCPServer`.
- Import `Context`, `Image`, `Audio`, `Resolve`, `Elicit`, `ElicitationResult`, `AcceptedElicitation`, `Message`, `UserMessage`, and `AssistantMessage` from `mcp.server.mcpserver`.
- Give the server name as the first `MCPServer` argument. Give all other constructor arguments as keyword arguments. Their positional order changed in SDK v2.
- Set `version`. If you do not set it, the server reports an empty version.
- Give the transport options (`transport`, `host`, `port`, `json_response`, `stateless_http`, `transport_security`) to `run()`, not to `MCPServer(...)`.
- The SDK v2 types use snake_case fields, for example `read_only_hint`, `structured_content`, and `is_error`.
- Raise `ToolError` for an error that the model must read. For other exceptions, the model gets only a generic error message.
- Do not raise `MCPError` for a tool failure. The client gets a protocol error, not a tool result with `is_error`. Many hosts do not show this error to the model.
- In a stdio server, stdout is the protocol channel. Do not call `print()`. Log to stderr with the `logging` module.
- Do not use `ctx.elicit()`. It fails on a 2026-07-28 connection. For user input during a tool call, annotate a parameter with `Resolve(fn)`. Return `Elicit(message, Model)` from `fn`.
- Send list change notifications with `await ctx.notify_tools_changed()`. A 2026-07-28 connection drops `ctx.session.send_tool_list_changed()`.
- For stdio and HTTP, the lifespan runs one time, when the server starts. Each in-memory `Client(mcp)` in a test runs the lifespan again. Read its object with `ctx.request_context.lifespan_context`.
- The 2026-07-28 revision deprecates these features ([SEP-2577](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2577)). Do not add them to a new server:
- **Sampling** (`ctx.session.create_message()`): Call the LLM provider API directly.
- **Protocol logging** (`ctx.log()`, `ctx.info()`, and similar methods): Use the standard `logging` module.
- **Roots** (`ctx.session.list_roots()`): Get paths from tool parameters, resource URIs, or the server configuration.
- The 2026-07-28 revision has no SSE transport. Use Streamable HTTP.
@@ -0,0 +1,46 @@
# Streamable HTTP Servers
Use this transport only for a remote server. A local server uses stdio.
## Run the server
Replace `mcp.run()` in `server.py`:
```python
import os
if __name__ == "__main__":
mcp.run(
transport="streamable-http",
host=os.environ.get("HOST", "127.0.0.1"),
port=int(os.environ.get("PORT", "8000")),
)
```
Clients connect to `http://HOST:PORT/mcp`. For VS Code, write `.vscode/mcp.json`:
```json
{
"servers": {
"demo": {
"type": "http",
"url": "http://localhost:8000/mcp"
}
}
}
```
## Mount the server in an ASGI app
1. Use `mcp.streamable_http_app()` to mount the server in a Starlette or FastAPI app.
2. Give the transport options to `streamable_http_app()`. This method has no `port` option.
3. Make the lifespan of the host app enter `mcp.session_manager.run()`.
## Gotchas
- Requests on the 2026-07-28 revision have no session. Any replica can answer a request.
- `stateless_http=True` changes only how the server serves clients of earlier revisions.
- `json_response=True` sends one JSON body for each request. In this mode, the server cannot send progress notifications during the request.
- If you do not set `transport_security`, the SDK checks the `Host` and `Origin` headers only when the host is `127.0.0.1`, `localhost`, or `::1`. For all other hosts, for example `0.0.0.0` or a public host name, the server does no check. For these hosts, give `transport_security=TransportSecuritySettings(allowed_hosts=[...], allowed_origins=[...])` (from `mcp.server.transport_security`) to `run()` or `streamable_http_app()`.
- For browser clients, add CORS to the host app. Allow the `Mcp-*` request headers. Expose the `Mcp-Session-Id` response header.
- For more than one worker, set `request_state_security=RequestStateSecurity(keys=[...])` (from `mcp.server.mcpserver`) on `MCPServer`. Use the same keys and the same server name on all workers.