Server implementation for the MCP SDK.
This crate provides the server-side implementation for the Model Context Protocol. It includes composable handler traits, a fluent builder API, and request routing.
Overview
Building an MCP server involves:
- Implementing the [
ServerHandler] trait (required) - Implementing optional capability traits ([
ToolHandler], [ResourceHandler], etc.) - Using [
ServerBuilder] to create a configured server - Running the server with a transport
Example
use ;
use ;
;
let server = new.build;
assert!;
Handler Traits
The server uses composable handler traits:
- [
ServerHandler]: Core trait required for all servers - [
ToolHandler]: Handle tool discovery and execution - [
ResourceHandler]: Handle resource discovery and reading - [
PromptHandler]: Handle prompt discovery and rendering - [
TaskHandler]: Handle long-running task operations - [
SamplingHandler]: Handle server-initiated LLM requests - [
ElicitationHandler]: Handle structured user input requests
Context
Handlers receive a [Context] that provides:
- Request metadata (ID, progress token)
- Client and server capabilities
- Cancellation checking
- Progress reporting
- Notification sending