ExMCP.HttpPlug (ex_mcp v1.0.0-rc.4)

Copy Markdown View Source

HTTP Plug for MCP (Model Context Protocol) requests. Compatible with Phoenix and Cowboy servers.

This plug provides HTTP transport for MCP servers, allowing integration with standard Elixir web applications. It supports both regular POST requests for RPC calls and Server-Sent Events (SSE) for real-time communication.

Handler options

:handler_opts configures the argument passed to a handler module's init/1. It may be a static term, a one-arity function called with the Plug.Conn, a two-arity function called with the Plug.Conn and decoded JSON-RPC request, or an {module, function, extra_args} tuple. MFA handlers are called as apply(module, function, [conn, request | extra_args]).

Usage

# With Cowboy
{:ok, _} = Plug.Cowboy.http(ExMCP.HttpPlug, [
  handler: MyApp.MCPServer,
  server_info: %{name: "my-app", version: "1.0.0"}
], port: 4000)

# With Phoenix
plug ExMCP.HttpPlug,
  handler: MyApp.MCPServer,
  server_info: %{name: "my-app", version: "1.0.0"}

OAuth 2.1 Integration

To enable OAuth 2.1 bearer token validation:

plug ExMCP.HttpPlug,
  handler: MyApp.MCPServer,
  server_info: %{name: "my-app"},
  oauth_enabled: true,
  auth_config: %{
    introspection_endpoint: "https://auth.example.com/introspect",
    realm: "my-mcp-server" # Optional, defaults to server_info.name
  }

Summary

Functions

Processes HTTP connections for MCP protocol.

Initializes the plug with configuration options.

Functions

call(conn, opts)

Processes HTTP connections for MCP protocol.

init(opts)

Initializes the plug with configuration options.

start_link(opts \\ [])