Skip to content

Commit f8a6e7e

Browse files
authored
Merge pull request #10 from trubesv/documentation
Reorganize the README installation and usage instructions
2 parents 741c092 + 38d0abc commit f8a6e7e

File tree

4 files changed

+125
-57
lines changed

4 files changed

+125
-57
lines changed

README.md

Lines changed: 123 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,61 @@
11
# MCP over SSE
22

3-
[![Module Version](https://img.shields.io/hexpm/v/mcp_sse.svg)](https://github.com/kEND/mcp_sse/releases)
4-
[![Hex Docs](https://img.shields.io/badge/hex-docs-purple.svg)](https://hexdocs.pm/mcp_sse/)
5-
[![Total Download](https://img.shields.io/hexpm/dt/mcp_sse.svg)](https://hex.pm/packages/mcp_sse)
6-
[![License](https://img.shields.io/hexpm/l/mcp_sse.svg)](https://github.com/kEND/mcp_sse/blob/main/LICENSE)
7-
[![Last Updated](https://img.shields.io/github/last-commit/kEND/mcp_sse.svg)](https://github.com/kEND/mcp_sse/commits/main)
3+
[![Releases](https://img.shields.io/hexpm/v/mcp_sse.svg)](https://github.com/kEND/mcp_sse/releases)
4+
[![Documentation](https://img.shields.io/badge/hex-docs-purple.svg)](https://hexdocs.pm/mcp_sse/)
5+
[![MCP Specification Version](https://img.shields.io/badge/spec-2024--11--05-blue)](https://modelcontextprotocol.io/specification/2024-11-05/index)
6+
[![Downloads](https://img.shields.io/hexpm/dt/mcp_sse.svg)](https://hex.pm/packages/mcp_sse)
7+
[![License](https://img.shields.io/badge/licence-MIT-blue.svg)](https://github.com/kEND/mcp_sse/blob/main/LICENSE)
8+
[![CI](https://github.com/kEND/mcp_sse/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/kEND/mcp_sse/actions/workflows/ci.yml?query=branch%3Amain)
9+
[![Last Commit](https://img.shields.io/github/last-commit/kEND/mcp_sse.svg)](https://github.com/kEND/mcp_sse/commits/main)
810

911
This library provides a simple implementation of the Model Context Protocol (MCP) over Server-Sent Events (SSE).
1012

1113
For more information about the Model Context Protocol, visit:
1214
[Model Context Protocol Documentation](https://modelcontextprotocol.io/introduction)
1315

16+
## Table of Contents
17+
18+
- [Features](#features)
19+
- [Create your own MCP server](#create-your-own-mcp-server)
20+
- [Installation](#installation)
21+
- [For Phoenix Applications](#for-phoenix-applications)
22+
- [For Plug Applications with Bandit](#for-plug-applications-with-bandit)
23+
- [Usage](#usage)
24+
- [For Cursor](#for-cursor)
25+
- [Configuration Options](#configuration-options)
26+
- [Quick Demo](#quick-demo)
27+
- [Other Notes](#other-notes)
28+
- [Example Client Usage](#example-client-usage)
29+
- [Session Management](#session-management)
30+
- [SSE Keepalive](#sse-keepalive)
31+
- [MCP Response Formatting](#mcp-response-formatting)
32+
- [Contributing](#contributing)
33+
34+
## Features
35+
36+
- Full MCP server implementation
37+
- SSE connection management
38+
- JSON-RPC message handling
39+
- Tool registration and execution
40+
- Session management
41+
- Automatic ping/keepalive
42+
- Error handling and validation
43+
44+
## Create your own MCP server
45+
46+
You must implement the `MCPServer` behaviour.
47+
48+
You only need to implement the required callbacks (`handle_ping/1` and `handle_initialize/2`) and any optional callbacks for features you want to support.
49+
50+
The `use MCPServer` macro provides:
51+
- Built-in message routing
52+
- Protocol version validation
53+
- Default implementations for optional callbacks
54+
- JSON-RPC error handling
55+
- Logging
56+
57+
See [`DefaultServer`](https://hexdocs.pm/mcp_sse/MCPServer.html#module-example) for a default implementation of the `MCPServer` behaviour.
58+
1459
## Installation
1560

1661
### For Phoenix Applications:
@@ -24,8 +69,7 @@ config :mime, :types, %{
2469
}
2570

2671
# Configure the MCP Server
27-
config :mcp_sse, :mcp_server, MCP.DefaultServer
28-
# config :mcp_sse, :mcp_server, YourApp.YourMCPServer
72+
config :mcp_sse, :mcp_server, YourApp.YourMCPServer
2973
```
3074

3175
2. Add to your dependencies in `mix.exs`:
@@ -48,12 +92,16 @@ end
4892
scope "/" do
4993
pipe_through :sse
5094
get "/sse", SSE.ConnectionPlug, :call
51-
52-
pipe_through :api
5395
post "/message", SSE.ConnectionPlug, :call
5496
end
5597
```
5698

99+
4. Run your application:
100+
101+
```bash
102+
mix phx.server
103+
```
104+
57105
### For Plug Applications with Bandit:
58106

59107
1. Create a new Plug application with supervision:
@@ -73,7 +121,7 @@ config :mime, :types, %{
73121
}
74122

75123
# Configure the MCP Server
76-
config :mcp_sse, :mcp_server, YourApp.MCPServer
124+
config :mcp_sse, :mcp_server, YourApp.YourMCPServer
77125
```
78126

79127
3. Add dependencies to `mix.exs`:
@@ -152,14 +200,48 @@ defmodule YourApp.Application do
152200
end
153201
```
154202

155-
### Session Management
203+
6. Run your application:
156204

157-
The MCP SSE server requires a session ID for each connection. The router automatically:
158-
- Uses an existing session ID from query parameters if provided
159-
- Generates a new session ID if none exists
160-
- Ensures all requests to `/sse` and `/message` endpoints have a valid session ID
205+
```bash
206+
mix run --no-halt
207+
```
208+
209+
## Usage
161210

162-
### Configuration Options
211+
### With MCP Inspector
212+
213+
- Start the inspector:
214+
215+
```bash
216+
MCP_SERVER_URL=localhost:4000 npx @modelcontextprotocol/inspector@latest
217+
```
218+
219+
- Navigate to http://localhost:6274/
220+
- Make sure your server is running
221+
- Click `Connect`
222+
- You can now list tools and call them
223+
224+
### With Cursor
225+
226+
- Open Cursor Settings
227+
- Navigate to the MCP tab
228+
- Click `Add new global MCP server`
229+
- Fill in the `~/.cursor/mcp.json` with:
230+
231+
```json
232+
{
233+
"mcpServers": {
234+
"your-mcp-server": {
235+
"url": "http://localhost:4000/sse"
236+
}
237+
}
238+
}
239+
```
240+
241+
- Make sure your server is running
242+
- Ask Cursor to run one of your tools
243+
244+
## Configuration Options
163245

164246
The Bandit server can be configured with additional options in your application module:
165247

@@ -176,45 +258,20 @@ children = [
176258
]
177259
```
178260

179-
The `use MCPServer` macro provides:
180-
- Built-in message routing
181-
- Protocol version validation
182-
- Default implementations for optional callbacks
183-
- JSON-RPC error handling
184-
- Logging
185-
186-
You only need to implement the required callbacks (`handle_ping/1` and `handle_initialize/2`) and any optional callbacks for features you want to support.
187-
188-
## Protocol Specification
189-
190-
For detailed information about the Model Context Protocol, visit:
191-
[Model Context Protocol Specification](https://modelcontextprotocol.io/specification/2024-11-05/index)
192-
193-
## Features
194-
195-
- Full MCP server implementation
196-
- SSE connection management
197-
- JSON-RPC message handling
198-
- Tool registration and execution
199-
- Session management
200-
- Automatic ping/keepalive
201-
- Error handling and validation
202-
203-
## Contributing
204-
205-
- Fork the repository and clone it
206-
- Create a new branch in your fork
207-
- Make your changes and commit them
208-
- Push the changes to your fork
209-
- Open a pull request in upstream
210-
211261
## Quick Demo
212262

213263
To see the MCP server in action:
214264

215-
1. Start the example server in one terminal:
265+
1. Start a server in one terminal:
216266
```bash
267+
# Our example server
217268
elixir dev/example_server.exs
269+
270+
# Your Phoenix application
271+
mix phx.server
272+
273+
# Your Plug application
274+
mix run --no-halt
218275
```
219276

220277
2. In another terminal, run the demo client script:
@@ -229,7 +286,7 @@ The client script will:
229286
- Call the upcase tool with example input
230287
- Display the results of each step
231288

232-
This provides a practical demonstration of the MCP protocol flow and server capabilities.
289+
This provides a practical demonstration of the Model Context Protocol flow and server capabilities.
233290

234291
## Other Notes
235292

@@ -261,14 +318,19 @@ fetch('/message?sessionId=YOUR_SESSION_ID', {
261318
});
262319
```
263320

321+
### Session Management
322+
323+
The MCP SSE server requires a session ID for each connection. The router automatically:
324+
- Uses an existing session ID from query parameters if provided
325+
- Generates a new session ID if none exists
326+
- Ensures all requests to `/sse` and `/message` endpoints have a valid session ID
327+
264328
### SSE Keepalive
265329

266330
The SSE connection sends periodic keepalive pings to prevent connection timeouts.
267-
You can configure the ping interval or disable it entirely:
331+
You can configure the ping interval or disable it entirely in `config/config.exs`:
268332

269333
```elixir
270-
# In config/config.exs
271-
272334
# Set custom ping interval (in milliseconds)
273335
config :mcp_sse, :sse_keepalive_timeout, 30_000 # 30 seconds
274336

@@ -355,3 +417,11 @@ end
355417
```
356418

357419
For more details on response formatting, see the [MCP Content Types Specification](https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/messages/#responses).
420+
421+
## Contributing
422+
423+
- Fork the repository and clone it
424+
- Create a new branch in your fork
425+
- Make your changes and commit them
426+
- Push the changes to your fork
427+
- Open a pull request in upstream

lib/mcp_sse/mcp/default_server.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule MCP.DefaultServer do
22
@moduledoc false
33

4-
# Default implementation of MCP Server Behaviour.
4+
# Default implementation of the MCPServer behaviour.
55
# Provides basic functionality and stubs for optional callbacks.
66
use MCPServer
77

lib/mcp_sse/mcp/mcp_server.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule MCPServer do
55
66
## Example
77
8-
defmodule YourApp.MCPServer do
8+
defmodule YourApp.YourMCPServer do
99
use MCPServer
1010
require Logger
1111

lib/mcp_sse/sse/connection_plug.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ defmodule SSE.ConnectionPlug do
1818
scope "/" do
1919
pipe_through :sse
2020
get "/sse", SSE.ConnectionPlug, :call
21-
22-
pipe_through :api
2321
post "/message", SSE.ConnectionPlug, :call
2422
end
2523

0 commit comments

Comments
 (0)