mcp 0.2.0 → 0.4.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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +2 -2
- data/.github/workflows/release.yml +1 -1
- data/.rubocop.yml +3 -0
- data/AGENTS.md +119 -0
- data/CHANGELOG.md +56 -0
- data/Gemfile +7 -4
- data/README.md +393 -50
- data/examples/http_client.rb +13 -13
- data/examples/http_server.rb +14 -12
- data/examples/stdio_server.rb +4 -4
- data/examples/streamable_http_client.rb +10 -12
- data/examples/streamable_http_server.rb +32 -32
- data/lib/mcp/client/http.rb +88 -0
- data/lib/mcp/client/tool.rb +16 -0
- data/lib/mcp/client.rb +116 -0
- data/lib/mcp/configuration.rb +31 -4
- data/lib/mcp/content.rb +0 -1
- data/lib/mcp/prompt/argument.rb +9 -5
- data/lib/mcp/prompt/message.rb +0 -1
- data/lib/mcp/prompt/result.rb +0 -1
- data/lib/mcp/prompt.rb +30 -3
- data/lib/mcp/resource/contents.rb +0 -1
- data/lib/mcp/resource/embedded.rb +0 -1
- data/lib/mcp/resource.rb +8 -7
- data/lib/mcp/resource_template.rb +8 -7
- data/lib/mcp/server/transports/streamable_http_transport.rb +21 -1
- data/lib/mcp/server.rb +43 -14
- data/lib/mcp/string_utils.rb +0 -1
- data/lib/mcp/tool/annotations.rb +4 -4
- data/lib/mcp/tool/input_schema.rb +10 -2
- data/lib/mcp/tool/output_schema.rb +69 -0
- data/lib/mcp/tool/response.rb +17 -5
- data/lib/mcp/tool.rb +47 -6
- data/lib/mcp/version.rb +1 -1
- data/lib/mcp.rb +4 -0
- metadata +8 -3
- data/.cursor/rules/release-changelogs.mdc +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 451bdb587fa89621924916d7cc137cf44a3a2293cf7803c3c6af1d97fb57332a
|
4
|
+
data.tar.gz: 3175f6a5d60426d5441b99b2bbf6d50b90d31daa9b713796029547f5efc6ab6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b9e312c047ebc31d0826ec2520e14fef34fd0a23f42d9bf849f4a64b8cdb924341aa8a431aab497824849da476de5b8b2d55ad3b3996b9871e04b9022161aa3
|
7
|
+
data.tar.gz: 772762d9cf650278dd0756867a995e57e13366e1a4a2a5b306433d8d9246e8bed2aadb00e057d4f31a521603dab6f8fadcbcdfc9650806c79d9881e2e1913acb
|
data/.github/workflows/ci.yml
CHANGED
@@ -13,7 +13,7 @@ jobs:
|
|
13
13
|
- { ruby: head, allowed-failure: true }
|
14
14
|
name: Test Ruby ${{ matrix.entry.ruby }}
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v5
|
17
17
|
- uses: ruby/setup-ruby@v1
|
18
18
|
with:
|
19
19
|
ruby-version: ${{ matrix.entry.ruby }}
|
@@ -25,7 +25,7 @@ jobs:
|
|
25
25
|
runs-on: ubuntu-latest
|
26
26
|
name: RuboCop
|
27
27
|
steps:
|
28
|
-
- uses: actions/checkout@
|
28
|
+
- uses: actions/checkout@v5
|
29
29
|
- uses: ruby/setup-ruby@v1
|
30
30
|
with:
|
31
31
|
ruby-version: 3.2 # Specify the oldest supported Ruby version.
|
@@ -16,7 +16,7 @@ jobs:
|
|
16
16
|
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
17
17
|
contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag
|
18
18
|
steps:
|
19
|
-
- uses: actions/checkout@
|
19
|
+
- uses: actions/checkout@v5
|
20
20
|
- name: Set up Ruby
|
21
21
|
uses: ruby/setup-ruby@v1
|
22
22
|
with:
|
data/.rubocop.yml
CHANGED
data/AGENTS.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# AGENTS.md
|
2
|
+
|
3
|
+
## Project overview
|
4
|
+
|
5
|
+
This is the official Ruby SDK for the Model Context Protocol (MCP), implementing both server and client functionality for JSON-RPC 2.0 based communication between LLM applications and context providers.
|
6
|
+
|
7
|
+
## Dev environment setup
|
8
|
+
|
9
|
+
- Ruby 3.2.0+ required
|
10
|
+
- Run `bundle install` to install dependencies
|
11
|
+
- Dependencies: `json_rpc_handler` ~> 0.1, `json-schema` >= 4.1
|
12
|
+
|
13
|
+
## Build and test commands
|
14
|
+
|
15
|
+
- `bundle install` - Install dependencies
|
16
|
+
- `rake test` - Run all tests
|
17
|
+
- `rake rubocop` - Run linter
|
18
|
+
- `rake` - Run tests and linting (default task)
|
19
|
+
- `ruby -I lib -I test test/path/to/specific_test.rb` - Run single test file
|
20
|
+
- `gem build mcp.gemspec` - Build the gem
|
21
|
+
|
22
|
+
## Testing instructions
|
23
|
+
|
24
|
+
- Test files are in `test/` directory with `_test.rb` suffix
|
25
|
+
- Run full test suite with `rake test`
|
26
|
+
- Run individual tests with `ruby -I lib -I test test/path/to/file_test.rb`
|
27
|
+
- Tests should pass before submitting PRs
|
28
|
+
|
29
|
+
## Code style guidelines
|
30
|
+
|
31
|
+
- Follow RuboCop rules (run `rake rubocop`)
|
32
|
+
- Use frozen string literals
|
33
|
+
- Follow Ruby community conventions
|
34
|
+
- Keep dependencies minimal
|
35
|
+
|
36
|
+
## Commit message conventions
|
37
|
+
|
38
|
+
- Use conventional commit format when possible
|
39
|
+
- Include clear, descriptive commit messages
|
40
|
+
- Releases are triggered by updating version in `lib/mcp/version.rb` and merging to main
|
41
|
+
|
42
|
+
## Release process
|
43
|
+
|
44
|
+
- Follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) format in CHANGELOG.md
|
45
|
+
- Update CHANGELOG.md before cutting releases
|
46
|
+
- Use git history and PR merge commits to construct changelog entries
|
47
|
+
- Format entries as: "Terse description of the change (#nnn)"
|
48
|
+
- Keep entries in flat list format (no nesting)
|
49
|
+
- Git tags mark commits that cut new releases
|
50
|
+
- Exclude maintenance PRs that don't concern end users
|
51
|
+
- Check upstream remote for PRs if available
|
52
|
+
|
53
|
+
## Architecture overview
|
54
|
+
|
55
|
+
### Core Components
|
56
|
+
|
57
|
+
**MCP::Server** (`lib/mcp/server.rb`):
|
58
|
+
|
59
|
+
- Main server class handling JSON-RPC requests
|
60
|
+
- Implements MCP protocol methods: initialize, ping, tools/list, tools/call, prompts/list, prompts/get, resources/list, resources/read
|
61
|
+
- Supports custom method registration via `define_custom_method`
|
62
|
+
- Handles instrumentation, exception reporting, and notifications
|
63
|
+
- Uses JsonRpcHandler for request processing
|
64
|
+
|
65
|
+
**MCP::Client** (`lib/mcp/client.rb`):
|
66
|
+
|
67
|
+
- Client interface for communicating with MCP servers
|
68
|
+
- Transport-agnostic design with pluggable transport layers
|
69
|
+
- Supports tool listing and invocation
|
70
|
+
|
71
|
+
**Transport Layer**:
|
72
|
+
|
73
|
+
- `MCP::Server::Transports::StdioTransport` - Command-line stdio transport
|
74
|
+
- `MCP::Server::Transports::StreamableHttpTransport` - HTTP with streaming support
|
75
|
+
- `MCP::Client::HTTP` - HTTP client transport (requires faraday gem)
|
76
|
+
|
77
|
+
**Protocol Components**:
|
78
|
+
|
79
|
+
- `MCP::Tool` - Tool definition with input/output schemas and annotations
|
80
|
+
- `MCP::Prompt` - Prompt templates with argument validation
|
81
|
+
- `MCP::Resource` - Resource registration and retrieval
|
82
|
+
- `MCP::Configuration` - Global configuration with exception reporting and instrumentation
|
83
|
+
|
84
|
+
### Key Patterns
|
85
|
+
|
86
|
+
**Three Ways to Define Components**:
|
87
|
+
|
88
|
+
1. Class inheritance (e.g., `class MyTool < MCP::Tool`)
|
89
|
+
2. Define methods (e.g., `MCP::Tool.define(name: "my_tool") { ... }`)
|
90
|
+
3. Server registration (e.g., `server.define_tool(name: "my_tool") { ... }`)
|
91
|
+
|
92
|
+
**Schema Validation**:
|
93
|
+
|
94
|
+
- Tools support input_schema and output_schema for JSON Schema validation
|
95
|
+
- Protocol version 2025-03-26+ supports tool annotations (destructive_hint, idempotent_hint, etc.)
|
96
|
+
- Validation is configurable via `configuration.validate_tool_call_arguments`
|
97
|
+
|
98
|
+
**Context Passing**:
|
99
|
+
|
100
|
+
- `server_context` hash passed through tool/prompt calls for request-specific data
|
101
|
+
- Methods can accept `server_context:` keyword argument for accessing context
|
102
|
+
|
103
|
+
### Dependencies
|
104
|
+
|
105
|
+
- `json_rpc_handler` ~> 0.1 - JSON-RPC 2.0 message handling
|
106
|
+
- `json-schema` >= 4.1 - Schema validation
|
107
|
+
- Ruby 3.2.0+ required
|
108
|
+
|
109
|
+
### Integration patterns
|
110
|
+
|
111
|
+
- **Rails controllers**: Use `server.handle_json(request.body.read)` for HTTP endpoints
|
112
|
+
- **Command-line tools**: Use `StdioTransport.new(server).open` for CLI applications
|
113
|
+
- **HTTP services**: Use `StreamableHttpTransport` for web-based servers
|
114
|
+
|
115
|
+
### Component definition patterns
|
116
|
+
|
117
|
+
1. **Class inheritance**: `class MyTool < MCP::Tool`
|
118
|
+
2. **Define methods**: `MCP::Tool.define(name: "my_tool") { ... }`
|
119
|
+
3. **Server registration**: `server.define_tool(name: "my_tool") { ... }`
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,62 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.4.0] - 2025-10-15
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Client resources support with `resources/list` and `resources/read` methods (#160)
|
15
|
+
- `_meta` field support for Tool schema (#124)
|
16
|
+
- `_meta` field support for Prompt
|
17
|
+
- `title` field support for prompt arguments
|
18
|
+
- `call_tool_raw` method to client for accessing full tool responses (#149)
|
19
|
+
- Structured content support in tool responses (#147)
|
20
|
+
- AGENTS.md development guidance documentation (#134)
|
21
|
+
- Dependabot configuration for automated dependency updates (#138)
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
- Set default `content` to empty array instead of `nil` (#150)
|
26
|
+
- Improved prompt spec compliance (#153)
|
27
|
+
- Allow output schema to be array of objects (#144)
|
28
|
+
- Return 202 response code for accepted JSON-RPC notifications (#114)
|
29
|
+
- Added validation to `MCP::Configuration` setters (#145)
|
30
|
+
- Updated metaschema URI format for cross-OS compatibility
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
|
34
|
+
- Client tools functionality and test coverage (#166)
|
35
|
+
- Client resources test for empty responses (#162)
|
36
|
+
- Documentation typos and incorrect examples (#157, #146)
|
37
|
+
- Removed redundant transport requires (#154)
|
38
|
+
- Cleaned up unused block parameters and magic comments
|
39
|
+
|
40
|
+
## [0.3.0] - 2025-09-14
|
41
|
+
|
42
|
+
### Added
|
43
|
+
|
44
|
+
- Tool output schema support with comprehensive validation (#122)
|
45
|
+
- HTTP client transport layer for MCP clients (#28)
|
46
|
+
- Tool annotations validation for protocol compatibility (#122)
|
47
|
+
- Server instructions support (#87)
|
48
|
+
- Title support in server info (#119)
|
49
|
+
- Default values for tool annotation hints (#118)
|
50
|
+
- Notifications/initialized method implementation (#84)
|
51
|
+
|
52
|
+
### Changed
|
53
|
+
|
54
|
+
- Make default protocol version the latest specification version (#83)
|
55
|
+
- Protocol version validation to ensure valid values (#80)
|
56
|
+
- Improved tool handling for tools with no arguments (#85, #86)
|
57
|
+
- Better error handling and response API (#109)
|
58
|
+
|
59
|
+
### Fixed
|
60
|
+
|
61
|
+
- JSON-RPC notification format in Streamable HTTP transport (#91)
|
62
|
+
- Errors when title is not specified (#126)
|
63
|
+
- Tools with missing arguments handling (#86)
|
64
|
+
- Namespacing issues in README examples (#89)
|
65
|
+
|
10
66
|
## [0.2.0] - 2025-07-15
|
11
67
|
|
12
68
|
### Added
|
data/Gemfile
CHANGED
@@ -6,10 +6,6 @@ source "https://rubygems.org"
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
# Specify development dependencies below
|
9
|
-
gem "minitest", "~> 5.1", require: false
|
10
|
-
gem "minitest-reporters"
|
11
|
-
gem "mocha"
|
12
|
-
|
13
9
|
gem "rubocop-minitest", require: false
|
14
10
|
gem "rubocop-rake", require: false
|
15
11
|
gem "rubocop-shopify", require: false
|
@@ -22,3 +18,10 @@ gem "activesupport"
|
|
22
18
|
gem "debug"
|
23
19
|
gem "rake", "~> 13.0"
|
24
20
|
gem "sorbet-static-and-runtime"
|
21
|
+
|
22
|
+
group :test do
|
23
|
+
gem "faraday", ">= 2.0"
|
24
|
+
gem "minitest", "~> 5.1", require: false
|
25
|
+
gem "mocha"
|
26
|
+
gem "webmock"
|
27
|
+
end
|