Module mcp_server

Source
Expand description

Includes the runtimes and traits required to create a type-safe MCP server.

Choosing Between server_runtime and server_runtime_core ?

rust-mcp-sdk provides two type of runtimes that you can chose from:

  • server_runtime : This is recommended runtime to be used for most MCP projects, and it works with mcp_server_handler trait that offers default implementation for common messages like handling initialization or responding to ping requests, so you only need to override and customize the handler functions relevant to your specific needs.

Refer to examples/hello-world-mcp-server for an example.

  • server_runtime_core: If you need more control over MCP messages, consider using server_runtime_core that goes with works with mcp_server_handler_core trait which offers methods to manage the three MCP message types: request, notification, and error. While still providing type-safe objects in these methods, it allows you to determine how to handle each message based on its type and parameters.

Refer to examples/hello-world-mcp-server-core for an example.

Modules§

error
hyper_server
hyper_server_core
server_runtime
server_runtime_core

Structs§

HyperServer
Hyper server struct for managing the Axum-based web server
HyperServerOptions
Configuration struct for the Hyper server Used to configure the HyperServer instance.
InMemorySessionStore
In-memory session store implementation
ServerRuntime
Struct representing the runtime core of the MCP server, handling transport and client details
UuidGenerator
Struct implementing the IdGenerator trait using UUID v4

Traits§

IdGenerator
Trait for generating session identifiers
ServerHandler
Defines the ServerHandler trait for handling Model Context Protocol (MCP) operations on a server. This trait provides default implementations for request and notification handlers in an MCP server, allowing developers to override methods for custom behavior.
ServerHandlerCore
Defines the ServerHandlerCore trait for handling Model Context Protocol (MCP) server operations. Unlike ServerHandler, this trait offers no default implementations, providing full control over MCP message handling while ensures type-safe processing of the messages through three distinct handlers for requests, notifications, and errors.
SessionStore
Trait defining the interface for session storage operations

Functions§

enforce_compatible_protocol_version
Enforces protocol version compatibility on for MCP Server , allowing the client to use a lower or equal version.

Type Aliases§

TxServer