You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add configurable exception reporter
Avoid leaking tool exceptions by sending them to a configurable exception reporter
Add optional context to pass to tools
Add basic instrumentation data/labels
The context parameter is the context passed into the server and can be used to pass per request information,
124
+
e.g. around authentication state.
125
+
88
126
## Prompts
89
127
90
128
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.
@@ -167,7 +205,8 @@ Register prompts with the MCP server:
167
205
```ruby
168
206
server =ModelContextProtocol::Server.new(
169
207
name:"my_server",
170
-
prompts: [MyPrompt.new]
208
+
prompts: [MyPrompt.new],
209
+
context:nil,
171
210
)
172
211
```
173
212
@@ -176,6 +215,28 @@ The server will handle prompt listing and execution through the MCP protocol met
176
215
-`prompts/list` - Lists all registered prompts and their schemas
177
216
-`prompts/get` - Retrieves and executes a specific prompt with arguments
178
217
218
+
### Instrumentation
219
+
220
+
The server allows registering a callback to receive information about instrumentation.
221
+
To register a handler pass a proc/lambda to as `instrumentation_callback` into the server constructor.
222
+
223
+
```ruby
224
+
ModelContextProtocol.configure do |config|
225
+
config.instrumentation_callback =-> (data) { puts"Got instrumentation data #{data.inspect}" }
226
+
end
227
+
```
228
+
229
+
The data contains the following keys:
230
+
`method`: the metod called, e.g. `ping`, `tools/list`, `tools/call` etc
231
+
`tool_name`: the name of the tool called
232
+
`prompt_name`: the name of the prompt called
233
+
`resource_uri`: the uri of the resource called
234
+
`error`: if looking up tools/prompts etc failed, e.g. `tool_not_found`
235
+
`duration`: the duration of the call in seconds
236
+
237
+
`tool_name`, `prompt_name` and `resource_uri` are only populated if a matching handler is registered.
238
+
This is to avoid potential issues with metric cardinality
0 commit comments