·
Last changedVersion:
This version passed the hardening gate. Hardening updated the skill content and independently checked the resulting changes. Classified findings before hardening: 4. Classified findings closed: 0. Classified findings remaining: 4. Unclassified scanner findings remaining: 0. Review findings closed: 19. Review findings remaining: 0.
2
2
2
2
Expand | File | Group | Subtype | Severity | Status |
|---|---|---|---|---|---|
SKILL.md | Malicious Code & Command Execution | — | Medium | Open | |
SKILL.md | Supply Chain & Install-Time Trust | Install-time download and execute | Medium | Open | |
SKILL.md | Tool & MCP Manipulation | MCP configuration abuse | Low | Open | |
references/streamable-http.md | Sensitive Data & Secret Exposure | Hardcoded secret | Low | Open |
4 findings
Create a Model Context Protocol (MCP) server in Python with the official MCP Python SDK v2. SDK v2 supports the MCP specification revision 2026-07-28. The same server also serves clients that use earlier revisions.
Copy this checklist and track your progress:
Run these commands:
Then delete main.py. The server goes in server.py.
--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.mcp package at version 2, stop and report this to the user. Ask the user before you install a preview build.Start from this template:
Then change the template for the request of the user:
divide with the tools that the user needs.TypedDict when the client needs machine-readable data. The SDK makes the output schema from the return type.async def for I/O. The SDK runs a sync tool on a worker thread.@mcp.tool(annotations=ToolAnnotations(read_only_hint=True)) (from mcp.types). Use destructive_hint=True for a destructive tool. These annotations are hints for the client. They are not access controls. Enforce limits in the tool code and in the credentials it uses.@mcp.resource("users://{user_id}")) and prompts (@mcp.prompt()) only when the user asks for them.Resolve(fn) whose function returns Elicit(message, Model).Use stdio by default. Read references/streamable-http.md only when the user asks for a remote server or an HTTP server.
Put test_server.py next to server.py. Write a test for each tool and for each ToolError:
Client needs no subprocess and no port. It connects with the 2026-07-28 revision.mcp package installs anyio, which supplies the anyio marker. Do not add pytest-asyncio.uv run pytest.uv run pytest again.For VS Code, write .vscode/mcp.json. If the file already exists, add the new server to the existing servers object and keep the other servers:
This file defines a command that the editor runs. Tell the user to review it before committing it. Keep secrets out of it.
For Claude Desktop, the command uv run mcp install server.py changes the Claude Desktop configuration in the home folder of the user and registers a command that runs when Claude Desktop starts. Tell the user this, and run the command only after the user confirms. Otherwise give the command to the user to run.
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 and downloads its code over the network at run time. Ask the user to confirm the Inspector source, and use a recent, reviewed version with proxy authentication on. The in-memory tests are the main way to verify the server.SDK v2 and the 2026-07-28 revision changed many SDK v1 patterns. Do not copy SDK v1 examples.
FastMCP and mcp.server.fastmcp. Import the server class with from mcp.server import MCPServer.Context, Image, Audio, Resolve, Elicit, ElicitationResult, AcceptedElicitation, Message, UserMessage, and AssistantMessage from mcp.server.mcpserver.MCPServer argument. Give all other constructor arguments as keyword arguments. Their positional order changed in SDK v2.version. If you do not set it, the server reports an empty version.transport, host, port, json_response, stateless_http, transport_security) to run(), not to MCPServer(...). For HTTP, bind to localhost by default, keep host checks on, and require authentication before exposing the server beyond localhost.read_only_hint, structured_content, and is_error.ToolError for an error that the model must read. For other exceptions, the model gets only a generic error message. Keep ToolError messages short. Leave out stack traces, queries, file paths, and secrets.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.print(). Log to stderr with the logging module.server.py, test code, and the client configuration file. Keep them out of ToolError messages and logs. Keep secret files out of version control.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.await ctx.notify_tools_changed(). A 2026-07-28 connection drops ctx.session.send_tool_list_changed().Client(mcp) in a test runs the lifespan again. Read its object with ctx.request_context.lifespan_context.mcp version is installed. Keep to the SDK v2 patterns in this skill, and ask the user before you install other packages.ctx.session.create_message()): Call the LLM provider API directly.ctx.log(), ctx.info(), and similar methods): Use the standard logging module.ctx.session.list_roots()): Get paths from tool parameters, resource URIs, or the server configuration.Get started with chainctlchainctl skill install public/github/python-mcp-server-generator:latest
Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.
skills.chainreg.biz/public/github.com/github/skills/python-mcp-server-generator:latest
MIT
HARDENING.md
LICENSE
SKILL.md
references/streamable-http.md