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//! - **Version-Based 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//!   - `group_schemas` - Group operation tool schemas
40//!   - `system_schemas` - System information tool schemas
41//! - `handlers/` - Tool execution handlers
42//!   - `user_crud` - User CRUD operation handlers
43//!   - `user_queries` - User query and search handlers
44//!   - `group_crud` - Group CRUD operation handlers
45//!   - `group_queries` - Group query and search handlers
46//!   - `system_info` - System metadata handlers
47//!
48//! ## Usage Example
49//!
50//! ```rust,no_run
51//! # #[cfg(feature = "mcp")]
52//! use scim_server::{ScimServer, mcp_integration::ScimMcpServer, providers::StandardResourceProvider};
53//! use scim_server::storage::InMemoryStorage;
54//! use serde_json::json;
55//!
56//! # #[cfg(feature = "mcp")]
57//! #[tokio::main]
58//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
59//!     // Create SCIM server
60//!     let storage = InMemoryStorage::new();
61//!     let provider = StandardResourceProvider::new(storage);
62//!     let scim_server = ScimServer::new(provider)?;
63//!
64//!     // Create MCP server
65//!     let mcp_server = ScimMcpServer::new(scim_server);
66//!
67//!     // Execute tool (simulating AI agent)
68//!     let result = mcp_server.execute_tool(
69//!         "scim_create_user",
70//!         json!({
71//!             "user_data": {
72//!                 "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
73//!                 "userName": "ai.agent@company.com",
74//!                 "active": true
75//!             }
76//!         })
77//!     ).await;
78//!
79//!     if result.success {
80//!         println!("User created successfully");
81//!     }
82//!     Ok(())
83//! }
84//! ```
85
86#[cfg(feature = "mcp")]
87pub mod core;
88#[cfg(feature = "mcp")]
89pub mod handlers;
90#[cfg(feature = "mcp")]
91pub mod protocol;
92#[cfg(feature = "mcp")]
93pub mod tools;
94
95#[cfg(all(feature = "mcp", test))]
96mod tests;
97
98// Re-export core types for convenience
99#[cfg(feature = "mcp")]
100pub use core::{McpServerInfo, ScimMcpServer, ScimToolResult};
101
102// Protocol functions are accessed through ScimMcpServer methods
103// No need to re-export protocol internals