Commit graph ruby-sdk/test
Author SHA1 Message Date
Koichi ITO
002df2c774
Merge pull request #107 from pusewicz/response-keyword-boolean
Response error keyword argument
2025-08-20 18:26:17 +09: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
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
Riley Shott
e546d76991 Rubocop 2025-06-09 14:12:13 -07:00
Riley Shott
55b03fc7aa Add notification support
Co-authored-by: Kevin Fischer <kfischer_okarin@yahoo.co.jp>
2025-06-09 14:12:13 -07:00
Riley Shott
3e03a2af66 Implement StreamableHTTP transport
Co-authored-by: Topher Bullock <topher.bullock@shopify.com>
2025-06-09 14:12:11 -07:00
Tyler Rowsell
8dee60cfc2
Fix: Disallow $ref in tool input schemas 2025-06-09 13:32:20 -04:00
Tyler Rowsell
934a5e8db4
Remove rescue block and add test for error bubbling in InputSchema validation 2025-06-09 10:25:51 -04:00
Tyler Rowsell
600c96f66a Validate ToolCall Args against Schema
(cherry picked from commit eeb287117535dfb43785704171625323f01d5bda)
2025-06-04 15:19:05 -04:00
Kevin Fischer
72663c0a3f
Extract server capabilities into dedicated Capabilities class
Refactor capabilities handling into MCP::Server::Capabilities to improve
code organization and separation of concerns. This provides a cleaner API
for configuring server capabilities including prompts, resources, tools,
completions, logging, and experimental features.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-04 22:52:16 +09:00
Koichi ITO
70680fce88 Fix build error
Follow-up to #27.

This PR fixes the following build error:

```console
$ bundle exec rake
/Users/koic/.rbenv/versions/3.5-dev/lib/ruby/3.5.0+1/bundled_gems.rb:59:in 'Kernel.require': cannot load such file -- mcp/transports/stdio (LoadError)
Did you mean?  mcp/transports/stdio_transport_test
        from /Users/koic/.rbenv/versions/3.5-dev/lib/ruby/3.5.0+1/bundled_gems.rb:59:in 'block (2 levels) in Kernel#replace_require'
        from /Users/koic/src/github.com/modelcontextprotocol/ruby-sdk/test/mcp/transports/stdio_transport_test.rb:4:in '<top (required)>'
        from /Users/koic/.rbenv/versions/3.5-dev/lib/ruby/3.5.0+1/bundled_gems.rb:59:in 'Kernel.require'
        from /Users/koic/.rbenv/versions/3.5-dev/lib/ruby/3.5.0+1/bundled_gems.rb:59:in 'block (2 levels) in Kernel#replace_require'
        from /Users/koic/.rbenv/versions/3.5-dev/lib/ruby/gems/3.5.0+1/gems/rake-13.3.0/lib/rake/rake_test_loader.rb:21:in 'block in <main>'
        from /Users/koic/.rbenv/versions/3.5-dev/lib/ruby/gems/3.5.0+1/gems/rake-13.3.0/lib/rake/rake_test_loader.rb:6:in 'Array#select'
        from /Users/koic/.rbenv/versions/3.5-dev/lib/ruby/gems/3.5.0+1/gems/rake-13.3.0/lib/rake/rake_test_loader.rb:6:in '<main>'
rake aborted!
Command failed with status (1)
/Users/koic/.rbenv/versions/3.5-dev/bin/bundle:25:in 'Kernel#load'
/Users/koic/.rbenv/versions/3.5-dev/bin/bundle:25:in '<main>'
Tasks: TOP => default => test
(See full trace by running task with --trace)
```

https://github.com/modelcontextprotocol/ruby-sdk/actions/runs/15428236624/job/43420346011

The following is stated in #27.

> Breaking Changes
> `MCP::Transports::StdioTransport` is now `MCP::Server::Transports::StdioTransport`

What is shown here is the new name `MCP::Server::Transports::StdioTransport`, not `MCP::Server::Transports::Stdio`.

Therefore, the file path has been updated from `lib/mcp/server/transports/stdio.rb` to `lib/mcp/server/transports/stdio_transport.rb` to
match the module name. If `MCP::Server::Transports::Stdio` is preferred instead, please let me know and I will open a separate PR.
2025-06-04 11:48:25 +09:00
Topher Bullock
dcc31ca6fd
Merge pull request #27 from jcat4/refactor-for-client-support
Refactor in preparation for client support
2025-06-03 17:27:54 -04:00
Koichi ITO
f33fe309b4 Rename test directory from model_context_protocol to mcp
Follow-up to #24.

The directory structure of the product code and test code is expected to match.
2025-06-01 02:13:28 +09:00
Joey Cardosi
5cc3d9d526
stop using shared dir 2025-05-30 14:33:22 -04:00
Joey Cardosi
3c8ff5a547
fix + cleanup stdio 2025-05-30 12:17:09 -04:00
Joey Cardosi
d80b13736e
just redo all of it from scratch 2025-05-30 12:15:11 -04:00
Ateş Göral
0b49c3f711
Merge pull request #26 from koic/suppress_rubocop_info
Enable RuboCop Minitest and RuboCop Rake for development
2025-05-30 00:27:06 -04:00