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
Copy file name to clipboardExpand all lines: README.md
+49-2Lines changed: 49 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -369,7 +369,7 @@ If no exception reporter is configured, a default no-op reporter is used that si
369
369
370
370
MCP spec includes [Tools](https://modelcontextprotocol.io/specification/2025-06-18/server/tools) which provide functionality to LLM apps.
371
371
372
-
This gem provides a `MCP::Tool` class that can be used to create tools in two ways:
372
+
This gem provides a `MCP::Tool` class that can be used to create tools in three ways:
373
373
374
374
1. As a class definition:
375
375
@@ -415,6 +415,22 @@ tool = MCP::Tool.define(
415
415
end
416
416
```
417
417
418
+
3. By using the `ModelContextProtocol::Server#define_tool` method with a block:
419
+
420
+
```ruby
421
+
server =ModelContextProtocol::Server.new
422
+
server.define_tool(
423
+
name:"my_tool",
424
+
description:"This tool performs specific functionality...",
425
+
annotations: {
426
+
title:"My Tool",
427
+
read_only_hint:true
428
+
}
429
+
) do |args, server_context|
430
+
Tool::Response.new([{ type:"text", text:"OK" }])
431
+
end
432
+
```
433
+
418
434
The server_context parameter is the server_context passed into the server and can be used to pass per request information,
419
435
e.g. around authentication state.
420
436
@@ -434,7 +450,7 @@ Annotations can be set either through the class definition using the `annotation
434
450
435
451
MCP spec includes [Prompts](https://modelcontextprotocol.io/specification/2025-06-18/server/prompts), which enable servers to define reusable prompt templates and workflows that clients can easily surface to users and LLMs.
436
452
437
-
The `MCP::Prompt` class provides two ways to create prompts:
453
+
The `MCP::Prompt` class provides three ways to create prompts:
438
454
439
455
1. As a class definition with metadata:
440
456
@@ -504,6 +520,37 @@ prompt = MCP::Prompt.define(
504
520
end
505
521
```
506
522
523
+
3. Using the `ModelContextProtocol::Server#define_protocol` method:
524
+
525
+
```ruby
526
+
server =ModelContextProtocol::Server.new
527
+
server.define_protocol(
528
+
name:"my_prompt",
529
+
description:"This prompt performs specific functionality...",
530
+
arguments: [
531
+
Prompt::Argument.new(
532
+
name:"message",
533
+
description:"Input message",
534
+
required:true
535
+
)
536
+
]
537
+
) do |args, server_context:|
538
+
Prompt::Result.new(
539
+
description:"Response description",
540
+
messages: [
541
+
Prompt::Message.new(
542
+
role:"user",
543
+
content:Content::Text.new("User message")
544
+
),
545
+
Prompt::Message.new(
546
+
role:"assistant",
547
+
content:Content::Text.new(args["message"])
548
+
)
549
+
]
550
+
)
551
+
end
552
+
```
553
+
507
554
The server_context parameter is the server_context passed into the server and can be used to pass per request information,
508
555
e.g. around authentication state or user preferences.
0 commit comments