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