All Integrations/SDK & Spec

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.

Environment-variable Bearer, API Key, or Basic Auth headersRecommended: Python FastMCP
Presets:
Context Footprint~861 tok
Lean context footprintOpenAPI 3.0.3

MCP Tool Selection

6 / 10 Free

6 endpoints parsed • 1 safety-guarded

GET/repos/{owner}/{repo}/issues~154t

List issues in a GitHub repository

tool:
readOnly5 params
POST/repos/{owner}/{repo}/issues~160t

Open a new GitHub issue

tool:
6 params
GET/repos/{owner}/{repo}/issues/{issue_number}~109t

Get details for a single GitHub issue

tool:
readOnly3 params
PATCH/repos/{owner}/{repo}/issues/{issue_number}~165t

Update issue title, state, or labels

tool:
6 params
POST/repos/{owner}/{repo}/issues/{issue_number}/comments~128t

Post a comment on an issue

tool:
4 params
PUT/repos/{owner}/{repo}/issues/{issue_number}/lock~145t

Lock an issue conversation thread

tool:
4 params
server.py126 lines
1"""
2Generated by Spec2MCP (https://spec2mcp.com)
3Server: github-issues-rest-api v2022-11-28
4Tools exposed: 6
5"""
6from __future__ import annotations
7
8import json
9import os
10from typing import Any, Optional
11from urllib.parse import quote
12
13import httpx
14from mcp.server.fastmcp import FastMCP
15
16BASE_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]:
19 return {"Authorization": f"Bearer {API_TOKEN}"} if API_TOKEN else {}
20
21mcp = FastMCP("github-issues-rest-api")
22
23
24async def call_upstream(
25 method: str,
26 path: str,
27 params: Optional[dict[str, Any]] = None,
28 json_body: Optional[dict[str, Any]] = None,
29) -> str:
30 url = f"{BASE_URL}{path}"
31 headers = {
32 "Accept": "application/json",
33 "User-Agent": "spec2mcp/github-issues-rest-api",
34 **build_auth_headers(),
35 }
36 try:
37 async with httpx.AsyncClient(timeout=20.0) as client:
38 response = await client.request(
39 method=method,
40 url=url,
41 headers=headers,
42 params=params,
43 json=json_body,
44 )
45 try:
46 body_text = json.dumps(response.json(), indent=2)
47 except Exception:
48 body_text = response.text
49
50 if response.is_error:
51 return f"HTTP {response.status_code} from {method} {path}\n{body_text}"
52 return body_text or f"HTTP {response.status_code} (empty body)"
53 except httpx.HTTPError as exc:
54 return f"Network error calling {method} {url}: {exc}"
55
56
57@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]"""
60 query_params: dict[str, Any] = {}
61 if state is not None:
62 query_params["state"] = state
63 if labels is not None:
64 query_params["labels"] = labels
65 if per_page is not None:
66 query_params["per_page"] = per_page
67 return await call_upstream(method="GET", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues", params=query_params)
68
69
70@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]"""
73 json_body: dict[str, Any] = {}
74 if title is not None:
75 json_body["title"] = title
76 if body is not None:
77 json_body["body"] = body
78 if labels is not None:
79 json_body["labels"] = labels
80 if assignees is not None:
81 json_body["assignees"] = assignees
82 return await call_upstream(method="POST", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues", json_body=json_body)
83
84
85@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}]"""
88 return await call_upstream(method="GET", path=f"/repos/{quote(str(owner), safe="")}/{quote(str(repo), safe="")}/issues/{quote(str(issue_number), safe="")}")
89
90
91@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}]"""
94 json_body: dict[str, Any] = {}
95 if title is not None:
96 json_body["title"] = title
97 if state is not None:
98 json_body["state"] = state
99 if labels is not None:
100 json_body["labels"] = labels
101 return 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)
102
103
104@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]"""
107 json_body: dict[str, Any] = {}
108 if body is not None:
109 json_body["body"] = body
110 return 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)
111
112
113@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]"""
116 if not confirm_destructive_action:
117 return "Blocked by safety guard: set confirm_destructive_action=True after user confirmation."
118 json_body: dict[str, Any] = {}
119 if lock_reason is not None:
120 json_body["lock_reason"] = lock_reason
121 return 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)
122
123
124if __name__ == "__main__":
125 mcp.run(transport="stdio")
126
$ pip install -r requirements.txt && GITHUB_ISSUES_REST_API_API_TOKEN=... python server.py
6 tools • ~861 tokens

How to export & compile your Python FastMCP OpenAPI spec

Load your OpenAPI JSON and switch the output tab to server.py + requirements.txt.

$uv run --with 'mcp[cli]' --with httpx python server.py

High-Signal Python FastMCP MCP Tools to Expose First

MethodEndpoint PathMCP Tool Name
GET/repos/{owner}/{repo}/issueslist_repo_issues
POST/repos/{owner}/{repo}/issuescreate_repo_issue
PATCH/repos/{owner}/{repo}/issues/{issue_number}update_issue

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 20
Transparent Developer Pricing

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.

Free Local Studio
$0/ forever

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
Use Free Studio Now
Most Popular
Pro Cloud
$29/ month

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
Team
$79/ month

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