Expand description
Generic MCP server infrastructure with pluggable backends
This crate provides a complete MCP server implementation that can be extended with custom backends for different domains (home automation, databases, APIs, etc.).
§Quick Start
use mcp_server::{McpServer, McpBackend, ServerConfig};
use pulseengine_mcp_protocol::*;
use async_trait::async_trait;
#[derive(Clone)]
struct MyBackend;
#[async_trait]
impl McpBackend for MyBackend {
type Error = Box<dyn std::error::Error + Send + Sync>;
type Config = ();
async fn initialize(_: ()) -> Result<Self, Self::Error> {
Ok(MyBackend)
}
fn get_server_info(&self) -> ServerInfo {
ServerInfo {
protocol_version: ProtocolVersion::default(),
capabilities: ServerCapabilities::default(),
server_info: Implementation {
name: "My Server".to_string(),
version: "1.0.0".to_string(),
},
instructions: Some("Example server".to_string()),
}
}
async fn list_tools(&self, _: PaginatedRequestParam) -> Result<ListToolsResult, Self::Error> {
Ok(ListToolsResult { tools: vec![], next_cursor: String::new() })
}
async fn call_tool(&self, _: CallToolRequestParam) -> Result<CallToolResult, Self::Error> {
Ok(CallToolResult { content: vec![], is_error: Some(false) })
}
// Implement other required methods (simplified for example)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let backend = MyBackend::initialize(()).await?;
let config = ServerConfig::default();
let mut server = McpServer::new(backend, config).await?;
server.run().await?;
Ok(())
}
Re-exports§
pub use backend::BackendError;
pub use backend::McpBackend;
pub use context::RequestContext;
pub use handler::GenericServerHandler;
pub use handler::HandlerError;
pub use middleware::Middleware;
pub use middleware::MiddlewareStack;
pub use server::McpServer;
pub use server::ServerConfig;
pub use server::ServerError;
pub use pulseengine_mcp_auth as auth;
pub use pulseengine_mcp_monitoring as monitoring;
pub use pulseengine_mcp_protocol as protocol;
pub use pulseengine_mcp_security as security;
pub use pulseengine_mcp_transport as transport;
Modules§
- backend
- Backend trait for pluggable MCP implementations
- context
- Request context for MCP operations
- error
- Error types for the MCP protocol
- handler
- Generic request handler for MCP protocol
- middleware
- Middleware stack for request/response processing
- model
- MCP model types for protocol messages and data structures
- server
- Generic MCP server implementation
- validation
- Validation utilities for MCP protocol types
Structs§
- Annotations
- Resource annotations
- Auth
Config - Authentication configuration
- Authentication
Manager - Authentication manager
- Call
Tool Request Param - Tool call parameters
- Call
Tool Result - Tool call result
- Complete
Request Param - Completion request parameters
- Complete
Result - Complete result
- Completion
Info - Completion information
- Error
- Core MCP error type
- GetPrompt
Request Param - Get prompt parameters
- GetPrompt
Result - Get prompt result
- Implementation
- Server implementation information
- Initialize
Request Param - Initialize request parameters
- Initialize
Result - Initialize result
- List
Prompts Result - List prompts result
- List
Resource Templates Result - List resource templates result
- List
Resources Result - List resources result
- List
Tools Result - List tools result
- Logging
Capability - Metrics
Collector - Metrics collector for MCP server
- Monitoring
Config - Monitoring configuration
- Paginated
Request Param - Pagination parameters
- Prompt
- Prompt definition
- Prompt
Argument - Prompt argument definition
- Prompt
Message - Prompt message
- Prompts
Capability - Protocol
Version - Protocol version information
- RawResource
- Raw resource (for internal use)
- Read
Resource Request Param - Read resource parameters
- Read
Resource Result - Read resource result
- Request
- JSON-RPC 2.0 Request
- Resource
- Resource definition
- Resource
Contents - Resource contents wrapper
- Resource
Template - Resource template definition
- Resources
Capability - Response
- JSON-RPC 2.0 Response
- Sampling
Capability - Security
Config - Security configuration
- Security
Middleware - Security middleware for request/response processing
- Server
Capabilities - Server capabilities configuration
- Server
Capabilities Builder - Server
Info - Server information response
- SetLevel
Request Param - Set logging level parameters
- Subscribe
Request Param - Subscribe request parameters
- Text
Content - Text content struct for compatibility
- Tool
- Tool definition
- Tools
Capability - Unsubscribe
Request Param - Unsubscribe request parameters
- Validator
- Protocol validation utilities
Enums§
- Content
- Content types for tool responses
- Prompt
Message Content - Prompt message content
- Prompt
Message Role - Prompt message role
- Transport
Config - Transport configuration
Constants§
- MCP_
VERSION - Protocol version constants
- SUPPORTED_
PROTOCOL_ VERSIONS
Traits§
- Transport
- Transport layer trait
Functions§
- is_
protocol_ version_ supported - Check if a protocol version is supported
- validate_
protocol_ version - Validate MCP protocol version compatibility
Type Aliases§
- Result
- Result type alias for MCP operations