scim_server/mcp_integration/mod.rs
1//! MCP (Model Context Protocol) Integration for SCIM Server
2//!
3//! This module provides comprehensive MCP integration that exposes SCIM operations
4//! as structured tools for AI agents. The integration enables AI systems to perform
5//! identity management operations through a standardized protocol interface.
6//!
7//! ## Overview
8//!
9//! The MCP integration transforms SCIM server operations into discoverable tools
10//! that AI agents can understand and execute. This enables:
11//!
12//! - **Automated Identity Management**: AI agents can provision/deprovision users
13//! - **Schema-Driven Operations**: AI agents understand SCIM data structures
14//! - **Multi-Tenant Support**: Tenant-aware operations for enterprise scenarios
15//! - **ETag Concurrency Control**: Built-in optimistic locking prevents lost updates
16//! - **Error Handling**: Structured error responses for AI decision making
17//! - **Real-time Operations**: Async operations suitable for AI workflows
18//!
19//! ## Architecture
20//!
21//! ```text
22//! ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
23//! │ AI Agent │───▶│ MCP Protocol │───▶│ SCIM Server │
24//! │ (Client) │ │ (This Module) │ │ (Operations) │
25//! └─────────────────┘ └──────────────────┘ └─────────────────┘
26//! │ │ │
27//! ▼ ▼ ▼
28//! Tool Discovery Tool Execution Resource Management
29//! Schema Learning JSON Validation Provider Integration
30//! Error Handling Tenant Context Multi-Tenant Isolation
31//! ```
32//!
33//! ## Module Structure
34//!
35//! - `core` - Core types and infrastructure (McpServerInfo, ScimToolResult, ScimMcpServer)
36//! - `protocol` - Tool discovery and dispatch functionality
37//! - `tools/` - JSON schema definitions for MCP tool discovery
38//! - `user_schemas` - User operation tool schemas
39//! - `system_schemas` - System information tool schemas
40//! - `handlers/` - Tool execution handlers
41//! - `user_crud` - User CRUD operation handlers
42//! - `user_queries` - User query and search handlers
43//! - `system_info` - System metadata handlers
44//!
45//! ## Usage Example
46//!
47//! ```rust,no_run
48//! # #[cfg(feature = "mcp")]
49//! use scim_server::{ScimServer, mcp_integration::ScimMcpServer, providers::InMemoryProvider};
50//! use serde_json::json;
51//!
52//! # #[cfg(feature = "mcp")]
53//! #[tokio::main]
54//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
55//! // Create SCIM server
56//! let provider = InMemoryProvider::new();
57//! let scim_server = ScimServer::new(provider)?;
58//!
59//! // Create MCP server
60//! let mcp_server = ScimMcpServer::new(scim_server);
61//!
62//! // Execute tool (simulating AI agent)
63//! let result = mcp_server.execute_tool(
64//! "scim_create_user",
65//! json!({
66//! "user_data": {
67//! "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
68//! "userName": "ai.agent@company.com",
69//! "active": true
70//! }
71//! })
72//! ).await;
73//!
74//! if result.success {
75//! println!("User created successfully");
76//! }
77//! Ok(())
78//! }
79//! ```
80
81#[cfg(feature = "mcp")]
82pub mod core;
83#[cfg(feature = "mcp")]
84pub mod handlers;
85#[cfg(feature = "mcp")]
86pub mod protocol;
87#[cfg(feature = "mcp")]
88pub mod tools;
89
90// Re-export core types for convenience
91#[cfg(feature = "mcp")]
92pub use core::{McpServerInfo, ScimMcpServer, ScimToolResult};
93
94// Protocol functions are accessed through ScimMcpServer methods
95// No need to re-export protocol internals