mcpkit_server/lib.rs
1//! Server implementation for the MCP SDK.
2//!
3//! This crate provides the server-side implementation for the Model Context
4//! Protocol. It includes composable handler traits, a fluent builder API,
5//! and request routing.
6//!
7//! # Overview
8//!
9//! Building an MCP server involves:
10//!
11//! 1. Implementing the [`ServerHandler`] trait (required)
12//! 2. Implementing optional capability traits ([`ToolHandler`], [`ResourceHandler`], etc.)
13//! 3. Using [`ServerBuilder`] to create a configured server
14//! 4. Running the server with a transport
15//!
16//! # Example
17//!
18//! ```rust
19//! use mcpkit_server::{ServerBuilder, ServerHandler};
20//! use mcpkit_core::capability::{ServerInfo, ServerCapabilities};
21//!
22//! struct MyServer;
23//!
24//! impl ServerHandler for MyServer {
25//! fn server_info(&self) -> ServerInfo {
26//! ServerInfo::new("my-server", "1.0.0")
27//! }
28//!
29//! fn capabilities(&self) -> ServerCapabilities {
30//! ServerCapabilities::new().with_tools()
31//! }
32//! }
33//!
34//! let server = ServerBuilder::new(MyServer).build();
35//! assert!(server.capabilities().has_tools());
36//! ```
37//!
38//! # Handler Traits
39//!
40//! The server uses composable handler traits:
41//!
42//! - [`ServerHandler`]: Core trait required for all servers
43//! - [`ToolHandler`]: Handle tool discovery and execution
44//! - [`ResourceHandler`]: Handle resource discovery and reading
45//! - [`PromptHandler`]: Handle prompt discovery and rendering
46//! - [`TaskHandler`]: Handle long-running task operations
47//! - [`SamplingHandler`]: Handle server-initiated LLM requests
48//! - [`ElicitationHandler`]: Handle structured user input requests
49//!
50//! # Context
51//!
52//! Handlers receive a [`Context`] that provides:
53//!
54//! - Request metadata (ID, progress token)
55//! - Client and server capabilities
56//! - Cancellation checking
57//! - Progress reporting
58//! - Notification sending
59
60#![deny(missing_docs)]
61#![warn(clippy::all)]
62#![warn(clippy::pedantic)]
63#![warn(clippy::unwrap_used)]
64#![warn(clippy::must_use_candidate)]
65#![allow(clippy::module_name_repetitions)]
66
67pub mod builder;
68pub mod capability;
69pub mod context;
70pub mod handler;
71pub mod router;
72pub mod server;
73pub mod state;
74
75// Re-export commonly used types
76pub use builder::{
77 FullServer, MinimalServer, NotRegistered, Registered, Server, ServerBuilder,
78};
79pub use context::{CancellationToken, CancelledFuture, Context, ContextData, NoOpPeer, Peer};
80pub use handler::{
81 CompletionHandler, ElicitationHandler, LogLevel, LoggingHandler, PromptHandler,
82 ResourceHandler, SamplingHandler, ServerHandler, TaskHandler, ToolHandler,
83};
84pub use server::{RequestRouter, RuntimeConfig, ServerRuntime, ServerState, TransportPeer};
85
86/// Prelude module for convenient imports.
87pub mod prelude {
88 pub use crate::builder::{
89 FullServer, MinimalServer, NotRegistered, Registered, Server, ServerBuilder,
90 };
91 pub use crate::context::{CancellationToken, CancelledFuture, Context, ContextData, NoOpPeer, Peer};
92 pub use crate::handler::{
93 CompletionHandler, ElicitationHandler, LogLevel, LoggingHandler, PromptHandler,
94 ResourceHandler, SamplingHandler, ServerHandler, TaskHandler, ToolHandler,
95 };
96}