Python MCP Server Generator
python-mcp-server-generator skill for programming & development
Category: development Source: githubA generator for creating MCP server implementations in Python with tool definitions, resource handlers, and async transport using FastMCP.
What Is This?
Overview
This skill generates complete MCP server implementations in Python with tool registration, resource handlers, and transport using async/await and type hints.
Who Should Use This
Perfect for Python developers building AI integrations, data science teams exposing tools to Claude, and backend engineers creating MCP services.
Why Use It?
Problems It Solves
Building MCP servers requires protocol knowledge and typed schemas. This skill generates compliant Python scaffolding with async patterns.
Core Highlights
- FastMCP Support - High-level API for rapid MCP development
- Async Native - Built on asyncio with async tool handlers
- Type Safety - Pydantic models for validation and serialization
- Dual Transport - Stdio for local and HTTP/SSE for remote
- Decorator API - Simple @tool and @resource decorators
How to Use It?
Basic Usage
Ask Claude to generate a Python MCP server, and this skill creates complete implementations.
Scenario 1: FastMCP Server
Ask Claude: "Create a Python MCP server with file search and text analysis tools"
Claude will generate:
from fastmcp import FastMCP
from pathlib import Path
import re
mcp = FastMCP("text-tools", version="1.0.0")
@mcp.tool()
async def search_files(pattern: str, directory: str = ".") -> str:
"""Search for files matching a glob pattern."""
matches = list(Path(directory).rglob(pattern))
if not matches:
return f"No files matching '{pattern}' in {directory}"
return "\n".join(str(m) for m in matches[:50])
@mcp.tool()
async def word_count(text: str) -> dict:
"""Count words, lines, and characters in text."""
words = len(text.split())
lines = text.count("\n") + 1
chars = len(text)
return {"words": words, "lines": lines, "characters": chars}
@mcp.tool()
async def find_pattern(text: str, regex: str) -> list[str]:
"""Find all regex matches in the given text."""
return re.findall(regex, text)
@mcp.resource("file:///{path}")
async def read_file(path: str) -> str:
"""Read contents of a file."""
return Path(path).read_text()
if __name__ == "__main__":
mcp.run()
Scenario 2: Database Query Server
Tell Claude: "Create an MCP server that queries PostgreSQL"
Claude will generate:
from fastmcp import FastMCP
import asyncpg
mcp = FastMCP("database-tools")
pool = None
@mcp.tool()
async def query_table(table: str, limit: int = 20, where: str = "") -> list[dict]:
"""Query a database table with optional WHERE clause."""
global pool
if pool is None:
pool = await asyncpg.create_pool(dsn="postgresql://user:pass@localhost/mydb")
sql = f"SELECT * FROM {table}"
if where:
sql += f" WHERE {where}"
sql += f" LIMIT {limit}"
async with pool.acquire() as conn:
rows = await conn.fetch(sql)
return [dict(r) for r in rows]
@mcp.tool()
async def list_tables() -> list[str]:
"""List all tables in the database."""
global pool
if pool is None:
pool = await asyncpg.create_pool(dsn="postgresql://user:pass@localhost/mydb")
async with pool.acquire() as conn:
rows = await conn.fetch(
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"
)
return [r["table_name"] for r in rows]
Real-World Examples
Data Science Toolkit
A data team exposed pandas operations via MCP. Analysts queried CSVs and generated statistics through natural language.
DevOps Automation
A platform team wrapped deployment scripts in an MCP server for conversational DevOps through Claude.
Advanced Tips
Dependency Injection
Pass connections through server context rather than globals for cleaner testing.
Error Handling
Use try/except around external calls, returning descriptive errors for useful Claude feedback.
When to Use It?
Use Cases
- Custom Tools - Build Python tools for Claude to access internal systems
- Data Analysis - Expose database queries and pandas via MCP
- DevOps - Wrap deployment scripts as MCP tools
- API Integration - Bridge REST APIs into MCP interfaces
Related Topics
When you ask Claude these questions, this skill will activate:
- "Create a Python MCP server"
- "Generate FastMCP tool handlers"
- "Build Python tools for Claude"
- "MCP server with database access in Python"
Important Notes
Requirements
- Python 3.10+ for modern async and type hint support
- fastmcp or mcp SDK package installed via pip
- asyncio event loop for async tool handlers
- Database drivers (asyncpg, aiosqlite) for data access tools
Usage Recommendations
Do:
- Use type hints - Enable automatic schema generation from function signatures
- Write docstrings - Tool descriptions are generated from docstrings
- Handle errors gracefully - Return meaningful error messages in results
- Use async throughout - Keep tool handlers non-blocking
Don't:
- Don't use sync I/O - Blocking calls freeze the entire server
- Don't skip validation - Validate inputs before database or API calls
- Don't hardcode credentials - Use environment variables for secrets
Limitations
- FastMCP API may differ from official SDK in some edge cases
- Stdio transport requires process management by the MCP client
- Async debugging is more complex than synchronous Python
- Large response payloads may hit MCP message size limits