Skip to content

Commit 6218495

Browse files
tylerrowselltopherbullock
authored andcommitted
Internal Release 0.6.0
Rename Context Arg
1 parent 6da8bfa commit 6218495

File tree

11 files changed

+52
-52
lines changed

11 files changed

+52
-52
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
model_context_protocol (0.5.2)
4+
model_context_protocol (0.6.0)
55
json_rpc_handler (~> 0.1)
66

77
GEM

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module ModelContextProtocol
4949
name: "my_server",
5050
tools: [SomeTool, AnotherTool],
5151
prompts: [MyPrompt],
52-
context: { user_id: current_user.id },
52+
server_context: { user_id: current_user.id },
5353
)
5454
render(json: server.handle_json(request.body.read).to_h)
5555
end
@@ -69,7 +69,7 @@ module ModelContextProtocol
6969
name: "my_server",
7070
tools: [SomeTool, AnotherTool],
7171
prompts: [MyPrompt],
72-
context: { user_id: current_user.id },
72+
server_context: { user_id: current_user.id },
7373
)
7474
render(json: server.handle(JSON.parse(request.body.read)).to_h)
7575
end
@@ -96,7 +96,7 @@ class ExampleTool < ModelContextProtocol::Tool
9696
required: ["message"]
9797

9898
class << self
99-
def call(message:, context:)
99+
def call(message:, server_context:)
100100
ModelContextProtocol::Tool::Response.new([{
101101
type: "text",
102102
text: "Hello from example tool! Message: #{message}",
@@ -137,7 +137,7 @@ server = ModelContextProtocol::Server.new(
137137
name: "my_server",
138138
tools: [SomeTool, AnotherTool],
139139
prompts: [MyPrompt],
140-
context: { user_id: current_user.id },
140+
server_context: { user_id: current_user.id },
141141
)
142142
request = {
143143
jsonrpc: "2.0",
@@ -154,11 +154,11 @@ The gem can be configured using the `ModelContextProtocol.configure` block:
154154

155155
```ruby
156156
ModelContextProtocol.configure do |config|
157-
config.exception_reporter = ->(exception, context) do
157+
config.exception_reporter = ->(exception, server_context) do
158158
# Your exception reporting logic here
159159
# For example with Bugsnag:
160160
Bugsnag.notify(exception) do |report|
161-
report.add_metadata(:model_context_protocol, context)
161+
report.add_metadata(:model_context_protocol, server_context)
162162
end
163163
end
164164

@@ -170,11 +170,11 @@ This is useful for systems where an application hosts more than one MCP server b
170170
they might require different instrumentation callbacks.
171171

172172
configuration = ModelContextProtocol::Configuration.new
173-
configuration.exception_reporter = ->(exception, context) do
173+
configuration.exception_reporter = ->(exception, server_context) do
174174
# Your exception reporting logic here
175175
# For example with Bugsnag:
176176
Bugsnag.notify(exception) do |report|
177-
report.add_metadata(:model_context_protocol, context)
177+
report.add_metadata(:model_context_protocol, server_context)
178178
end
179179
end
180180

@@ -207,9 +207,9 @@ Be sure to check the [MCP spec](https://spec.modelcontextprotocol.io/specificati
207207
The exception reporter receives two arguments:
208208

209209
- `exception`: The Ruby exception object that was raised
210-
- `context`: A hash containing contextual information about where the error occurred
210+
- `server_context`: A hash containing contextual information about where the error occurred
211211

212-
The context hash includes:
212+
The server_context hash includes:
213213

214214
- For tool calls: `{ tool_name: "name", arguments: { ... } }`
215215
- For general request handling: `{ request: { ... } }`
@@ -248,7 +248,7 @@ class MyTool < ModelContextProtocol::Tool
248248
},
249249
required: ['message']
250250

251-
def self.call(message:, context:)
251+
def self.call(message:, server_context:)
252252
Tool::Response.new([{ type: "text", text: "OK" }])
253253
end
254254
end
@@ -266,12 +266,12 @@ tool = ModelContextProtocol::Tool.define(
266266
title: "My Tool",
267267
read_only_hint: true
268268
}
269-
) do |args, context|
269+
) do |args, server_context|
270270
Tool::Response.new([{ type: "text", text: "OK" }])
271271
end
272272
```
273273

274-
The context parameter is the context passed into the server and can be used to pass per request information,
274+
The server_context parameter is the server_context passed into the server and can be used to pass per request information,
275275
e.g. around authentication state.
276276

277277
### Tool Annotations
@@ -307,7 +307,7 @@ class MyPrompt < ModelContextProtocol::Prompt
307307
]
308308

309309
class << self
310-
def template(args, context:)
310+
def template(args, server_context:)
311311
Prompt::Result.new(
312312
description: "Response description",
313313
messages: [
@@ -341,7 +341,7 @@ prompt = ModelContextProtocol::Prompt.define(
341341
required: true
342342
)
343343
]
344-
) do |args, context:|
344+
) do |args, server_context:|
345345
Prompt::Result.new(
346346
description: "Response description",
347347
messages: [
@@ -358,7 +358,7 @@ prompt = ModelContextProtocol::Prompt.define(
358358
end
359359
```
360360

361-
The context parameter is the context passed into the server and can be used to pass per request information,
361+
The server_context parameter is the server_context passed into the server and can be used to pass per request information,
362362
e.g. around authentication state or user preferences.
363363

364364
### Key Components
@@ -376,7 +376,7 @@ Register prompts with the MCP server:
376376
server = ModelContextProtocol::Server.new(
377377
name: "my_server",
378378
prompts: [MyPrompt],
379-
context: { user_id: current_user.id },
379+
server_context: { user_id: current_user.id },
380380
)
381381
```
382382

examples/stdio_server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ExampleTool < ModelContextProtocol::Tool
1515
required: ["message"]
1616

1717
class << self
18-
def call(message:, context:)
18+
def call(message:, server_context:)
1919
ModelContextProtocol::Tool::Response.new([{
2020
type: "text",
2121
text: "Hello from example tool! Message: #{message}",

lib/model_context_protocol/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def merge(other)
6565
private
6666

6767
def default_exception_reporter
68-
@default_exception_reporter ||= ->(exception, context) {}
68+
@default_exception_reporter ||= ->(exception, server_context) {}
6969
end
7070

7171
def default_instrumentation_callback

lib/model_context_protocol/prompt.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class << self
5050
attr_reader :description_value
5151
attr_reader :arguments_value
5252

53-
def template(args, context:)
53+
def template(args, server_context:)
5454
raise NotImplementedError, "Subclasses must implement template"
5555
end
5656

@@ -98,8 +98,8 @@ def define(name: nil, description: nil, arguments: [], &block)
9898
prompt_name name
9999
description description
100100
arguments arguments
101-
define_singleton_method(:template) do |args, context:|
102-
instance_exec(args, context:, &block)
101+
define_singleton_method(:template) do |args, server_context:|
102+
instance_exec(args, server_context:, &block)
103103
end
104104
end
105105
end

lib/model_context_protocol/server.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ def initialize(message, request, error_type: :internal_error, original_error: ni
2020

2121
include Instrumentation
2222

23-
attr_accessor :name, :tools, :prompts, :resources, :context, :configuration
23+
attr_accessor :name, :tools, :prompts, :resources, :server_context, :configuration
2424

25-
def initialize(name: "model_context_protocol", tools: [], prompts: [], resources: [], context: nil,
25+
def initialize(name: "model_context_protocol", tools: [], prompts: [], resources: [], server_context: nil,
2626
configuration: nil)
2727
@name = name
2828
@tools = tools.to_h { |t| [t.name_value, t] }
2929
@prompts = prompts.to_h { |p| [p.name_value, p] }
3030
@resources = resources
3131
@resource_index = index_resources_by_uri(resources)
32-
@context = context
32+
@server_context = server_context
3333
@configuration = ModelContextProtocol.configuration.merge(configuration)
3434
@handlers = {
3535
Methods::RESOURCES_LIST => method(:list_resources),
@@ -154,7 +154,7 @@ def call_tool(request)
154154
add_instrumentation_data(tool_name:)
155155

156156
begin
157-
tool.call(**request[:arguments], context:).to_h
157+
tool.call(**request[:arguments], server_context:).to_h
158158
rescue => e
159159
raise RequestHandlerError.new("Internal error calling tool #{tool_name}", request, original_error: e)
160160
end
@@ -179,7 +179,7 @@ def get_prompt(request)
179179
prompt_args = request[:arguments]
180180
prompt.validate_arguments!(prompt_args)
181181

182-
prompt.template(prompt_args, context:).to_h
182+
prompt.template(prompt_args, server_context:).to_h
183183
end
184184

185185
def list_resources(request)
@@ -202,8 +202,8 @@ def read_resource(request)
202202
resource.to_h
203203
end
204204

205-
def report_exception(exception, context = {})
206-
configuration.exception_reporter.call(exception, context)
205+
def report_exception(exception, server_context = {})
206+
configuration.exception_reporter.call(exception, server_context)
207207
end
208208

209209
def index_resources_by_uri(resources)

lib/model_context_protocol/tool.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class << self
4444
attr_reader :input_schema_value
4545
attr_reader :annotations_value
4646

47-
def call(*args, context:)
47+
def call(*args, server_context:)
4848
raise NotImplementedError, "Subclasses must implement call"
4949
end
5050

@@ -108,8 +108,8 @@ def define(name: nil, description: nil, input_schema: nil, annotations: nil, &bl
108108
description description
109109
input_schema input_schema
110110
self.annotations(annotations) if annotations
111-
define_singleton_method(:call) do |*args, context:|
112-
instance_exec(*args, context:, &block)
111+
define_singleton_method(:call) do |*args, server_context:|
112+
instance_exec(*args, server_context:, &block)
113113
end
114114
end
115115
end

lib/model_context_protocol/version.rb

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

33
module ModelContextProtocol
4-
VERSION = "0.5.2"
4+
VERSION = "0.6.0"
55
end

test/model_context_protocol/configuration_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ class ConfigurationTest < ActiveSupport::TestCase
1010

1111
# The default reporter should be callable but do nothing
1212
exception = StandardError.new("test error")
13-
context = { test: "context" }
13+
server_context = { test: "context" }
1414

1515
# Should not raise any errors
16-
config.exception_reporter.call(exception, context)
16+
config.exception_reporter.call(exception, server_context)
1717
end
1818

1919
test "allows setting a custom exception reporter" do
2020
config = Configuration.new
2121
reported_exception = nil
2222
reported_context = nil
2323

24-
config.exception_reporter = ->(exception, context) do
24+
config.exception_reporter = ->(exception, server_context) do
2525
reported_exception = exception
26-
reported_context = context
26+
reported_context = server_context
2727
end
2828

2929
test_exception = StandardError.new("test error")

test/model_context_protocol/prompt_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TestPrompt < Prompt
1212
]
1313

1414
class << self
15-
def template(args, context:)
15+
def template(args, server_context:)
1616
Prompt::Result.new(
1717
description: "Hello, world!",
1818
messages: [
@@ -35,7 +35,7 @@ def template(args, context:)
3535
],
3636
}
3737

38-
result = prompt.template({ "test_argument" => "Hello, friend!" }, context: { user_id: 123 })
38+
result = prompt.template({ "test_argument" => "Hello, friend!" }, server_context: { user_id: 123 })
3939

4040
assert_equal expected_template_result, result.to_h
4141
end
@@ -49,7 +49,7 @@ class MockPrompt < Prompt
4949
]
5050

5151
class << self
52-
def template(args, context:)
52+
def template(args, server_context:)
5353
Prompt::Result.new(
5454
description: "Hello, world!",
5555
messages: [
@@ -77,7 +77,7 @@ def template(args, context:)
7777
],
7878
}
7979

80-
result = prompt.template({ "test_argument" => "Hello, friend!" }, context: { user_id: 123 })
80+
result = prompt.template({ "test_argument" => "Hello, friend!" }, server_context: { user_id: 123 })
8181
assert_equal expected_template_result, result.to_h
8282
end
8383

@@ -89,7 +89,7 @@ class DefaultNamePrompt < Prompt
8989
]
9090

9191
class << self
92-
def template(args, context:)
92+
def template(args, server_context:)
9393
Prompt::Result.new(
9494
description: "Hello, world!",
9595
messages: [
@@ -115,8 +115,8 @@ def template(args, context:)
115115
arguments: [
116116
Prompt::Argument.new(name: "test_argument", description: "Test argument", required: true),
117117
],
118-
) do |args, context:|
119-
content = Content::Text.new(args["test_argument"] + " user: #{context[:user_id]}")
118+
) do |args, server_context:|
119+
content = Content::Text.new(args["test_argument"] + " user: #{server_context[:user_id]}")
120120

121121
Prompt::Result.new(
122122
description: "Hello, world!",
@@ -139,7 +139,7 @@ def template(args, context:)
139139
],
140140
}
141141

142-
result = prompt.template({ "test_argument" => "Hello, friend!" }, context: { user_id: 123 })
142+
result = prompt.template({ "test_argument" => "Hello, friend!" }, server_context: { user_id: 123 })
143143
assert_equal expected, result.to_h
144144
end
145145
end

0 commit comments

Comments
 (0)