Skip to content

azmaveth/ex_mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ExMCP

Hex.pm Documentation CI Coverage License

A complete Elixir implementation of the Model Context Protocol (MCP)

Getting Started | User Guide | API Docs | Examples | Changelog


βœ… Production Ready: ExMCP v0.6.0 is now production-ready with 100% MCP compliance and comprehensive testing. The API is stable and ready for production use.

Overview

ExMCP is a comprehensive Elixir implementation of the Model Context Protocol, enabling AI models to securely interact with local and remote resources through a standardized protocol. It provides both client and server implementations with multiple transport options, including native Phoenix integration via Plug compatibility.

✨ Key Features

Protocol & Standards

  • πŸš€ Multiple MCP Versions - Supports protocol versions 2024-11-05, 2025-03-26, and 2025-06-18
  • βœ… 100% MCP Compliant - Full implementation of official MCP specification
  • πŸ› οΈ Complete Feature Set - Tools, Resources, Prompts, Roots, Subscriptions, Batch requests
  • πŸ” OAuth 2.1 Support - Complete Resource Server implementation

Performance & Reliability

  • ⚑ Ultra-fast Native BEAM - ~15ΞΌs local calls with zero serialization overhead
  • πŸ”„ Auto-Reconnection - Built-in reconnection with exponential backoff
  • πŸ—οΈ OTP Integration - Built on solid OTP principles with supervision trees
  • πŸ“Š Progress Notifications - Track long-running operations

Integration & Flexibility

  • πŸ”Œ Phoenix Plug - Native Phoenix integration with ExMCP.HttpPlug
  • 🌐 Multiple Transports - HTTP/SSE, stdio, and native BEAM support
  • 🎯 Session Management - Automatic session tracking for SSE connections
  • πŸ”„ Bi-directional Communication - Servers can make requests to clients

Developer Experience

  • πŸ§ͺ Well Tested - Comprehensive test suite with 500+ tests
  • πŸ“š Extensive Documentation - Complete guides and real-world examples
  • πŸ”§ Easy Configuration - Sensible defaults with flexible customization
  • πŸ›‘οΈ Security First - Built-in authentication, TLS/SSL, CORS support

πŸ“¦ Installation

Add ex_mcp to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_mcp, "~> 0.6.0"}
  ]
end

Then run:

mix deps.get

πŸš€ Quick Start

Phoenix Integration (Recommended)

Add MCP server capabilities to your Phoenix app:

# In your Phoenix router (lib/my_app_web/router.ex)
defmodule MyAppWeb.Router do
  use MyAppWeb, :router
  
  pipeline :mcp do
    plug :accepts, ["json"]
    # Add your authentication/authorization here
  end
  
  scope "/api/mcp" do
    pipe_through :mcp
    
    # Mount MCP server at /api/mcp
    forward "/", ExMCP.HttpPlug,
      handler: MyApp.MCPHandler,
      server_info: %{name: "my-phoenix-app", version: "1.0.0"},
      sse_enabled: true,
      cors_enabled: true
  end
end

# Create your MCP handler (lib/my_app/mcp_handler.ex)
defmodule MyApp.MCPHandler do
  use ExMCP.Server.Handler
  
  @impl true
  def init(_args), do: {:ok, %{}}
  
  @impl true
  def handle_initialize(_params, state) do
    {:ok, %{
      name: "my-phoenix-app",
      version: "1.0.0",
      capabilities: %{tools: %{}, resources: %{}}
    }, state}
  end
  
  @impl true
  def handle_list_tools(state) do
    tools = [
      %{
        name: "get_user_count",
        description: "Get total number of users",
        input_schema: %{type: "object", properties: %{}}
      }
    ]
    {:ok, tools, state}
  end
  
  @impl true
  def handle_call_tool("get_user_count", _args, state) do
    count = MyApp.Accounts.count_users()
    {:ok, [%{type: "text", text: "Total users: #{count}"}], state}
  end
end

Connect from any MCP client:

mcp connect http://localhost:4000/api/mcp

Standalone MCP Client

# Connect to a stdio-based server
{:ok, client} = ExMCP.Client.start_link(
  transport: :stdio,
  command: ["node", "my-mcp-server.js"]
)

# List available tools
{:ok, tools} = ExMCP.Client.list_tools(client)

# Call a tool
{:ok, result} = ExMCP.Client.call_tool(client, "search", %{
  query: "Elixir programming",
  limit: 10
})

Ultra-Fast Native BEAM Services

For trusted Elixir clusters, use the native BEAM transport:

# Create a service using the ExMCP.Service macro
defmodule MyToolService do
  use ExMCP.Service, name: :my_tools

  @impl true
  def handle_mcp_request("list_tools", _params, state) do
    tools = [
      %{
        "name" => "ping",
        "description" => "Test tool",
        "inputSchema" => %{"type" => "object", "properties" => %{}}
      }
    ]
    {:ok, %{"tools" => tools}, state}
  end

  @impl true
  def handle_mcp_request("tools/call", %{"name" => "ping"}, state) do
    {:ok, %{"content" => [%{"type" => "text", "text" => "Pong!"}]}, state}
  end
end

# Start your service (automatically registers with ExMCP.Native)
{:ok, _} = MyToolService.start_link()

# Direct service calls (~15ΞΌs latency)
{:ok, tools} = ExMCP.Native.call(:my_tools, "list_tools", %{})

πŸ“š Documentation

ExMCP provides comprehensive documentation organized for different needs:

πŸš€ Getting Started

πŸ“– Comprehensive Guides

πŸ”§ Development & API

πŸ“‹ Protocol & Specifications

🎯 Transport Performance

Transport Latency Best For Use Case
Native BEAM ~15ΞΌs Internal services Elixir cluster communication
stdio ~1-5ms External tools Subprocess communication
HTTP/SSE ~5-20ms Network clients Web applications, remote APIs

✨ What's New in v0.6.0

  • Enhanced Security: Complete OAuth 2.1 Resource Server implementation
  • MCP 2025-06-18 Support: Latest protocol version with structured tool output
  • Improved Testing: Comprehensive compliance test suite
  • Better Performance: Optimized native BEAM transport
  • Documentation: Enhanced guides and examples

See the CHANGELOG for complete details and breaking changes.

🀝 Contributing

We welcome contributions! Please see:

Before contributing:

  1. Fork the repository
  2. Create a feature branch
  3. Run make quality to ensure code quality
  4. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • The Model Context Protocol specification creators
  • The Elixir community for excellent tooling and libraries
  • Contributors and early adopters providing feedback

Made with ❀️ for the Elixir community

About

Model Context Protocol client/server library for Elixir

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages