Commit graph ruby-sdk/lib
Author SHA1 Message Date
Koichi ITO
4968d9cffc
Merge pull request #204 from koic/make_tool_names_stricter
Make tool names stricter
2026-01-04 06:58:20 +09:00
Koichi ITO
ab4f0807d4
Merge pull request #205 from koic/add_icons
Support `icons` parameter
2026-01-03 01:46:43 +09:00
Koichi ITO
b29d522d27 Show exception messages for tool call errors
Claude Code sometimes only shows `Error: MCP error -32603: Internal error`
when an unexpected exception occurs during a tool call.

This change broadens the exception handling scope so the server can surface
the exception message more often, making failures easier to diagnose.
2025-12-31 19:38:14 +09:00
Koichi ITO
028c5f3291 Support icons parameter
This PR adds support for the optional `icons` parameter in prompt, resource,
resource template, and server info.

The specifications for `icons` are as follows.
https://modelcontextprotocol.io/specification/2025-11-25/schema#icon

Resolves https://github.com/modelcontextprotocol/ruby-sdk/issues/127.
2025-12-30 05:35:22 +09:00
Koichi ITO
84ff1fcba1 Make tool names stricter
Follow-up to https://github.com/modelcontextprotocol/ruby-sdk/pull/199#issuecomment-3659688807

Tool names are now validated to comply with the specification.
https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-names

Since the tool name is optional, `nil` value is treated as "not specified" and is ignored without validation.
2025-12-29 01:19:39 +09:00
Koichi ITO
771163cc94
Merge pull request #188 from koic/add_website_url_to_server_info
Add support for the optional `websiteUrl` parameter in `serverInfo`
2025-12-24 00:49:35 +09:00
Koichi ITO
dee80d20ae Raise an error when duplicate tool names are registered
This raises an exception when duplicate tool names are registered,
instead of silently overwriting tools. Tool names are required to be
unique within a server, so this behavior aligns with the MCP specification.

> Tool names SHOULD be unique within a server.

https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-names

Validation for tool names could be made more strictly spec-compliant in a separate effort.

Fixes #197
2025-12-21 22:48:43 +09:00
Koichi ITO
62615d65e4 Add support for the optional websiteUrl parameter in serverInfo
This PR adds support for the optional `websiteUrl` parameter in `serverInfo`.
This parameter has been supported since the 2025-11-25 MCP specification.

This PR also implements part of https://github.com/modelcontextprotocol/ruby-sdk/issues/127.
2025-12-21 22:44:36 +09:00
Koichi ITO
851974e454 Add support for the optional description parameter in serverInfo
This PR adds support for the optional `description` parameter in `serverInfo`.
This parameter has been supported since the 2025-11-25 MCP specification.
https://modelcontextprotocol.io/specification/2025-11-25/schema#implementation
2025-12-20 19:12:45 +09:00
Koichi ITO
67e03d7b3d Allow stable protocol specification version "2025-11-25"
The MCP specification dated 2025-11-25 has been released:

- https://modelcontextprotocol.io/specification/2025-11-25
- https://blog.modelcontextprotocol.io/posts/2025-11-25-first-mcp-anniversary

This PR allows `'2025-11-25'` to be specified for the `:protocol_version` keyword argument
in `MCP::Configuration.new`.
2025-12-20 18:58:28 +09:00
Koichi ITO
baeb75c8d8
Merge pull request #190 from koic/avoid_draft_protocol_version
Default to the latest stable protocol version
2025-12-20 18:55:18 +09:00
Koichi ITO
4eab486d56
Merge pull request #198 from ebeigarts/feature/schema-additional-properties
Refactor schema validation to reduce duplication and add additionalProperties support
2025-12-16 10:32:42 +09:00
Koichi ITO
0429284d5d Remove redundant String#dup
Since no destructive methods are being called, `dup` isn’t necessary.
2025-12-14 14:32:10 +09:00
Edgars Beigarts
a3c24d2bcc
Refactor schema validation to reduce duplication and add additionalProperties support
This refactoring extracts common schema validation logic into a base Schema
class, eliminating ~100 lines of duplicate code between InputSchema and
OutputSchema. It also adds support for the JSON Schema `additionalProperties`
keyword to allow fine-grained control over extra properties in tool arguments.

Previously `additionalParameters` could be set only on OutputSchema.

Key changes:

- Created MCP::Tool::Schema base class consolidating:
  - Schema validation against JSON Schema Draft 4 metaschema
  - Deep key transformation (string to symbol conversion)
  - $ref disallowance checking
  - Common validation methods

- Refactored InputSchema to inherit from Schema:
  - Simplified constructor to accept full schema hash
  - Changed required fields storage from symbols to strings
  - Removed ~40 lines of duplicated validation logic

- Refactored OutputSchema to inherit from Schema:
  - Removed ~54 lines of duplicated validation logic
  - Now shares all common functionality with InputSchema

- Updated Tool.input_schema setter:
  - Simplified to pass full hash directly to InputSchema

- Added additionalProperties support:
  - By default, tools now allow additional properties (JSON Schema default)
  - Can explicitly set `additionalProperties: false` to disallow extras
  - Added comprehensive test coverage for both behaviors
2025-12-12 12:49:52 +02:00
Devon Boyer
b34fae93f0 Fix symlink path comparison in schema validation 2025-12-04 22:39:23 -05:00
Koichi ITO
c786a14f61 Default to the latest stable protocol version
When starting an MCP server in Claude Code with `protocol_version` set to `DRAFT-2025-v3`,
it fails with the following error:

```console
2025-12-04T02:58:01.548Z [DEBUG] MCP server "example": Connection failed after 2093ms: Server's protocol version is not supported: DRAFT-2025-v3
2025-12-04T02:58:01.548Z [ERROR] MCP server "example" Connection failed: Server's protocol version is not supported: DRAFT-2025-v3
```

This PR changes the default behavior so that if `protocol_version` is not specified,
it uses the latest stable protocol version instead of the draft version.

This PR also updates the README to note that the latest stable protocol version includes
new features from the draft version.
2025-12-04 14:58:41 +09:00
Koichi ITO
d31c3da8f2
Merge pull request #178 from koic/add_elicitation_skeleton
Add Elicitation skeleton
2025-11-25 01:02:30 +09:00
Koichi ITO
11aea51c42
Merge pull request #179 from koic/add_draft_version
Add "Draft" protocol version to supported protocol versions
2025-11-22 01:57:51 +09:00
Koichi ITO
dd458b1fb7 Add Elicitation skeleton
The MCP 2025-06-18 specification includes a feature called Elicitation:
https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation

Like Log Level, an implementation is expected to be provided in the near future.
This PR adds Elicitation as a skeleton implementation for now.
2025-11-21 02:42:20 +09:00
Koichi ITO
1c4ac125e1 Refactor to extract duplicate error tool response in MCP::Server
Consolidates four identical constructions of error `Tool::Response` in
`handle_call_tool_request` into a single private `error_tool_response` method,
reducing duplication and improving maintainability. No behavior change.
2025-11-14 13:54:44 +09:00
Koichi ITO
bf729baef2 Add "Draft" protocol version to supported protocol versions
For example, the `title` introduced in #109 is not supported in the latest stable protocol version "2025-06-18":
https://modelcontextprotocol.io/specification/2025-06-18

It is supported in the Draft of the next version:
https://modelcontextprotocol.io/specification/draft

In other words, the fact that the Ruby SDK treats "2025-06-18" as the default protocol version while `title` is
only supported in the Draft results in an inconsistency.

Because of this, a new version `"Draft"` has been added to the list of supported versions.
Its value follows the schema below and is defined as `DRAFT-2025-v3`:
14ec41c/schema/draft/schema.ts (L15)

It was also considered to continue using the latest stable version "2025-06-18" as the Ruby SDK default instead of the Draft.
However, in that case, users would need to explicitly specify `MCP::Server.new(protocol_version: 'DRAFT-2025-v3')`,
which adds extra burden. In this PR, Draft is made the default in order to provide the following benefits:

- Users are likely to prefer using the Draft version over the latest stable version
- No need to specify the `protocol_version` option when initializing `MCP::Server`
- Users generally do not need to know the internal development value `DRAFT-2025-v3`

The primary case for specifying `protocol_version` explicitly is when strict adherence to a particular version is required.
However, it seems more practical to prioritize use cases where backward-compatible features, including those from the Draft,
are desirable. This is the rationale behind making the Draft version the default.

In addition, making the Draft version the default protocol version preserves backward compatibility for `MCP::Server`.

NOTE: `DRAFT-2025-v3` is a development code, so its value cannot be set externally.
It is applied either when `protocol_version` is omitted or when `nil` is set explicitly,
such as with `MCP::Configuration.new(protocol_version: nil)`.
This prevents users from creating implementations that depend on development codes like `DRAFT-2025-v3`.
2025-11-11 15:44:36 +09:00
Hiren Hiranandani
08a84c7320
Introduce stateless mode to allow for HA
- Create failing tests for `stateless` mode
- Implement `stateless` mode by turning of SSE in Streamable HTTP,
  making the interaction a standard HTTP Req/Resp
2025-11-04 15:26:12 -08:00
Ateş Göral
3f5f6f8494
Internalize json_rpc_handler along with an XSS vulnerability fix (#175)
* Copy-paste of files from original gem

* Update copied code to match repo style

* Use the lib instead of the gem
2025-10-30 17:43:31 -04:00
Koichi ITO
61d48cd6d9
Merge pull request #165 from Jflick58/fix/make-tool-error-spec-compliant
Fix tool error handling to follow MCP spec
2025-10-22 10:58:29 +09:00
Justin Flick
389cc2e8e6 Fix tool error handling to follow MCP spec
Tool execution errors now return successful responses with isError: true
instead of JSON-RPC protocol errors, per the MCP specification.

This allows clients to distinguish between protocol-level errors and
tool execution errors, providing better error context.

Fixes #159
2025-10-21 18:33:42 -07:00
Koichi ITO
ad87c8d805
Merge pull request #163 from dak2/add-client-prompts-support
Add `prompts/list` and `prompts/get` support to client
2025-10-19 02:24:36 +09:00
Topher Bullock
9aafc9add5 Release 0.4.0 2025-10-15 01:25:05 -04:00
dak2
e88deb6b65 Add prompts/list and prompts/get support to client
This commit adds two new methods to `MCP::Client`:
- prompts: Lists available prompts from the server via `prompts/list`
- get_prompt: Retrieves a specific prompt by name via `prompts/get`

Both methods follow the same pattern as the existing resources support,
including comprehensive test coverage and README documentation updates.

ref. https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/2025-03-26/server/prompts.mdx#protocol-messages
2025-10-15 13:16:41 +09:00
Koichi ITO
f312695798
Merge pull request #153 from modelcontextprotocol/prompt-spec-compliance
fix `Prompt` type gaps with 2025-06-18 spec
2025-10-15 01:22:45 +09:00
Topher Bullock
2d1a1da937 add resources/list and resources/read support to client 2025-10-10 10:51:42 -04:00
Topher Bullock
a1dd3dd005 add _meta field to Prompt
> See [General fields: `_meta`](/specification/2025-06-18/basic/index#meta) for notes on `_meta` usage.

51e093b8eb/schema/2025-06-18/schema.ts (L680-L683)
2025-10-10 09:05:55 -04:00
Topher Bullock
701f6faab6 add title field to prompt argument
`PromptArgument extends BaseMetadata`, which includes both name and
title
 - 51e093b8eb/schema/2025-06-18/schema.ts (L686-L698)
 - 51e093b8eb/schema/2025-06-18/schema.ts (L294-l309)
2025-10-06 09:35:42 -04:00
ramos
4c13f6dc08 Update metaschema URI format in input_schema.rb and output_schema.rb for
cross-compatibility across different OS
2025-10-03 17:29:50 -03:00
Koichi ITO
c5f2f98077
Merge pull request #150 from koic/set_default_content_to_an_empty_array_instead_of_nil
Set default `content` to an empty array instead of `nil`
2025-10-03 10:22:46 +09:00
Koichi ITO
0034952df9 Set default content to an empty array instead of nil
Follow-up to https://github.com/modelcontextprotocol/ruby-sdk/pull/147.

According to the specification schema, `content` is not optional and therefore cannot be omitted:

```typescript
interface CallToolResult {
  _meta?: { [key: string]: unknown };
  content: ContentBlock[];
  isError?: boolean;
  structuredContent?: { [key: string]: unknown };
  [key: string]: unknown;
}
```

https://modelcontextprotocol.io/specification/2025-06-18/schema#calltoolresult

Instead of `nil`, an empty array is set as the default value.

There may be a better value for `content`, but at the very least it should not be missing.
2025-10-02 23:52:19 +09:00
Tyler Untisz
73cec83b99
Add support for _meta field on tool schema (#124)
* Add support for _meta field on tool schema

* use `meta` naming for `_meta` field on tool schema

* apply suggestions to fix `_meta` tests

Co-authored-by: Ateş Göral <ates@magnetiq.com>

* Update lib/mcp/tool.rb

Co-authored-by: Ateş Göral <ates@magnetiq.com>

* Update lib/mcp/tool.rb

Co-authored-by: Ateş Göral <ates@magnetiq.com>

---------

Co-authored-by: Topher Bullock <topherbullock@users.noreply.github.com>
Co-authored-by: Ateş Göral <ates@magnetiq.com>
2025-10-01 17:21:27 -04:00
Justin Harris
ae60e2d904
[client] Add call_tool_raw method to get the full tool response to help get structuredContent 2025-10-01 15:18:02 -04:00
Koichi ITO
010ae74edc
Merge pull request #145 from koic/add_validation_to_mcp_configuration_setters
Add validation to `MCP::Configuration` setters
2025-10-01 10:50:38 +09:00
Koichi ITO
de1e833ae3
Merge pull request #144 from nilcolor/output_schema_arrays
Allow output schema to be array of objects
2025-09-28 03:17:09 +09:00
Anandaroop Roy
f7cf080cc0
Support structuredContent in tool response (#147) 2025-09-27 02:23:41 -04:00
dak2
cd7a54a5c9 Fix to return a response code 202 if the server accepts JSON-RPC notifications and responses
If the server accepts JSON-RPC notifications and responses, it must return an HTTP status code of 202 without a body.

refs
- https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#sending-messages-to-the-server
- https://www.jsonrpc.org/specification

Follow up: https://github.com/modelcontextprotocol/ruby-sdk/issues/111
2025-09-26 00:18:01 +09:00
Alexey Blinov
4ee128ad67 Allow output schema to be array of objects
closes #142
2025-09-25 11:56:03 +05:00
Koichi ITO
cb5e87581b Add validation to MCP::Configuration setters
I noticed through the existing tests that `MCP::Configuration#protocol_version=`
allows setting an arbitrary protocol version.

Since the official MCP Ruby SDK is an implementation of the MCP specification,
it should not support arbitrary protocol versions. This change adds validation
to the setter, consistent with `Configuration#initialize`.

The same validation has also been added to `MCP::Configuration#validate_tool_call_arguments=`.
2025-09-24 19:19:02 +09:00
Koichi ITO
0c8937de34 Remove unused block parameters
There are some unused block variables. This change removes block parameters
that consist solely of unused block parameters.
Where `Hash#values` suffices instead of ignoring unused variables,
replace such code with `Hash#values`.
2025-09-20 14:45:08 +09:00
Koichi ITO
b626425521 Remove useless magic comment
This PR removes useless magic comment.
2025-09-15 12:33:09 +09:00
Ates Goral
deebefd26f Release v0.3.0
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-14 01:09:18 -04:00
Ateş Göral
cd4681351d
Merge branch 'main' into main 2025-09-13 17:11:23 -04:00
Ateş Göral
5c5f420f42
Merge pull request #122 from koic/add_validation_for_tool_annotation
Validate tool annotations value
2025-09-13 14:22:42 -04:00
Valentino Stoll
aad8e94530
Add Tool output_schema support with comprehensive validation
This commit implements optional JSON Schema validation for tool outputs according to the MCP specification:

- Add MCP::Tool::OutputSchema class mirroring InputSchema functionality
- Support output_schema in class definitions, Tool.define, and OutputSchema objects
- Include validate_result method for runtime validation
- Update MCP::Client::Tool to track output schemas
- Add comprehensive test coverage with 249 passing tests
- Update README with dedicated Tool Output Schemas section
- Follow MCP spec requirements for server/client validation
2025-09-11 11:12:27 -04:00
Koichi ITO
08048283e4 Validate tool annotations value
Tool annotations were introduced in the "2025-03-26" specification:

> Added comprehensive tool annotations for better describing tool behavior,
> like whether it is read-only or destructive (PR modelcontextprotocol/modelcontextprotocol#185)

https://modelcontextprotocol.io/specification/2025-03-26/changelog#major-changes

This means they are not supported in the "2024-11-05" specification,
so validation errors will be raised for `protocol_version: "2024-11-05"`.
2025-09-11 10:48:56 +09:00