Skip to content

Commit 0cfd107

Browse files
committed
Test README prompts instrumentation callback example
1 parent 404c627 commit 0cfd107

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ The server will handle prompt listing and execution through the MCP protocol met
448448
The server allows registering a callback to receive information about instrumentation.
449449
To register a handler pass a proc/lambda to as `instrumentation_callback` into the server constructor.
450450

451+
<!-- SNIPPET ID: prompts_instrumentation_callback -->
451452
```ruby
452453
MCP.configure do |config|
453454
config.instrumentation_callback = ->(data) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
require "mcp"
4+
require_relative "code_snippet"
5+
6+
puts MCP::Server.new.handle_json({ jsonrpc: "2.0", id: "1", method: "ping" }.to_json)

test/integration/readme_code_snippets_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ class ReadmeCodeSnippetsTest < ActiveSupport::TestCase
239239
)
240240
end
241241

242+
test "Prompts Instrumentation Callback example works exactly as documented in README" do
243+
stdout = run_code_snippet("prompts_instrumentation_callback")
244+
245+
assert_equal(<<~STDOUT, stdout)
246+
Got instrumentation data {method: "ping", duration: 1.23}
247+
#{{ jsonrpc: "2.0", id: "1", result: {} }.to_json}
248+
STDOUT
249+
end
250+
242251
private
243252

244253
def assert_json_lines(expected, actual, message = "Expected the given JSON lines")

0 commit comments

Comments
 (0)