mcpField
πŸ”
πŸ” Rust MCP Server + Inspector Example: SSE Transport with an Add Tool

πŸ” Rust MCP Server + Inspector Example: SSE Transport with an Add Tool

Local
github.com/RGGHDeveloper Tools8Updated 81w ago

About πŸ” Rust MCP Server + Inspector Example: SSE Transport with an Add Tool

This Rust example demonstrates an MCP server and client communicating over SSE, with an add-two-numbers tool. It also shows a RIG agent using the tool and provides an MCP Inspector workflow for testing.

Key features

  1. 01Set up an MCP server with SSE transport
  2. 02Register a tool that adds two numbers
  3. 03Connect an MCP client and list tools
  4. 04Use the tool through a RIG agent
  5. 05Inspect the server with MCP Inspector

Use cases

  1. 01Learn an SSE-based MCP server setup
  2. 02Test a custom addition tool with an agent
  3. 03Explore MCP connections using Inspector

MCP support

The example creates an MCP server that exposes an addition tool over SSE, and connects an MCP client that lists and uses it. MCP Inspector can connect to the server for testing.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json Β· Universal config
{
"mcpServers": {
"rig": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/inspector"
]
}
}
}
Run commandnpx -y @modelcontextprotocol/inspector

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npm@modelcontextprotocol/inspector

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

Rust

πŸ” 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 agent for LLM prompting.


πŸš€ Getting Started

Clone this repo and run with:

cargo run

In a separate terminal start the MCP Inspector with:

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


πŸ› οΈ 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

#[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<ToolResponseContent> {
    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:

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
  • πŸ“‘ 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:

[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 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

Screenshot from 2025-04-07 23-22-21


πŸ“¬ Questions or Feedback?

Feel free to open an issue or start a discussion!

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.