Token导航 LogoToken导航TokenDH.com
MCP Ruby logo
开发工具未说明官方级别未说明来源级核验

MCP Ruby

MCP Server

A easy-to-use and minimal server implementation for the Model Context Protocol (MCP) in Ruby.

工具数

3

提示词数

0

GitHub Stars

13

资源数

0
Ruby中间件ClaudeClaude DesktopClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

sergiobayona

提供方

sergiobayona

最后核验

2026/5/18 02:51

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

矢量MCP

](https://badge.fury.io/rb/vector_mcp) ![Docs](https://sergiobayona.github.io/vector_mcp/) ![Build Status](https://github.com/sergiobayona/vector_mcp/actions/workflows/ruby.yml) ![Maintainability](https://qlty.sh/gh/sergiobayona/projects/vector_mcp) ![License: MIT](https://opensource.org/licenses/MIT)

VectorMCP是模型上下文协议(MCP)服务器端规范的Ruby实现。它为您提供了一个框架,用于通过MCP流式HTTP传输公开工具、资源、提示、根、采样、中间件和安全性。

亮点

  • 流式HTTP是内置的传输方式,具有会话管理、可恢复性和MCP 2025-11-25合规性
  • 基于类的工具通过 VectorMCP::Tool,加上原始的基于块的 register_tool API
  • 机架和轨道安装贯穿 server.rack_app
  • 选择参与身份验证和授权、结构化日志记录和中间件挂钩
  • 图像感知工具/资源/提示、根和服务器启动的采样
  • 基于令牌的字段匿名化中间件,将敏感值排除在LLM上下文之外

需求

  • Ruby 3.2+

安装

gem install vector_mcp
gem "vector_mcp"

快速开始

require "vector_mcp"

class Greet  "/mcp"

对于ActiveRecord支持的工具,请选择加入 VectorMCP::Rails::Tool:

require "vector_mcp/rails/tool"

class FindUser < VectorMCP::Rails::Tool
  description "Find a user by id"
  param :id, type: :integer, required: true

  def call(args, _session)
    user = find!(User, args[:id])
    { id: user.id, email: user.email }
  end
end

docs/rails-setup-guide.md 获取完整的设置指南。

工具、资源和提示

公开可调用工具:

server.register_tool(
  name: "calculate",
  description: "Performs basic math",
  input_schema: {
    type: "object",
    properties: {
      operation: { type: "string", enum: ["add", "subtract", "multiply"] },
      a: { type: "number" },
      b: { type: "number" }
    },
    required: ["operation", "a", "b"]
  }
) do |args|
  case args["operation"]
  when "add" then args["a"] + args["b"]
  when "subtract" then args["a"] - args["b"]
  when "multiply" then args["a"] * args["b"]
  end
end

公开可读资源:

server.register_resource(
  uri: "file://config.json",
  name: "App Configuration",
  description: "Current application settings"
) { File.read("config.json") }

定义提示模板:

server.register_prompt(
  name: "code_review",
  description: "Reviews code for best practices",
  arguments: [
    { name: "language", description: "Programming language", required: true },
    { name: "code", description: "Code to review", required: true }
  ]
) do |args|
  {
    messages: [{
      role: "user",
      content: {
        type: "text",
        text: "Review this #{args["language"]} code:\n\n#{args["code"]}"
      }
    }]
  }
end

VectorMCP::Tool 还支持 type: :datetype: :datetime,它们在JSON模式中被验证为字符串,并被强制为 DateTime 之前 #call 跑。

安全和中间件

VectorMCP保留了安全选项,但基元是内置的:

server.enable_authentication!(
  strategy: :api_key,
  keys: ["your-secret-key"]
)

server.enable_authorization! do
  authorize_tools do |user, _action, tool|
    user[:role] == "admin" || !tool.name.start_with?("admin_")
  end
end

自定义身份验证也有效:

server.enable_authentication!(strategy: :custom) do |request|
  api_key = request[:headers]["X-API-Key"]
  user = User.find_by(api_key: api_key)
  user ? { user_id: user.id, role: user.role } : false
end

对于使用OAuth 2.1的MCP客户端(例如Claude Desktop),请传递 resource_metadata_url: 打开RFC 9728发现。未经身份验证的请求 /mcp 返回 401 带着一个 WWW-Authenticate 头指向配置的元数据文档,客户端自动驱动OAuth舞蹈的其余部分。看 docs/oauth_resource_server.md 用于特征参考和 docs/rails_oauth_integration.md 获取完整的Rails+Dookeeper食谱。

中间件可以连接到工具、资源、提示、采样、身份验证和传输事件,包括 before_auth, after_auth, on_auth_error, before_request, after_response,以及 on_transport_error.

安全/README.md 查看完整的安全指南。

现场匿名

通过用稳定的不透明标记替换敏感字符串值,将其排除在LLM上下文之外。值在出站工具结果上被标记,并在入站工具参数上被还原,因此LLM在处理程序接收原始数据时只看到标记。

anonymizer = VectorMCP::Middleware::Anonymizer.new(
  store: VectorMCP::TokenStore.new,
  field_rules: [
    { pattern: /email/i, prefix: "EMAIL" },
    { pattern: /\bssn\b/i, prefix: "SSN" }
  ]
)
anonymizer.install_on(server)

运输注意事项

  • VectorMCP内置了可流式传输的HTTP
  • POST /mcp 接受单个JSON-RPC请求、通知或响应;批处理数组被拒绝
  • GET /mcp 为服务器发起的消息打开SSE流
  • DELETE /mcp 终止会话
  • 服务器通告MCP协议 2025-11-25 并接受 2025-03-262024-11-05 兼容性标头
  • 默认允许的源仅限于本地主机和环回地址

使用curl初始化会话:

curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"curl","version":"1.0"}}}'

更多功能

  • 根通过 register_rootregister_root_from_path
  • 图像资源和图像感知工具/提示
  • 使用组件记录器进行结构化日志记录
  • 服务器启动采样,支持流媒体/工具调用
  • 中间件驱动的请求整形和可观察性

文档

贡献

欢迎在上提交Bug报告和拉取请求 .

许可证

可作为开源在 MIT许可证.

目录标签

目录标签

Ruby中间件Claudedeveloper-tools本地部署Ruby框架MCP协议HTTP流传输工具集成

支持客户端

Claude DesktopClaude

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

3

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP