https://github.com/rggh/rig-mcp-server
Rig MCP Server Example (April 7, 2025)
https://github.com/rggh/rig-mcp-server
mcp-server rig rust
Last synced: about 1 year ago
JSON representation
Rig MCP Server Example (April 7, 2025)
- Host: GitHub
- URL: https://github.com/rggh/rig-mcp-server
- Owner: RGGH
- Created: 2025-04-07T22:12:58.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-09T14:02:28.000Z (about 1 year ago)
- Last Synced: 2025-04-10T01:12:55.822Z (about 1 year ago)
- Topics: mcp-server, rig, rust
- Language: Rust
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/RGGH/rig-mcp-server/actions/workflows/rust.yml)
# ๐ Rust MCP Server + Inspector Example: SSE Transport with an Add Tool
credit : https://dev.to/joshmo_dev/using-model-context-protocol-with-rig-m7o
This project demonstrates how to set up an MCP (Model Context Protocol) server and client using Server-Sent Events (SSE) for communication. It includes a simple tool that adds two numbers and integrates with the [RIG](https://github.com/modelcontext/rig) agent for LLM prompting.
---
## ๐ Getting Started
Clone this repo and run with:
```bash
cargo run
```
In a separate terminal start the MCP Inspector with:
```bash
npx @modelcontextprotocol/inspector sse http://127.0.0.1:3001/sse
```
You'll see output like:
```
Starting MCP inspector...
Proxy server listening on port 3000
New SSE connection
Query parameters: { transportType: 'sse', url: 'http://localhost:3001/sse' }
SSE transport: url=http://localhost:3001/sse, headers=
Connected to SSE transport
Connected MCP client to backing server transport
Created web app transport
Set up MCP proxy
๐ MCP Inspector is up and running at http://localhost:5173 ๐
```
You can now view the web interface at [http://localhost:5173](http://localhost:5173)
---
## ๐ ๏ธ Features
- โ
Sets up a custom MCP server using `ServerSseTransport`
- โ
Connects a MCP client to the server
- โ
Registers a custom tool: `AddTool`, which adds two numbers
- โ
Lists registered tools via MCP
- โ
Integrates with RIG and prompts an LLM agent using the tool
---
## ๐ง Code Overview
```rust
#[tool(
name = "Add",
description = "Adds two numbers together.",
params(a = "The first number to add", b = "The second number to add")
)]
async fn add_tool(a: f64, b: f64) -> Result {
Ok(tool_text_content!((a + b).to_string()))
}
```
This defines the `Add` tool that is registered in the MCP server.
The main function sets up:
- Tracing
- The MCP server and transport (SSE)
- A MCP client that initializes and lists available tools
- A RIG agent with OpenAI backend, which uses the MCP tool
The agent then runs a prompt:
```rust
let response = agent.prompt("Add 10 + 10").await;
```
---
## ๐งช Sample Output
When run successfully, you'll see logs like:
```
Initialized: Ok(...)
Tools: Ok([...])
Building RIG agent
Prompting RIG agent
Agent response: Some("20")
```
---
## ๐งฐ Tech Stack
- ๐ฆ Rust with [tokio](https://tokio.rs/)
- ๐ก SSE transport from `mcp_core`
- ๐ง MCP server/client architecture
- ๐ค RIG agent with OpenAI model
- ๐ MCP Inspector web interface
---
## ๐ฆ Dependencies
Make sure you have these in your `Cargo.toml`:
```toml
[dependencies]
tokio = { version = "1", features = ["full"] }
anyhow = "1"
serde_json = "1"
mcp_core = "..."
mcp_core_macros = "..."
rig = "..."
```
> Replace `...` with the appropriate versions based on your environment.
---
## ๐ Inspector GUI
Visit [http://localhost:5173](http://localhost:5173) to view and interact with the MCP Inspector UI.
---
## โ
Test Log Sample
```
Query parameters: { transportType: 'sse', url: 'http://localhost:3001/sse' }
Connected to SSE transport
Connected MCP client to backing server transport
Set up MCP proxy
Received message for sessionId cdd4a8be-57e2-44e3-9b81-3df300e86f22
```

---
## ๐ฌ Questions or Feedback?
Feel free to open an issue or start a discussion!
```