Commit graph ruby-sdk/examples
Author SHA1 Message Date
Ates Goral
c8fdf25cdb Use the new --json arg of curl 2025-07-14 20:43:43 -04:00
Koichi ITO
6335d21349 [Doc] Use console instead of bash for code block highlighting
Follow-up to https://github.com/modelcontextprotocol/ruby-sdk/pull/67#discussion_r2162083685.

This PR updates code blocks for command examples to use `console` as the language identifier.
2025-06-25 19:14:30 +09:00
Sam Bostock
9a85975d12
Log headers in all curl examples
The examples showcase to the user how the server works, so it makes
sense to include headers to show the full picture.
2025-06-24 11:23:33 -04:00
Sam Bostock
cccb7494fa
Log headers in curl initialize requests
The user needs the `mcp-session-id` header, so we should log headers.
2025-06-24 11:22:46 -04:00
Sam Bostock
7a2043b49c
Add space before pipe 2025-06-24 11:21:27 -04:00
Koichi ITO
c806e1ecd2
Merge pull request #67 from koic/remove_chebang_from_example_files
Remove shebang from example files
2025-06-24 02:21:12 +09:00
dak2
7a5bd7c18f Fix handling response when sending notifications in examples/streamable_http_client.rb
Even though the 'tools/call' request to 'notification_tool' is successful and an 'MCP::Tool::Response' is returned, the logger still prints 'Error:'.

```
% ruby examples/streamable_http_client.rb
=== MCP SSE Test Client ===

[CLIENT] INFO 15:41:04.696 - Initializing session...
[CLIENT] INFO 15:41:04.698 - Session initialized: SESSION_ID
[CLIENT] INFO 15:41:04.698 - Server info: {"name" => "sse_test_server", "version" => "0.1.0"}
[CLIENT] INFO 15:41:04.698 - Connecting to SSE stream...
[CLIENT] INFO 15:41:04.698 - SSE stream connected successfully

=== Available Actions ===
1. Send custom notification
2. Test echo
3. List tools
0. Exit

Choose an action: 1
Enter notification message: notification test
Enter delay in seconds (0 for immediate):
[CLIENT] INFO 15:41:11.248 - SSE data: {"jsonrpc":"2.0","id":"0f657eeb-3e05-47bb-b7b4-898e2cb503af","result":{"content":[{"type":"text","text":"Notification: notification test (timestamp: 2025-06-21T15:41:11+09:00)"}],"isError":false}}
[CLIENT] ERROR 15:41:11.249 - Error:

=== Available Actions ===
1. Send custom notification
2. Test echo
3. List tools
0. Exit
```

It is probably trying to output an MCP::Tool::Response, but these appear in the SSE stream. Therefore, the response it is handling this time should either be accepted or an error.

I modified it so that it could handle them.
2025-06-21 19:38:33 +09:00
Koichi ITO
100d1a1ab3 Remove shebang from example files
Since the example files are not executable binaries, this PR removes the shebangs.

This ensures that all examples are consistently executed via `ruby` command.
It also removes the executable permission from `examples/stdio_server.rb` using `chmod 444`,
bringing it in line with the other example files.
2025-06-19 16:00:38 +09:00
dak2
10cb6c0eb9 Rename the example file names related to SSE.
This PR renamed the files related to the SSE example and fixed the README.md.
Because missing files were specified in README.md.

And also, I removed the word 'test' from the file names related to the SSE example.
Other examples file names do not contain the word `test`.
2025-06-18 18:30:40 +09: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
Riley Shott
580029954f Cleanup logs for examples/http_server.rb 2025-06-09 14:13:49 -07:00
Riley Shott
711216f66a Fix examples 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
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
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
Joey Cardosi
d80b13736e
just redo all of it from scratch 2025-05-30 12:15:11 -04:00
Topher Bullock
9d2447b351 rename lib/{model_context_protocol => mcp} 2025-05-29 17:11:40 -04:00
Kevin Fischer
7b390053bd
Update README and example with server version 2025-05-13 23:58:38 +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