Implementation of the Model Context Protocol (MCP) RPC functionality.
This module handles HTTP requests and responses according to the MCP specification, supporting both synchronous and streaming communication patterns. It also handles the core JSON-RPC message processing for the protocol.
Summary
Functions
Get the MCP server name
Get the MCP server version
Handle HTTP DELETE request for session termination
Process an HTTP GET request to open an SSE stream
Process an HTTP POST request containing JSON-RPC messages
Create a standard JSON-RPC error response
Parse the JSON-RPC request
Process a single JSON-RPC message
Computes the sandbox domain for an mcp_ui_resource from the MCP server URL.
Send an SSE event over the chunked connection
Functions
Get the MCP server name
Get the MCP server version
Handle HTTP DELETE request for session termination
Process an HTTP GET request to open an SSE stream
Process an HTTP POST request containing JSON-RPC messages
Create a standard JSON-RPC error response
Parse the JSON-RPC request
Process a single JSON-RPC message
Computes the sandbox domain for an mcp_ui_resource from the MCP server URL.
MCP hosts render UI resources in sandboxed iframes, and each host determines the iframe's origin differently:
| Host | Domain format | Behavior |
|---|---|---|
| Claude | {sha256_hash}.claudemcpcontent.com | Hash derived from the MCP server endpoint URL. |
| ChatGPT | {connector_id}.web-sandbox.oaiusercontent.com | Auto-assigned by ChatGPT; ignores the domain field. |
Since ChatGPT ignores domain entirely, this function generates a Claude-compatible
value so that a single configuration works across both hosts.
When domain is set to :auto (the default), this is called automatically at
request time using the server URL derived from the incoming connection.
Examples
iex> AshAi.Mcp.Server.sandbox_domain("http://localhost:4000/mcp")
"0307c5dc3988887979d60ecbb5101189.claudemcpcontent.com"
Send an SSE event over the chunked connection