/mcp-tools:mcp-server-scaffolding-asynciofrom mcp-tools
Use asyncio.TaskGroup() instead of asyncio.gather() for Python 3.13 MCP servers. PROACTIVELY activate for: (1) creating new MCP servers, (2) async server patterns, (3) Python 3.13 asyncio. Triggers: "mcp server", "asyncio taskgroup", "server scaffolding"
Ships in mcp-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Keywords: mcp server, asyncio, taskgroup, async server, python 3.13
File Patterns: **/server.py, **/main.py
Modes: backend_python
CRITICAL: Use asyncio.TaskGroup() instead of asyncio.gather() for Python 3.13.
# ❌ OLD PATTERN (Python 3.10)
results = await asyncio.gather(task1(), task2())
# ✅ NEW PATTERN (Python 3.13)
async with asyncio.TaskGroup() as tg:
t1 = tg.create_task(task1())
t2 = tg.create_task(task2())
results = [t1.result(), t2.result()]
from mcp.server import Server
from mcp.server.stdio import stdio_server
import asyncio
from typing import Any
# Initialize server
server = Server("my-mcp-server")
@server.list_tools()
async def list_tools() -> list[dict[str, Any]]:
"""Return available tools with schemas."""
return [
{
"name": "example_tool",
"description": "Example tool description",
"inputSchema": ExampleInput.model_json_schema()
}
]
@server.call_tool()
async def call_tool(name: str, arguments: dict) -> dict[str, Any]:
"""Execute requested tool."""
if name == "example_tool":
# Pydantic validates input
input_data = ExampleInput(**arguments)
result = await execute_example(input_data)
return result.model_dump()
raise ValueError(f"Unknown tool: {name}")
async def main():
"""Run MCP server via stdio transport."""
async with stdio_server() as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
server.create_initialization_options()
)
if __name__ == "__main__":
asyncio.run(main())
mcp_server_project/
├── pyproject.toml # Dependencies
├── server.py # Main server
├── tools/
│ ├── __init__.py
│ ├── schemas.py # Pydantic models
│ └── handlers.py # Tool implementations
├── resources/
│ ├── __init__.py
│ └── providers.py # Resource handlers
└── tests/
├── test_protocol.py
└── test_tools.py
[project]
name = "my-mcp-server"
version = "1.0.0"
requires-python = ">=3.13"
dependencies = [
"mcp>=1.0.0",
"pydantic>=2.0.0",
"aiofiles>=24.0.0"
]
[project.optional-dependencies]
dev = [
"pytest>=8.0.0",
"pytest-asyncio>=0.23.0",
"pytest-cov>=4.0.0",
"ruff>=0.1.0",
"mypy>=1.8.0"
]
class DatabaseConnection:
"""Async context manager for database."""
async def __aenter__(self):
self.conn = await connect_db()
return self.conn
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.conn.close()
# Usage in tool
async def execute_query_tool(query: str):
async with DatabaseConnection() as db:
result = await db.execute(query)
return result
from mcp.types import McpError
@server.call_tool()
async def call_tool(name: str, arguments: dict):
try:
if name == "risky_operation":
input_data = RiskyInput(**arguments)
return await risky_operation(input_data)
except ValidationError as e:
# Pydantic validation failed
raise McpError(
code=-32602, # Invalid params
message=f"Validation error: {str(e)}"
)
except Exception as e:
# Unexpected error
raise McpError(
code=-32603, # Internal error
message=f"Tool execution failed: {str(e)}"
)
import aiofiles
@server.read_resource()
async def read_resource(uri: str) -> dict[str, Any]:
"""Read resource content asynchronously."""
if not uri.startswith("file:///"):
raise ValueError(f"Unsupported URI: {uri}")
path = uri.removeprefix("file://")
# Async file reading
async with aiofiles.open(path, "r") as f:
content = await f.read()
return {
"contents": [
{
"uri": uri,
"text": content,
"mimeType": "text/plain"
}
]
}
Development:
python server.py
Claude Desktop Integration (claude_desktop_config.json):
{
"mcpServers": {
"my-server": {
"command": "python",
"args": ["/path/to/server.py"]
}
}
}
❌ Using asyncio.gather() (outdated for Python 3.13)
❌ Blocking I/O in async functions (use aiofiles, httpx, etc.)
❌ Missing async context manager cleanup
❌ No error handling in tool execution
Python Asyncio Docs: https://docs.python.org/3.13/library/asyncio.html MCP Python SDK: https://github.com/modelcontextprotocol/python-sdk TaskGroup Guide: https://docs.python.org/3.13/library/asyncio-task.html#task-groups
What SKILL.md sets; muted values are Claude Code's defaults
6 skills in this plugin
/mcp-advanced-tool-patternsFor long-running operations, stream results incrementally with progress reporting. PROACTIVELY activate for: (1) streaming tool results, (2) tool orchestration, (3) cancellation and timeout handling. Triggers: "streaming", "tool orchestration", "progress reporting"
/mcp-protocol-compliance-testingTest JSON-RPC 2.0 protocol compliance and Pydantic schema validation for MCP servers. PROACTIVELY activate for: (1) writing MCP server tests, (2) protocol compliance validation, (3) async tool testing. Triggers: "mcp testing", "protocol compliance", "pytest asyncio"
/mcp-protocol-fundamentalsMCP is built on JSON-RPC 2.0 for bidirectional communication between Claude and servers. PROACTIVELY activate for: (1) understanding MCP protocol structure, (2) JSON-RPC message formats, (3) tool vs resource distinction. Triggers: "mcp protocol", "json-rpc", "model context protocol"
/mcp-pydantic-tool-definitionPydantic V2 models are the single source of truth for MCP tool schemas. PROACTIVELY activate for: (1) defining tool input/output schemas, (2) strict mode validation, (3) JSON schema generation. Triggers: "pydantic schema", "tool schema", "strict mode"
/mcp-resource-exposure-patternsResources provide read-only context to Claude using URI-based identification. PROACTIVELY activate for: (1) exposing data as MCP resources, (2) URI scheme design, (3) list_resources implementation. Triggers: "mcp resources", "uri patterns", "read_resource"
npx claudepluginhub agentient/vibekit --plugin mcp-toolsOther plugins' skills for the same job