| Crates.io | kodegen_server_http |
| lib.rs | kodegen_server_http |
| version | 0.10.11 |
| created_at | 2025-11-03 10:36:03.054749+00 |
| updated_at | 2026-01-02 15:03:38.503072+00 |
| description | KODEGEN.ᴀɪ: Database query and schema exploration MCP tools for AI agents. |
| homepage | https://kodegen.ai |
| repository | https://github.com/cyrup-ai/kodegen-server-http |
| max_upload_size | |
| id | 1914424 |
| size | 4,170,575 |
HTTP/HTTPS server infrastructure for building MCP (Model Context Protocol) tools servers.
kodegen-server-http is a Rust library that provides the foundation for creating category-specific MCP servers that expose tools and prompts via HTTP. It handles all the boilerplate including:
This library is designed to be used by category servers (filesystem, browser, database, etc.) - it is not a standalone application.
🚀 Easy Integration - Single run_http_server() call handles all setup
🔒 TLS Support - Optional HTTPS with certificate-based encryption
🎯 Graceful Shutdown - Coordinated shutdown of HTTP server and managed resources
📊 Built-in Tracking - Automatic usage tracking and tool history
🔄 Stateful Sessions - Support for stateful HTTP sessions with SSE keep-alive
🌐 CORS Enabled - Permissive CORS for cross-origin requests
Create a category server in main.rs:
use kodegen_server_http::{run_http_server, RouterSet, Managers, register_tool};
use rmcp::handler::server::router::{prompt::PromptRouter, tool::ToolRouter};
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
run_http_server("my-category", |config, tracker| {
let mut tool_router = ToolRouter::new();
let mut prompt_router = PromptRouter::new();
let mut managers = Managers::new();
// Register your tools
(tool_router, prompt_router) = register_tool(
tool_router,
prompt_router,
MyTool::new(config.clone()),
);
// Register managers that need shutdown
// let my_manager = Arc::new(MyManager::new());
// managers.register(my_manager.clone());
Ok(RouterSet::new(tool_router, prompt_router, managers))
}).await
}
# Basic HTTP server
cargo run -- --http 127.0.0.1:8080
# HTTPS with TLS
cargo run -- --http 127.0.0.1:8443 \
--tls-cert /path/to/cert.pem \
--tls-key /path/to/key.pem
# Custom shutdown timeout
cargo run -- --http 127.0.0.1:8080 --shutdown-timeout-secs 60
| Option | Required | Description | Default |
|---|---|---|---|
--http <ADDRESS> |
Yes | HTTP server bind address (e.g., 127.0.0.1:8080) |
- |
--tls-cert <PATH> |
No | Path to TLS certificate file (enables HTTPS) | - |
--tls-key <PATH> |
No | Path to TLS private key file | - |
--shutdown-timeout-secs <SECONDS> |
No | Graceful shutdown timeout | 30 |
Note: Both --tls-cert and --tls-key must be provided together to enable HTTPS.
The library uses an inversion of control pattern. You provide a registration callback to run_http_server(), and the library handles:
RouterSet<S>Container holding your tool router, prompt router, and managers.
pub struct RouterSet<S> {
pub tool_router: ToolRouter<S>,
pub prompt_router: PromptRouter<S>,
pub managers: Managers,
}
HttpServerThe MCP server implementation that serves tools via Streamable HTTP. Implements the rmcp::ServerHandler trait.
ManagersContainer for components requiring graceful shutdown (browsers, tunnels, background tasks, etc.).
let my_manager = Arc::new(MyManager::new());
managers.register(my_manager.clone());
Your manager must implement the ShutdownHook trait:
impl ShutdownHook for MyManager {
fn shutdown(&self) -> Pin<Box<dyn Future<Output = Result<()>> + Send + '_>> {
Box::pin(async move {
// Cleanup logic here
Ok(())
})
}
}
Two helper functions for registering tools:
// Takes ownership, wraps in Arc
let (tool_router, prompt_router) = register_tool(
tool_router,
prompt_router,
MyTool::new(config.clone()),
);
// For pre-Arc'd tools (when you need a reference)
let my_tool = Arc::new(MyTool::new(config.clone()));
let (tool_router, prompt_router) = register_tool_arc(
tool_router,
prompt_router,
my_tool.clone(),
);
The library implements a coordinated graceful shutdown:
--shutdown-timeout-secs for all to complete# Build
cargo build
# Run tests
cargo test
# Run Clippy
cargo clippy
# Format code
cargo fmt
# Build release
cargo build --release
rust-toolchain.toml)Dual-licensed under Apache 2.0 or MIT terms. See LICENSE.md for details.
KODEGEN.ᴀɪ