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::InMemoryProvider};
103///
104/// # #[cfg(feature = "mcp")]
105/// #[tokio::main]
106/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
107/// let provider = InMemoryProvider::new();
108/// let scim_server = ScimServer::new(provider)?;
109/// let mcp_server = ScimMcpServer::new(scim_server);
110///
111/// // Get available tools
112/// let tools = mcp_server.get_tools();
113/// println!("Available tools: {}", tools.len());
114///
115/// // Run MCP server
116/// mcp_server.run_stdio().await.unwrap();
117/// Ok(())
118/// }
119/// ```
120pub struct ScimMcpServer<P: ResourceProvider> {
121 pub(crate) operation_handler: ScimOperationHandler<P>,
122 pub(crate) server_info: McpServerInfo,
123}
124
125impl<P: ResourceProvider + Send + Sync + 'static> ScimMcpServer<P> {
126 /// Create a new MCP server with default configuration
127 ///
128 /// # Arguments
129 /// * `scim_server` - The SCIM server instance to wrap
130 ///
131 /// # Examples
132 ///
133 /// ```rust,no_run
134 /// # #[cfg(feature = "mcp")]
135 /// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
136 /// use scim_server::{ScimServer, mcp_integration::ScimMcpServer, providers::InMemoryProvider};
137 ///
138 /// let provider = InMemoryProvider::new();
139 /// let scim_server = ScimServer::new(provider)?;
140 /// let mcp_server = ScimMcpServer::new(scim_server);
141 /// # Ok(())
142 /// # }
143 /// ```
144 pub fn new(scim_server: ScimServer<P>) -> Self {
145 let operation_handler = ScimOperationHandler::new(scim_server);
146 Self {
147 operation_handler,
148 server_info: McpServerInfo::default(),
149 }
150 }
151
152 /// Create a new MCP server with custom server information
153 ///
154 /// # Arguments
155 /// * `scim_server` - The SCIM server instance to wrap
156 /// * `server_info` - Custom server metadata for AI agent discovery
157 pub fn with_info(scim_server: ScimServer<P>, server_info: McpServerInfo) -> Self {
158 let operation_handler = ScimOperationHandler::new(scim_server);
159 Self {
160 operation_handler,
161 server_info,
162 }
163 }
164
165 /// Get server information for introspection
166 ///
167 /// Returns a reference to the server metadata that AI agents use for discovery.
168 /// This is primarily used for testing and debugging purposes.
169 pub fn server_info(&self) -> &McpServerInfo {
170 &self.server_info
171 }
172}