Module: McpToolkit::Server

Defined in:
lib/mcp_toolkit/server.rb

Overview

Builds the official-SDK MCP::Server for this app: the JSON-RPC dispatcher with the toolkit's generic tools registered. The transport / session / HTTP layer lives in McpToolkit::Transport::ControllerMethods; this is purely the gem's dispatcher with tools + the per-request server_context.

The official mcp gem is the JSON-RPC core (per the 2026-06-18 architecture decision: standardize on the gem, wrapped, rather than a hand-rolled protocol).

Constant Summary collapse

GENERIC_TOOLS =

The generic, registry-driven toolset every server gets. Apps that want additional bespoke tools pass them via extra_tools:.

[
  McpToolkit::Tools::Resources,
  McpToolkit::Tools::ResourceSchema,
  McpToolkit::Tools::Get,
  McpToolkit::Tools::List
].freeze

Class Method Summary collapse

Class Method Details

.build(server_context:, config: McpToolkit.config, extra_tools: []) ⇒ MCP::Server

Parameters:

  • server_context (Hash)

    per-request context threaded to tools: :bearer_token, :header_account_id, :mcp_config, and (merged in by the gem) :_meta.

  • config (McpToolkit::Configuration) (defaults to: McpToolkit.config)
  • extra_tools (Array<Class>) (defaults to: [])

    additional MCP::Tool subclasses to expose.

Returns:

  • (MCP::Server)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mcp_toolkit/server.rb', line 26

def self.build(server_context:, config: McpToolkit.config, extra_tools: [])
  context = server_context.dup
  context[:mcp_config] ||= config

  kwargs = {
    name: config.server_name,
    version: config.server_version,
    instructions: config.server_instructions,
    tools: GENERIC_TOOLS + Array(extra_tools),
    server_context: context
  }
  if config.protocol_version
    kwargs[:configuration] =
      MCP::Configuration.new(protocol_version: config.protocol_version)
  end

  MCP::Server.new(**kwargs)
end