Skip to content

Commit 91219d3

Browse files
Merge pull request #24 from modelcontextprotocol/update-gemspec
Update gemspec to reflect `mcp` naming
2 parents 6b49222 + bf07d4a commit 91219d3

38 files changed

+156
-145
lines changed

.cursor/rules/release-changelogs.mdc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
---
22
description: writing changelog markdown when cutting a new release of the gem
3-
globs:
3+
globs:
44
alwaysApply: false
55
---
6-
- output the changelog as markdown when asked.
6+
- output the changelog as markdown when asked.
77
- git tags are used to mark the commit that cut a new release of the gem
8-
- the gem version is located in [version.rb](mdc:lib/model_context_protocol/version.rb)
8+
- the gem version is located in [version.rb](mdc:lib/mcp/version.rb)
99
- use the git history, especially merge commits from PRs to construct the changelog
10-
- when necessary, look at the diff of files changed to determine whether a PR should be listed in
10+
- when necessary, look at the diff of files changed to determine whether a PR should be listed in
1111
- ## Added; adds new functionality
1212
- ## Changed; alters functionality; especially backward compatible changes
13-
- ## Fixed; bugfixes that are forward compatible
13+
- ## Fixed; bugfixes that are forward compatible
1414

1515
use the following format for changelogs:
1616

17-
https://cloudsmith.io/~shopify/repos/gems/packages/detail/ruby/mcp-ruby/{gem version}/
18-
19-
# Changelog
20-
17+
```
2118
## Added
2219
- New functionality added that was not present before
2320

2421
## Changed
2522
- Alterations to functionality that may indicate breaking changes
2623

2724
## Fixed
28-
- Bug fixes
25+
- Bug fixes
2926

3027
#### Full change list:
31-
- [Name of the PR #123](mdc:https:/github.com/Shopify/mcp-ruby/pull/123) @github-author-username
32-
- [Name of the PR #456](mdc:https:/github.com/Shopify/mcp-ruby/pull/456) @another-github-author
28+
- [Name of the PR #123](https:/github.com/modelcontextprotocol/ruby-sdk/pull/123) @github-author-username
29+
- [Name of the PR #456](https:/github.com/modelcontextprotocol/ruby-sdk/pull/456) @another-github-author
30+
```

README.md

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,29 @@
22

33
A Ruby gem for implementing Model Context Protocol servers
44

5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'mcp'
11+
```
12+
13+
And then execute:
14+
15+
```bash
16+
$ bundle install
17+
```
18+
19+
Or install it yourself as:
20+
21+
```bash
22+
$ gem install mcp
23+
```
24+
525
## MCP Server
626

7-
The `ModelContextProtocol::Server` class is the core component that handles JSON-RPC requests and responses.
27+
The `MCP::Server` class is the core component that handles JSON-RPC requests and responses.
828
It implements the Model Context Protocol specification, handling model context requests and responses.
929

1030
### Key Features
@@ -44,19 +64,17 @@ requests.
4464
You can use the `Server#handle_json` method to handle requests.
4565

4666
```ruby
47-
module ModelContextProtocol
48-
class ApplicationController < ActionController::Base
49-
50-
def index
51-
server = ModelContextProtocol::Server.new(
52-
name: "my_server",
53-
version: "1.0.0",
54-
tools: [SomeTool, AnotherTool],
55-
prompts: [MyPrompt],
56-
server_context: { user_id: current_user.id },
57-
)
58-
render(json: server.handle_json(request.body.read).to_h)
59-
end
67+
class ApplicationController < ActionController::Base
68+
69+
def index
70+
server = MCP::Server.new(
71+
name: "my_server",
72+
version: "1.0.0",
73+
tools: [SomeTool, AnotherTool],
74+
prompts: [MyPrompt],
75+
server_context: { user_id: current_user.id },
76+
)
77+
render(json: server.handle_json(request.body.read))
6078
end
6179
end
6280
```
@@ -67,11 +85,11 @@ If you want to build a local command-line application, you can use the stdio tra
6785

6886
```ruby
6987
#!/usr/bin/env ruby
70-
require "model_context_protocol"
71-
require "model_context_protocol/transports/stdio"
88+
require "mcp"
89+
require "mcp/transports/stdio"
7290

7391
# Create a simple tool
74-
class ExampleTool < ModelContextProtocol::Tool
92+
class ExampleTool < MCP::Tool
7593
description "A simple example tool that echoes back its arguments"
7694
input_schema(
7795
properties: {
@@ -82,7 +100,7 @@ class ExampleTool < ModelContextProtocol::Tool
82100

83101
class << self
84102
def call(message:, server_context:)
85-
ModelContextProtocol::Tool::Response.new([{
103+
MCP::Tool::Response.new([{
86104
type: "text",
87105
text: "Hello from example tool! Message: #{message}",
88106
}])
@@ -91,13 +109,13 @@ class ExampleTool < ModelContextProtocol::Tool
91109
end
92110

93111
# Set up the server
94-
server = ModelContextProtocol::Server.new(
112+
server = MCP::Server.new(
95113
name: "example_server",
96114
tools: [ExampleTool],
97115
)
98116

99117
# Create and start the transport
100-
transport = ModelContextProtocol::Transports::StdioTransport.new(server)
118+
transport = MCP::Transports::StdioTransport.new(server)
101119
transport.open
102120
```
103121

@@ -112,10 +130,10 @@ $ ./stdio_server.rb
112130

113131
## Configuration
114132

115-
The gem can be configured using the `ModelContextProtocol.configure` block:
133+
The gem can be configured using the `MCP.configure` block:
116134

117135
```ruby
118-
ModelContextProtocol.configure do |config|
136+
MCP.configure do |config|
119137
config.exception_reporter = ->(exception, server_context) {
120138
# Your exception reporting logic here
121139
# For example with Bugsnag:
@@ -135,7 +153,7 @@ This is useful for systems where an application hosts more than one MCP server b
135153
they might require different instrumentation callbacks.
136154

137155
```ruby
138-
configuration = ModelContextProtocol::Configuration.new
156+
configuration = MCP::Configuration.new
139157
configuration.exception_reporter = ->(exception, server_context) {
140158
# Your exception reporting logic here
141159
# For example with Bugsnag:
@@ -148,7 +166,7 @@ configuration.instrumentation_callback = ->(data) {
148166
puts "Got instrumentation data #{data.inspect}"
149167
}
150168

151-
server = ModelContextProtocol::Server.new(
169+
server = MCP::Server.new(
152170
# ... all other options
153171
configuration:,
154172
)
@@ -167,7 +185,7 @@ server_context: { [String, Symbol] => Any }
167185

168186
**Example:**
169187
```ruby
170-
server = ModelContextProtocol::Server.new(
188+
server = MCP::Server.new(
171189
name: "my_server",
172190
server_context: { user_id: current_user.id, request_id: request.uuid }
173191
)
@@ -218,13 +236,13 @@ config.instrumentation_callback = ->(data) {
218236
The server's protocol version can be overridden using the `protocol_version` class method:
219237

220238
```ruby
221-
ModelContextProtocol::Server.protocol_version = "2024-11-05"
239+
MCP::Server.protocol_version = "2024-11-05"
222240
```
223241

224242
This will make all new server instances use the specified protocol version instead of the default version. The protocol version can be reset to the default by setting it to `nil`:
225243

226244
```ruby
227-
ModelContextProtocol::Server.protocol_version = nil
245+
MCP::Server.protocol_version = nil
228246
```
229247

230248
Be sure to check the [MCP spec](https://spec.modelcontextprotocol.io/specification/2024-11-05/) for the protocol version to understand the supported features for the version being set.
@@ -253,12 +271,12 @@ If no exception reporter is configured, a default no-op reporter is used that si
253271

254272
MCP spec includes [Tools](https://modelcontextprotocol.io/docs/concepts/tools) which provide functionality to LLM apps.
255273

256-
This gem provides a `ModelContextProtocol::Tool` class that can be used to create tools in two ways:
274+
This gem provides a `MCP::Tool` class that can be used to create tools in two ways:
257275

258276
1. As a class definition:
259277

260278
```ruby
261-
class MyTool < ModelContextProtocol::Tool
279+
class MyTool < MCP::Tool
262280
description "This tool performs specific functionality..."
263281
input_schema(
264282
properties: {
@@ -275,17 +293,17 @@ class MyTool < ModelContextProtocol::Tool
275293
)
276294

277295
def self.call(message:, server_context:)
278-
Tool::Response.new([{ type: "text", text: "OK" }])
296+
MCP::Tool::Response.new([{ type: "text", text: "OK" }])
279297
end
280298
end
281299

282300
tool = MyTool
283301
```
284302

285-
2. By using the `ModelContextProtocol::Tool.define` method with a block:
303+
2. By using the `MCP::Tool.define` method with a block:
286304

287305
```ruby
288-
tool = ModelContextProtocol::Tool.define(
306+
tool = MCP::Tool.define(
289307
name: "my_tool",
290308
description: "This tool performs specific functionality...",
291309
annotations: {
@@ -316,12 +334,12 @@ Annotations can be set either through the class definition using the `annotation
316334

317335
MCP spec includes [Prompts](https://modelcontextprotocol.io/docs/concepts/prompts), which enable servers to define reusable prompt templates and workflows that clients can easily surface to users and LLMs.
318336

319-
The `ModelContextProtocol::Prompt` class provides two ways to create prompts:
337+
The `MCP::Prompt` class provides two ways to create prompts:
320338

321339
1. As a class definition with metadata:
322340

323341
```ruby
324-
class MyPrompt < ModelContextProtocol::Prompt
342+
class MyPrompt < MCP::Prompt
325343
prompt_name "my_prompt" # Optional - defaults to underscored class name
326344
description "This prompt performs specific functionality..."
327345
arguments [
@@ -354,10 +372,10 @@ end
354372
prompt = MyPrompt
355373
```
356374

357-
2. Using the `ModelContextProtocol::Prompt.define` method:
375+
2. Using the `MCP::Prompt.define` method:
358376

359377
```ruby
360-
prompt = ModelContextProtocol::Prompt.define(
378+
prompt = MCP::Prompt.define(
361379
name: "my_prompt",
362380
description: "This prompt performs specific functionality...",
363381
arguments: [
@@ -399,7 +417,7 @@ e.g. around authentication state or user preferences.
399417
Register prompts with the MCP server:
400418

401419
```ruby
402-
server = ModelContextProtocol::Server.new(
420+
server = MCP::Server.new(
403421
name: "my_server",
404422
prompts: [MyPrompt],
405423
server_context: { user_id: current_user.id },
@@ -417,7 +435,7 @@ The server allows registering a callback to receive information about instrument
417435
To register a handler pass a proc/lambda to as `instrumentation_callback` into the server constructor.
418436

419437
```ruby
420-
ModelContextProtocol.configure do |config|
438+
MCP.configure do |config|
421439
config.instrumentation_callback = ->(data) {
422440
puts "Got instrumentation data #{data.inspect}"
423441
end
@@ -439,16 +457,16 @@ This is to avoid potential issues with metric cardinality
439457

440458
MCP spec includes [Resources](https://modelcontextprotocol.io/docs/concepts/resources)
441459

442-
The `ModelContextProtocol::Resource` class provides a way to register resources with the server.
460+
The `MCP::Resource` class provides a way to register resources with the server.
443461

444462
```ruby
445-
resource = ModelContextProtocol::Resource.new(
463+
resource = MCP::Resource.new(
446464
uri: "example.com/my_resource",
447465
mime_type: "text/plain",
448466
text: "Lorem ipsum dolor sit amet"
449467
)
450468

451-
server = ModelContextProtocol::Server.new(
469+
server = MCP::Server.new(
452470
name: "my_server",
453471
resources: [resource],
454472
)

examples/stdio_server.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# frozen_string_literal: true
33

44
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
5-
require "model_context_protocol"
6-
require "model_context_protocol/transports/stdio"
5+
require "mcp"
6+
require "mcp/transports/stdio"
77

88
# Create a simple tool
99
class ExampleTool < MCP::Tool

lib/mcp-ruby.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/mcp.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "mcp/server"
4+
require_relative "mcp/string_utils"
5+
require_relative "mcp/tool"
6+
require_relative "mcp/tool/input_schema"
7+
require_relative "mcp/tool/annotations"
8+
require_relative "mcp/tool/response"
9+
require_relative "mcp/content"
10+
require_relative "mcp/resource"
11+
require_relative "mcp/resource/contents"
12+
require_relative "mcp/resource/embedded"
13+
require_relative "mcp/resource_template"
14+
require_relative "mcp/prompt"
15+
require_relative "mcp/prompt/argument"
16+
require_relative "mcp/prompt/message"
17+
require_relative "mcp/prompt/result"
18+
require_relative "mcp/version"
19+
require_relative "mcp/configuration"
20+
require_relative "mcp/methods"
21+
22+
module MCP
23+
class << self
24+
def configure
25+
yield(configuration)
26+
end
27+
28+
def configuration
29+
@configuration ||= Configuration.new
30+
end
31+
end
32+
33+
class Annotations
34+
attr_reader :audience, :priority
35+
36+
def initialize(audience: nil, priority: nil)
37+
@audience = audience
38+
@priority = priority
39+
end
40+
end
41+
end

lib/model_context_protocol/configuration.rb renamed to lib/mcp/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module ModelContextProtocol
3+
module MCP
44
class Configuration
55
DEFAULT_PROTOCOL_VERSION = "2024-11-05"
66

lib/model_context_protocol/content.rb renamed to lib/mcp/content.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# typed: true
22
# frozen_string_literal: true
33

4-
module ModelContextProtocol
4+
module MCP
55
module Content
66
class Text
77
attr_reader :text, :annotations

lib/model_context_protocol/instrumentation.rb renamed to lib/mcp/instrumentation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module ModelContextProtocol
3+
module MCP
44
module Instrumentation
55
def instrument_call(method, &block)
66
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

lib/model_context_protocol/methods.rb renamed to lib/mcp/methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module ModelContextProtocol
3+
module MCP
44
module Methods
55
INITIALIZE = "initialize"
66
PING = "ping"

0 commit comments

Comments
 (0)