json-rpc protocol request routing and dispatch
The MCP::Server class implements a JSON-RPC 2.0 request handler that routes incoming protocol method calls to appropriate handler methods based on the MCP specification. It parses JSON-RPC requests, validates method names against the protocol spec, dispatches to corresponding handler implementations, and returns properly formatted JSON-RPC responses or error objects. The server maintains an internal method registry that maps protocol methods (e.g., 'tools/list', 'resources/read') to handler implementations.
Unique: Implements MCP specification routing natively in Ruby with automatic method dispatch based on protocol-defined method names, eliminating the need for manual switch statements or route definitions for each protocol method
vs alternatives: Provides tighter MCP spec compliance than generic JSON-RPC libraries because it bakes in knowledge of the specific protocol methods and their expected signatures
tool registration and schema-based invocation
The SDK provides a ModelContextProtocol::Tool class that allows developers to register callable functions with JSON Schema input definitions. Tools are registered on the server instance, and when an AI client requests tool execution, the server validates the input against the schema, invokes the tool's implementation block, and returns the result. The tool registry maintains metadata (name, description, input schema) that is exposed via the 'tools/list' protocol method, enabling AI clients to discover and understand available tools.
Unique: Combines tool registration with automatic JSON Schema validation and discovery, allowing AI clients to introspect available tools and their input requirements before invocation, with the server enforcing schema compliance at execution time
vs alternatives: More structured than generic function-calling approaches because it requires explicit schema definition upfront, enabling better AI model understanding and safer execution with guaranteed input validation
prompt template definition and argument substitution
The ModelContextProtocol::Prompt class enables developers to define reusable prompt templates with named arguments and structured messaging. Prompts are registered on the server and exposed via the 'prompts/list' protocol method. When an AI client requests a prompt, the server substitutes provided arguments into the template and returns the rendered prompt with proper message structure. The prompt system supports multiple message types and allows templates to define which arguments are required vs optional.
Unique: Implements prompts as first-class protocol resources with automatic discovery and argument binding, allowing AI clients to request and customize prompts at runtime rather than embedding them in client code
vs alternatives: Decouples prompt management from AI client code by centralizing templates on the server, enabling prompt updates without client redeployment and allowing multiple clients to share consistent prompt patterns
resource uri-based content access and streaming
The ModelContextProtocol::Resource class provides a mechanism to register and serve content via URI-based access. Resources are registered with a URI pattern and implementation, and when an AI client requests a resource via the 'resources/read' protocol method, the server retrieves and returns the content. The resource system supports multiple content types (text, images, binary data) and can stream large resources. Resources are discoverable via the 'resources/list' protocol method, exposing their URI patterns and MIME types to clients.
Unique: Implements resources as discoverable, URI-addressed content endpoints that AI clients can query, combining a registry pattern with content streaming to provide flexible access to diverse data types without requiring clients to know implementation details
vs alternatives: More structured than ad-hoc file serving because it provides protocol-level discovery and standardized access patterns, allowing AI clients to understand available resources and their content types before making requests
multi-transport protocol support (http and stdio)
The transport layer abstracts communication mechanisms, supporting both HTTP and stdio transports. The SDK provides transport implementations that handle the protocol-specific details of receiving JSON-RPC requests and sending responses. HTTP transport integrates with web frameworks, while stdio transport enables command-line tool integration. The server is transport-agnostic — the same server implementation works with any transport backend. Transport selection is configured at initialization time.
Unique: Provides a transport abstraction layer that decouples the MCP server implementation from communication mechanisms, allowing the same server code to operate over HTTP or stdio without modification, with transport selection at initialization
vs alternatives: More flexible than transport-specific implementations because it enables deployment across different environments (web, CLI, containerized) without code changes, reducing development and maintenance burden
notification broadcasting to connected clients
The SDK supports server-initiated notifications that can be sent to connected clients via the 'notifications' protocol mechanism. The server maintains a list of subscribed clients and can broadcast notifications (e.g., resource updates, tool availability changes) to all or specific clients. Notifications are sent asynchronously and do not require a corresponding client request. The notification system uses the JSON-RPC notification format (no response expected).
Unique: Implements server-initiated notifications as a first-class protocol feature, allowing the server to push updates to clients without client polling, enabling real-time synchronization of tool and resource availability
vs alternatives: More efficient than polling-based approaches because clients receive updates immediately when server state changes, reducing latency and network overhead in dynamic AI systems
configuration and instrumentation for error handling
The SDK provides configuration options for exception reporting, instrumentation hooks, and protocol versioning. Developers can configure how the server handles errors (logging, reporting, custom handlers), enable instrumentation for monitoring request/response metrics, and specify protocol version compatibility. The configuration system uses a block-based DSL for setting options at initialization time. Error handling includes automatic JSON-RPC error response generation with proper error codes and messages.
Unique: Provides a declarative configuration DSL that centralizes error handling, instrumentation, and protocol settings, allowing developers to customize server behavior without modifying core logic or implementing custom middleware
vs alternatives: More convenient than manual error handling because it provides built-in hooks for common observability needs, reducing boilerplate and enabling consistent error handling across the entire server
utility classes for common mcp patterns
The SDK includes utility classes that encapsulate common patterns for building MCP servers, such as base classes for tools and resources, helper methods for schema generation, and validation utilities. These utilities reduce boilerplate by providing pre-built implementations of common functionality. Developers can extend or use these utilities directly rather than implementing patterns from scratch. The utilities follow Ruby conventions and integrate seamlessly with the rest of the SDK.
Unique: Provides a set of utility classes and helpers that encapsulate MCP patterns, reducing boilerplate and enabling developers to build compliant servers with minimal code while following established conventions
vs alternatives: More productive than building from scratch because utilities provide pre-built implementations of common patterns, reducing development time and ensuring consistency across MCP server implementations
+2 more capabilities