关于 MCP-RB
MCP-RB 是一个轻量的 Ruby 框架,采用类似 Sinatra 的 DSL 来构建 MCP 服务。适合希望用 Ruby 快速实现 MCP 服务的开发者。README 列出的规范版本为 MCP 2024-11-05,目前仅支持部分能力。
主要功能
- 01类似 Sinatra 的 DSL 定义服务
- 02支持 resources 与 tools 能力
- 03基于 stdio 传输
- 04兼容 MCP Inspector 调试
适用场景
- 01用 Ruby 编写向 MCP 客户端提供资源的服务
- 02用 Ruby 实现可供 LLM 调用的工具服务
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
暂未收录安装方式
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
MCP-RB
一个轻量级 Ruby 框架,可通过类似 Sinatra 的 DSL 实现 MCP(Model Context Protocol)服务。
安装
将以下代码行添加到应用的 Gemfile 中:
gem 'mcp-rb'
用法
下面是创建 MCP 服务的简单示例:
require 'mcp'
name "hello-world"
version "1.0.0"
# Define a resource
resource "hello://world" do
name "Hello World"
description "A simple hello world message"
call { "Hello, World!" }
end
# Define a resource template
resource_template "hello://{user_name}" do
name "Hello User"
description "A simple hello user message"
call { |args| "Hello, #{args[:user_name]}!" }
end
# Define a tool
tool "greet" do
description "Greet someone by name"
argument :name, String, required: true, description: "Name to greet"
call do |args|
"Hello, #{args[:name]}!"
end
end
# Define a tool with nested arguments
tool "greet_full_name" do
description "Greet someone by their full name"
argument :person, required: true, description: "Person to greet" do
argument :first_name, String, required: false, description: "First name"
argument :last_name, String, required: false, description: "Last name"
end
call do |args|
"Hello, First: #{args[:person][:first_name]} Last: #{args[:person][:last_name]}!"
end
end
# Define a tool with an Array argument
tool "group_greeting" do
description "Greet multiple people at once"
argument :people, Array, required: true, items: String, description: "People to greet"
call do |args|
args[:people].map { |person| "Hello, #{person}!" }.join(", ")
end
end
支持的规范
- 基础协议
- ping
- stdio 传输
- 服务端功能
- 资源
- resources/read
- resources/list
- resources/templates/list
- 工具
- tools/list
- tools/call
- 资源
目前尚不支持任何能力。
测试
rake test
rake test:unit # run only the unit tests, skipping tests that test a running server
使用 MCP Inspector 测试
bunx @modelcontextprotocol/inspector $(pwd)/examples/hello_world.rb
格式化
bundle exec standardrb --fix
也可以使用 rake 任务:
rake lint # Run standardrb to check code style
rake lint:fix # Auto-fix standardrb issues
发布
发布新版本:
- 更新
lib/mcp/version.rb中的版本号 - 更新
CHANGELOG.md - 创建 git 标签
git add .
git commit -m "Release vx.y.z"
git tag vx.y.z
git push --tags
- 构建并推送到 RubyGems
gem build mcp-rb.gemspec
gem push mcp-rb-*.gem
更新日志
参见 CHANGELOG.md
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。