Hermes.Server.Handlers.Resources (hermes_mcp v0.9.1)

Handles MCP protocol resource-related methods.

This module processes:

  • resources/list - Lists available resources with optional pagination
  • resources/read - Reads content from one or more resources

Pagination Support

The resources/list method supports pagination through cursor parameters:

# Request
%{"method" => "resources/list", "params" => %{"cursor" => "optional-cursor"}}

# Response with more results
%{
  "resources" => [...],
  "nextCursor" => "next-page-cursor"
}

# Response for last page
%{"resources" => [...]}

Resource Reading

The resources/read method supports reading multiple resources at once:

# Single resource
%{"method" => "resources/read", "params" => %{"uri" => "file:///example.txt"}}

# Multiple resources  
%{"method" => "resources/read", "params" => %{"uris" => ["file:///a.txt", "file:///b.txt"]}}

# Response (always wrapped in contents array)
%{
  "contents" => [
    %{
      "uri" => "file:///example.txt",
      "mimeType" => "text/plain", 
      "text" => "content"
    }
  ]
}

Summary

Functions

Handles the resources/list request with optional pagination.

Handles the resources/read request to read content from one or more resources.

Functions

handle_list(frame, server_module)

@spec handle_list(Hermes.Server.Frame.t(), module()) ::
  {:reply, map(), Hermes.Server.Frame.t()}
  | {:error, Hermes.MCP.Error.t(), Hermes.Server.Frame.t()}

Handles the resources/list request with optional pagination.

Parameters

  • request - The MCP request containing optional cursor in params
  • frame - The server frame
  • server_module - The server module implementing resource components

Returns

  • {:reply, result, frame} - List of resources with optional nextCursor
  • {:error, error, frame} - If pagination cursor is invalid

handle_read(map, frame, server_module)

@spec handle_read(map(), Hermes.Server.Frame.t(), module()) ::
  {:reply, map(), Hermes.Server.Frame.t()}
  | {:error, Hermes.MCP.Error.t(), Hermes.Server.Frame.t()}

Handles the resources/read request to read content from one or more resources.

Supports both single URI and multiple URIs formats:

  • Single: %{"uri" => "file:///example.txt"}
  • Multiple: %{"uris" => ["file:///a.txt", "file:///b.txt"]}

Parameters

  • request - The MCP request containing URI(s) to read
  • frame - The server frame
  • server_module - The server module implementing resource components

Returns

  • {:reply, result, frame} - Resource contents wrapped in "contents" array
  • {:error, error, frame} - If resource not found or read fails