mirror of
https://github.com/github/awesome-copilot.git
synced 2026-10-12 23:04:14 +00:00
docs(python-mcp): update skill, instructions, agent, and plugin for MCP Python SDK v2 🤖🤖🤖 (#4737)
* docs(python-mcp-server-generator): rewrite skill for MCP Python SDK v2 - Target MCP Python SDK v2 (MCPServer) and MCP specification 2026-07-28 - Replace FastMCP imports with `from mcp.server import MCPServer` - Rewrite the description with explicit triggers and exclusions - Add the compatibility field (uv, Python 3.10+, npx for the Inspector) - Add a five-step workflow checklist: create, write, test, validate, configure - Pin the SDK with `uv add "mcp[cli]>=2,<3"` and use a flat uv app layout - Add server and in-memory Client test templates - Add a test-fix-retest validation loop with `uv run pytest` - Add a Gotchas section for SDK v1 to v2 changes and deprecated features - Move Streamable HTTP guidance to references/streamable-http.md - Remove generic guidance that the model already knows * docs(python-mcp-server): update instructions for MCP Python SDK v2 - Target MCP Python SDK v2 (MCPServer) and MCP specification 2026-07-28 - Replace FastMCP imports with MCPServer and mcp.server.mcpserver imports - Move transport options from the constructor to run() and streamable_http_app() - Use Resolve and Elicit for user input instead of ctx.elicit() - Use ctx.notify_tools_changed() for list change notifications - Explain ToolError and MCPError behavior for tool failures - Mark sampling, protocol logging, and roots as deprecated - Add transport security, CORS, and multi-worker guidance - Add an in-memory Client test pattern - Rewrite the text in ASD-STE100 Simplified Technical English - Use single-quoted frontmatter values * docs(python-mcp-expert): update agent for MCP Python SDK v2 - Target MCP Python SDK v2 (MCPServer) and MCP specification 2026-07-28 - Replace the retired GPT-4.1 model with GPT-6 Sol - Replace FastMCP guidance with MCPServer guidance - Add guidance for transport options, Resolve and Elicit, and notify_tools_changed() - Explain ToolError and MCPError behavior for tool failures - Mark sampling, protocol logging, and roots as deprecated - Add SDK v1 to v2 migration as a supported scenario - Rewrite the text in ASD-STE100 Simplified Technical English - Use single-quoted frontmatter values * chore(python-mcp-development): update plugin metadata for MCP Python SDK v2 - Remove FastMCP from the plugin description and README - Describe the actual plugin contents: one skill and one agent - Replace the fastmcp keyword with mcp-python-sdk - Bump the plugin version to 2.0.0 - Regenerate marketplace.json and docs/README.plugins.md * fix(python-mcp-server-generator): correct transport security, lifespan, and SSE notes * fix(python-mcp-server): remove invalid structured_output advice and align with skill * fix(python-mcp-expert): add missing SDK v2 rules and remove repeated guidance * fix(python-mcp-expert): remove the retired model from frontmatter * fix(python-mcp-server-generator): state Node.js as the MCP Inspector prerequisite
This commit is contained in:
@@ -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.
|
||||
Reference in New Issue
Block a user