R

mcp-sdk

...
Created 11/29/2024byAntigmaLabs

Language:

Rust

Stars:

40

Forks:

5

Model Context Protocol (MCP)

Minimalistic Rust Implementation Of Model Context Protocol(MCP).

Crates.io

Main repo from Anthropic: MCP

Minimalistic approach

Given it is still very early stage of MCP adoption, the goal is to remain agile and easy to understand. This implementation aims to capture the core idea of MCP while maintaining compatibility with Claude Desktop. Many optional features are not implemented yet.

Some guidelines:

  • use primitive building blocks and avoid framework if possible
  • keep it simple and stupid

Examples

Tools Example

Using a Tool trait for better compile time reusability.

impl Tool for CreateEntitiesTool {
    fn name(&self) -> String {
        "create_entities".to_string()
    }

    fn description(&self) -> String {
        "Create multiple new entities".to_string()
    }

    fn input_schema(&self) -> serde_json::Value {
        json!({
           "type":"object",
           "properties":{
              "entities":{
                 "type":"array",
                 "items":{
                    "type":"object",
                    "properties":{
                       "name":{"type":"string"},
                       "entityType":{"type":"string"},
                       "observations":{
                          "type":"array", "items":{"type":"string"}
                       }
                    },
                    "required":["name","entityType","observations"]
                 }
              }
           },
           "required":["entities"]
        })
    }

    fn call(&self, input: Option) -> Result {
        let args = input.unwrap_or_default();
        let entities = args
            .get("entities")
            .ok_or(anyhow::anyhow!("missing arguments `entities`"))?;

            
        
            
                        let entities: Vec = serde_json::from_value(entities.clone())?;
        let created = self.kg.lock().unwrap().create_entities(entities)?;
        self.kg
            .lock()
            .unwrap()
            .save_to_file(&self.memory_file_path)?;
        Ok(CallToolResponse {
            content: vec![ToolResponseContent::Text {
                text: json!(created).to_string(),
            }],
            is_error: None,
            meta: None,
        })
    }
}

Server Example

    let server = Server::builder(StdioTransport)
        .capabilities(ServerCapabilities {
            tools: Some(json!({})),
            ..Default::default()
        })
        .request_handler("tools/list", list_tools)
        .request_handler("tools/call", call_tool)
        .request_handler("resources/list", |_req: ListRequest| {
            Ok(ResourcesListResponse {
                resources: vec![],
                next_cursor: None,
                meta: None,
            })
        })
        .build();

Client Example

#[tokio::main]
async fn main() -> Result {
    #[cfg(unix)]
    {
        // Create transport connected to cat command which will stay alive
        let transport = ClientStdioTransport::new("cat", &[])?;

        // Open transport
        transport.open()?;

        let client = ClientBuilder::new(transport).build();
        let client_clone = client.clone();
        tokio::spawn(async move { client_clone.start().await });
        let response = client
            .request(
                "echo",
                None,
                RequestOptions::default().timeout(Duration::from_secs(1)),
            )
            .await?;
        println!("{:?}", response);
    }
    #[cfg(windows)]
    {
        println!("Windows is not supported yet");
    }
    Ok(())
}

Other Sdks

Official

            - [typescript-sdk](https://github.com/modelcontextprotocol/typescript-sdk)

Community

For complete feature please refer to the MCP specification.

Features

Basic Protocol

  • Basic Message Types
  • Error and Signal Handling
  • Transport
    • Stdio
    • In Memory Channel (not yet supported in formal specification)
    • SSE
    • More compact serialization format (not yet supported in formal specification)
  • Utilities
    • Ping
    • Cancellation
    • Progress

Server

  • Tools
  • Prompts
  • Resources
    • Pagination
    • Completion

Client

For now use claude desktop as client.

Monitoring

  • Logging
  • Metrics
Last updated: 3/2/2025

Publisher info

AntigmaLabs's avatar

AntigmaLabs

building substrate for self-organizing intelligence

5
followers
0
following
3
repos

More MCP servers built with Rust

cal2prompt

✨ Fetches your schedule (Google Calendar) and outputs it as a single LLM prompt, with an optional MCP server mode.

By shuntaka95764
mcp-sdk-rs

An MCP client/server library for Rust

By jgmartin3
mcp-server-runner

A WebSocket server implementation for running Model Context Protocol (MCP) servers. This application enables MCP servers to be accessed via WebSocket connections, facilitating integration with web applications and other network-enabled clients.

By yonaka153