allframe-mcp
MCP (Model Context Protocol) Server for AllFrame
Expose your AllFrame APIs as LLM-callable tools using the Model Context Protocol.
What is MCP?
The Model Context Protocol (MCP) is an open standard by Anthropic that enables AI assistants like Claude to safely interact with external data sources and tools. allframe-mcp automatically converts your AllFrame router handlers into MCP tools that LLMs can discover and call.
Features
- Automatic Tool Discovery - Handlers become callable tools automatically
- Type-Safe Integration - Leverages AllFrame's router architecture
- Zero Configuration - Works out of the box with any AllFrame router
- Flexible Deployment - Library-first design for maximum flexibility
- OpenAPI Integration - Converts OpenAPI schemas to JSON Schema for tools
Installation
Add to your Cargo.toml:
[]
= "0.1"
= "0.1"
= { = "1.48", = ["full"] }
Quick Start
use Router;
use McpServer;
async
Usage Patterns
Pattern 1: Standalone MCP Server
Create a dedicated MCP server binary:
// src/main.rs
use Router;
use McpServer;
use ;
async
async
Configure in Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json):
Pattern 2: Embedded in Web Application
Integrate MCP into an existing Axum web server:
use ;
use Router;
use McpServer;
use Arc;
async
async
async
Pattern 3: Serverless Deployment (AWS Lambda)
Deploy MCP server as a serverless function:
use ;
use Value;
use Router;
use McpServer;
use Arc;
async
async
API Overview
McpServer
The main MCP server struct that wraps an AllFrame Router.
McpTool
Represents a single MCP tool (derived from a router handler).
Schema Utilities
Convert between OpenAPI and JSON Schema formats:
/// Convert OpenAPI schema to JSON Schema
;
/// Validate input against a JSON schema
;
/// Coerce input to match expected type
;
/// Extract enum values from schema
;
Examples
See the examples/ directory for complete working examples:
mcp_server.rs- Basic MCP server setupmcp_stdio_server.rs- Full stdio transport implementation
Run an example:
Testing
All MCP functionality is fully tested:
# Run all tests
# Run with output
# Test specific module
Current test coverage: 33 tests passing
Architecture
Zero-Bloat Design
allframe-mcp is a separate crate from allframe-core, ensuring:
- Opt-in only: MCP code is never compiled unless you add it as a dependency
- No feature flags: Clean separation, no conditional compilation
- Zero overhead: Applications without MCP pay zero cost
How It Works
- Tool Discovery:
McpServerscans theRouterfor registered handlers - Schema Generation: Each handler becomes an
McpToolwith JSON Schema - Tool Execution: Calls are routed through the AllFrame router
- Response Mapping: Router responses are converted to MCP format
┌─────────────┐
│ LLM │ (Claude, GPT-4, etc.)
└──────┬──────┘
│ MCP Protocol
┌──────▼──────┐
│ McpServer │ (allframe-mcp)
└──────┬──────┘
│ Router API
┌──────▼──────┐
│ Router │ (allframe-core)
└──────┬──────┘
│
┌──────▼──────┐
│ Handlers │ (Your business logic)
└─────────────┘
Deployment Options
Docker
FROM rust:1.86 as builder
WORKDIR /app
COPY . .
RUN cargo build --release --bin my-mcp-server
FROM debian:bookworm-slim
COPY --from=builder /app/target/release/my-mcp-server /usr/local/bin/
CMD ["my-mcp-server"]
Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcp-server
spec:
replicas: 3
template:
spec:
containers:
- name: mcp-server
image: my-mcp-server:latest
ports:
- containerPort: 3000
Fly.io
# fly.toml
= "my-mcp-server"
[]
= "paketobuildpacks/builder:base"
[[]]
= 3000
= "tcp"
Performance
MCP overhead is minimal:
- Tool Discovery: O(n) where n = number of handlers (one-time on startup)
- Tool Execution: Direct router call (no additional overhead)
- Memory: ~100 bytes per tool for metadata
Benchmark results (on MacBook Pro M1):
tool_discovery ... 1.2µs per handler
tool_call ... 45µs per call (includes router overhead)
list_tools ... 3.5µs (cached)
Roadmap
Phase 1 (Current)
- ✅ Basic MCP server implementation
- ✅ Tool discovery from router
- ✅ Simple tool execution
- ✅ Schema conversion utilities
Phase 2 (Planned)
- Advanced argument mapping (nested objects, arrays)
- Tool metadata from handler annotations
- Streaming responses for long-running operations
- Rate limiting and authentication
Phase 3 (Future)
- MCP resources (file/data access)
- MCP prompts (templated interactions)
- Tool composition (multi-step workflows)
- OpenAPI schema auto-import
Contributing
Contributions welcome! Please read CONTRIBUTING.md first.
Key areas for contribution:
- Additional transport implementations (HTTP, WebSocket)
- More comprehensive schema validation
- Performance optimizations
- Documentation improvements
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Resources
- Documentation: https://docs.rs/allframe-mcp
- AllFrame Core: https://docs.rs/allframe-core
- MCP Specification: https://modelcontextprotocol.io
- Examples: ./examples/
- Issues: https://github.com/all-source-os/all-frame/issues
Acknowledgments
Built on top of:
- AllFrame - Protocol-agnostic Rust web framework
- Model Context Protocol - By Anthropic
- Tokio - Async runtime for Rust
Made with ❤️ by the AllFrame team