Skip to content

A modern template for agentic orchestration — built for rapid iteration and scalable deployment using highly customizable, community-supported tools like MCP, LangGraph, and more.

License

Notifications You must be signed in to change notification settings

NicholasGoh/fastapi-mcp-langgraph-template

Repository files navigation

FastAPI MCP LangGraph Template

FastAPI MCP LangGraph Template

Read the docs with demo videos here.

Core Features

MCP Client is an open protocol that standardizes how apps provide context to LLMs.

  • Seamlessly integrates LLM with growing list of community integrations found here MCP Server
  • No LLM provider lock in

LangGraph for Customizable Agentic Orchestration

  • Native streaming for UX in complex Agentic Workflows
  • Native persisted chat history and state management

Technology Stack and Features

  • FastAPI for Python backend API
  • SQLModel for Python SQL database interactions (ORM + Validation).
    • Wrapper of SQLAlchemy
  • Pydantic for Data Validation and Settings Management.
  • Supabase for DB RBAC
    • PostgreSQL Relational DB
    • PGVector Vector Store
  • Nginx Reverse Proxy
  • Compose for development and production.

Planned Features

  • LangFuse for LLM Observability and LLM Metrics
  • Prometheus for scraping Metrics
  • Grafana for visualizing Metrics
  • Auth0 SaaS for JWT authentication
  • CI/CD via Github Actions
    • 💵 Deploy live demo to Fargate
    • Provision with Terraform IaC
    • Push built images to ECR and Dockerhub

Architecture

Inspector

Inspector communicates via SSE protocol with each MCP Server, while each server adheres to MCP specification.

graph LR

  subgraph localhost
    A[Inspector]
    B[DBHub Server]
    C[Youtube Server]
    D[Custom Server]
  end

  subgraph Supabase Cloud
    E[Supabase DB]
  end

  subgraph Google Cloud
    F[Youtube API]
  end

  A<-->|Protocol|B
  A<-->|Protocol|C
  A<-->|Protocol|D
  B<-->E
  C<-->F
Loading

Template Setup

The current template does not connect to all MCP servers. Additionally, the API server communicates with the database using a SQL ORM.

graph LR

  subgraph localhost
    A[API Server]
    B[DBHub Server]
    C[Youtube Server]
    D[Custom Server]
  end

  subgraph Supabase Cloud
    E[Supabase DB]
  end

  A<-->|Protocol|D
  A<-->E
Loading

Reverse Proxy

graph LR
  A[Web Browser]

  subgraph localhost
    B[Nginx Reverse Proxy]
    C[API Server]
  end

  A-->B
  B-->C
Loading

Monitoring and Observability

graph LR

  subgraph localhost
    A[API Server]
  end

  subgraph Grafana Cloud
    B[Grafana]
  end

  subgraph Langfuse Cloud
    C[Langfuse]
  end

  A -->|Metrics & Logs| B
  A -->|Traces & Events| C
Loading

Getting Started

Build community youtube MCP image with:

./community/youtube/build.sh

Tip

Instead of cloning or submoduling the repository locally, then building the image, this script builds the Docker image inside a temporary Docker-in-Docker container. This approach avoids polluting your local environment with throwaway files by cleaning up everything once the container exits.

Then build the other images with:

docker compose -f compose-dev.yaml build

Copy environment file:

cp .env.sample .env

Add your following API keys and value to the respective file: ./envs/backend.env, ./envs/youtube.env and .env.

OPENAI_API_KEY=sk-proj-...
POSTGRES_DSN=postgresql://postgres...
YOUTUBE_API_KEY=...

Set environment variables in shell: (compatible with bash and zsh)

set -a; for env_file in ./envs/*; do source $env_file; done; set +a

Start production containers:

docker compose up -d

Development

First, set environment variables as per above.

VSCode Devcontainer

Warning

Only replace the following if you plan to start debugger for FastAPI server in VSCode.

Replace ./compose-dev.yaml entrypoint to allow debugging FastAPI server:

# ...
  api:
    # ...
    # entrypoint: uv run fastapi run api/main.py --root-path=/api --reload
    # replace above with:
    entrypoint: bash -c "sleep infinity"
    # ...
code --no-sandbox .

Press F1 and type Dev Containers: Rebuild and Reopen in Container to open containerized environment with IntelliSense and Debugger for FastAPI.

Without VSCode Devcontainer

Run development environment with:

docker compose -f compose-dev.yaml up -d

Refactored Markdown Files

The following markdown files provide additional details on other features:

MCP

./docs/mcp.md

Supabase

./docs/supabase.md

Debugging

Sometimes in development, nginx reverse proxy needs to reload its config to route services properly.

docker compose -f compose-dev.yaml exec nginx sh -c "nginx -s reload"

Star History Chart

About

A modern template for agentic orchestration — built for rapid iteration and scalable deployment using highly customizable, community-supported tools like MCP, LangGraph, and more.

Topics

Resources

License

Stars

Watchers

Forks