Support offical MCP Gem as a Backend #89
Open
+31,173
−5,334
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Official MCP SDK Support with Adapter Pattern
Overview
This PR introduces a major architectural refactor that adds support for the official Ruby MCP SDK while maintaining full backward compatibility. The gem now uses an adapter pattern that allows users to choose between the native full-featured implementation or the official Anthropic-maintained SDK.
What's New
🎛️ Dual SDK Support (v0.8.0+)
Users can now choose their MCP implementation:
:ruby_llmadapter (default) - Native full-featured implementation with all advanced MCP features:mcp_sdkadapter (new) - Official Anthropic-maintained SDK with core MCP features🏗️ Adapter Architecture
Introduced a flexible adapter system that:
BaseAdapter) for all MCP implementationsKey Changes
New Files & Architecture
Adapter System:
lib/ruby_llm/mcp/adapters/base_adapter.rb- Base adapter interfacelib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb- Native implementation adapterlib/ruby_llm/mcp/adapters/mcp_sdk_adapter.rb- Official SDK adapterNative Implementation Reorganization:
lib/ruby_llm/mcp/native/namespacenative/client.rb,native/transport.rb, andnative/protocol.rbEnhanced Configuration
config.default_adapter = :ruby_llmadapter: :mcp_sdkDocumentation
New comprehensive Adapters Guide with:
Updated README with adapter selection guidance
Enhanced configuration documentation
Feature Comparison
Testing
spec/ruby_llm/mcp/adapters/mcp_sdk_sse_spec.rbspec/ruby_llm/mcp/native/transport_spec.rbspec/ruby_llm/mcp/native/transports/*.rbspec/support/adapter_test_helpers.rbBackward Compatibility
✅ Fully backward compatible - existing code continues to work without changes:
:ruby_llm(maintains current behavior)Usage Examples
Using the Native Adapter (Default)
Using the Official SDK Adapter
Mixed Adapter Usage
Dependencies
mcpgem (>= 0.4) - only required when using:mcp_sdkadapterMigration Path
For users upgrading from v0.7.x:
gem 'mcp'to use official SDK adapterTesting Checklist
Review Focus Areas