Hermolaos.Protocol.Messages (Hermolaos v0.3.0)
View SourceMCP message builders for all protocol methods.
This module provides functions to build properly formatted MCP request and notification messages. Each function returns a map that can be sent through a transport.
Protocol Version
The default protocol version is 2025-03-26.
This can be overridden in the initialize/3 function.
Message Categories
Lifecycle Messages
initialize/3- Initialize connectioninitialized_notification/0- Confirm initialization completeping/0- Liveness check
Tool Messages
tools_list/1- List available toolstools_call/2- Invoke a tool
Resource Messages
resources_list/1- List resourcesresources_read/1- Read a resourceresources_subscribe/1- Subscribe to changesresources_unsubscribe/1- Unsubscribe
Prompt Messages
prompts_list/1- List promptsprompts_get/2- Get a prompt
Other Messages
logging_set_level/1- Set logging levelcompletion_complete/2- Request completions
Summary
Functions
Builds a cancellation notification.
Builds a completion/complete request.
Returns the default MCP protocol version.
Builds an initialize request message.
Builds the initialized notification.
Builds a logging/setLevel request.
Builds a ping request.
Builds a response to a ping request.
Builds a progress notification.
Builds a prompts/get request.
Builds a prompts/list request.
Builds a resources/list request.
Builds a resources/read request.
Builds a resources/subscribe request.
Builds a resources/templates/list request.
Builds a resources/unsubscribe request.
Builds a roots/list_changed notification.
Builds a response to a roots/list request.
Builds an error response to a sampling/createMessage request.
Builds a tools/call request.
Builds a tools/list request.
Functions
Builds a cancellation notification.
Sent to cancel a pending request.
Parameters
request_id- ID of the request to cancelreason- Optional cancellation reason
Examples
msg = Hermolaos.Protocol.Messages.cancelled_notification(123)
msg = Hermolaos.Protocol.Messages.cancelled_notification(123, "User cancelled")
Builds a completion/complete request.
Requests argument completion suggestions.
Parameters
ref- Reference object (prompt or resource)argument- Argument to complete
Examples
msg = Hermolaos.Protocol.Messages.completion_complete(
%{"type" => "ref/prompt", "name" => "code_review"},
%{"name" => "language", "value" => "eli"}
)
@spec default_protocol_version() :: String.t()
Returns the default MCP protocol version.
Builds an initialize request message.
This is the first message sent by the client to establish the connection and negotiate capabilities.
Parameters
protocol_version- The protocol version to requestcapabilities- Client capabilities mapclient_info- Client identification info
Examples
msg = Hermolaos.Protocol.Messages.initialize(
"2025-03-26",
%{roots: %{listChanged: true}},
%{name: "MyClient", version: "1.0.0"}
)
@spec initialized_notification() :: map()
Builds the initialized notification.
Sent by the client after receiving a successful initialize response to indicate the handshake is complete.
Examples
msg = Hermolaos.Protocol.Messages.initialized_notification()
# => %{"method" => "notifications/initialized"}
Builds a logging/setLevel request.
Sets the server's logging level.
Parameters
level- Log level (debug, info, notice, warning, error, critical, alert, emergency)
Examples
msg = Hermolaos.Protocol.Messages.logging_set_level("debug")
@spec ping() :: map()
Builds a ping request.
Used to check if the connection is alive.
Examples
msg = Hermolaos.Protocol.Messages.ping()
# => %{"method" => "ping"}
@spec ping_response() :: map()
Builds a response to a ping request.
Builds a progress notification.
Sent to report progress on a long-running operation.
Parameters
progress_token- Token identifying the operationprogress- Current progress valuetotal- Optional total value
Examples
msg = Hermolaos.Protocol.Messages.progress_notification("op123", 50, 100)
Builds a prompts/get request.
Gets a specific prompt, optionally with argument values.
Parameters
name- Prompt namearguments- Optional argument values
Examples
msg = Hermolaos.Protocol.Messages.prompts_get("code_review")
msg = Hermolaos.Protocol.Messages.prompts_get("summarize", %{"language" => "elixir"})
Builds a prompts/list request.
Lists all prompts available on the server.
Parameters
cursor- Optional pagination cursor
Examples
msg = Hermolaos.Protocol.Messages.prompts_list()
Builds a resources/list request.
Lists all resources available on the server.
Parameters
cursor- Optional pagination cursor
Examples
msg = Hermolaos.Protocol.Messages.resources_list()
Builds a resources/read request.
Reads the content of a specific resource.
Parameters
uri- Resource URI
Examples
msg = Hermolaos.Protocol.Messages.resources_read("file:///project/README.md")
Builds a resources/subscribe request.
Subscribes to updates for a specific resource.
Parameters
uri- Resource URI
Examples
msg = Hermolaos.Protocol.Messages.resources_subscribe("file:///project/src/main.rs")
Builds a resources/templates/list request.
Lists resource templates available on the server.
Parameters
cursor- Optional pagination cursor
Builds a resources/unsubscribe request.
Unsubscribes from updates for a specific resource.
Parameters
uri- Resource URI
@spec roots_list_changed_notification() :: map()
Builds a roots/list_changed notification.
Sent when the client's root list changes.
Builds a response to a roots/list request.
Parameters
roots- List of root objects
Examples
msg = Hermolaos.Protocol.Messages.roots_list_response([
%{"uri" => "file:///project", "name" => "Project Root"}
])
@spec sampling_not_supported_error() :: map()
Builds an error response to a sampling/createMessage request.
Used when the client doesn't support sampling.
Builds a tools/call request.
Invokes a tool with the given arguments.
Parameters
name- Tool namearguments- Tool arguments map
Examples
msg = Hermolaos.Protocol.Messages.tools_call("read_file", %{"path" => "/tmp/test.txt"})
Builds a tools/list request.
Lists all tools available on the server.
Parameters
cursor- Optional pagination cursor
Examples
msg = Hermolaos.Protocol.Messages.tools_list()
msg = Hermolaos.Protocol.Messages.tools_list("cursor123")