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 and optional output 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//!     output_schema: Some(json!({
28//!         "type": "object",
29//!         "properties": {
30//!             "temperature": {"type": "string"},
31//!             "condition": {"type": "string"}
32//!         }
33//!     })),
34//!     title: None,
35//!     annotations: None,
36//!     icons: None,
37//!     execution: None,
38//!     _meta: None,
39//! };
40//!
41//! // Create a tool response with optional structured content
42//! let result = CallToolResult {
43//!     content: vec![Content::text("Current weather: 22°C, sunny".to_string())],
44//!     is_error: Some(false),
45//!     structured_content: Some(json!({
46//!         "temperature": "22°C",
47//!         "condition": "sunny"
48//!     })),
49//!     _meta: None,
50//! };
51//! ```
52//!
53//! This crate is currently used in production by the Loxone MCP Server
54//! for home automation with 30+ tools.
55
56pub mod error;
57pub mod errors;
58pub mod model;
59pub mod ui;
60pub mod validation;
61
62#[cfg(test)]
63mod error_tests;
64#[cfg(test)]
65mod lib_tests;
66#[cfg(test)]
67mod model_tests;
68#[cfg(test)]
69mod ui_tests;
70#[cfg(test)]
71mod validation_tests;
72
73// Re-export core types for easy access
74pub use error::{Error, ErrorCode, McpResult, Result};
75pub use errors::{CommonError, CommonResult};
76pub use model::*;
77pub use ui::*;
78pub use validation::Validator;
79
80/// Protocol version constants
81pub const MCP_VERSION: &str = "2025-11-25";
82pub const SUPPORTED_PROTOCOL_VERSIONS: &[&str] =
83    &["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
84
85/// Check if a protocol version is supported
86pub fn is_protocol_version_supported(version: &str) -> bool {
87    SUPPORTED_PROTOCOL_VERSIONS.contains(&version)
88}
89
90/// Validate MCP protocol version compatibility
91///
92/// # Errors
93///
94/// Returns an error if the client version is not supported by this server
95pub fn validate_protocol_version(client_version: &str) -> Result<()> {
96    if is_protocol_version_supported(client_version) {
97        Ok(())
98    } else {
99        Err(Error::protocol_version_mismatch(
100            client_version,
101            MCP_VERSION,
102        ))
103    }
104}