Skip to content

Commit 825594a

Browse files
committed
Test README instrumentation callback example
1 parent 7bee412 commit 825594a

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
@@ -231,6 +231,7 @@ instrumentation_callback = ->(data) { ... }
231231
```
232232

233233
**Example:**
234+
<!-- SNIPPET ID: instrumentation_callback -->
234235
```ruby
235236
config.instrumentation_callback = ->(data) {
236237
puts "Instrumentation: #{data.inspect}"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require "mcp"
4+
5+
MCP.configure do |config|
6+
eval(File.read("code_snippet.rb"), binding) # rubocop:disable Security/Eval -- We need to run the snippet in this context to pass the config
7+
8+
config.instrumentation_callback.call({ example: "data" })
9+
end

test/integration/readme_code_snippets_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class ReadmeCodeSnippetsTest < ActiveSupport::TestCase
126126
)
127127
end
128128

129+
test "Instrumentation Callback example works exactly as documented in README" do
130+
assert_equal(<<~STDOUT, run_code_snippet("instrumentation_callback"))
131+
Instrumentation: {example: "data"}
132+
STDOUT
133+
end
134+
129135
private
130136

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

0 commit comments

Comments
 (0)