ExMCP.Protocol.RequestProcessor (ex_mcp v0.9.0)

View Source

Processes JSON-RPC requests for MCP servers.

This module handles:

  • Request routing based on method name
  • Standard MCP method implementations
  • Delegation to custom handlers
  • Response building for each method type

Supported Methods

  • initialize - Protocol handshake and capability negotiation
  • tools/list - List available tools
  • tools/call - Execute a tool
  • resources/list - List available resources
  • resources/read - Read a resource
  • prompts/list - List available prompts
  • prompts/get - Get a prompt
  • notifications/initialized - Client initialization complete

Summary

Functions

Processes a JSON-RPC request and returns the appropriate response.

Types

process_result()

@type process_result() ::
  {:response, map(), state()} | {:notification, state()} | {:async, state()}

request()

@type request() :: map()

state()

@type state() :: map()

Functions

process(request, state)

@spec process(request(), state()) :: process_result()

Processes a JSON-RPC request and returns the appropriate response.

Returns:

  • {:response, response_map, new_state} - Synchronous response
  • {:notification, new_state} - For notifications (no response needed)
  • {:async, new_state} - For async operations (response sent separately)

Examples

iex> request = %{"method" => "tools/list", "id" => 123}
iex> RequestProcessor.process(request, state)
{:response, %{"jsonrpc" => "2.0", "id" => 123, "result" => %{"tools" => []}}, state}