ExMCP.HttpPlug (ex_mcp v0.9.0)

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.

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 \\ [])