pulseengine_mcp_protocol/
lib.rs

1//! Core Model Context Protocol types and validation
2//!
3//! This crate provides the fundamental types, traits, and validation logic
4//! for the Model Context Protocol. It serves as the foundation for building
5//! MCP servers and clients with strong type safety and validation.
6//!
7//! # Quick Start
8//!
9//! ```rust
10//! use pulseengine_mcp_protocol::{Tool, Content, CallToolResult};
11//! use serde_json::json;
12//!
13//! // Define a tool with proper schema
14//! let tool = Tool {
15//!     name: "get_weather".to_string(),
16//!     description: "Get current weather for a location".to_string(),
17//!     input_schema: json!({
18//!         "type": "object",
19//!         "properties": {
20//!             "location": {
21//!                 "type": "string",
22//!                 "description": "City name or coordinates"
23//!             }
24//!         },
25//!         "required": ["location"]
26//!     }),
27//! };
28//!
29//! // Create a tool response
30//! let result = CallToolResult {
31//!     content: vec![Content::text("Current weather: 22°C, sunny".to_string())],
32//!     is_error: Some(false),
33//! };
34//! ```
35//!
36//! This crate is currently used in production by the Loxone MCP Server
37//! for home automation with 30+ tools.
38
39pub mod error;
40pub mod model;
41pub mod validation;
42
43#[cfg(test)]
44mod error_tests;
45#[cfg(test)]
46mod lib_tests;
47#[cfg(test)]
48mod model_tests;
49#[cfg(test)]
50mod validation_tests;
51
52// Re-export core types for easy access
53pub use error::{Error, Result};
54pub use model::*;
55pub use validation::Validator;
56
57/// Protocol version constants
58pub const MCP_VERSION: &str = "2025-03-26";
59pub const SUPPORTED_PROTOCOL_VERSIONS: &[&str] = &[MCP_VERSION];
60
61/// Check if a protocol version is supported
62pub fn is_protocol_version_supported(version: &str) -> bool {
63    SUPPORTED_PROTOCOL_VERSIONS.contains(&version)
64}
65
66/// Validate MCP protocol version compatibility
67///
68/// # Errors
69///
70/// Returns an error if the client version is not supported by this server
71pub fn validate_protocol_version(client_version: &str) -> Result<()> {
72    if is_protocol_version_supported(client_version) {
73        Ok(())
74    } else {
75        Err(Error::protocol_version_mismatch(
76            client_version,
77            MCP_VERSION,
78        ))
79    }
80}