Commit graph ruby-sdk/test
Author SHA1 Message Date
Koichi ITO
dd5b318b11
Merge pull request #126 from koic/fix_errors_when_title_is_not_specified
Fix errors when `title` is not specified
2025-09-11 10:30:15 +09:00
Joey Cardosi
8b764428b1
Add basic HTTP client support with pluggable transports 2025-09-08 15:52:37 -05:00
Koichi ITO
47d29e8014 Fix errors when title is not specified
Since the optional `title` becomes `title: null` when not provided, the following error occurs.
This occurs with Claude Code 1.0.100.

```console
[DEBUG] MCP server "example": Connection failed after 1591ms: [
  {
    "code": "invalid_type",
    "expected": "string",
    "received": "null",
    "path": [
      "serverInfo",
      "title"
    ],
    "message": "Expected string, received null"
  }
]
```

By adding `compact`, the `title` key will be removed if the optional `title` keyword argument is not specified.
2025-09-03 12:31:33 +09:00
Koichi ITO
b982074daa
Merge pull request #119 from koic/add_title_to_server_info
Add `title` to `serverInfo`
2025-08-30 02:01:53 +09:00
Koichi ITO
ef56280518 Add title to serverInfo
Follow-up to #109.

`title` has also been added to `serverInfo` and `clientInfo` by
https://github.com/modelcontextprotocol/modelcontextprotocol/pull/663.

Since `clientInfo` is not treated as product code, support is implemented only in `serverInfo`.

See also https://modelcontextprotocol.io/specification/2025-06-18/schema#implementation.
2025-08-29 14:36:39 +09:00
Koichi ITO
cae30547d2 Set default values for ToolAnnotations hints
According to the specification, `destructive_hint`, `idempotent_hint`, `open_world_hint`,
and `read_only_hint` of `ToolAnnotations` are optional with default values:
https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations

This PR sets their default values in accordance with the specification.

Additionally, for readability, the hints have been reordered to follow the specification.
2025-08-28 01:13:57 +09:00
Koichi ITO
092aebf1a4 Extract MCP::Tool::Annotations unit tests
The tests related to `MCP::Tool::Annotations` will be extracted from the `MCP::ToolTest` test class
into a dedicated `MCP::Tool::AnnotationsTest` unit test class as a testing pair.

This improves test clarity, file level test independence, and file level execution speed.
It also ensures consistent placement as a testing pair under `MCP::Tool::*`:

```console
$ ls lib/mcp/tool/
annotations.rb  input_schema.rb  response.rb
$ ls test/mcp/tool/
annotations_test.rb  input_schema_test.rb  response_test.rb
```
2025-08-27 13:33:21 +09:00
Koichi ITO
ae5a41588e Tweak assert_equal argument order in tests
The argument order for `assert_equal` is expected, actual:
https://github.com/minitest/minitest/blob/v5.25.5/lib/minitest/assertions.rb#L214

This PR corrects the arguments that were reversed to the expected order.
It also enables `Minitest/LiteralAsActualArgument`, which can detect and
autocorrect some of these cases:
https://docs.rubocop.org/rubocop-minitest/0.38/cops_minitest.html#minitestliteralasactualargument
2025-08-27 01:43:55 +09:00
Jens Kraemer
be5e7db2a6 implements the notifications/initialized method
- According to
  https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle,
  "After successful initialization, the client MUST send an initialized
  notification to indicate it is ready to begin normal operations".
2025-08-25 13:44:21 +08:00
Koichi ITO
b4da129aa0 Document title as Draft and restore annotations.title
Follow-up to #109.

The introduction of `title` in #109 is still a draft and is not supported in the latest specification, `Version 2025-06-18 (latest)`.

In this PR, the README.md will be updated to mention this point and restore the references to the removed `annotations.title`.

This aims to inform users that, as of `Version 2025-06-18 (latest)`, the use of `annotations.title` is considered stable.

Additionally, separate validation for these parameters could be added.

Please refer to the following comment regarding `annotations.title` and `title`:
https://github.com/modelcontextprotocol/modelcontextprotocol/pull/663#issuecomment-2963519737
2025-08-23 00:12:12 +09:00
Topher Bullock
06bf90dd98
Merge pull request #97 from honzasterba/rubymine_test_runner_support
[test] minites-reporters do not work with RubyMine
2025-08-20 16:25:13 -04:00
Topher Bullock
62360338f4
Merge pull request #109 from jdnvn/main
Add title to tools, prompts and resources
2025-08-20 16:19:38 -04:00
Koichi ITO
002df2c774
Merge pull request #107 from pusewicz/response-keyword-boolean
Response error keyword argument
2025-08-20 18:26:17 +09:00
Jan Sterba
1895168115 [test] remove minitest-reporters
gem not compatible with rubymine test runner
2025-08-20 11:17:20 +02:00
Piotr Usewicz
6689db2ca0
Nicer error API
Both the combination of positional argument and naming does not feel
like Ruby.

This change makes `is_error` argument a keyword argument called `error`.

Thanks to this, the usage is more self-explanatory:

```ruby
response = Response.new([], error: true)
```
2025-08-18 16:50:20 +02:00
jdnvn
8b4085468e add titles to tools, prompts and resources 2025-08-17 22:58:15 -04:00
Koichi ITO
d1c6a46e1a
Merge pull request #105 from siddhantbajaj/handle-notification-initialized-method
Return HTTP status code 202 for notification initialized method
2025-08-13 00:38:36 +09:00
Siddhant Bajaj
4a65f62158 Return HTTP status code 202 for notification initialized method 2025-08-11 10:40:17 -04:00
Koichi ITO
216266756a Remove useless code in test/test_helper.rb
This PR removes useless code in test/test_helper.rb.
2025-08-10 01:11:21 +08:00
Koichi ITO
930173a04e
Merge pull request #87 from koic/add_instructions_support_to_mcp_server
Add `instructions` support to `MCP::Server`
2025-08-09 03:22:08 +09:00
Koichi ITO
22a7db73fd
Merge pull request #104 from koic/fix_an_incorrect_url
[Doc] Fix an incorrect URL
2025-08-08 01:31:08 +09:00
Koichi ITO
2e4e80f727 [Doc] Fix an incorrect URL
This PR fixes the following incorrect URL:
https://spec.MCP.io/specification/2025-03-26/basic/utilities/ping/#behavior-requirements

The specification version used in the official links follows "2025-06-18,"
which is the version consistently used throughout the README.md.
2025-08-07 12:45:50 +09:00
Koichi ITO
f6f064ab71 Add instructions support to MCP::Server
The response of the `init` method can include `instructions`.
https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle

`instructions` appear to be supported starting from the 2025-03-26 specification.

- https://modelcontextprotocol.io/specification/2025-03-26/basic/lifecycle (supports `instructions`)
- https://modelcontextprotocol.io/specification/2024-11-05/basic/lifecycle (does not support `instructions`)

If `instructions` is used with an unsupported protocol version, an `ArgumentError` will be raised.

As additional context, the TypeScript SDK also treats `instructions` as optional.
https://github.com/modelcontextprotocol/typescript-sdk/blob/1.16.0/src/types.ts#L356-L361
2025-08-07 12:17:57 +09:00
Koichi ITO
122bbd0c6c
Merge pull request #102 from koic/remove_redundant_required_features
Remove redundant `require` statements
2025-08-04 06:22:56 +09:00
Koichi ITO
c5dde9ce2b Remove redundant require statements
This PR removes redundant `require` statements.
2025-08-02 00:57:31 +09:00
Piotr Usewicz
2508defc79
inputSchema interface requires type key
When defining a tool without any arguments taken, it should be allowed
to not have to define the `input_schema` at all, and the default value
for such a scenario should be `{ type: "object" }` as per the schema.

16d91abb68/schema/2025-06-18/schema.ts (L896-L900)
2025-07-31 08:36:18 +02:00
Koichi ITO
d1ca0cbcfe
Merge pull request #91 from dak2/fix/json-rpc-of-notification
Fix JSON-RPC notification format in Streamable HTTP transport
2025-07-29 02:05:16 +09:00
Andy Waite
8b92ce005f Use valid syntax for URI examples 2025-07-27 11:29:03 -04:00
dak2
e7fafddf94 Fix JSON-RPC notification format in Streamable HTTP transport
Update send_notification method to properly construct JSON-RPC notification objects with jsonrpc version and method fields.
This ensures notifications conform to the JSON-RPC 2.0 specification when sent over HTTP transport.

https://www.jsonrpc.org/specification#notification

Another goal is to standardise the `send_notification` interface.
Before the revision, it was sufficient to pass the method and parameters in the case of stdio.
However, in the case of Streamable, a hash based on the JSON-RPC specification must be passed.
2025-07-26 17:58:31 +09:00
calin
47215c98ce Account for missing arguments 2025-07-23 15:17:23 +03:00
Sheldon Nunes
74737223a0 Fix tools with no args 2025-07-23 13:42:19 +12:00
Koichi ITO
2b36bf6b2d Set default protocol version to the latest specification
Currently, MCP has three versions: 2024-11-05, 2025-03-26, and 2025-06-18.

- https://modelcontextprotocol.io/specification/2024-11-05/basic/transports (stdio and HTTP with SSE)
- https://modelcontextprotocol.io/specification/2025-03-26/basic/transports (stdio and Streamable HTTP)
- https://modelcontextprotocol.io/specification/2025-06-18/basic/transports (stdio and Streamable HTTP)

The newer specification supports stdio and Streamable HTTP as transport mechanisms.
Only the oldest version, 2024-11-05, supports stdin and HTTP with SSE,
but that version is now considered legacy.

Given the current behavior of the Ruby SDK, it likely makes more sense to set
the default protocol version to the latest one, 2025-06-18, rather than the oldest, 2024-11-05.

Ideally, the implementation should adjust its behavior based on the version,
but this PR is limited to updating the default protocol version only.
2025-07-20 16:36:18 +09:00
Koichi ITO
e4d5f19574
Merge pull request #80 from koic/validate_protocol_version_value
Validate `protocol_version` value
2025-07-19 16:14:49 +09:00
Jan Sterba
ed9e0fbc9c [tests] fix warnings and erros after warnings removed 2025-07-17 14:50:10 +02:00
Koichi ITO
f13522d416 Validate protocol_version value
## Motivation and Context

Currently, MCP supports the following three protocol versions:
"2025-06-18", "2025-03-26", and "2024-11-05".
https://modelcontextprotocol.io/introduction

As shown in the changes to `test/mcp/configuration_test.rb`,
the `protocol_version` value is not currently being validated,
which allows unexpected `protocol_version` values to be accepted.

This PR ensures that only supported protocol versions are accepted.

## How Has This Been Tested?

Existing tests have been updated and new tests have been added.

## Breaking Changes

None. If it becomes an issue, it means a value that was not originally intended has been used.

## Additional context

While one possible approach might be to fall back to a default protocol version
when an invalid `protocol_version` value is provided,
this PR opts to reject invalid `protocol_version` values explicitly.
The reasoning is that encouraging users to provide intentional,
valid input is preferable to silently falling back to a default,
which could lead to unexpected behavior.
2025-07-16 12:38:49 +09:00
Ates Goral
1ed313951a Add define_custom_method to define custom methods 2025-07-14 20:12:29 -04:00
Koichi ITO
189d5fc5a5
Merge pull request #74 from mogox/increase_streamable_coverage
Adding test for streamable errors for StreamableHTTPTransport
2025-07-14 09:34:23 +09:00
Enrique Mogollan
b1fa433a47 Adding test for streamable errors for http transport 2025-07-13 02:24:20 -07:00
Koichi ITO
13bee9f60e
Merge pull request #63 from kfischer-okarin/check-notification-capabilities
Check all methods & capabilities
2025-07-13 11:34:42 +09:00
Koichi ITO
1a89cc5537
Merge pull request #61 from kfischer-okarin/simplify-and-add-missing-capabilities
Remove automatic capability determination and add missing capabilities
2025-07-12 19:01:35 +09:00
Jens Kraemer
271ccb43d0 fixes input schema validation for schemas without required fields 2025-07-11 11:27:59 +02:00
Juliano Julio Costa
5d0c5b7f0e Merge remote-tracking branch 'upstream/main' into make_server_context_optional_and_sorbet_friendly 2025-06-19 11:08:00 -04:00
Kevin Fischer
222147014a
Fix hash format in tests 2025-06-18 13:23:51 +09:00
Kevin Fischer
d7c866efcf
Simplify capability handling again 2025-06-18 13:23:25 +09:00
Topher Bullock
8dda58e77c
Merge pull request #43 from tylerrowsell/tool-arg-validation
Validate ToolCall Args against Schema
2025-06-17 17:39:13 -04:00
Kevin Fischer
ff92a3d016
Add missing checks 2025-06-15 17:35:18 +09:00
Kevin Fischer
e4c9644e78
Refactor ensure capability tests 2025-06-15 17:35:18 +09:00
dak2
dc38c9f84a Rename to MCP when handling exceptions in Streamable HTTP transport
The reason for the change is that a NameError occurs when a POST request is made while the stream is closed because ModelContextProtocol is undefined.

I have also added test cases to check the behaviour when IOError and Errno::EPIPE occurs.
2025-06-15 15:21:22 +09:00
Riley Shott
4d79263a87 Addressing feedback 2025-06-11 13:44:54 -07:00
Juliano Julio Costa
c10c0ddf9d Refactor MCP tool and server to handle optional server_context parameter
- Updated `call` method in `MCP::Tool` and `MCP::Prompt` to accept `server_context` as an optional parameter.
- Refactored `MCP::Server` to streamline argument handling for tool and prompt calls, introducing helper methods `call_tool_with_args` and `call_prompt_template_with_args`.
- Adjusted tests to reflect changes in method signatures and ensure compatibility with optional `server_context` parameter.
2025-06-10 15:40:28 -04:00