<!DOCTYPE HTML>
<html lang="en" class="light sidebar-visible" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Setting Up Your MCP Server - SCIM Server Guide</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="../favicon.svg">
<link rel="shortcut icon" href="../favicon.png">
<link rel="stylesheet" href="../css/variables.css">
<link rel="stylesheet" href="../css/general.css">
<link rel="stylesheet" href="../css/chrome.css">
<link rel="stylesheet" href="../css/print.css" media="print">
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="../fonts/fonts.css">
<link rel="stylesheet" id="highlight-css" href="../highlight.css">
<link rel="stylesheet" id="tomorrow-night-css" href="../tomorrow-night.css">
<link rel="stylesheet" id="ayu-highlight-css" href="../ayu-highlight.css">
<script>
const path_to_root = "../";
const default_light_theme = "light";
const default_dark_theme = "navy";
window.path_to_searchindex_js = "../searchindex.js";
</script>
<script src="../toc.js"></script>
</head>
<body>
<div id="mdbook-help-container">
<div id="mdbook-help-popup">
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
<div>
<p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p>
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
<p>Press <kbd>?</kbd> to show this help</p>
<p>Press <kbd>Esc</kbd> to hide this help</p>
</div>
</div>
</div>
<div id="body-container">
<script>
try {
let theme = localStorage.getItem('mdbook-theme');
let sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<script>
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
let theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
const html = document.documentElement;
html.classList.remove('light')
html.classList.add(theme);
html.classList.add("js");
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<script>
let sidebar = null;
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
sidebar_toggle.checked = false;
}
if (sidebar === 'visible') {
sidebar_toggle.checked = true;
} else {
html.classList.remove('sidebar-visible');
}
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="../toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">SCIM Server Guide</h1>
<div class="right-buttons">
<a href="../print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<div class="search-wrapper">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
<div class="spinner-wrapper">
<i class="fa fa-spinner fa-spin"></i>
</div>
</div>
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<h1 id="setting-up-your-mcp-server"><a class="header" href="#setting-up-your-mcp-server">Setting Up Your MCP Server</a></h1>
<p>This guide shows you how to set up a working Model Context Protocol (MCP) server that exposes your SCIM operations as discoverable tools for AI agents.</p>
<h2 id="what-is-mcp-integration"><a class="header" href="#what-is-mcp-integration">What is MCP Integration?</a></h2>
<p>The MCP integration allows AI agents to interact with your SCIM server through a standardized protocol. AI agents can discover available tools (like "create user" or "search users") and execute them with proper validation and error handling.</p>
<p><strong>Key Benefits:</strong></p>
<ul>
<li><strong>AI-Friendly Interface</strong> - Structured tool discovery and execution</li>
<li><strong>Multi-Tenant Support</strong> - Isolated operations for different clients</li>
<li><strong>Schema Introspection</strong> - AI agents can understand your data model</li>
<li><strong>Error Handling</strong> - Graceful error responses with detailed information</li>
</ul>
<h2 id="quick-start"><a class="header" href="#quick-start">Quick Start</a></h2>
<h3 id="1-enable-the-mcp-feature"><a class="header" href="#1-enable-the-mcp-feature">1. Enable the MCP Feature</a></h3>
<p>Add the MCP feature to your <code>Cargo.toml</code>:</p>
<pre><code class="language-toml">[dependencies]
scim-server = { version = "0.3.11", features = ["mcp"] }
tokio = { version = "1.0", features = ["full"] }
serde_json = "1.0"
env_logger = "0.10" # For logging (recommended)
</code></pre>
<h3 id="2-basic-mcp-server-30-lines"><a class="header" href="#2-basic-mcp-server-30-lines">2. Basic MCP Server (30 lines)</a></h3>
<p>Create a minimal MCP server that exposes SCIM operations:</p>
<pre><pre class="playground"><code class="language-rust">use scim_server::{
mcp_integration::ScimMcpServer,
multi_tenant::ScimOperation,
providers::StandardResourceProvider,
resource_handlers::create_user_resource_handler,
scim_server::ScimServer,
storage::InMemoryStorage,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Initialize logging for debugging
env_logger::init();
// Create SCIM server with in-memory storage
let storage = InMemoryStorage::new();
let provider = StandardResourceProvider::new(storage);
let mut scim_server = ScimServer::new(provider)?;
// Register User resource type with full operations
let user_schema = scim_server
.get_schema_by_id("urn:ietf:params:scim:schemas:core:2.0:User")?
.clone();
let user_handler = create_user_resource_handler(user_schema);
scim_server.register_resource_type(
"User",
user_handler,
vec![
ScimOperation::Create, ScimOperation::Read,
ScimOperation::Update, ScimOperation::Delete,
ScimOperation::List, ScimOperation::Search,
],
)?;
// Create and start MCP server
let mcp_server = ScimMcpServer::new(scim_server);
println!("🚀 MCP Server starting - listening on stdio");
// This runs until EOF (Ctrl+D) or process termination
mcp_server.run_stdio().await?;
Ok(())
}</code></pre></pre>
<h3 id="3-run-your-mcp-server"><a class="header" href="#3-run-your-mcp-server">3. Run Your MCP Server</a></h3>
<pre><code class="language-bash">cargo run --features mcp
</code></pre>
<p>The server starts and listens on standard input/output for MCP protocol messages.</p>
<h2 id="testing-your-server"><a class="header" href="#testing-your-server">Testing Your Server</a></h2>
<p>You can test the server by sending JSON-RPC messages directly:</p>
<h3 id="1-initialize-connection"><a class="header" href="#1-initialize-connection">1. Initialize Connection</a></h3>
<pre><code class="language-bash">echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{}}}' | your_server
</code></pre>
<h3 id="2-discover-available-tools"><a class="header" href="#2-discover-available-tools">2. Discover Available Tools</a></h3>
<pre><code class="language-bash">echo '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | your_server
</code></pre>
<h3 id="3-create-a-user"><a class="header" href="#3-create-a-user">3. Create a User</a></h3>
<pre><code class="language-bash">echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"scim_create_user","arguments":{"user_data":{"schemas":["urn:ietf:params:scim:schemas:core:2.0:User"],"userName":"alice@example.com","active":true}}}}' | your_server
</code></pre>
<h2 id="production-ready-setup"><a class="header" href="#production-ready-setup">Production-Ready Setup</a></h2>
<p>For production use, you'll want a more comprehensive setup:</p>
<pre><pre class="playground"><code class="language-rust">use scim_server::{
mcp_integration::{McpServerInfo, ScimMcpServer},
multi_tenant::ScimOperation,
providers::StandardResourceProvider,
resource_handlers::{create_user_resource_handler, create_group_resource_handler},
scim_server::ScimServer,
storage::InMemoryStorage, // Replace with your database storage
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Production logging configuration
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.init();
// Create SCIM server (use your production storage here)
let storage = InMemoryStorage::new(); // Replace with PostgresStorage, etc.
let provider = StandardResourceProvider::new(storage);
let mut scim_server = ScimServer::new(provider)?;
// Register User resource type
let user_schema = scim_server
.get_schema_by_id("urn:ietf:params:scim:schemas:core:2.0:User")?
.clone();
let user_handler = create_user_resource_handler(user_schema);
scim_server.register_resource_type(
"User",
user_handler,
vec![
ScimOperation::Create, ScimOperation::Read, ScimOperation::Update,
ScimOperation::Delete, ScimOperation::List, ScimOperation::Search,
],
)?;
// Register Group resource type (if needed)
if let Some(group_schema) = scim_server
.get_schema_by_id("urn:ietf:params:scim:schemas:core:2.0:Group")
{
let group_handler = create_group_resource_handler(group_schema.clone());
scim_server.register_resource_type(
"Group",
group_handler,
vec![
ScimOperation::Create, ScimOperation::Read, ScimOperation::Update,
ScimOperation::Delete, ScimOperation::List, ScimOperation::Search,
],
)?;
}
// Create MCP server with custom information
let server_info = McpServerInfo {
name: "Production SCIM Server".to_string(),
version: env!("CARGO_PKG_VERSION").to_string(),
description: "Enterprise SCIM server with MCP integration".to_string(),
supported_resource_types: vec!["User".to_string(), "Group".to_string()],
};
let mcp_server = ScimMcpServer::with_info(scim_server, server_info);
// Log available tools
let tools = mcp_server.get_tools();
log::info!("🔧 Available MCP tools: {}", tools.len());
for tool in &tools {
if let Some(name) = tool.get("name").and_then(|n| n.as_str()) {
log::info!(" • {}", name);
}
}
log::info!("🚀 MCP Server ready - listening on stdio");
// Start the server
mcp_server.run_stdio().await?;
log::info!("✅ MCP Server shutdown complete");
Ok(())
}</code></pre></pre>
<h2 id="available-mcp-tools"><a class="header" href="#available-mcp-tools">Available MCP Tools</a></h2>
<p>Your MCP server exposes these tools to AI agents:</p>
<h3 id="user-management"><a class="header" href="#user-management">User Management</a></h3>
<ul>
<li><strong><code>scim_create_user</code></strong> - Create a new user</li>
<li><strong><code>scim_get_user</code></strong> - Retrieve user by ID</li>
<li><strong><code>scim_update_user</code></strong> - Update existing user</li>
<li><strong><code>scim_delete_user</code></strong> - Delete user by ID</li>
<li><strong><code>scim_list_users</code></strong> - List all users with pagination</li>
<li><strong><code>scim_search_users</code></strong> - Search users by attribute</li>
<li><strong><code>scim_user_exists</code></strong> - Check if user exists</li>
</ul>
<h3 id="system-information"><a class="header" href="#system-information">System Information</a></h3>
<ul>
<li><strong><code>scim_get_schemas</code></strong> - Get all SCIM schemas</li>
<li><strong><code>scim_server_info</code></strong> - Get server capabilities and info</li>
</ul>
<h2 id="multi-tenant-support"><a class="header" href="#multi-tenant-support">Multi-Tenant Support</a></h2>
<p>The MCP server supports multi-tenant operations out of the box:</p>
<pre><code class="language-json">{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "scim_create_user",
"arguments": {
"user_data": {
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"userName": "bob@tenant-a.com",
"active": true
},
"tenant_id": "tenant-a"
}
}
}
</code></pre>
<p>Each tenant's data is completely isolated from others.</p>
<h2 id="integration-with-ai-agents"><a class="header" href="#integration-with-ai-agents">Integration with AI Agents</a></h2>
<p>Your MCP server can be used with any MCP-compatible AI agent or framework. The AI agent will:</p>
<ol>
<li><strong>Initialize</strong> - Establish connection and capabilities</li>
<li><strong>Discover Tools</strong> - Get list of available SCIM operations</li>
<li><strong>Get Schemas</strong> - Understand your data model structure</li>
<li><strong>Execute Operations</strong> - Create, read, update, delete resources</li>
<li><strong>Handle Errors</strong> - Process validation and operation errors gracefully</li>
</ol>
<h2 id="error-handling"><a class="header" href="#error-handling">Error Handling</a></h2>
<p>The MCP server provides structured error responses for AI agents:</p>
<pre><code class="language-json">{
"jsonrpc": "2.0",
"id": 5,
"error": {
"code": -32000,
"message": "Tool execution failed: Validation error: userName is required"
}
}
</code></pre>
<h2 id="logging-and-monitoring"><a class="header" href="#logging-and-monitoring">Logging and Monitoring</a></h2>
<p>Enable comprehensive logging for production deployments:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// In your main function
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.format_timestamp_secs()
.init();
log::info!("MCP Server starting");
log::debug!("Available tools: {:?}", mcp_server.get_tools().len());
<span class="boring">}</span></code></pre></pre>
<h2 id="running-examples"><a class="header" href="#running-examples">Running Examples</a></h2>
<p>The crate includes complete working examples:</p>
<pre><code class="language-bash"># Basic MCP server
cargo run --example mcp_stdio_server --features mcp
# Comprehensive example with demos
cargo run --example mcp_server_example --features mcp
</code></pre>
<h2 id="next-steps"><a class="header" href="#next-steps">Next Steps</a></h2>
<ul>
<li><strong><a href="../storage/overview.html">Storage Backends</a></strong> - Replace InMemoryStorage with PostgreSQL or other databases</li>
<li><strong><a href="../multi-tenant/setup.html">Multi-Tenant Configuration</a></strong> - Advanced tenant management</li>
<li><strong><a href="../advanced/custom-resources.html">Custom Resource Types</a></strong> - Beyond User and Group</li>
<li><strong><a href="../deployment/mcp-production.html">Production Deployment</a></strong> - Scaling and monitoring MCP servers</li>
</ul>
<h2 id="complete-working-example"><a class="header" href="#complete-working-example">Complete Working Example</a></h2>
<p>See <a href="../../../../examples/mcp_stdio_server.rs"><code>examples/mcp_stdio_server.rs</code></a> for a complete, production-ready MCP server implementation with:</p>
<ul>
<li>Comprehensive error handling</li>
<li>Multi-tenant support</li>
<li>Full logging configuration</li>
<li>Tool discovery and execution</li>
<li>Schema introspection</li>
<li>Graceful shutdown handling</li>
</ul>
<p>The MCP integration makes your SCIM server AI-ready with minimal configuration!</p>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<a rel="prev" href="../getting-started/first-server.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../architecture.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
<a rel="prev" href="../getting-started/first-server.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../architecture.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="../elasticlunr.min.js"></script>
<script src="../mark.min.js"></script>
<script src="../searcher.js"></script>
<script src="../clipboard.min.js"></script>
<script src="../highlight.js"></script>
<script src="../book.js"></script>
</div>
</body>
</html>