pulseengine_mcp_server/lib.rs
1//! Generic MCP server infrastructure with pluggable backends
2//!
3//! This crate provides a complete MCP server implementation that can be extended
4//! with custom backends for different domains (home automation, databases, APIs, etc.).
5//!
6//! # Quick Start
7//!
8//! ```rust,ignore
9//! use pulseengine_mcp_server::{McpServer, McpBackend, ServerConfig};
10//! use pulseengine_mcp_protocol::*;
11//! use async_trait::async_trait;
12//!
13//! #[derive(Clone)]
14//! struct MyBackend;
15//!
16//! #[async_trait]
17//! impl McpBackend for MyBackend {
18//! type Error = Box<dyn std::error::Error + Send + Sync>;
19//! type Config = ();
20//!
21//! async fn initialize(_: ()) -> std::result::Result<Self, Self::Error> {
22//! Ok(MyBackend)
23//! }
24//!
25//! fn get_server_info(&self) -> ServerInfo {
26//! ServerInfo {
27//! protocol_version: ProtocolVersion::default(),
28//! capabilities: ServerCapabilities::default(),
29//! server_info: Implementation {
30//! name: "My Server".to_string(),
31//! version: "1.0.0".to_string(),
32//! },
33//! instructions: Some("Example server".to_string()),
34//! }
35//! }
36//!
37//! async fn list_tools(&self, _: PaginatedRequestParam) -> std::result::Result<ListToolsResult, Self::Error> {
38//! Ok(ListToolsResult { tools: vec![], next_cursor: None })
39//! }
40//!
41//! async fn call_tool(&self, _: CallToolRequestParam) -> Result<CallToolResult, Self::Error> {
42//! Ok(CallToolResult { content: vec![], is_error: Some(false) })
43//! }
44//!
45//! // Implement other required methods (simplified for example)
46//! # async fn list_resources(&self, _: PaginatedRequestParam) -> Result<ListResourcesResult, Self::Error> {
47//! # Ok(ListResourcesResult { resources: vec![], next_cursor: String::new() })
48//! # }
49//! # async fn read_resource(&self, _: ReadResourceRequestParam) -> Result<ReadResourceResult, Self::Error> {
50//! # Err("No resources".into())
51//! # }
52//! # async fn list_prompts(&self, _: PaginatedRequestParam) -> Result<ListPromptsResult, Self::Error> {
53//! # Ok(ListPromptsResult { prompts: vec![], next_cursor: String::new() })
54//! # }
55//! # async fn get_prompt(&self, _: GetPromptRequestParam) -> Result<GetPromptResult, Self::Error> {
56//! # Err("No prompts".into())
57//! # }
58//! }
59//!
60//! #[tokio::main]
61//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
62//! let backend = MyBackend::initialize(()).await?;
63//! let config = ServerConfig::default();
64//! let mut server = McpServer::new(backend, config).await?;
65//! server.run().await?;
66//! Ok(())
67//! }
68//! ```
69
70pub mod backend;
71pub mod context;
72pub mod handler;
73pub mod middleware;
74pub mod server;
75
76// Re-export core types
77pub use backend::{BackendError, McpBackend};
78pub use context::RequestContext;
79pub use handler::{GenericServerHandler, HandlerError};
80pub use middleware::{Middleware, MiddlewareStack};
81pub use server::{McpServer, ServerConfig, ServerError};
82
83// Re-export from dependencies for convenience
84pub use pulseengine_mcp_auth::{self as auth, AuthConfig, AuthenticationManager};
85pub use pulseengine_mcp_monitoring::{self as monitoring, MetricsCollector, MonitoringConfig};
86pub use pulseengine_mcp_protocol::{self as protocol, *};
87pub use pulseengine_mcp_security::{self as security, SecurityConfig, SecurityMiddleware};
88pub use pulseengine_mcp_transport::{self as transport, Transport, TransportConfig};