pub mod auth;
pub mod schema;
pub mod server;
pub mod transport;
pub use auth::BearerAuth;
pub use schema::{ResourceDescription, ToolDescription};
pub use server::{AsyncToolHandler, Handler, McpServer};
pub use transport::JsonRpcDispatcher;
#[cfg(feature = "mcp-http")]
pub mod http;
#[cfg(feature = "mcp-http")]
pub use http::{HttpTransport, serve};
#[derive(Debug, Clone)]
pub enum McpNotification {
ToolsListChanged,
ResourcesListChanged,
Progress {
progress_token: String,
progress: u64,
total: Option<u64>,
},
}
impl McpServer {
pub fn format_notification(&self, notification: McpNotification) -> String {
let method = match ¬ification {
McpNotification::ToolsListChanged => "notifications/tools/list_changed",
McpNotification::ResourcesListChanged => "notifications/resources/list_changed",
McpNotification::Progress { .. } => "notifications/progress",
};
let mut params = serde_json::json!({});
if let McpNotification::Progress {
progress_token,
progress,
total,
} = ¬ification
{
params["progressToken"] = serde_json::json!(progress_token);
params["progress"] = serde_json::json!(progress);
if let Some(t) = total {
params["total"] = serde_json::json!(t);
}
}
serde_json::to_string(&serde_json::json!({
"jsonrpc": "2.0",
"method": method,
"params": params,
}))
.unwrap_or_default()
}
}