scim_server/mcp_integration/core.rs
1//! Core MCP integration infrastructure
2//!
3//! This module contains the foundational types and constructors for MCP integration.
4//! It provides the basic building blocks that other MCP modules depend on.
5
6use crate::{ResourceProvider, operation_handler::ScimOperationHandler, scim_server::ScimServer};
7use serde_json::Value;
8
9/// Information about the MCP server for AI agent discovery
10///
11/// This structure provides metadata that AI agents use to understand
12/// the capabilities and context of the SCIM server.
13///
14/// # Examples
15///
16/// ```rust
17/// # #[cfg(feature = "mcp")]
18/// use scim_server::mcp_integration::McpServerInfo;
19///
20/// # #[cfg(feature = "mcp")]
21/// let server_info = McpServerInfo {
22/// name: "Enterprise SCIM Server".to_string(),
23/// version: "2.0.0".to_string(),
24/// description: "Production SCIM server for HR systems".to_string(),
25/// supported_resource_types: vec!["User".to_string(), "Group".to_string()],
26/// };
27/// ```
28#[derive(Debug, Clone)]
29pub struct McpServerInfo {
30 /// Human-readable name of the SCIM server
31 pub name: String,
32 /// Version string for the server implementation
33 pub version: String,
34 /// Description of the server's purpose and capabilities
35 pub description: String,
36 /// List of SCIM resource types supported (e.g., "User", "Group")
37 pub supported_resource_types: Vec<String>,
38}
39
40impl Default for McpServerInfo {
41 fn default() -> Self {
42 Self {
43 name: "SCIM Server".to_string(),
44 version: "2.0".to_string(),
45 description: "A comprehensive SCIM 2.0 server implementation".to_string(),
46 supported_resource_types: vec!["User".to_string(), "Group".to_string()],
47 }
48 }
49}
50
51/// Tool execution result for MCP clients
52///
53/// Represents the outcome of an AI agent's tool execution request.
54/// Provides structured feedback that AI agents can use for decision making.
55///
56/// # Examples
57///
58/// ```rust
59/// # #[cfg(feature = "mcp")]
60/// use scim_server::mcp_integration::ScimToolResult;
61/// use serde_json::{json, Value};
62///
63/// # #[cfg(feature = "mcp")]
64/// // Successful operation result
65/// let success_result = ScimToolResult {
66/// success: true,
67/// content: json!({"id": "123", "userName": "john.doe"}),
68/// metadata: Some(json!({"operation": "create", "resource_type": "User"}))
69/// };
70///
71/// # #[cfg(feature = "mcp")]
72/// // Error result
73/// let error_result = ScimToolResult {
74/// success: false,
75/// content: json!({"error": "User not found"}),
76/// metadata: Some(json!({"error_code": "404"}))
77/// };
78/// ```
79#[derive(Debug, Clone)]
80pub struct ScimToolResult {
81 /// Whether the tool execution was successful
82 pub success: bool,
83 /// The main result content (resource data or error information)
84 pub content: Value,
85 /// Optional metadata providing additional context about the operation
86 pub metadata: Option<Value>,
87}
88
89/// MCP server wrapper for SCIM operations
90///
91/// This is the main entry point for MCP integration. It wraps a SCIM server
92/// and exposes its operations as MCP tools that AI agents can discover and execute.
93///
94/// # Type Parameters
95///
96/// * `P` - The resource provider implementation that handles data persistence
97///
98/// # Examples
99///
100/// ```rust,no_run
101/// # #[cfg(feature = "mcp")]
102/// use scim_server::{ScimServer, mcp_integration::ScimMcpServer, providers::StandardResourceProvider};
103/// use scim_server::storage::InMemoryStorage;
104///
105/// # #[cfg(feature = "mcp")]
106/// #[tokio::main]
107/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
108/// let storage = InMemoryStorage::new();
109/// let provider = StandardResourceProvider::new(storage);
110/// let scim_server = ScimServer::new(provider)?;
111/// let mcp_server = ScimMcpServer::new(scim_server);
112///
113/// // Get available tools
114/// let tools = mcp_server.get_tools();
115/// println!("Available tools: {}", tools.len());
116///
117/// // Run MCP server
118/// mcp_server.run_stdio().await.unwrap();
119/// Ok(())
120/// }
121/// ```
122pub struct ScimMcpServer<P: ResourceProvider> {
123 pub(crate) operation_handler: ScimOperationHandler<P>,
124 pub(crate) server_info: McpServerInfo,
125}
126
127impl<P: ResourceProvider + Send + Sync + 'static> ScimMcpServer<P> {
128 /// Create a new MCP server with default configuration
129 ///
130 /// # Arguments
131 /// * `scim_server` - The SCIM server instance to wrap
132 ///
133 /// # Examples
134 ///
135 /// ```rust,no_run
136 /// # #[cfg(feature = "mcp")]
137 /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
138 /// use scim_server::{ScimServer, mcp_integration::ScimMcpServer, providers::StandardResourceProvider};
139 /// use scim_server::storage::InMemoryStorage;
140 ///
141 /// let storage = InMemoryStorage::new();
142 /// let provider = StandardResourceProvider::new(storage);
143 /// let scim_server = ScimServer::new(provider)?;
144 /// let mcp_server = ScimMcpServer::new(scim_server);
145 /// # Ok(())
146 /// # }
147 /// ```
148 pub fn new(scim_server: ScimServer<P>) -> Self {
149 let operation_handler = ScimOperationHandler::new(scim_server);
150 Self {
151 operation_handler,
152 server_info: McpServerInfo::default(),
153 }
154 }
155
156 /// Create a new MCP server with custom server information
157 ///
158 /// # Arguments
159 /// * `scim_server` - The SCIM server instance to wrap
160 /// * `server_info` - Custom server metadata for AI agent discovery
161 pub fn with_info(scim_server: ScimServer<P>, server_info: McpServerInfo) -> Self {
162 let operation_handler = ScimOperationHandler::new(scim_server);
163 Self {
164 operation_handler,
165 server_info,
166 }
167 }
168
169 /// Get server information for introspection
170 ///
171 /// Returns a reference to the server metadata that AI agents use for discovery.
172 /// This is primarily used for testing and debugging purposes.
173 pub fn server_info(&self) -> &McpServerInfo {
174 &self.server_info
175 }
176}