Erlang implementation of the Model Context Protocol (MCP) SDK.
MCP enables seamless communication between AI assistants and local services through a standardized protocol. This SDK provides both client and server implementations with full OTP compliance, allowing you to build robust, fault-tolerant integrations that expose resources, tools, and prompts to AI systems.
Requirements: Erlang/OTP 25 or later
# Add to your rebar.config deps
{deps, [
{erlmcp, {git, "https://github.com/banyan-platform/erlmcp.git", {branch, "main"}}}
]}.
# Fetch and compile
rebar3 get-deps
rebar3 compile%% Start a server that exposes resources
{ok, Server} = erlmcp_server:start_link({stdio, []}, Capabilities),
%% Add a resource
erlmcp_server:add_resource(Server, <<"hello://world">>,
fun(_Uri) -> <<"Hello from Erlang!">> end),
%% Add a tool with JSON Schema validation
Schema = #{<<"type">> => <<"object">>,
<<"properties">> => #{<<"name">> => #{<<"type">> => <<"string">>}}},
erlmcp_server:add_tool_with_schema(Server, <<"greet">>,
fun(#{<<"name">> := Name}) ->
<<"Hello, ", Name/binary, "!">>
end, Schema).%% Connect to an MCP server
{ok, Client} = erlmcp_client:start_link({stdio, []}, #{strict_mode => false}),
%% Initialize connection
{ok, _} = erlmcp_client:initialize(Client, Capabilities),
%% List available resources
{ok, #{<<"resources">> := Resources}} = erlmcp_client:list_resources(Client),
%% Call a tool
{ok, Result} = erlmcp_client:call_tool(Client, <<"greet">>,
#{<<"name">> => <<"World">>}).See the examples directory for comprehensive examples:
- Weather Server - Full MCP server with resources, tools, and subscriptions
- Calculator Client - Sophisticated client with connection management
- Complete Application - OTP application with supervision
- Architecture Overview - System design and components
- Protocol Guide - MCP protocol implementation details
- OTP Patterns - Erlang/OTP best practices used
- API Reference - Complete API documentation
- ✅ Full MCP protocol support (resources, tools, prompts)
- ✅ OTP-compliant with supervision trees
- ✅ Multiple transport layers (stdio, TCP, HTTP)
- ✅ JSON Schema validation for tools
- ✅ Resource subscriptions with notifications
- ✅ Automatic reconnection with backoff
- ✅ Comprehensive error handling
- ✅ Production-ready logging and monitoring
Apache 2.0
