pforge-runtime
Core runtime for building high-performance Model Context Protocol (MCP) servers with pforge.
Features
- Type-Safe Handlers: Define MCP tools with full Rust type safety
- Multiple Handler Types: Native Rust, CLI wrappers, HTTP proxies, and pipelines
- State Management: Built-in persistent state with memory and Sled backends
- Middleware System: Composable middleware for logging, validation, recovery, and metrics
- Resource Management: URI-based resource handling with template matching
- Prompt Templates: Mustache-style templating for dynamic prompts
- Circuit Breaker: Fault tolerance with configurable circuit breaking
- Retry Policies: Exponential backoff with jitter
- Error Tracking: Automatic error classification and monitoring
Performance
Built on pmcp (Pragmatic AI Labs MCP SDK):
- < 1μs hot handler dispatch (O(1) lookup with FxHash)
- > 100K req/s sequential throughput
- > 500K req/s concurrent throughput (8-core)
- < 512KB memory baseline
- < 256B memory per tool
Installation
Quick Example
use *;
use ;
;
async
Handler Types
Native Handlers
Pure Rust handlers compiled into your binary:
CLI Handlers
Wrap command-line tools as MCP tools:
- type: cli
name: git_status
description: "Check git status"
command: git
args:
HTTP Handlers
Proxy HTTP endpoints as MCP tools:
- type: http
name: fetch_user
description: "Fetch user data"
endpoint: "https://api.example.com/users/{id}"
method: GET
Pipeline Handlers
Chain multiple tools together:
- type: pipeline
name: process_data
description: "Fetch and transform data"
steps:
- tool: fetch_data
- tool: transform
- tool: validate
Middleware
Build composable middleware stacks:
use ;
let mut chain = new;
// Add logging
chain.add;
// Add validation
chain.add;
// Add recovery with circuit breaker
chain.add;
// Execute through middleware
let result = chain.execute.await?;
State Management
Persistent state for your handlers:
use ;
let state = new;
// Set a value
state.set.await?;
// Get a value
if let Some = state.get.await?
// Delete a value
state.delete.await?;
Circuit Breaker
Prevent cascading failures:
use ;
let cb = new;
let result = cb.call.await?;
Retry Policies
Resilient execution with exponential backoff:
use ;
let policy = new
.with_backoff
.with_jitter;
let result = retry_with_policy.await?;
Documentation
License
MIT