use std::sync::Arc;
use rmcp::{
handler::server::ServerHandler,
model::{ServerCapabilities, ServerInfo},
};
use rmcp_server_kit::{
auth::AuthConfig,
oauth::OAuthConfig,
rbac::{RbacConfig, RbacPolicy, RoleConfig},
transport::{McpServerConfig, serve},
};
#[derive(Clone)]
struct OAuthHandler;
impl ServerHandler for OAuthHandler {
fn get_info(&self) -> ServerInfo {
ServerInfo::new(ServerCapabilities::builder().enable_tools().build())
}
}
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
async fn main() -> rmcp_server_kit::Result<()> {
let _ = rmcp_server_kit::observability::init_tracing("info,rmcp_server_kit=debug");
let oauth = OAuthConfig::builder(
"https://auth.example.com/",
"rmcp-server-kit-oauth-example",
"https://auth.example.com/.well-known/jwks.json",
)
.scope("mcp:admin", "admin")
.scope("mcp:read", "viewer")
.build();
let mut auth = AuthConfig::with_keys(vec![]);
auth.oauth = Some(oauth);
let rbac = Arc::new(RbacPolicy::new(&RbacConfig::with_roles(vec![
RoleConfig::new("admin", vec!["*".into()], vec!["*".into()]),
RoleConfig::new("viewer", vec!["resource_list".into()], vec!["*".into()]),
])));
let config = McpServerConfig::new(
"127.0.0.1:8080",
"rmcp-server-kit-oauth-example",
env!("CARGO_PKG_VERSION"),
)
.with_auth(auth)
.with_rbac(rbac)
.with_public_url("http://127.0.0.1:8080");
serve(config.validate()?, || OAuthHandler).await
}