MCP Forge Python - Production-Ready MCP Server with OAuth

A comprehensive MCP (Model Context Protocol) server template with OAuth support, JWT validation, and production-ready deployment options for Python developers.

View on GitHub

Configuration

This document explains how to configure the MCP-Forge-Python server for different environments and use cases.

Configuration File

The server uses a TOML configuration file (config.toml) with the following structure:

[server]
name = "MCP Forge Python"
version = "0.1.0"

[server.transport]
type = "http"

[server.transport.http]
host = "0.0.0.0"

[middleware.access_logs]
excluded_headers = ["authorization"]
redacted_headers = ["x-api-key"]

[middleware.cors]
allow_origins = ["*"]
allow_credentials = true
allow_methods = ["*"]
allow_headers = ["*"]

[middleware.jwt]
enabled = true

[middleware.jwt.validation]
strategy = "local"
forwarded_header = "X-Validated-Jwt"

[middleware.jwt.validation.local]
jwks_uri = "https://your-keycloak.example.com/realms/your-realm/protocol/openid-connect/certs"
cache_interval = 10
whitelist_domains = ["your-keycloak.example.com"]
issuer = "https://your.keycloak.example.com/"
audience = "your-client-id"

[[middleware.jwt.validation.local.allow_conditions]]
expression = 'has(payload.email) && payload.email.endswith("@yourdomain.com")'

jwt_exposed_claims = "all"

[oauth_authorization_server]
enabled = false
issuer_uri = "http://localhost:8080/auth/realms/master"

[oauth_protected_resource]
enabled = false
resource = "mcp-resource"
auth_servers = ["http://localhost:8080/auth/realms/master"]
jwks_uri = "http://localhost:8080/auth/realms/master/protocol/openid-connect/certs"
scopes_supported = ["openid", "profile", "email"]

oauth_whitelist_domains = ["localhost", "yourdomain.com"]

[auth]
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
redirect_uri = "http://localhost:8080/callback"

Server Configuration

Middleware Configuration

Access Logs

CORS

JWT Validation

JWT Claims Exposure

OAuth Configuration

The OAuth configuration implements RFC 8414 (OAuth 2.0 Authorization Server Metadata) and RFC 9728 (OAuth 2.0 Protected Resource Metadata).

Authorization Server

Protected Resource

OAuth Whitelist Domains

Auth Configuration

For OAuth authorization code flows:

Environment-Specific Configuration

Create multiple configuration files for different environments:

Load them by setting the CONFIG_FILE environment variable:

export CONFIG_FILE=config.prod.toml
uv run http

Additional Endpoints

The server provides these endpoints beyond MCP protocol:

Security Notes