Skip to main content

Crate mcp_proxy

Crate mcp_proxy 

Source
Expand description

MCP Proxy – config-driven reverse proxy with auth, rate limiting, and observability.

This crate can be used as a library to embed an MCP proxy in your application, or run standalone via the mcp-proxy CLI.

§Library Usage

Build a proxy from a TOML config file:

use mcp_proxy::{Proxy, ProxyConfig};

let config = ProxyConfig::load("proxy.toml".as_ref())?;
let proxy = Proxy::from_config(config).await?;

// Embed in an existing axum app
let (router, session_handle) = proxy.into_router();

// Or serve standalone
// proxy.serve().await?;

Or build programmatically with ProxyBuilder:

use mcp_proxy::ProxyBuilder;

let proxy = ProxyBuilder::new("my-proxy")
    .listen("0.0.0.0", 9090)
    .http_backend("api", "http://api:8080")
    .stdio_backend("files", "npx", &["-y", "@mcp/server-files"])
    .build()
    .await?;

proxy.serve().await?;

§Hot Reload

Enable hot_reload = true in the config to watch the config file for new backends. The proxy will add them dynamically without restart.

Re-exports§

pub use builder::ProxyBuilder;
pub use config::ProxyConfig;

Modules§

access_log
Structured access logging middleware.
admin
Admin API for proxy introspection.
admin_tools
MCP admin tools for proxy introspection.
alias
Tool aliasing middleware for the proxy.
bearer_scope
Per-token tool scoping for bearer token authentication.
builder
Programmatic proxy builder for library users.
cache
Response caching middleware for the proxy.
canary
Canary / weighted routing middleware.
coalesce
Request coalescing middleware for the proxy.
composite
Composite tool middleware for fan-out to multiple backend tools.
config
Proxy configuration types and TOML parsing.
discovery
BM25-based tool discovery and search.
failover
Backend failover middleware.
filter
Capability filtering middleware for the proxy.
inject
Argument injection middleware for tool calls.
introspection
OAuth 2.1 token introspection and authorization server discovery.
mcp_json
Support for .mcp.json / mcp.json config format.
metrics
Prometheus metrics middleware for the proxy.
mirror
Traffic mirroring / shadowing middleware.
outlier
Passive health checks via outlier detection.
param_override
Parameter override middleware for tool customization.
rbac
Role-based access control middleware for the proxy.
reload
Hot reload: watch the config file for changes and manage backends dynamically.
retry
Retry middleware for per-backend request retries with exponential backoff.
token
Token passthrough middleware for forwarding client credentials to backends.
validation
Request validation middleware for the proxy.
ws_transport
WebSocket client transport for connecting to WebSocket-based MCP backends.

Structs§

Proxy
A fully constructed MCP proxy ready to serve or embed.