oxify-mcp
Model Context Protocol (MCP) Implementation for Oxify
A comprehensive Rust implementation of the Model Context Protocol, providing both client and server capabilities with built-in servers for common operations.
Table of Contents
- Overview
- Features
- Quick Start
- Built-in Servers
- Authentication
- Load Balancing
- Custom MCP Servers
- Integration
- Examples
- Testing
- License
Overview
The Model Context Protocol (MCP) is a standardized protocol for exposing tools and capabilities to AI models. oxify-mcp provides:
- MCP Client: Connect to external MCP servers via HTTP or stdio
- MCP Server Trait: Build custom MCP servers with tool discovery and execution
- Server Registry: Manage multiple MCP servers with load balancing and failover
- Built-in Servers: Pre-built servers for filesystem, git, shell, web, database, and workflow operations
- Authentication: Support for API keys, basic auth, bearer tokens, and custom headers
- Transport Layer: HTTP and stdio transports with configurable timeouts and response limits
Features
✅ Core MCP Protocol
- Full MCP specification support (JSON-RPC over HTTP/stdio)
- Tool discovery (
list_tools) with JSON Schema validation - Tool invocation (
call_tool) with typed parameters - Comprehensive error handling
✅ Server Registry
- Manage multiple MCP servers simultaneously
- Dynamic server registration/unregistration
- Tool discovery across all registered servers
- Server statistics and health tracking
✅ Load Balancing & Failover
- Strategies: Round-robin, least connections, random, weighted
- Health Tracking: Automatic degradation detection (Healthy/Degraded/Unhealthy)
- Metrics: Request/error counts, average response times
- Failover: Automatic retry with backup servers
- Tag-based Selection: Route tools to specific server groups
✅ Authentication
- API Key: Header-based API key authentication (with optional prefix)
- Basic Auth: HTTP Basic authentication (username:password)
- Bearer Token: OAuth2/JWT bearer tokens
- OAuth2: Full OAuth2 support with client credentials, authorization code, and refresh token flows
- Automatic token refresh with expiry tracking
- PKCE support for authorization code flow
- Scope management
- Custom Headers: Arbitrary custom authentication headers
- Multi-Server: Different credentials per server via
CredentialStore
✅ Built-in Servers
- Filesystem: Read, write, list, delete, check existence (with sandboxing)
- Shell: Execute commands, find binaries (with command whitelisting)
- Git: Status, clone, commit, push, pull, log, diff, branch operations
- Web: HTTP GET/POST, web scraping
- Database: PostgreSQL queries, commands, transactions (requires
databasefeature) - Workflow: Expose oxify workflows as MCP tools
✅ Security
- Path traversal prevention (filesystem operations)
- Command whitelisting (shell operations)
- Repository path validation (git operations)
- Read-only mode (database operations)
- Response size limits (10MB default)
- Request/response validation
Quick Start
Add oxify-mcp to your Cargo.toml:
[]
= { = "../oxify-mcp" }
# For database support:
= { = "../oxify-mcp", = ["database"] }
Basic Usage
use ;
use ;
use json;
async
Connecting to External MCP Server
use ;
use json;
async
Built-in Servers
FilesystemServer
Provides secure filesystem operations with sandboxing.
use FilesystemServer;
use json;
// Create server with base directory
let server = new?;
// Read file
let content = server.call_tool.await?;
// Write file
server.call_tool.await?;
// List directory
let files = server.call_tool.await?;
Tools: fs_read, fs_write, fs_list, fs_delete, fs_exists
Security: Prevents path traversal attacks, enforces base directory sandboxing.
ShellServer
Execute shell commands with whitelisting.
use ShellServer;
use json;
// Create server with allowed commands
let server = new;
// Execute command
let result = server.call_tool.await?;
// Find command
let path = server.call_tool.await?;
Tools: shell_exec, shell_which
Security: Only whitelisted commands can be executed.
GitServer
Git repository operations.
use GitServer;
use json;
let server = new;
// Get status
let status = server.call_tool.await?;
// Commit changes
server.call_tool.await?;
Tools: git_status, git_clone, git_add, git_commit, git_push, git_pull, git_log, git_diff, git_branch, git_checkout
WebServer
HTTP operations and web scraping.
use WebServer;
use json;
let server = new;
// HTTP GET
let html = server.call_tool.await?;
// HTTP POST
server.call_tool.await?;
// Web scraping
let text = server.call_tool.await?;
Tools: http_get, http_post, web_scrape, web_screenshot (not yet implemented)
DatabaseServer
PostgreSQL database operations (requires database feature).
use ;
use json;
// Create server
let config = postgres
.with_max_connections
.with_read_only;
let server = new.await?;
// Query
let results = server.call_tool.await?;
// Execute
server.call_tool.await?;
// Transaction
server.call_tool.await?;
// Describe table
let schema = server.call_tool.await?;
Tools: db_query, db_execute, db_transaction, db_describe, db_tables
Features:
- Connection pooling
- Read-only mode
- Transaction support with rollback
- Type conversion (bool, int, float, text, uuid, timestamp, json, bytea)
- Result truncation (configurable max rows)
WorkflowServer
Expose oxify workflows as MCP tools.
use WorkflowServer;
use Workflow;
let mut server = new;
// Register workflow
let workflow = Workflow ;
server.register_workflow?;
// Now "sentiment_analysis" tool is available
let result = server.call_tool.await?;
Features:
- Automatic tool schema generation from workflow metadata
- Template variable extraction for input parameters
- Custom input schemas and descriptions
- Pluggable executor function
Authentication
API Key Authentication
use ;
let auth = new
.with_prefix; // Optional: "Bearer my-api-key"
let transport = new?;
let client = new;
Basic Authentication
use ;
let auth = new;
let transport = new?;
Bearer Token
use ;
let auth = new;
let transport = new?;
Custom Headers
use ;
use HashMap;
let mut headers = new;
headers.insert;
headers.insert;
let auth = new;
let transport = new?;
OAuth2 Authentication
Client Credentials Flow
use ;
// Create OAuth2 auth with client credentials
let mut auth = client_credentials.with_scopes;
// Request initial token
auth.request_token.await?;
// Create authenticated transport
let config = AuthConfig ;
let transport = new?;
Authorization Code Flow (with PKCE)
use OAuth2Auth;
let mut auth = authorization_code
.with_pkce // PKCE support
.with_scopes;
// Exchange authorization code for tokens
auth.request_token.await?;
Token Refresh
use OAuth2Auth;
// Create OAuth2 auth with existing tokens
let mut auth = with_tokens;
// Automatically refresh if expired
let refreshed = auth.refresh_if_needed.await?;
if refreshed
// Check if token is expired
if auth.is_token_expired
Multi-Server Credentials
use ;
let mut store = new;
// Different credentials for each server
store.set_credentials;
store.set_credentials;
// Use when registering servers
if let Some = store.get_credentials
Load Balancing
Round-Robin
use ;
let mut registry = new;
registry.set_load_balancing_strategy;
// Register multiple servers for the same tool
// Calls will be distributed evenly
Least Connections
registry.set_load_balancing_strategy;
// Routes to server with fewest active connections
Weighted Distribution
use ;
registry.set_load_balancing_strategy;
// Set server weights (higher = more traffic)
registry.set_server_weight; // 75% of traffic
registry.set_server_weight; // 25% of traffic
Failover
// Automatic failover to backup servers
let result = registry.invoke_tool_with_failover.await?;
// If first server fails, tries next available server
Tag-based Selection
// Tag servers by capability
registry.tag_server;
registry.tag_server;
// Route to servers with specific tags
let servers = registry.get_servers_by_tag;
Custom MCP Servers
Implement the McpServer trait to create custom servers:
use ;
use async_trait;
use ;
Best Practices
- Tool Naming: Use lowercase with underscores (e.g.,
my_tool,process_data) - JSON Schema: Provide detailed schemas with descriptions
- Error Handling: Return appropriate
McpErrorvariants - Validation: Validate all inputs before processing
- Security: Implement appropriate access controls and sandboxing
- Performance: Use async operations for I/O-bound tasks
- Testing: Write comprehensive unit tests for each tool
Integration
With oxify-engine
The MCP client is integrated with oxify-engine for workflow execution:
use MCP_EXECUTOR;
use json;
// MCP tools are automatically available in workflows
// Priority: Local servers → HTTP MCP → HTTP fallback
// Register local server
MCP_EXECUTOR.register_local_server.await?;
// Execute tool from workflow
let result = MCP_EXECUTOR.execute_tool.await?;
With oxify-api
The MCP registry is fully integrated with oxify-api, providing REST endpoints:
# List registered servers with metrics
# List available tools (optionally filtered by server_id)
{
}
# Invoke a tool
{
}
# Get registry statistics
Examples
See the examples/ directory:
- basic_usage.rs: Demonstrates all built-in servers
- transport_example.rs: HTTP and stdio transports
- multi_server_orchestration.rs: Advanced registry usage with load balancing
- api_integration.rs: Integration with oxify-api MCP endpoints
Run an example:
Testing
Run all tests:
# Without database feature
# With database feature
# Show test output
# Run specific test
Test Coverage:
- ✅ 86 unit tests passing
- ✅ 0 compilation warnings
- ✅ All servers tested (Filesystem, Shell, Git, Web, Database, Workflow)
- ✅ Transport layer tested (HTTP, stdio)
- ✅ Authentication tested (API key, basic, bearer, OAuth2, custom)
- ✅ Registry tested (registration, discovery, load balancing)
- ✅ Security tested (path traversal, command whitelist, validation)
License
Apache-2.0 - See LICENSE file for details.
Contributing
Contributions are welcome! Please ensure:
- All tests pass (
cargo test) - No compilation warnings (
cargo check) - Code is formatted (
cargo fmt) - Clippy is happy (
cargo clippy)
Changelog
v0.1.0 (Initial Release)
Features:
- Full MCP protocol implementation (client, server, transport)
- 6 built-in servers (Filesystem, Shell, Git, Web, Database, Workflow)
- Authentication (API key, basic, bearer, OAuth2 with refresh, custom headers)
- OAuth2 client credentials flow
- OAuth2 authorization code flow with PKCE support
- Automatic token refresh
- Load balancing (round-robin, least connections, weighted, failover)
- Server registry with health tracking
- 86 comprehensive unit tests
- Zero compilation warnings
Security:
- Path traversal prevention
- Command whitelisting
- Response size limits
- Request/response validation
Performance:
- Async operations throughout
- Connection pooling (database)
- Configurable timeouts
- Response size limits
For more information, see the TODO.md for development roadmap and implementation details.