Back to Integrations

FastAPI Quickstart

Export your OpenAPI spec from FastAPI/Starlette and generate MCP tools. Follow the flowchart below to set up your spec and link it with LegacyAI.

01

Expose OpenAPI Specification

FastAPI automatically generates an OpenAPI spec based on your routes and Pydantic schemas. Simply run your server to expose it.

# main.py
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="FastAPI MCP Tools Service", version="1.0.0")

class ToolInput(BaseModel):
    name: str

@app.post("/items/create")
def create_item(payload: ToolInput):
    return {"message": f"Item {payload.name} created successfully!"}
python
Tip:

Your interactive docs are available at /docs and the raw OpenAPI JSON is exposed at /openapi.json.

02

Generate the MCP Server

Provide your OpenAPI JSON schema to LegacyAI to generate a typed Model Context Protocol (MCP) server.

Tip:

In the LegacyAI Dashboard, select "Create Project", select "FastAPI", and enter your endpoint: http://127.0.0.1:8000/openapi.json or upload your openapi.json file.

03

Register in Claude Desktop

Add the generated server configuration block to your local Claude Desktop config file.

{
  "mcpServers": {
    "legacy-fastapi-tools": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-openapi", "http://127.0.0.1:8000/openapi.json"]
    }
  }
}
json
Tip:

Locate your config file at %APPDATA%\Claude\claude_desktop_config.json on Windows.

04

Test in Claude Desktop

Restart your Claude Desktop app. Once reloaded, Claude will discover your new tools and you can ask it to execute them (e.g. "create a new item named Widget").

Flowchart Complete