rmcp-server-kit
rmcp-server-kit is a production-grade, reusable framework for building Model Context Protocol servers in Rust. It provides a Streamable HTTP transport with TLS/mTLS, structured observability, authentication (Bearer / mTLS / OAuth 2.1 JWT), role-based access control (RBAC), per-IP rate limiting, and optional Prometheus metrics -- all wired up and ready to go.
You supply a rmcp::handler::server::ServerHandler implementation; rmcp-server-kit
handles everything else.
Quick Start
[]
= { = "1", = ["oauth"] }
= { = "1.5", = ["server", "macros"] }
= { = "1", = ["rt-multi-thread", "macros", "signal"] }
use ;
use ServerHandler;
use ;
;
async
Full API documentation and worked examples live in docs/GUIDE.md. Two runnable end-to-end examples ship in the repository:
Common configurations
API key + RBAC + per-tool argument allowlist:
use ;
use ;
use Arc;
let = generate_api_key?;
let auth = with_keys;
let viewer = new
.with_argument_allowlists;
let rbac = new;
OAuth 2.1 resource server (JWT validation against JWKS):
use AuthConfig;
use OAuthConfig;
let oauth = builder
.scope
.scope
.build;
let mut auth = with_keys;
auth.oauth = Some;
Since
1.3.0, the OAuth fetcher and the sharedOauthHttpClientenforce a strict per-hop SSRF guard and JWKS key caps. PreferOauthHttpClient::with_config(&oauth_config)over the deprecatedOauthHttpClient::new()— the new constructor wires the configured CA bundle, the SSRF guard, and the HTTPS-downgrade-rejecting redirect policy in one call. Seedocs/MIGRATION.mdandSECURITY.md.
Prometheus metrics on a separate listener:
let config = new
.with_metrics;
TLS:
let config = new
.with_tls;
Features
- Transport: Streamable HTTP (
/mcp), health (/healthz,/readyz), admin diagnostics, graceful shutdown, configurable TLS and mTLS. - Auth: API-key (Argon2 hashed), mTLS client certs, OAuth 2.1 JWT validation against JWKS (feature-gated).
- RBAC: Tool-scoped allow-lists with per-role argument constraints and
task-local
current_role()/current_identity()accessors. - Observability: Tracing, JSON logs, optional audit-file sink.
- Hardening: Per-IP rate limiting (governor), request-body caps, OWASP security headers, configurable CORS and Host allow-lists.
- Metrics: Prometheus
/metricsendpoint (opt-in viametricsfeature).
Cargo features
| Feature | Default | Description |
|---|---|---|
oauth |
No | OAuth 2.1 JWT validation via JWKS. |
metrics |
No | Prometheus metrics registry and /metrics. |
Minimum supported Rust
rmcp-server-kit targets stable Rust 1.95 or newer (tracks edition = "2024").
Repository
- GitHub (canonical): https://github.com/andrico21/rmcp-server-kit
The canonical release artifact is the rmcp-server-kit crate on crates.io.
License
Dual-licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.