mcp 0.7.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +182 -5
  3. data/lib/mcp/client/stdio.rb +222 -0
  4. data/lib/mcp/client.rb +21 -3
  5. data/lib/mcp/content.rb +28 -1
  6. data/lib/mcp/progress.rb +22 -0
  7. data/lib/mcp/prompt.rb +8 -3
  8. data/lib/mcp/resource/contents.rb +2 -2
  9. data/lib/mcp/resource.rb +3 -0
  10. data/lib/mcp/server/transports/stdio_transport.rb +6 -4
  11. data/lib/mcp/server/transports/streamable_http_transport.rb +146 -36
  12. data/lib/mcp/server/transports.rb +10 -0
  13. data/lib/mcp/server.rb +98 -43
  14. data/lib/mcp/server_context.rb +44 -0
  15. data/lib/mcp/server_session.rb +79 -0
  16. data/lib/mcp/tool/schema.rb +0 -4
  17. data/lib/mcp/tool.rb +5 -0
  18. data/lib/mcp/transport.rb +2 -2
  19. data/lib/mcp/version.rb +1 -1
  20. data/lib/mcp.rb +11 -24
  21. metadata +8 -30
  22. data/.gitattributes +0 -4
  23. data/.github/dependabot.yml +0 -6
  24. data/.github/workflows/ci.yml +0 -54
  25. data/.github/workflows/release.yml +0 -57
  26. data/.gitignore +0 -10
  27. data/.rubocop.yml +0 -15
  28. data/AGENTS.md +0 -107
  29. data/CHANGELOG.md +0 -143
  30. data/CODE_OF_CONDUCT.md +0 -74
  31. data/Gemfile +0 -29
  32. data/RELEASE.md +0 -12
  33. data/Rakefile +0 -17
  34. data/bin/console +0 -15
  35. data/bin/generate-gh-pages.sh +0 -119
  36. data/bin/rake +0 -31
  37. data/bin/setup +0 -8
  38. data/dev.yml +0 -30
  39. data/docs/_config.yml +0 -6
  40. data/docs/index.md +0 -7
  41. data/docs/latest/index.html +0 -19
  42. data/examples/README.md +0 -197
  43. data/examples/http_client.rb +0 -184
  44. data/examples/http_server.rb +0 -169
  45. data/examples/stdio_server.rb +0 -94
  46. data/examples/streamable_http_client.rb +0 -207
  47. data/examples/streamable_http_server.rb +0 -172
  48. data/mcp.gemspec +0 -35
data/CHANGELOG.md DELETED
@@ -1,143 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- ## [0.7.0] - 2026-02-14
11
-
12
- ### Added
13
-
14
- - `logging` support (#103)
15
- - Protocol version negotiation to server initialization (#223)
16
- - Tool arguments to instrumentation data (#218)
17
- - Client info to instrumentation callback (#221)
18
- - `resource_templates` to `MCP::Client` (#225)
19
-
20
- ### Changed
21
-
22
- - Extract `MCP::Annotations` into a dedicated file (#224)
23
-
24
- ### Fixed
25
-
26
- - `Resource::Embedded` not setting `@resource` in `initialize` (#220)
27
-
28
- ## [0.6.0] - 2026-01-16
29
-
30
- ### Changed
31
-
32
- - Update licensing to Apache 2.0 for new contributions (#213)
33
-
34
- ### Fixed
35
-
36
- - Omit `icons` from responses when empty or nil to reduce context window usage (#212)
37
-
38
- ## [0.5.0] - 2026-01-11
39
-
40
- ### Added
41
-
42
- - Protocol specification version "2025-11-25" support (#184)
43
- - `icons` parameter support (#205)
44
- - `websiteUrl` parameter in `serverInfo` (#188)
45
- - `description` parameter in `serverInfo` (#201)
46
- - `additionalProperties` support for schema validation (#198)
47
- - "Draft" protocol version to supported versions (#179)
48
- - `stateless` mode for high availability (#101)
49
- - Exception messages for tool call errors (#194)
50
- - Elicitation skeleton (#178)
51
- - `prompts/list` and `prompts/get` support to client (#163)
52
- - Accept header validation for HTTP client transport (#207)
53
- - Ruby 2.7 - Ruby 3.1 support (#206)
54
-
55
- ### Changed
56
-
57
- - Make tool names stricter (#204)
58
-
59
- ### Fixed
60
-
61
- - Symlink path comparison in schema validation (#193)
62
- - Duplicate tool names across namespaces now raise an error (#199)
63
- - Tool error handling to follow MCP spec (#165)
64
- - XSS vulnerability in json_rpc_handler (#175)
65
-
66
- ## [0.4.0] - 2025-10-15
67
-
68
- ### Added
69
-
70
- - Client resources support with `resources/list` and `resources/read` methods (#160)
71
- - `_meta` field support for Tool schema (#124)
72
- - `_meta` field support for Prompt
73
- - `title` field support for prompt arguments
74
- - `call_tool_raw` method to client for accessing full tool responses (#149)
75
- - Structured content support in tool responses (#147)
76
- - AGENTS.md development guidance documentation (#134)
77
- - Dependabot configuration for automated dependency updates (#138)
78
-
79
- ### Changed
80
-
81
- - Set default `content` to empty array instead of `nil` (#150)
82
- - Improved prompt spec compliance (#153)
83
- - Allow output schema to be array of objects (#144)
84
- - Return 202 response code for accepted JSON-RPC notifications (#114)
85
- - Added validation to `MCP::Configuration` setters (#145)
86
- - Updated metaschema URI format for cross-OS compatibility
87
-
88
- ### Fixed
89
-
90
- - Client tools functionality and test coverage (#166)
91
- - Client resources test for empty responses (#162)
92
- - Documentation typos and incorrect examples (#157, #146)
93
- - Removed redundant transport requires (#154)
94
- - Cleaned up unused block parameters and magic comments
95
-
96
- ## [0.3.0] - 2025-09-14
97
-
98
- ### Added
99
-
100
- - Tool output schema support with comprehensive validation (#122)
101
- - HTTP client transport layer for MCP clients (#28)
102
- - Tool annotations validation for protocol compatibility (#122)
103
- - Server instructions support (#87)
104
- - Title support in server info (#119)
105
- - Default values for tool annotation hints (#118)
106
- - Notifications/initialized method implementation (#84)
107
-
108
- ### Changed
109
-
110
- - Make default protocol version the latest specification version (#83)
111
- - Protocol version validation to ensure valid values (#80)
112
- - Improved tool handling for tools with no arguments (#85, #86)
113
- - Better error handling and response API (#109)
114
-
115
- ### Fixed
116
-
117
- - JSON-RPC notification format in Streamable HTTP transport (#91)
118
- - Errors when title is not specified (#126)
119
- - Tools with missing arguments handling (#86)
120
- - Namespacing issues in README examples (#89)
121
-
122
- ## [0.2.0] - 2025-07-15
123
-
124
- ### Added
125
-
126
- - Custom methods support via `define_custom_method` (#75)
127
- - Streamable HTTP transport implementation (#33)
128
- - Tool argument validation against schemas (#43)
129
-
130
- ### Changed
131
-
132
- - Server context is now optional for Tools and Prompts (#54)
133
- - Improved capability handling and removed automatic capability determination (#61, #63)
134
- - Refactored architecture in preparation for client support (#27)
135
-
136
- ### Fixed
137
-
138
- - Input schema validation for schemas without required fields (#73)
139
- - Error handling when sending notifications (#70)
140
-
141
- ## [0.1.0] - 2025-05-30
142
-
143
- Initial release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at topher.bullock@shopify.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify runtime dependencies in the gemspec
6
- gemspec
7
-
8
- # Specify development dependencies below
9
- gem "rubocop-minitest", require: false
10
- gem "rubocop-rake", require: false
11
- gem "rubocop-shopify", ">= 2.18", require: false if RUBY_VERSION >= "3.1"
12
-
13
- gem "puma", ">= 5.0.0"
14
- gem "rackup", ">= 2.1.0"
15
-
16
- gem "activesupport"
17
- # Fix io-console install error when Ruby 3.0.
18
- gem "debug" if RUBY_VERSION >= "3.1"
19
- gem "rake", "~> 13.0"
20
- gem "sorbet-static-and-runtime" if RUBY_VERSION >= "3.0"
21
- gem "yard", "~> 0.9"
22
- gem "yard-sorbet", "~> 0.9" if RUBY_VERSION >= "3.1"
23
-
24
- group :test do
25
- gem "faraday", ">= 2.0"
26
- gem "minitest", "~> 5.1", require: false
27
- gem "mocha"
28
- gem "webmock"
29
- end
data/RELEASE.md DELETED
@@ -1,12 +0,0 @@
1
- ## Releases
2
-
3
- This gem is published to [RubyGems.org](https://rubygems.org/gems/mcp)
4
-
5
- Releases are triggered by PRs to the `main` branch updating the version number in `lib/mcp/version.rb`.
6
-
7
- 1. **Update the version number** in `lib/mcp/version.rb`, following [semver](https://semver.org/)
8
- 2. **Update CHANGELOG.md**, backfilling the changes since the last release if necessary, and adding a new section for the new version, clearing out the Unreleased section
9
- 3. **Create a PR and get approval from a maintainer**
10
- 4. **Merge your PR to the main branch** - This will automatically trigger the release workflow via GitHub Actions
11
-
12
- When changes are merged to the `main` branch, the GitHub Actions workflow (`.github/workflows/release.yml`) is triggered and the gem is published to RubyGems.
data/Rakefile DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.ruby_opts = ["-W0", "-W:deprecated"]
8
- t.libs << "test"
9
- t.libs << "lib"
10
- t.test_files = FileList["test/**/*_test.rb"]
11
- end
12
-
13
- require "rubocop/rake_task"
14
-
15
- RuboCop::RakeTask.new
16
-
17
- task default: [:test, :rubocop]
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "mcp"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
@@ -1,119 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- # Generates versioned documentation links and commits to gh-pages branch
5
- #
6
- # PURPOSE:
7
- # This script generates a landing page with links to API documentation on
8
- # RubyDoc.info for a specific version tag. This script is invoked by the
9
- # publish-gh-pages job in the GitHub Actions workflow
10
- # (.github/workflows/release.yml) when a release is published.
11
- #
12
- # HOW IT WORKS:
13
- # - Creates isolated git worktrees for the specified tag and gh-pages branch
14
- # - Copies static Jekyll template files from docs/
15
- # - Generates _data/versions.yml with list of versions
16
- # - Commits changes to gh-pages (does not push automatically)
17
- #
18
- # WORKFLOW:
19
- # 1. Run this script with a tag name: `generate-gh-pages.sh v1.2.3`
20
- # 2. Script generates docs and commits to local gh-pages branch
21
- # 3. Push gh-pages branch to deploy: `git push origin gh-pages`
22
-
23
- # Parse semantic version from tag name (ignoring arbitrary prefixes)
24
- if [[ "${1}" =~ ([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?)$ ]]; then
25
- VERSION="v${BASH_REMATCH[1]}"
26
- else
27
- echo "Error: Must specify a tag name that contains a valid semantic version"
28
- echo "Usage: ${0} <tag-name>"
29
- echo "Examples:"
30
- echo " ${0} 1.2.3"
31
- echo " ${0} v2.0.0-rc.1"
32
- exit 1
33
- fi
34
-
35
- TAG_NAME="${1}"
36
- REPO_ROOT="$(git rev-parse --show-toplevel)"
37
-
38
- echo "Generating documentation for tag: ${TAG_NAME}"
39
-
40
- # Create temporary directories for both worktrees
41
- WORKTREE_DIR=$(mktemp -d)
42
- GHPAGES_WORKTREE_DIR=$(mktemp -d)
43
-
44
- # Set up trap to clean up both worktrees on exit
45
- trap 'git worktree remove --force "${WORKTREE_DIR}" 2>/dev/null || true; \
46
- git worktree remove --force "${GHPAGES_WORKTREE_DIR}" 2>/dev/null || true' EXIT
47
-
48
- echo "Creating worktree for ${TAG_NAME}..."
49
- git worktree add --quiet "${WORKTREE_DIR}" "${TAG_NAME}"
50
-
51
- # Check if gh-pages branch exists
52
- if git show-ref --verify --quiet refs/heads/gh-pages; then
53
- echo "Creating worktree for existing gh-pages branch..."
54
- git worktree add --quiet "${GHPAGES_WORKTREE_DIR}" gh-pages
55
- elif git ls-remote --exit-code --heads origin gh-pages > /dev/null 2>&1; then
56
- echo "Creating worktree for gh-pages branch from remote..."
57
- git worktree add --quiet "${GHPAGES_WORKTREE_DIR}" -b gh-pages origin/gh-pages
58
- else
59
- echo "Creating worktree for new orphan gh-pages branch..."
60
- git worktree add --quiet --detach "${GHPAGES_WORKTREE_DIR}"
61
- git -C "${GHPAGES_WORKTREE_DIR}" checkout --orphan gh-pages
62
- git -C "${GHPAGES_WORKTREE_DIR}" rm -rf . > /dev/null 2>&1 || true
63
- fi
64
-
65
- # Change to gh-pages worktree
66
- cd "${GHPAGES_WORKTREE_DIR}"
67
-
68
- # Determine if this tag is the latest version
69
- echo "Determining if ${VERSION} is the latest version..."
70
-
71
- # Get all existing version tags from the repository (reverse sorted, newest first)
72
- ALL_VERSIONS=$(
73
- git -C "${REPO_ROOT}" tag --list | \
74
- sed -nE 's/^[^0-9]*([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?)$/v\1/p' | \
75
- sort -Vr
76
- )
77
-
78
- # Get the latest version from all version tags
79
- LATEST_VERSION=$(echo "${ALL_VERSIONS}" | head -n 1)
80
-
81
- if [ "${VERSION}" = "${LATEST_VERSION}" ]; then
82
- echo "${VERSION} is the latest version"
83
- else
84
- echo "${VERSION} is not the latest version (latest is ${LATEST_VERSION})"
85
- fi
86
-
87
- # Update custom documentation for latest version
88
- if [ "${VERSION}" = "${LATEST_VERSION}" ]; then
89
- echo "Updating custom documentation..."
90
-
91
- # Clean up old custom docs from gh-pages root
92
- echo "Cleaning gh-pages root..."
93
- git ls-tree --name-only HEAD | xargs -r git rm -rf
94
-
95
- # Copy custom docs from docs/ directory
96
- echo "Copying custom docs from ${WORKTREE_DIR}/docs/..."
97
- cp -r "${WORKTREE_DIR}/docs/." "${GHPAGES_WORKTREE_DIR}/"
98
- fi
99
-
100
- # Generate version data for Jekyll
101
- echo "Generating _data/versions.yml..."
102
- mkdir -p _data
103
- echo "${ALL_VERSIONS}" | sed 's/^v/- /' > _data/versions.yml
104
-
105
- # Stage all changes
106
- git add .
107
-
108
- # Commit if there are changes
109
- if git diff --staged --quiet; then
110
- echo "No changes to commit"
111
- else
112
- echo "Committing documentation for ${VERSION}..."
113
- git commit -m "Add ${VERSION} docs"
114
-
115
- echo "Documentation committed to gh-pages branch!"
116
- echo "Push to remote to deploy to GitHub Pages"
117
- fi
118
-
119
- echo "Done!"
data/bin/rake DELETED
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rake' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
13
- "../../Gemfile",
14
- Pathname.new(__FILE__).realpath,
15
- )
16
-
17
- bundle_binstub = File.expand_path("../bundle", __FILE__)
18
-
19
- if File.file?(bundle_binstub)
20
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
- load(bundle_binstub)
22
- else
23
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
24
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
25
- end
26
- end
27
-
28
- require "rubygems"
29
- require "bundler/setup"
30
-
31
- load Gem.bin_path("rake", "rake")
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/dev.yml DELETED
@@ -1,30 +0,0 @@
1
- name: mcp-ruby
2
-
3
- type: ruby
4
-
5
- up:
6
- - ruby
7
- - bundler
8
-
9
- commands:
10
- console:
11
- desc: Open console with the gem loaded
12
- run: bin/console
13
- build:
14
- desc: Build the gem using rake build
15
- run: bin/rake build
16
- test:
17
- desc: Run tests
18
- syntax:
19
- argument: file
20
- optional: args...
21
- run: |
22
- if [[ $# -eq 0 ]]; then
23
- bin/rake test
24
- else
25
- bin/rake -I test "$@"
26
- fi
27
- style:
28
- desc: Run rubocop
29
- aliases: [rubocop, lint]
30
- run: bin/rake rubocop
data/docs/_config.yml DELETED
@@ -1,6 +0,0 @@
1
- # Use package name as site title
2
- title: "MCP Ruby SDK"
3
-
4
- # Include generated files and directories which may start with underscores
5
- include:
6
- - "_*"
data/docs/index.md DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- # Empty Jekyll front matter to enable Liquid templating (see {{ ... }} below)
3
- ---
4
-
5
- {% for version in site.data.versions -%}
6
- - [v{{ version }}](https://rubydoc.info/gems/mcp/{{ version }})
7
- {% endfor %}
@@ -1,19 +0,0 @@
1
- ---
2
- # Empty Jekyll front matter to enable Liquid templating (see {{ ... }} below)
3
- ---
4
-
5
- <!DOCTYPE html>
6
- <html>
7
- <head>
8
- <meta charset="utf-8">
9
- <title>Redirecting to latest documentation...</title>
10
- <meta http-equiv="refresh" content="0; url=https://rubydoc.info/gems/mcp">
11
- <link rel="canonical" href="https://rubydoc.info/gems/mcp">
12
- </head>
13
- <body>
14
- <p>Redirecting to <a href="https://rubydoc.info/gems/mcp">latest documentation</a>...</p>
15
- <script>
16
- window.location.href = "https://rubydoc.info/gems/mcp";
17
- </script>
18
- </body>
19
- </html>