All Integrations/Backend Framework

Turn Your FastAPI /openapi.json into an MCP Server

Every FastAPI application already exposes a rich OpenAPI 3.1 schema at /openapi.json. Compile it directly into a standalone, decoupled FastMCP or TypeScript MCP server.

FastAPI HTTPBearer / OAuth2PasswordBearer / APIKeyHeaderRecommended: Python FastMCP
Presets:
Context Footprint~958 tok
Lean context footprintOpenAPI 3.0.3

MCP Tool Selection

10 / 10 Free

12 endpoints parsed • 1 safety-guarded

12 endpoints detected — Free tier compiles up to 10

Unlock unlimited endpoints, hosted Remote MCP URL, OAuth2 proxy & GitHub CI auto-sync with Pro Cloud.

GET/tasks~126t

List workspace tasks with status & assignee filters

tool:
readOnly3 params
POST/tasks~130t

Create a new engineering or CRM task

tool:
4 params
GET/tasks/{task_id}~67t

Get task details and subtasks

tool:
readOnly1 param
PATCH/tasks/{task_id}~135t

Update task status, priority, or assignee

tool:
4 params
DELETE/tasks/{task_id}~70t

Permanently delete a task

tool:
1 param
GET/projects~72t

List active workspace projects

tool:
readOnly1 param
POST/projects~86t

Create a new project milestone

tool:
2 params
GET/contacts~100t

Search CRM contacts by email or company

tool:
readOnly2 params
POST/contacts~103t

Add a new CRM contact

tool:
3 params
GET/deals~69t

List pipeline deals and ARR values

tool:
readOnly1 param
POST/deals/{deal_id}/notes~92t

Attach a call summary or note to a deal

tool:
2 params
DELETE/contacts/{contact_id}~75t

GDPR purge a CRM contact record

tool:
1 param
server.py167 lines
1"""
2Generated by Spec2MCP (https://spec2mcp.com)
3Server: workspace-crm-tasks-api v2.1.0
4Tools exposed: 10
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("WORKSPACE_CRM_TASKS_API_BASE_URL", "https://api.workspace-crm.example.com/v2").rstrip("/")
17API_KEY = os.environ.get("WORKSPACE_CRM_TASKS_API_API_KEY", "")
18def build_auth_headers() -> dict[str, str]:
19 return {"X-Workspace-Key": API_KEY} if API_KEY else {}
20
21mcp = FastMCP("workspace-crm-tasks-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/workspace-crm-tasks-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_tasks")
58async def list_tasks(status: Optional[str] = None, assignee_id: Optional[str] = None, limit: Optional[int] = None) -> str:
59 """List workspace tasks with status & assignee filters [GET /tasks]"""
60 query_params: dict[str, Any] = {}
61 if status is not None:
62 query_params["status"] = status
63 if assignee_id is not None:
64 query_params["assignee_id"] = assignee_id
65 if limit is not None:
66 query_params["limit"] = limit
67 return await call_upstream(method="GET", path="/tasks", params=query_params)
68
69
70@mcp.tool(name="create_task")
71async def create_task(title: str, project_id: str, priority: Optional[int] = None, due_date: Optional[str] = None) -> str:
72 """Create a new engineering or CRM task [POST /tasks]"""
73 json_body: dict[str, Any] = {}
74 if title is not None:
75 json_body["title"] = title
76 if project_id is not None:
77 json_body["project_id"] = project_id
78 if priority is not None:
79 json_body["priority"] = priority
80 if due_date is not None:
81 json_body["due_date"] = due_date
82 return await call_upstream(method="POST", path="/tasks", json_body=json_body)
83
84
85@mcp.tool(name="get_task")
86async def get_task(task_id: str) -> str:
87 """Get task details and subtasks [GET /tasks/{task_id}]"""
88 return await call_upstream(method="GET", path=f"/tasks/{quote(str(task_id), safe="")}")
89
90
91@mcp.tool(name="update_task")
92async def update_task(task_id: str, status: Optional[str] = None, priority: Optional[int] = None, assignee_id: Optional[str] = None) -> str:
93 """Update task status, priority, or assignee [PATCH /tasks/{task_id}]"""
94 json_body: dict[str, Any] = {}
95 if status is not None:
96 json_body["status"] = status
97 if priority is not None:
98 json_body["priority"] = priority
99 if assignee_id is not None:
100 json_body["assignee_id"] = assignee_id
101 return await call_upstream(method="PATCH", path=f"/tasks/{quote(str(task_id), safe="")}", json_body=json_body)
102
103
104@mcp.tool(name="delete_task")
105async def delete_task(task_id: str, confirm_destructive_action: bool = False) -> str:
106 """Permanently delete a task [DELETE /tasks/{task_id}]"""
107 if not confirm_destructive_action:
108 return "Blocked by safety guard: set confirm_destructive_action=True after user confirmation."
109 return await call_upstream(method="DELETE", path=f"/tasks/{quote(str(task_id), safe="")}")
110
111
112@mcp.tool(name="list_projects")
113async def list_projects(archived: Optional[bool] = None) -> str:
114 """List active workspace projects [GET /projects]"""
115 query_params: dict[str, Any] = {}
116 if archived is not None:
117 query_params["archived"] = archived
118 return await call_upstream(method="GET", path="/projects", params=query_params)
119
120
121@mcp.tool(name="create_project")
122async def create_project(name: str, lead_id: Optional[str] = None) -> str:
123 """Create a new project milestone [POST /projects]"""
124 json_body: dict[str, Any] = {}
125 if name is not None:
126 json_body["name"] = name
127 if lead_id is not None:
128 json_body["lead_id"] = lead_id
129 return await call_upstream(method="POST", path="/projects", json_body=json_body)
130
131
132@mcp.tool(name="search_crm_contacts")
133async def search_crm_contacts(q: Optional[str] = None, stage: Optional[str] = None) -> str:
134 """Search CRM contacts by email or company [GET /contacts]"""
135 query_params: dict[str, Any] = {}
136 if q is not None:
137 query_params["q"] = q
138 if stage is not None:
139 query_params["stage"] = stage
140 return await call_upstream(method="GET", path="/contacts", params=query_params)
141
142
143@mcp.tool(name="create_crm_contact")
144async def create_crm_contact(email: str, full_name: str, company: Optional[str] = None) -> str:
145 """Add a new CRM contact [POST /contacts]"""
146 json_body: dict[str, Any] = {}
147 if email is not None:
148 json_body["email"] = email
149 if full_name is not None:
150 json_body["full_name"] = full_name
151 if company is not None:
152 json_body["company"] = company
153 return await call_upstream(method="POST", path="/contacts", json_body=json_body)
154
155
156@mcp.tool(name="list_deals")
157async def list_deals(stage: Optional[str] = None) -> str:
158 """List pipeline deals and ARR values [GET /deals]"""
159 query_params: dict[str, Any] = {}
160 if stage is not None:
161 query_params["stage"] = stage
162 return await call_upstream(method="GET", path="/deals", params=query_params)
163
164
165if __name__ == "__main__":
166 mcp.run(transport="stdio")
167
$ pip install -r requirements.txt && WORKSPACE_CRM_TASKS_API_API_KEY=... python server.py
10 tools • ~958 tokens

How to export & compile your FastAPI OpenAPI spec

Run curl http://localhost:8000/openapi.json > openapi.json while FastAPI is running, then upload it in the studio above.

$curl -s http://127.0.0.1:8000/openapi.json -o openapi.json

High-Signal FastAPI MCP Tools to Expose First

MethodEndpoint PathMCP Tool Name
GET/api/v1/itemslist_items
POST/api/v1/itemscreate_item
DELETE/api/v1/items/{item_id}delete_item

Best Practices for FastAPI

  • Give every FastAPI route an explicit operation_id and summary= so generated MCP tool names stay clean instead of auto-suffixed.
  • FastAPI Pydantic models serialize into #/components/schemas/... references—Spec2MCP resolves all local $refs automatically.
  • Keep your MCP server decoupled from FastAPI internals so you can iterate on prompts, safety guards, and auth without redeploying your core API.

Common FastAPI MCP Gotchas

  • FastAPI defaults to OpenAPI 3.1 with anyOf: [{type: 'string'}, {type: 'null'}] for Optional fields; Spec2MCP normalizes nullable types cleanly.
  • If your FastAPI app runs locally on port 8000, set BASE_URL to http://127.0.0.1:8000 in mcp.json so Claude Desktop can reach it.
  • Exclude healthcheck routes (/health, /metrics) in the endpoint checklist so they don't waste tool tokens.

FastAPI to MCP Server — Frequently Asked Questions

Why generate a standalone MCP server instead of mounting MCP inside FastAPI?

A standalone stdio MCP server works instantly with Claude Desktop and Cursor against localhost or staging without adding MCP runtime dependencies to your production FastAPI container.

Does Spec2MCP handle FastAPI's OpenAPI 3.1 output?

Yes. Spec2MCP resolves OpenAPI 3.0 and 3.1 schemas, including component schema $ref links and array type declarations.

Should I output Python FastMCP or TypeScript for a FastAPI backend?

Both work identically over HTTP, though Python teams typically pick server.py (FastMCP + httpx) to keep a single language across the repo.

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