Build an Agent That Uses Your FastAPI Application

A clean architecture places business logic below both FastAPI routes and MCP tools.

FastAPI routes ─┐
                ├→ Services → DB / APIs
MCP tools ──────┘

Avoid internal HTTP loops

If FastAPI and MCP run in the same application, call shared Python services directly rather than making the MCP tool call your own REST endpoint over localhost.

Keep auth context explicit

Translate authenticated MCP caller context into the same domain authorization checks used by REST. Do not bypass service-layer permissions because the request came from an agent.

Use one observability story

Propagate trace context across the agent run, MCP call, service layer, and downstream APIs so production incidents can be debugged end-to-end.

Outcome: MCP becomes another interface to your application, not a second implementation of the application.