Commit graph

120 commits

Author SHA1 Message Date
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
Sam Bostock
ffa06b103d
Merge pull request #64 from sambostock/duplicate-method-instrumentation
Remove duplicate `method` instrumentation
2025-06-17 11:58:36 -04:00
Koichi ITO
0027ce7126
Merge pull request #51 from koic/add_migration_path_for_server_transports_std_transport
Add a migration path for `Server::Transports::StdioTransport`
2025-06-18 00:25:00 +09:00
Sam Bostock
ce1c8719cf
Remove duplicate method instrumentation
`handle_request` already adds the `method` to the instrumentation data,
so there is no need to repeat this. Moreover, consumers can override
these anyway.
2025-06-17 02:07:25 -04:00
Koichi ITO
529f3bbe57
Merge pull request #62 from dak2/fix/rename-to-mcp
Rename to `MCP` when handling exceptions in Streamable HTTP transport
2025-06-15 15:43:28 +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
Topher Bullock
382ae13e25
Merge pull request #33 from Ginja/streamable-http
Implement Streamable HTTP transport
2025-06-13 18:29:40 -04:00
Topher Bullock
110160b40f
Merge pull request #58 from koic/update_the_mcp_spec_url
[Doc] Update the MCP spec URL
2025-06-13 18:25:06 -04:00
Riley Shott
4d79263a87 Addressing feedback 2025-06-11 13:44:54 -07:00
Riley Shott
2942d456cc JSON body fix in examples/http_server.rb 2025-06-10 12:54:21 -07:00
Koichi ITO
1b87b3ffde [Doc] Update the MCP spec URL
https://spec.modelcontextprotocol.io/specification/2024-11-05/ URL is redirected to
https://modelcontextprotocol.io/specification/2025-03-26

This update avoids unnecessary redirects from the old URL to the new URL.
2025-06-11 02:00:12 +09:00
Koichi ITO
16ab4bac81 Add a migration path for Server::Transports::StdioTransport
Follow-up to #27.

This PR adds a migration path for `Server::Transports::StdioTransport`. e.g.,

```console
$ cat /tmp/example.rb
require "mcp/transports/stdio"

MCP::Transports::StdioTransport
```

This change displays the following warning instead of raising an error for such cases, allowing execution to proceed:

```console
$ bundle exec ruby /tmp/example.rb
/tmp/example.rb:1: warning: Use `require "mcp/server/transports/stdio_transport"` instead of `require "mcp/transports/stdio"`.
Also use `MCP::Server::Transports::StdioTransport` instead of `MCP::Transports::StdioTransport`.
This API is deprecated and will be removed in a future release.
```

Currently (v0.1.0), it results in an error without any warning.
This MCP gem is not yet close to version 1.0, but introducing breaking changes to a published interface is undesirable.

This compatibility code should be removed at some point after a few releases.

Closes #50.
2025-06-10 16:27:22 +09:00
Riley Shott
91af9ad19a Gracefully handle POST requests with nil bodies 2025-06-09 14:14:41 -07:00
Riley Shott
580029954f Cleanup logs for examples/http_server.rb 2025-06-09 14:13:49 -07:00
Riley Shott
9a23141ac7 Add rackup as a development dependency 2025-06-09 14:12:49 -07:00
Riley Shott
711216f66a Fix examples 2025-06-09 14:12:13 -07: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
8fbb2e86aa Remove transport-specific code from server 2025-06-09 14:12:13 -07:00
Riley Shott
08be669b58 Move rack to a development dependency 2025-06-09 14:12:13 -07:00
Riley Shott
4e4455772b StreamableHTTP -> Streamable HTTP 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
bae35facf6
Change Error Handling 2025-06-09 13:32:12 -04:00
Koichi ITO
04710ac472
Merge pull request #47 from koic/tweak_an_example_for_mcp_resource_in_readme
[Doc] Tweak an example for `MCP::Resource` in the README
2025-06-10 00:35:18 +09:00
Koichi ITO
2ee3d39814
Merge pull request #49 from koic/suppress_interrupt_exception_for_stdio_server
Suppress `Interrupt` exception for stdio server
2025-06-10 00:34:52 +09:00
Koichi ITO
b65d9b6553
Merge pull request #52 from koic/add_link_to_badge
[Doc] Add links to badges
2025-06-10 00:21:12 +09:00
Tyler Rowsell
934a5e8db4
Remove rescue block and add test for error bubbling in InputSchema validation 2025-06-09 10:25:51 -04:00
Koichi ITO
eecc0eaefb [Doc] Add links to badges
This PR adds links to the following two badges:

1. RubyGems badge: A link to the `mcp` gem will be added. The repository name is `ruby-sdk`,
following the modelcontextprotocol org's naming convention. Since the repository name and
the gem name are different, the link will help make it clear which gem it refers to.
2. MIT license badge: This will link to the MIT license file in the repository.

NOTE: Separately from this PR, the copyright notice in the MIT license should probably be addressed.
It currently says `Copyright (c) 2025 TODO: Write your name`, so the TODO should be resolved:
https://github.com/modelcontextprotocol/ruby-sdk/blob/v0.1.0/LICENSE.txt#L3

Other language SDKs seem to list `Anthropic, PBC` as the copyright holder,
though I would defer that decision to someone more knowledgeable.
2025-06-09 14:36:29 +09:00
Koichi ITO
85252e0546 Suppress Interrupt exception for stdio server
This PR suppresses the following backtrace of `Interrupt` (Ctrl+c) exception for stdio server:

## Before

```console
$ ./examples/stdio_server.rb
^C/Users/koic/src/github.com/modelcontextprotocol/ruby-sdk/lib/mcp/server/transports/stdio_transport.rb:20:
in 'IO#gets': Interrupt
        from /Users/koic/src/github.com/modelcontextprotocol/ruby-sdk/lib/mcp/server/transports/stdio_transport.rb:20:
             in 'MCP::Server::Transports::StdioTransport#open'
        from ./examples/stdio_server.rb:95:in '<main>'
$ echo $?
130
```

## After

```console
$ ./examples/stdio_server.rb
^C
Exiting...
$ echo $?
130
```

This change should prevent unexpected backtrace from appearing when running the example:
https://github.com/modelcontextprotocol/ruby-sdk?tab=readme-ov-file#stdio-transport
2025-06-07 19:25:37 +09:00
Koichi ITO
e9403c58a7 [Doc] Tweak an example for MCP::Resource in the README
`MCP::Resource` doesn't have `text` attribute:
https://github.com/modelcontextprotocol/ruby-sdk/blob/v0.1.0/lib/mcp/resource.rb#L8-L13

I've replaced it with attributes that it actually supports.

Also, the use of `text: "Hello, world!"` in the example of `server.resources_read_handler` implementation resulted in
an unexpected response the first time I worked with `Resource`. While it may not be the best (but better),
in my experience using Resources with Cline, `text: params[:uri]` served as a clearer response when interacting with an LLM,
making it easier to understand.
2025-06-06 13:36:33 +09:00
Ateş Göral
fda5640394
Merge pull request #46 from modelcontextprotocol/ag/badges
Update title + desc and add badges
2025-06-05 10:03:31 -04:00
Ateş Göral
9d78717718
Add CI badge
Co-authored-by: Koichi ITO <koic.ito@gmail.com>
2025-06-05 09:16:42 -04:00
Ateş Göral
d2c4d3ec18
Merge pull request #42 from kfischer-okarin/extract-capabilities-object
Refactor: Extract Capabilities object
2025-06-05 01:11:04 -04:00
Ates Goral
652a06ca6f Update title + desc and add badges 2025-06-05 00:57:47 -04:00
Ateş Göral
5649f0312c
Merge pull request #45 from koic/fix_a_typo
[Doc] Fix a typo
2025-06-05 00:22:10 -04:00
Koichi ITO
ced9481194 [Doc] Fix a typo 2025-06-05 11:19:31 +09:00
Tyler Rowsell
600c96f66a Validate ToolCall Args against Schema
(cherry picked from commit eeb287117535dfb43785704171625323f01d5bda)
2025-06-04 15:19:05 -04:00
Kevin Fischer
4a666ed0d9
Use Capabilities object instead of private method 2025-06-04 22:55:08 +09: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
Ateş Göral
a601558a21
Merge pull request #40 from koic/fix_build_error
Fix build error
2025-06-03 22:58:13 -04: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
e901f94a3d
Merge pull request #37 from koic/tweak_stdio_transport_example_code_in_the_readme
[Doc] Tweak stdio transport example code in the README
2025-06-03 17:28:53 -04: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
6de5468c8b [Doc] Tweak stdio transport example code in the README
The example code is located at `./examples/stdio_server.rb`.
Also, the content provided as input via stdio has been updated to avoid returning an error data.
Using ping pong as an example, here's the difference:

## Before

An error data is returned.

```console
$ ./examples/stdio_server.rb
{"jsonrpc":"2.0","id":"1","result":"pong"}
{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request","data":"Method name must be a string and not start with \"rpc.\""}}
```

This error message is generated in the following location:
https://github.com/Shopify/json-rpc-handler/blob/v0.1.1/lib/json_rpc_handler.rb#L70

## After

The expected result is returned without error data.

```console
$ ./examples/stdio_server.rb
{"jsonrpc":"2.0","id":"1","method":"ping"}
{"jsonrpc":"2.0","id":"1","result":{}}
```

The other stdin example has been updated to use data that does not cause errors.

With this document update, users can verify the behavior of the MCP server via stdin without using an MCP client.
2025-06-03 23:41:13 +09:00
Ateş Göral
08abc3e17b
Merge pull request #36 from koic/remove_unused_config_from_dot_rubocop
Remove unused config from .rubocop.yml
2025-06-01 13:23:20 -04:00
Koichi ITO
4db222f659 Remove unused config from .rubocop.yml
Follow-up to #24.

lib/mcp-ruby.rb was removed in https://github.com/modelcontextprotocol/ruby-sdk/pull/24.
2025-06-02 01:44:42 +09:00
Ateş Göral
8d88156d71
Merge pull request #34 from koic/make_some_optional_kwargs_in_resource
Make `description` and `mime_type` optional keyword arguments in `Resource`
2025-05-31 13:34:25 -04:00
Ateş Göral
0f3384e5aa
Merge pull request #35 from koic/rename_directory_from_model_context_protocol_to_mcp
Rename test directory from `model_context_protocol` to `mcp`
2025-05-31 13:33:18 -04:00