11# AGENTS.md
22
33## Project overview
4+
45This 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.
56
67## Dev environment setup
8+
79- Ruby 3.2.0+ required
810- Run ` bundle install ` to install dependencies
911- Dependencies: ` json_rpc_handler ` ~ > 0.1, ` json-schema ` >= 4.1
1012
1113## Build and test commands
14+
1215- ` bundle install ` - Install dependencies
1316- ` rake test ` - Run all tests
1417- ` rake rubocop ` - Run linter
@@ -17,23 +20,27 @@ This is the official Ruby SDK for the Model Context Protocol (MCP), implementing
1720- ` gem build mcp.gemspec ` - Build the gem
1821
1922## Testing instructions
23+
2024- Test files are in ` test/ ` directory with ` _test.rb ` suffix
2125- Run full test suite with ` rake test `
2226- Run individual tests with ` ruby -I lib -I test test/path/to/file_test.rb `
2327- Tests should pass before submitting PRs
2428
2529## Code style guidelines
30+
2631- Follow RuboCop rules (run ` rake rubocop ` )
2732- Use frozen string literals
2833- Follow Ruby community conventions
2934- Keep dependencies minimal
3035
3136## Commit message conventions
37+
3238- Use conventional commit format when possible
3339- Include clear, descriptive commit messages
3440- Releases are triggered by updating version in ` lib/mcp/version.rb ` and merging to main
3541
3642## Release process
43+
3744- Follow [ Keep a Changelog] ( https://keepachangelog.com/en/1.1.0/ ) format in CHANGELOG.md
3845- Update CHANGELOG.md before cutting releases
3946- Use git history and PR merge commits to construct changelog entries
@@ -48,23 +55,27 @@ This is the official Ruby SDK for the Model Context Protocol (MCP), implementing
4855### Core Components
4956
5057** MCP::Server** (` lib/mcp/server.rb ` ):
58+
5159- Main server class handling JSON-RPC requests
5260- Implements MCP protocol methods: initialize, ping, tools/list, tools/call, prompts/list, prompts/get, resources/list, resources/read
5361- Supports custom method registration via ` define_custom_method `
5462- Handles instrumentation, exception reporting, and notifications
5563- Uses JsonRpcHandler for request processing
5664
5765** MCP::Client** (` lib/mcp/client.rb ` ):
66+
5867- Client interface for communicating with MCP servers
5968- Transport-agnostic design with pluggable transport layers
6069- Supports tool listing and invocation
6170
6271** Transport Layer** :
72+
6373- ` MCP::Server::Transports::StdioTransport ` - Command-line stdio transport
6474- ` MCP::Server::Transports::StreamableHttpTransport ` - HTTP with streaming support
6575- ` MCP::Client::HTTP ` - HTTP client transport (requires faraday gem)
6676
6777** Protocol Components** :
78+
6879- ` MCP::Tool ` - Tool definition with input/output schemas and annotations
6980- ` MCP::Prompt ` - Prompt templates with argument validation
7081- ` MCP::Resource ` - Resource registration and retrieval
@@ -73,30 +84,36 @@ This is the official Ruby SDK for the Model Context Protocol (MCP), implementing
7384### Key Patterns
7485
7586** Three Ways to Define Components** :
87+
76881 . Class inheritance (e.g., ` class MyTool < MCP::Tool ` )
77892 . Define methods (e.g., ` MCP::Tool.define(name: "my_tool") { ... } ` )
78903 . Server registration (e.g., ` server.define_tool(name: "my_tool") { ... } ` )
7991
8092** Schema Validation** :
93+
8194- Tools support input_schema and output_schema for JSON Schema validation
8295- Protocol version 2025-03-26+ supports tool annotations (destructive_hint, idempotent_hint, etc.)
8396- Validation is configurable via ` configuration.validate_tool_call_arguments `
8497
8598** Context Passing** :
99+
86100- ` server_context ` hash passed through tool/prompt calls for request-specific data
87101- Methods can accept ` server_context: ` keyword argument for accessing context
88102
89103### Dependencies
104+
90105- ` json_rpc_handler ` ~ > 0.1 - JSON-RPC 2.0 message handling
91106- ` json-schema ` >= 4.1 - Schema validation
92107- Ruby 3.2.0+ required
93108
94109### Integration patterns
110+
95111- ** Rails controllers** : Use ` server.handle_json(request.body.read) ` for HTTP endpoints
96112- ** Command-line tools** : Use ` StdioTransport.new(server).open ` for CLI applications
97113- ** HTTP services** : Use ` StreamableHttpTransport ` for web-based servers
98114
99115### Component definition patterns
116+
1001171 . ** Class inheritance** : ` class MyTool < MCP::Tool `
1011182 . ** Define methods** : ` MCP::Tool.define(name: "my_tool") { ... } `
1021193 . ** Server registration** : ` server.define_tool(name: "my_tool") { ... } `
0 commit comments