Skip to main content

Overview

The MCP (Model Context Protocol) integration allows IronClaw to connect to external tool servers that provide additional capabilities through a standardized protocol. Supports both:
  • Local servers: Unauthenticated servers running on localhost
  • Hosted servers: OAuth-authenticated remote servers

McpClient

Client for connecting to MCP servers.

Constructor (Simple)

src/tools/mcp/client.rs
Creates a simple MCP client without authentication (for local servers).
String
required
Base URL of the MCP server (e.g., “http://localhost:8080”)
Example:

Constructor (Authenticated)

src/tools/mcp/client.rs
Creates an authenticated MCP client for hosted servers.
McpServerConfig
required
Server configuration including OAuth settings
Arc<McpSessionManager>
required
Session manager for token storage
Arc<dyn SecretsStore>
required
Secrets store for credential management
String
required
User ID for scoped authentication

create_tools

src/tools/mcp/client.rs
Lists available tools from the server and creates Tool implementations for each. Returns: Result<Vec<Arc<dyn Tool>>, McpError> - List of tools ready to register Example:

initialize

src/tools/mcp/client.rs
Initializes the connection to the MCP server. Returns: Server capabilities and metadata

list_tools

src/tools/mcp/client.rs
Lists all tools available on the server.

call_tool

src/tools/mcp/client.rs
Calls a tool on the server.
&str
required
Tool name
serde_json::Value
required
Tool arguments

McpServerConfig

Configuration for an MCP server.
src/tools/mcp/config.rs
String
required
Unique server name
String
required
Server base URL
Option<OAuthConfig>
Optional OAuth configuration for authentication
String
default:"untrusted"
Trust level: “trusted” or “untrusted”

OAuthConfig

OAuth authentication configuration.
src/tools/mcp/config.rs
String
required
OAuth client ID
String
required
Authorization endpoint URL
String
required
Token exchange endpoint URL
Vec<String>
required
OAuth scopes to request

McpServersFile

File format for MCP server configuration.
src/tools/mcp/config.rs

from_path

src/tools/mcp/config.rs
Loads MCP server configurations from a JSON file. Example mcp_servers.json:

McpTool

Tool metadata from an MCP server.
src/tools/mcp/protocol.rs
String
required
Tool name
String
required
Human-readable description
serde_json::Value
required
JSON Schema for tool parameters

McpSessionManager

Manages OAuth sessions and token refresh.

Constructor

src/tools/mcp/session.rs
Creates a new session manager.
Arc<dyn Database>
required
Database for persistent token storage

get_access_token

src/tools/mcp/session.rs
Gets a valid access token for a server, refreshing if needed.

store_tokens

src/tools/mcp/session.rs
Stores OAuth tokens after successful authentication.

Authentication Helpers

is_authenticated

src/tools/mcp/auth.rs
Checks if the user has valid authentication for a server.

refresh_access_token

src/tools/mcp/auth.rs
Refreshes an expired access token.

Example: Local Server

Example: Hosted Server with OAuth

Example: Load from Configuration File