tiny_mcp 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0d3ff46332bafaed3f77ab40c84bf5057a3e1db50ef94ae0bf7116fcc5acfc10
4
+ data.tar.gz: 6172e0eb037331572c7fdb44a97bc47e312f5addc801c8e3fe7b7778f2bd6dee
5
+ SHA512:
6
+ metadata.gz: a4a38fd1aa93d06ccedb1753ed91242d8f43fcf5892b1ed0aedaaa1b7de7815889ca0737decd659477eb9db53d5edf9304e981fee1ab92b90770aac035d156d4
7
+ data.tar.gz: 3241f7c94c8e95fd80f19b4a8e45e5e272a675b2051197627521ac1c4e758afd6461cf8f1cb714bc9a1a574f0d495d778c7cc5e9d312a2e0683a20f49ca8e0a1
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-05-26
4
+
5
+ - Initial release
data/CLAUDE.md ADDED
@@ -0,0 +1,72 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Commands
6
+
7
+ ### Development
8
+ - `bundle install` - Install dependencies
9
+ - `bin/setup` - Setup script that installs dependencies
10
+ - `bin/console` - Interactive Ruby console with the gem loaded
11
+
12
+ ### Testing
13
+ - `rake test` or `bundle exec rake test` - Run all tests
14
+ - `rake` - Default task (runs tests)
15
+ - `ruby -Ilib:test test/test_tiny_mcp.rb` - Run specific test file
16
+
17
+ ### Building and Release
18
+ - `bundle exec rake install` - Build and install gem locally
19
+ - `bundle exec rake release` - Create git tag and push gem to RubyGems
20
+
21
+ ## Architecture Overview
22
+
23
+ TinyMCP is a Ruby implementation of an MCP (Model Context Protocol) server that enables creating tools callable through JSON-RPC.
24
+
25
+ ### Core Components
26
+
27
+ 1. **TinyMCP::Server** - JSON-RPC server that:
28
+ - Reads requests from STDIN
29
+ - Processes tool calls via JSON-RPC protocol
30
+ - Writes responses to STDOUT
31
+ - Implements MCP server protocol
32
+
33
+ 2. **TinyMCP::Tool** - Base class for tools:
34
+ - Inherit from this class to create new tools
35
+ - Use DSL methods: `name`, `desc`, `arg`, `opt` for metadata
36
+ - Implement `call` method with tool logic
37
+ - Parameters are automatically validated
38
+
39
+ 3. **Data Classes** (using Ruby's Data.define):
40
+ - `Definition` - Tool metadata (name, description, parameters)
41
+ - `Prop` - Parameter properties (name, description, type, required)
42
+
43
+ ### Tool Definition Pattern
44
+
45
+ Tools use a declarative DSL:
46
+ ```ruby
47
+ class MyTool < TinyMCP::Tool
48
+ name 'my_tool'
49
+ desc 'Tool description'
50
+ arg :required_param, 'string', 'Parameter description'
51
+ opt :optional_param, 'string', 'Optional parameter'
52
+
53
+ def call(required_param:, optional_param: nil)
54
+ # Implementation
55
+ end
56
+ end
57
+ ```
58
+
59
+ ### JSON-RPC Protocol
60
+
61
+ The server implements standard JSON-RPC 2.0 for MCP:
62
+ - Methods: `initialize`, `tools/list`, `tools/call`
63
+ - Input/output via STDIN/STDOUT
64
+ - Request/response format follows MCP specification
65
+
66
+ ## Important Notes
67
+
68
+ - Ruby version requirement: >= 3.1.0
69
+ - Test framework: Minitest
70
+ - No linting configuration currently set up
71
+ - Gem is in early development (has TODOs in gemspec)
72
+ - CI runs on Ruby 3.4.1 via GitHub Actions
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Max Chernyak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # TinyMCP
2
+
3
+ A tiny Ruby implementation of the Model Context Protocol (MCP) that makes it easy to create and serve tools locally for AI assistants.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install tiny_mcp
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Create tools by inheriting from `TinyMCP::Tool`:
14
+
15
+ ```ruby
16
+ #!/usr/bin/env ruby
17
+ require 'tiny_mcp'
18
+
19
+ class WeatherTool < TinyMCP::Tool
20
+ name 'get_weather'
21
+ desc 'Get current weather for a city'
22
+ arg :city, :string, 'City name'
23
+ opt :units, :string, 'Temperature units (celsius/fahrenheit)'
24
+
25
+ def call(city:, units: 'celsius')
26
+ # Your implementation here
27
+ "Weather in #{city}: 20°C, sunny"
28
+ end
29
+ end
30
+
31
+ class TimeTool < TinyMCP::Tool
32
+ name 'get_time'
33
+ desc 'Get current time'
34
+ opt :timezone, :string, 'Timezone name'
35
+
36
+ def call(timezone: 'UTC')
37
+ Time.now.getlocal(timezone).to_s
38
+ end
39
+ end
40
+
41
+ # Serve multiple tools
42
+ TinyMCP.serve(WeatherTool, TimeTool)
43
+ ```
44
+
45
+ You can put this in a bin/mcp file for example, and make it executable:
46
+
47
+ ```bash
48
+ chmod +x bin/mcp
49
+ ```
50
+
51
+ Then add it to Claude Code:
52
+
53
+ ```bash
54
+ claude mcp add my-mcp bin/mcp
55
+ ```
56
+
57
+ The server reads JSON-RPC requests from stdin and writes responses to stdout, making it compatible with MCP clients.
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maxim/tiny_mcp. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/maxim/tiny_mcp/blob/main/CODE_OF_CONDUCT.md).
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
72
+
73
+ ## Code of Conduct
74
+
75
+ Everyone interacting in the TinyMCP project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/maxim/tiny_mcp/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'minitest/test_task'
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TinyMCP
4
+ VERSION = '0.1.0'
5
+ end
data/lib/tiny_mcp.rb ADDED
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tiny_mcp/version'
4
+ require 'json'
5
+ require 'shellwords'
6
+
7
+ module TinyMCP
8
+ Prop = Data.define(:name, :type, :desc, :req) do
9
+ def to_h = { type: type, description: desc }
10
+ end
11
+
12
+ class Definition
13
+ attr_accessor :name, :desc, :props
14
+ def initialize = @props = []
15
+
16
+ def to_h
17
+ {
18
+ name:,
19
+ description: desc,
20
+ inputSchema: {
21
+ type: 'object',
22
+ properties: props.map { [_1.name, _1.to_h] }.to_h,
23
+ required: props.select(&:req).map(&:name)
24
+ }
25
+ }
26
+ end
27
+ end
28
+
29
+ class Tool
30
+ class << self
31
+ attr_accessor :mcp
32
+ def inherited(base) = base.mcp = Definition.new
33
+ def name(string) = mcp.name = string
34
+ def desc(string) = mcp.desc = string
35
+ def arg(*args) = mcp.props << Prop[*args, true]
36
+ def opt(*args) = mcp.props << Prop[*args, false]
37
+ end
38
+
39
+ def call = raise 'Override in subclass'
40
+ end
41
+
42
+ class Server
43
+ ERROR_TYPES = {
44
+ invalid_json: [-32700, 'Invalid JSON'].freeze,
45
+ invalid_request: [-32600, 'Invalid request'].freeze,
46
+ method_not_found: [-32601, 'Method not found'].freeze,
47
+ invalid_params: [-32602, 'Invalid params'].freeze,
48
+ internal: [-32603, 'Internal error'].freeze
49
+ }.freeze
50
+
51
+ def initialize *tools,
52
+ protocol_version: '2024-11-05',
53
+ server_name: 'ruby-tinymcp-server',
54
+ server_version: '1.0.0',
55
+ capabilities: { tools: {} }
56
+
57
+
58
+ @tool_defs = tools.map { [_1.mcp.name, _1.mcp.to_h] }.to_h
59
+ @tools = tools.map(&:new)
60
+
61
+ @protocol_version = protocol_version
62
+ @server_name = server_name
63
+ @server_version = server_version
64
+ @capabilities = capabilities
65
+ end
66
+
67
+ def run
68
+ loop do
69
+ input = STDIN.gets
70
+ break if input.nil?
71
+
72
+ request =
73
+ begin
74
+ JSON.parse(input.strip)
75
+ rescue
76
+ puts error_for({'id' => nil}, :invalid_json)
77
+ STDOUT.flush
78
+ next
79
+ end
80
+
81
+ response = handle_request(request)
82
+
83
+ puts JSON.generate(response)
84
+ STDOUT.flush
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def handle_request(request)
91
+ case request['method']
92
+ when 'initialize'
93
+ response_for request,
94
+ protocolVersion: @protocol_version,
95
+ capabilities: @capabilities,
96
+ serverInfo: { name: @server_name, version: @server_version }
97
+ when 'tools/list'
98
+ response_for request, tools: @tool_defs.values
99
+ when 'tools/call'
100
+ handle_tool_call request
101
+ else
102
+ error_for(request, :method_not_found)
103
+ end
104
+ end
105
+
106
+ def handle_tool_call(request)
107
+ name = request.dig('params', 'name')
108
+ tool = @tools.find { _1.class.mcp.name == name }
109
+
110
+ if !tool
111
+ return error_for(request, :invalid_params, "Unknown_tool: #{name}")
112
+ end
113
+
114
+ args = request.dig('params', 'arguments')&.transform_keys(&:to_sym)
115
+
116
+ begin
117
+ result = tool.call(**args)
118
+ # TODO: Support other content types (ask claude code which ones).
119
+ response_for(request, content: [{ type: 'text', text: result.to_s }])
120
+ rescue => e
121
+ error_for(request, :internal, e.full_message(highlight: false))
122
+ end
123
+ end
124
+
125
+ def error_for(request, type, message = ERROR_TYPES[type][1])
126
+ code = ERROR_TYPES[type][0]
127
+ { jsonrpc: '2.0', id: request['id'], error: { code:, message: } }
128
+ end
129
+
130
+ def response_for(request, **hash)
131
+ { jsonrpc: '2.0', id: request['id'], result: hash }
132
+ end
133
+ end
134
+
135
+ def self.serve(*args, **kwargs) = Server.new(*args, **kwargs).run
136
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny_mcp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Chernyak
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-05-26 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Make local MCP tools in Ruby and easily serve them.
13
+ email:
14
+ - hello@max.engineer
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - CHANGELOG.md
20
+ - CLAUDE.md
21
+ - CODE_OF_CONDUCT.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/tiny_mcp.rb
26
+ - lib/tiny_mcp/version.rb
27
+ homepage: https://github.com/maxim/tiny_mcp
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ allowed_push_host: https://rubygems.org
32
+ homepage_uri: https://github.com/maxim/tiny_mcp
33
+ source_code_uri: https://github.com/maxim/tiny_mcp
34
+ changelog_uri: https://github.com/maxim/tiny_mcp/blob/main/CHANGELOG.md
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.1.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.6.3
50
+ specification_version: 4
51
+ summary: Tiny Ruby-based MCP server
52
+ test_files: []