The backend consists of several main components:
- ACI: The root package for the MCP Gateway.
- Alembic: Database migrations
- CLI: Command-line interface for local development, admin operations, etc.
- Common: Shared code and utilities used across components
- Control Plane: The Service powering the core operations of the gateway
- MCP: The Service for hosting Remote MCP Servers
- Virtual MCP: The Service for hosting Virtual MCP Servers
- MCP Server: MCP servers indexed by the MCP Gateway
- Virtual MCP Server: Virtual MCP servers hosted by Virtual MCP service
- Python 3.12+
- Docker and Docker Compose
uvpackage manager
We follow strict code quality standards:
- Formatting & Linting: We use
rufffor code formatting and linting - Type Checking: We use
mypyfor static type checking - Pre-commit Hooks: Install with
pre-commit install
For VS Code or VS Code compatible IDEs, use .vscode folder for configuration.
-
Clone the repository:
git clone https://github.com/aipotheosis-labs/mcp-gateway.git cd mcp-gateway/backend -
Install dependencies and activate virtual environment:
uv sync source .venv/bin/activate -
Install
pre-commithooks:pre-commit install
-
Set up environment variables for local development:
cp .env.example .env.local
Most sensitive variables and dummy values are already defined in
.env.example, so you only need to set the following env vars in.env.local:CONTROL_PLANE_OPENAI_API_KEYMCP_OPENAI_API_KEYCLI_OPENAI_API_KEY
You might need to set AWS related variables if you want to test relevant features
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGION
-
Start services with Docker Compose:
docker compose up --build # or if you want to enable OpenTelemetry: docker compose --profile otel up --buildThis will start:
control-plane: Backend API servicemcp: MCP servicevirtual-mcp: Virtual MCP servicerunner: Container for running commands like pytest, cli commands or scriptstest-runner: Container for running pytestdb: PostgreSQL database for local developmenttest-db: PostgreSQL database for running pytest
-
Seed the database with cli commands:
-
Insert mcp servers and tools
for server_dir in ./mcp_servers/*/; do server_file="${server_dir}server.json" tools_file="${server_dir}tools.json" dotenv run python -m aci.cli mcp upsert-server --server-file "$server_file" dotenv run python -m aci.cli mcp upsert-tools --tools-file "$tools_file" done
-
Insert virtual mcp servers and tools
for server_dir in ./virtual_mcp_servers/*/; do server_file="${server_dir}server.json" tools_file="${server_dir}tools.json" dotenv run python -m aci.cli virtual-mcp upsert-server --server-file "$server_file" dotenv run python -m aci.cli virtual-mcp upsert-tools --tools-file "$tools_file" done
-
-
(Optional) Connect to the database using a GUI client (e.g.,
Beekeeper Studio)- Parameters for the db connection can be found in the
.env.localfile you created in step 4.
- Parameters for the db connection can be found in the
-
Access the API documentation at:
http://localhost:8000/v1/control-plane/docs
Run the test suite in an ephemeral container (automatically applies migrations before executing tests):
docker compose exec test-runner pytestWhen making changes to database models:
-
Check for detected changes:
docker compose exec runner alembic check -
Generate a migration:
docker compose exec runner alembic revision --autogenerate -m "description of changes"
-
Manually review and edit the generated file in
database/alembic/versions/if needed to add custom changes, e.g.,:- pgvector library imports
- Index creation/deletion
- Vector extension setup
- Other database-specific operations
-
Apply the migration (to the local db):
docker compose exec runner alembic upgrade head -
To revert the latest migration:
docker compose exec runner alembic downgrade -1
Please refer to the Contributing Guide for details on making contributions to this project.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.