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

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

Rig MCP Server Example (April 7, 2025)

RGGH

Developer Tools
Visit Server

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!


Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
MCP Package Docs Server

MCP Package Docs Server

Facilitates LLMs to efficiently access and fetch structured documentation for packages in Go, Python, and NPM, enhancing software development with multi-language support and performance optimization.

Featured
Local
TypeScript
Claude Code MCP

Claude Code MCP

An implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.

Featured
Local
JavaScript
@kazuph/mcp-taskmanager

@kazuph/mcp-taskmanager

Model Context Protocol server for Task Management. This allows Claude Desktop (or any MCP client) to manage and execute tasks in a queue-based system.

Featured
Local
JavaScript
Linear MCP Server

Linear MCP Server

Enables interaction with Linear's API for managing issues, teams, and projects programmatically through the Model Context Protocol.

Featured
JavaScript
mermaid-mcp-server

mermaid-mcp-server

A Model Context Protocol (MCP) server that converts Mermaid diagrams to PNG images.

Featured
JavaScript
Jira-Context-MCP

Jira-Context-MCP

MCP server to provide Jira Tickets information to AI coding agents like Cursor

Featured
TypeScript
Linear MCP Server

Linear MCP Server

A Model Context Protocol server that integrates with Linear's issue tracking system, allowing LLMs to create, update, search, and comment on Linear issues through natural language interactions.

Featured
JavaScript
Sequential Thinking MCP Server

Sequential Thinking MCP Server

This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Featured
Python