mcpkit_warp/
lib.rs

1//! Warp integration for the Rust MCP SDK.
2//!
3//! This crate provides integration between the MCP SDK and the Warp web framework,
4//! making it easy to expose MCP servers over HTTP.
5//!
6//! # Features
7//!
8//! - HTTP POST endpoint for JSON-RPC messages
9//! - Server-Sent Events (SSE) streaming for notifications
10//! - Session management with automatic cleanup
11//! - Protocol version validation
12//! - CORS support via Warp filters
13//!
14//! # Quick Start
15//!
16//! ```ignore
17//! use mcpkit::prelude::*;
18//! use mcpkit_warp::McpRouter;
19//!
20//! // Your MCP server handler (use #[mcp_server] macro)
21//! #[mcp_server(name = "my-server", version = "1.0.0")]
22//! impl MyServer {
23//!     #[tool(description = "Say hello")]
24//!     async fn hello(&self, name: String) -> ToolOutput {
25//!         ToolOutput::text(format!("Hello, {name}!"))
26//!     }
27//! }
28//!
29//! #[tokio::main]
30//! async fn main() {
31//!     McpRouter::new(MyServer::new())
32//!         .serve(([0, 0, 0, 0], 3000))
33//!         .await;
34//! }
35//! ```
36
37#![deny(missing_docs)]
38
39mod error;
40/// Handler module for MCP request processing.
41pub mod handler;
42mod router;
43mod session;
44mod state;
45
46pub use error::WarpError;
47pub use handler::{handle_mcp_post, handle_sse};
48pub use router::McpRouter;
49pub use session::{SessionManager, SessionStore};
50pub use state::McpState;
51
52/// Prelude module for convenient imports.
53pub mod prelude {
54    pub use crate::error::WarpError;
55    pub use crate::handler::{handle_mcp_post, handle_sse};
56    pub use crate::router::McpRouter;
57    pub use crate::session::{SessionManager, SessionStore};
58    pub use crate::state::McpState;
59}
60
61/// Protocol versions supported by this extension.
62pub const SUPPORTED_VERSIONS: &[&str] = &["2024-11-05", "2025-03-26", "2025-06-18", "2025-11-25"];
63
64/// Check if a protocol version is supported.
65#[must_use]
66pub fn is_supported_version(version: Option<&str>) -> bool {
67    version.is_some_and(|v| SUPPORTED_VERSIONS.contains(&v))
68}