Elixir MCP Server

by epinault

377 downloads
Not rated
GitHub

About

An example of how to implement an MCP server using Elixir and SSE transport

Details

Author
epinault
Downloads
377
Categories
Other

- Implements the Model Context Protocol (MCP) using SSE transport
- Built with Elixir, Bandit, and Plug
- Provides three built-in tools: list_files, echo, get_weather
- Supports custom tools by modifying handle_initialize and handle_call_tool
- Can be tested with the NXP Inspector client

Install dependencies with mix deps.get, then start the server with the WEATHER_API_KEY environment variable set: WEATHER_API_KEY="your_key" mix run --no-halt. The server is available at http://localhost:4000/sse for SSE and http://localhost:4000/message for messages.

Elixir MCP Server

An Elixir implementation of the Model Context Protocol (MCP) server using Elixir with Bandit and Plug.

The Model Context Protocol (MCP) is an open protocol that enables AI models to securely interact with local and remote resources through standardized server implementations.
This project is a basic example of an MCP server using SSE (Server-Sent Events) as the transport protocol. It is based off the example at https://modelcontextprotocol.io/quickstart/server

Prerequisites

- Elixir 1.18 or higher
- Erlang/OTP 27 or higher

- The weather API key can be set through the WEATHER_API_KEY environment variable.
The default service is using the free tier of https://www.weatherapi.com/.

Getting Started

1. Install dependencies:

   mix deps.get

2. Start the server:
``
WEATHER_API_KEY="1234567890abcdef" mix run --no-halt

3. The server will be available at:
- SSE endpoint: http://localhost:4000/sse
- Message endpoint: http://localhost:4000/message

Available Tools

- list_files: List files in a directory
-
echo: Echo a message back
-
get_weather: Get weather information

Testing with MCP Client

Install the NXP Inspector client and follow the instructions to connect to the server.

Make sure to use SSE (Server-Sent Events) as the transport protocol, then you should be able to list available tools and call them. Also to ping/keepalive the connection, you can use the ping tool.

Adding Custom Tools

To add custom tools, update the handle_initialize/2 function to include your tool definitions and implement corresponding handle_call_tool/3` clauses.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.