Commit graph ruby-sdk/lib
Author SHA1 Message Date
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
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
Joey Cardosi
0fbd229ae3
sort imports 2025-05-30 20:01:31 -04:00
Joey Cardosi
5cc3d9d526
stop using shared dir 2025-05-30 14:33:22 -04:00
Topher Bullock
542e3766f3 release 0.1.0 2025-05-30 13:53:16 -04:00
Koichi ITO
eb1c93909b Make description and mime_type optional keyword arguments in Resource
This change is related to #29.

According to the specification, both `description` and `mimeType` of Resource are optional:
https://modelcontextprotocol.io/specification/2025-03-26/server/resources#resource

Therefore, it makes sense to treat them as optional keyword arguments,
similar to how this is done in `ResourceTemplate`:
https://github.com/modelcontextprotocol/ruby-sdk/blob/0b49c3/lib/mcp/resource_template.rb#L8

As additional context, the TypeScript SDK also treats them as optional.
https://github.com/modelcontextprotocol/typescript-sdk/blob/1.12.1/src/types.ts#L438-L466
2025-05-31 01:24:23 +09: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
Koichi ITO
2f354a872a Suppress redundant attributes in Resources
According to the specification, the following attributes are optional,
so using `compact` ensures consistency.

- `description`: Optional description
- `mimeType`: Optional MIME type
- `size`: Optional size in bytes

https://modelcontextprotocol.io/specification/2025-03-26/server/resources#resource
2025-05-30 10:41:18 +09:00
Topher Bullock
9d2447b351 rename lib/{model_context_protocol => mcp} 2025-05-29 17:11:40 -04:00
Topher Bullock
a09f4786b4 update entrypoint 2025-05-29 17:11:33 -04:00
Ateş Göral
6b49222edb
Merge pull request #22 from koic/fix_incorrect_capabilities_handling_for_completion_complete
Fix incorrect capabilities handling for `completion/complete`
2025-05-26 20:01:57 -04:00
Ateş Göral
1ba438feec
Merge pull request #21 from koic/remove_duplicate_require_relative
Remove redundant `require_relative`
2025-05-26 20:01:21 -04:00
Ateş Göral
34fa53c305
Merge pull request #10 from chrisbutcher/fix-sorbet-runtime-compatibility
Support Sorbet typed tools
2025-05-26 20:01:05 -04:00
Koichi ITO
d3dcde2460 Fix incorrect capabilities handling for completion/complete
This PR fixes incorrect capabilities handling for `completion/complete`.
As specified, the capability of `completion/complete` is `completions`, not `prompts`:
https://modelcontextprotocol.io/specification/2025-03-26/server/utilities/completion#capabilities

Note that in the Ruby SDK, `completion/complete`, like `logging/setLevel`, is not yet implemented.
Therefore, an empty implementation has been added to server.rb.
2025-05-26 17:37:13 +09:00
Koichi ITO
2a9926b51b Remove redundant require_relative
This PR removes a redundant require statement that is already present in the `server.rb`:
89ef9d8/lib/model_context_protocol/server.rb (L5)
2025-05-24 16:06:26 +09:00
Ateş Göral
a202b62b1f
Merge pull request #19 from koic/remove_unused_constant
Remove unused constant
2025-05-24 00:36:51 -04:00
Koichi ITO
8f64324f6c Fix a typo
The method that overrides `Methods::RESOURCES_READ` is named `resources_read_handler`,
not `read_resource_handler`:
18f3e87/lib/model_context_protocol/server.rb (L97-L99)
2025-05-24 01:02:04 +09:00
Koichi ITO
9bcb3bf15b Remove unused constant
This PR removes an unused constant that is not referenced anywhere
and was likely left over during development.
2025-05-24 00:53:05 +09:00
Topher Bullock
18f3e8761e
Merge pull request #8 from kfischer-okarin/auto-determine-capabilities
Auto determine capabilities
2025-05-21 14:23:11 -04:00
Topher Bullock
049bac648d
Merge pull request #16 from koic/use_require_relative
Use `require_relative`
2025-05-21 14:22:44 -04:00
Koichi ITO
e8620659a6 Use require_relative
If there are many searches in the `$LOAD_PATH` in the user environment,
require will perform unnecessary searches that are not needed.
In contrast, `require_relative` is efficient because it uses a relative path.
2025-05-22 00:56:22 +09:00
Koichi ITO
5f7a5b5d7e Remove useless ModelContextProtocol::JsonRPC module
JSON-RPC is handled by https://github.com/Shopify/json-rpc-handler,
so `ModelContextProtocol::JsonRPC` module seems to have been
unintentionally left behind in the following commit:
c5591be

The files under `model_context_protocol/json_rpc/*.rb` have already been removed.
2025-05-22 00:53:21 +09:00
Christopher Butcher
84e83841b0
Support Sorbet typed tools 2025-05-21 09:03:19 -04:00
Topher Bullock
032a28d660
Update lib/model_context_protocol/server.rb 2025-05-20 17:05:29 -04:00
Topher Bullock
00e1ed8fec
Merge branch 'main' into auto-determine-capabilities 2025-05-20 17:01:45 -04:00
Topher Bullock
e89af18e95
Merge pull request #7 from kfischer-okarin/specify-server-version
Allow specifying the server version
2025-05-20 16:58:17 -04:00
Kevin Fischer
0f33dc05e1
Default capability determination 2025-05-14 00:25:49 +09:00
Kevin Fischer
81fa3a9efa
Move default capabilities into a private method 2025-05-14 00:10:32 +09:00
Kevin Fischer
ea4828987c
Allow specifying a server version 2025-05-13 23:51:02 +09:00
iberianpig
01460b0b4f
fix: force UTF-8 encoding for stdio streams
This change forces $stdin/$stdout to use UTF-8 encoding,
similar to PR 198 in the python-sdk.
https://github.com/modelcontextprotocol/python-sdk/pull/198

It addresses platform-dependent encoding issues.
2025-05-13 17:26:10 +09:00
Tyler Rowsell
baeb99ffbc Internal Release 0.7.0
- add support for resource templates
- improve capability negotiation on handlers
- clean up readme
- reduce default protocol version to "2024-11-05"
- address spec compliance of resources
- add debug gem to development
- alias ModelContextProtocol to MCP
- move prompt subclasses to subdir
- improve tool and prompt definition
- improve passing of server context to tools
- improve tool input schema validation
2025-05-08 17:38:19 -04:00
Tyler Rowsell
62184957e0 Internal Release 0.6.0
Rename Context Arg
2025-05-08 17:38:13 -04:00
Topher Bullock
6da8bfab1a Internal Release 0.5.2
Added
- Added stdio transport functionality.
Changed
- Added stdio details to the README.
2025-05-08 17:38:09 -04:00
Topher Bullock
d2b6a33788 Internal Release 0.5.1
- Allow protocol version to be set at the server level through configuration instead of a class method, providing more flexibility in protocol version management [#43](https://github.com/Shopify/mcp-ruby/pull/43) @topherbullock

- Fixed instrumentation handling to ensure accurate timing information and proper error reporting [#42](https://github.com/Shopify/mcp-ruby/pull/42) @tobiasbales
  - Improved error handling and reporting in the server
  - Fixed timing information collection in instrumentation
  - Added proper error types for different failure scenarios
  - Enhanced test coverage for error cases

- [Allow protocol version to be set at the server level #43](https://github.com/Shopify/mcp-ruby/pull/43) @topherbullock
- [Fix instrumentation handling #42](https://github.com/Shopify/mcp-ruby/pull/42) @tobiasbales
2025-05-08 17:38:05 -04:00
Topher Bullock
7175d49108 Internal Release 0.5.0
Bump protocol version to 2025-03-26
Provide fallback value for tool_name
Make configuration per server
Add support for tool annotations
document tool annotations
2025-05-08 17:38:02 -04:00
Topher Bullock
2eca3681df Internal Release 0.4.0
- Added support for handle_json method from JSON RPC gem to allow consumers to pass JSON strings
- Added context parameter to prompt templating system

- Updated tool and prompt registration to use class references instead of instances
- Changed tool response is_error to isError to match protocol specification
2025-05-08 17:37:57 -04:00
Topher Bullock
0645351585 Internal Release 0.3.0
Add configurable exception reporter
Avoid leaking tool exceptions by sending them to a configurable exception reporter
Add optional context to pass to tools
Add basic instrumentation data/labels
2025-05-08 17:37:54 -04:00
Topher Bullock
f5a3567494 Internal Release 0.2.5
changes in this release:
- fix ping response #17
- add prompts and resources support to init response #18
- Bump json from 2.10.1 to 2.10.2 #14
2025-05-08 17:37:51 -04:00
Ates Goral
c5591be30b Internal Release 0.2.4
- remove activesupport as a runtime dependency
- use alternative to activesupport/inflector methods
- use `json_rpc_handler` gem
- add json_rpc_handler to gem dependencies
2025-05-08 17:37:45 -04:00
Topher Bullock
6004f42573 Internal Release 0.2.0
- fix `lib/mcp-ruby` auto-import path
- implement server resources
- add basic listing of resources to Server
- allow setting handlers on Server
- wrap handler method results
- make tool definition more declarative
- make prompt definition more declarative
- bump dependency versions
2025-05-08 17:37:40 -04:00
Topher Bullock
a4df3b8688 Internal Release v0.1.1
- implement `Prompt`
- adjust Tool approach
- update readme for tool calling
- document usage of `Prompt`
2025-05-08 17:37:27 -04:00