Convert OpenAPI 3.x to a Python FastMCP Server
Generate idiomatic async Python MCP servers using mcp.server.fastmcp, httpx.AsyncClient, and clean Python type annotations ready to launch via uv or pip.
MCP Tool Selection
6 / 10 Free6 endpoints parsed • 1 safety-guarded
List issues in a GitHub repository
Open a new GitHub issue
Get details for a single GitHub issue
Update issue title, state, or labels
Post a comment on an issue
Lock an issue conversation thread
1"""2Generated by Spec2MCP (https://spec2mcp.com)3Server: github-issues-rest-api v2022-11-284Tools exposed: 65"""6from __future__ import annotations78import json9import os10from typing import Any, Optional11from urllib.parse import quote1213import httpx14from mcp.server.fastmcp import FastMCP1516BASE_URL = os.environ.get("GITHUB_ISSUES_REST_API_BASE_URL", "https://api.github.com").rstrip("/")17API_TOKEN = os.environ.get("GITHUB_ISSUES_REST_API_API_TOKEN", "")18def build_auth_headers() -> dict[str, str]:19return {"Authorization": f"Bearer {API_TOKEN}"} if API_TOKEN else {}2021mcp = FastMCP("github-issues-rest-api")222324async def call_upstream(25method: str,26path: str,27params: Optional[dict[str, Any]] = None,28json_body: Optional[dict[str, Any]] = None,29) -> str:30url = f"{BASE_URL}{path}"31headers = {32"Accept": "application/json",33"User-Agent": "spec2mcp/github-issues-rest-api",34**build_auth_headers(),35}36try:37async with httpx.AsyncClient(timeout=20.0) as client:38response = await client.request(39method=method,40url=url,41headers=headers,42params=params,43json=json_body,44)45try:46body_text = json.dumps(response.json(), indent=2)47except Exception:48body_text = response.text4950if response.is_error:51return f"HTTP {response.status_code} from {method} {path}\n{body_text}"52return body_text or f"HTTP {response.status_code} (empty body)"53except httpx.HTTPError as exc:54return f"Network error calling {method} {url}: {exc}"555657@mcp.tool(name="list_repo_issues")58async def list_repo_issues(owner: str, repo: str, state: Optional[str] = None, labels: Optional[str] = None, per_page: Optional[int] = None) -> str:59"""List issues in a GitHub repository [GET /repos/{owner}/{repo}/issues]"""60query_params: dict[str, Any] = {}61if state is not None:62query_params["state"] = state63if labels is not None:64query_params["labels"] = labels65if per_page is not None:66query_params["per_page"] = per_page67return await call_upstream(method="GET", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues", params=query_params)686970@mcp.tool(name="create_repo_issue")71async def create_repo_issue(owner: str, repo: str, title: str, body: Optional[str] = None, labels: Optional[list[Any]] = None, assignees: Optional[list[Any]] = None) -> str:72"""Open a new GitHub issue [POST /repos/{owner}/{repo}/issues]"""73json_body: dict[str, Any] = {}74if title is not None:75json_body["title"] = title76if body is not None:77json_body["body"] = body78if labels is not None:79json_body["labels"] = labels80if assignees is not None:81json_body["assignees"] = assignees82return await call_upstream(method="POST", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues", json_body=json_body)838485@mcp.tool(name="get_issue")86async def get_issue(owner: str, repo: str, issue_number: int) -> str:87"""Get details for a single GitHub issue [GET /repos/{owner}/{repo}/issues/{issue_number}]"""88return await call_upstream(method="GET", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues/{quote(str(issue_number), safe="")}")899091@mcp.tool(name="update_issue")92async def update_issue(owner: str, repo: str, issue_number: int, title: Optional[str] = None, state: Optional[str] = None, labels: Optional[list[Any]] = None) -> str:93"""Update issue title, state, or labels [PATCH /repos/{owner}/{repo}/issues/{issue_number}]"""94json_body: dict[str, Any] = {}95if title is not None:96json_body["title"] = title97if state is not None:98json_body["state"] = state99if labels is not None:100json_body["labels"] = labels101return await call_upstream(method="PATCH", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues/{quote(str(issue_number), safe="")}", json_body=json_body)102103104@mcp.tool(name="create_issue_comment")105async def create_issue_comment(owner: str, repo: str, issue_number: int, body: str) -> str:106"""Post a comment on an issue [POST /repos/{owner}/{repo}/issues/{issue_number}/comments]"""107json_body: dict[str, Any] = {}108if body is not None:109json_body["body"] = body110return await call_upstream(method="POST", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues/{quote(str(issue_number), safe="")}/comments", json_body=json_body)111112113@mcp.tool(name="lock_issue_conversation")114async def lock_issue_conversation(owner: str, repo: str, issue_number: int, lock_reason: Optional[str] = None, confirm_destructive_action: bool = False) -> str:115"""Lock an issue conversation thread [PUT /repos/{owner}/{repo}/issues/{issue_number}/lock]"""116if not confirm_destructive_action:117return "Blocked by safety guard: set confirm_destructive_action=True after user confirmation."118json_body: dict[str, Any] = {}119if lock_reason is not None:120json_body["lock_reason"] = lock_reason121return await call_upstream(method="PUT", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues/{quote(str(issue_number), safe="")}/lock", json_body=json_body)122123124if __name__ == "__main__":125mcp.run(transport="stdio")126
How to export & compile your Python FastMCP OpenAPI spec
Load your OpenAPI JSON and switch the output tab to server.py + requirements.txt.
High-Signal Python FastMCP MCP Tools to Expose First
| Method | Endpoint Path | MCP Tool Name | Purpose |
|---|---|---|---|
| GET | /repos/{owner}/{repo}/issues | list_repo_issues | Async GET with Optional[str] query filters |
| POST | /repos/{owner}/{repo}/issues | create_repo_issue | Async JSON payload submission |
| PATCH | /repos/{owner}/{repo}/issues/{issue_number} | update_issue | Partial issue mutation with httpx |
Best Practices for Python FastMCP
- FastMCP automatically turns Python type hints and docstrings into JSON Schema tool definitions—keep summaries concise and action-oriented.
- Use uv run --with mcp[cli] --with httpx python server.py in mcp.json so teammates never fight local virtualenv paths.
- Prefer async def tools with httpx.AsyncClient so concurrent tool calls from multi-step agents do not block the event loop.
Common Python FastMCP MCP Gotchas
- Python reserved keywords like from, class, or type in OpenAPI query params are automatically suffixed with _param to prevent SyntaxError.
- Avoid print() statements in server.py when using transport='stdio'; write diagnostics to sys.stderr instead.
- Always set an explicit httpx timeout (Spec2MCP defaults to 20s) so hung upstream APIs don't freeze Claude or Cursor.
OpenAPI to Python FastMCP Server — Frequently Asked Questions
Does the generated server.py work with both pip and uv?
Yes. You can install dependencies from the generated requirements.txt with pip, or run zero-install using the generated uv command in the mcp.json tab.
Why choose Python FastMCP over TypeScript for an MCP server?
Choose Python FastMCP when your team already maintains Python data pipelines, FastAPI backends, or AI agent workflows using Pydantic and httpx.
How are optional query parameters handled in FastMCP?
Spec2MCP sorts required arguments first and optional parameters as Optional[T] = None, omitting None values from the outbound httpx request.
Related OpenAPI-to-MCP Converters
View all 20FastAPI HTTPBearer / OAuth2PasswordBearer / APIKeyHeader
DRF Token / JWT Bearer / API Key Header
Bearer, API Key Header/Query, or Basic via process.env
Auto-detects Swagger 2.0 securityDefinitions (apiKey, basic, oauth2)
Free locally forever. Upgrade when your team goes remote.
Compile focused local TypeScript & Python MCP servers in your browser for $0. Move to Pro Cloud or Team when you need unlimited endpoints, hosted Remote MCP URLs, OAuth2 proxying, and CI sync.
Everything solo engineers need to turn REST APIs into local stdio MCP servers with zero login.
- Local TypeScript SDK + Zod codegen
- Local Python FastMCP + httpx codegen
- Up to 10 endpoints per MCP server
- Live context-window token estimator
- Destructive action confirmation guards
- Claude Desktop, Cursor, Windsurf & Antigravity mcp.json
- 100% client-side — specs stay in browser
Compile unlimited endpoints and publish a hosted Remote MCP URL with encrypted credential vaulting.
- Unlimited OpenAPI endpoints & tool grouping
- 1-click hosted Remote MCP endpoint (Streamable HTTP)
- Encrypted OAuth2 & API-Key secret vault
- Custom tool presets & OpenAPI overlay persistence
- Response payload truncation to stop context blowups
- Priority email & Discord support
Built for engineering orgs keeping internal MCP servers automatically synced with OpenAPI repos.
- Everything in Pro Cloud
- GitHub / GitLab CI auto-sync on OpenAPI PR merges
- Per-tool invocation audit logs & latency metrics
- Per-user rate limits & destructive-tool approval policies
- Role-based access across engineering & ops teams
- Dedicated onboarding & custom auth helpers