EM

emillindfors/mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

18 stars 10 forks 质量 36 趋势 10

一个用于制作MCP(模型上下文协议)兼容Rust程序的箱子

概览

Rust 实现的模型上下文协议(MCP),为 AI 模型访问外部上下文和资源提供了标准化方式。 mcp.rs 是 Model Context 协议的高性能、类型安全 Rust 实现,旨在实现 AI 应用及其集成之间的无缝通信。它为构建能够向 AI 模型暴露各种资源(文件、数据、API)的 MCP 服务器提供了坚实基础。 - : - CLI工具的标准输入/输出(stdio)传输 - 用于Web集成的HTTP与服务器发送事件(SSE) - 自定义实现的可扩展传输系统 - : - 文件系统资源提供者 - 资源模板支持 - 实时资源更新 - 资源订阅功能 - : - YAML/JSON 配置文件 - 环境变量覆盖 - 命令行参数 - 合理的默认值 - : - 内置访问控制 - 路径穿越保护 - 速率限制 - 支持 CORS 添加MCP。

概述(AI 翻译)

Rust 实现的模型上下文协议(MCP),为 AI 模型访问外部上下文和资源提供了标准化方式。

快速开始

客户

服务器

概述

mcp.rs 是 Model Context 协议的高性能、类型安全 Rust 实现,旨在实现 AI 应用及其集成之间的无缝通信。它为构建能够向 AI 模型暴露各种资源(文件、数据、API)的 MCP 服务器提供了坚实基础。

特色

  • 多种运输类型:

  • CLI工具的标准输入/输出(stdio)传输

  • HTTP与服务器发送事件(SSE)用于网页集成

  • 可扩展传输系统,用于自定义实现

  • 资源管理:

  • 文件系统资源提供者

  • 资源模板支持

  • 实时资源更新

  • 资源订阅功能

  • 灵活配置:

  • YAML/JSON 配置文件

  • 环境变量覆盖

  • 命令行参数

  • 合理的默认设置

  • 安全:

  • 内置门禁控制

  • 路径穿越保护

  • 速率限制

  • CORS支持

安装

把 mcp.rs 加到你项目的“货物”里。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

mcp.rs

A Rust implementation of the Model Context Protocol (MCP), providing a standardized way for AI models to access external context and resources.

Quickstart

Client

# List resources
cargo run --bin client list-resources

# Read a specific file
cargo run --bin client read-resource -u "file:///path/to/file"

# Use a prompt
cargo run --bin client get-prompt -n "code_review" -a '{"code": "fn main() {}", "language": "rust"}'

# Call a tool
cargo run --bin client -- --server "http://127.0.0.1:3000" call-tool --name "file_system" --args '{\"operation\": \"read_file\", \"path\": \"Config.toml\"}'

# Set log level
cargo run --bin client set-log-level -l "debug"

# Use SSE transport
cargo run --bin client -t sse -s http://localhost:3000 list-resources

Server

# Run with test config
cargo run --bin server -- --config "../servers/test.json"

Overview

mcp.rs is a high-performance, type-safe Rust implementation of the Model Context Protocol, designed to enable seamless communication between AI applications and their integrations. It provides a robust foundation for building MCP servers that can expose various types of resources (files, data, APIs) to AI models.

Features

  • Multiple Transport Types:

    • Standard Input/Output (stdio) transport for CLI tools
    • HTTP with Server-Sent Events (SSE) for web integrations
    • Extensible transport system for custom implementations
  • Resource Management:

    • File system resource provider
    • Resource templating support
    • Real-time resource updates
    • Resource subscription capabilities
  • Flexible Configuration:

    • YAML/JSON configuration files
    • Environment variable overrides
    • Command-line arguments
    • Sensible defaults
  • Security:

    • Built-in access controls
    • Path traversal protection
    • Rate limiting
    • CORS support

Installation

Add mcp.rs to your project’s Cargo.toml:

[dependencies]
mcp = "0.1.0"

Quick Start

  1. Create a basic MCP server:
use mcp::{McpServer, ServerConfig};

#[tokio::main]
async fn main() -> Result {
    // Create server with default configuration
    let server = McpServer::new(ServerConfig::default());
    
    // Run the server
    server.run().await
}
  1. Configure via command line:
# Run with stdio transport
mcp-server -t stdio

# Run with SSE transport on port 3000
mcp-server -t sse -p 3000

# Enable debug logging
mcp-server -l debug
  1. Or use a configuration file:
server:
  name: "my-mcp-server"
  version: "1.0.0"
  transport: sse
  port: 3000

resources:
  root_path: "./resources"
  allowed_schemes:
    - file
  max_file_size: 10485760

security:
  enable_auth: false
  allowed_origins:
    - "*"

logging:
  level: "info"
  format: "pretty"

Architecture

mcp.rs follows a modular architecture:

  • Transport Layer: Handles communication between clients and servers
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →