resque-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: 1f899cb2c9bb3c59a5185841550784e81dac79b0848da767f1cd5a81910efc84
4
+ data.tar.gz: 26775e429aa90ffcf60ed7b1517f74744d7786f137890376b9263392fd1d5719
5
+ SHA512:
6
+ metadata.gz: 4185dc24785f9425db9089136725a30ca45995d5dc35883dec9cbdfd0cdb2a47105037d376bc37315097f3136d90c22e2521487bd42351593593b86ea1446b0a
7
+ data.tar.gz: f2e8f0558eec1d6cd83589695eddd3dca1703d65130f71530a23596f81540e3c3a3a6611cb5360cac95c3cdf97fa95bced0177c197b12ef4a58d4a82d790ff31
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.1.0]
6
+
7
+ - Mountable Rails engine serving a stateless MCP Streamable HTTP endpoint (`POST` only; all other verbs answer 405).
8
+ - `overview` tool: global Resque health snapshot (pending/processed/failed totals, queue count and sizes, worker counts) with an environment + Redis-target meta footer (Redis credentials stripped).
9
+ - Mandatory bearer-token auth: `Resque::Mcp.configure { |c| c.auth_token = … }`; unauthenticated requests get 401 + `WWW-Authenticate: Bearer`, a blank configured token gets 503.
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "resque-mcp" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["9265647+jbockler@users.noreply.github.com"](mailto:"9265647+jbockler@users.noreply.github.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Josch Bockler
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,76 @@
1
+ # resque-mcp
2
+
3
+ An MCP server for [Resque](https://github.com/resque/resque), mountable as a Rails engine. Lets MCP clients (e.g. Claude Code) inspect queues, workers, and failed jobs — and retry or clear failures — over a single authenticated Streamable HTTP endpoint.
4
+
5
+ ## Requirements
6
+
7
+ - Ruby >= 3.2
8
+ - Rails >= 7.2
9
+ - Resque >= 2.7, < 4
10
+
11
+ ## Installation
12
+
13
+ Not yet published to RubyGems. Until then, install from git:
14
+
15
+ ```ruby
16
+ # Gemfile
17
+ gem "resque-mcp", github: "jbockler/resque-mcp"
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ Mount the engine and configure the auth token:
23
+
24
+ ```ruby
25
+ # config/routes.rb
26
+ mount Resque::Mcp::Engine => "/resque-mcp"
27
+
28
+ # config/initializers/resque_mcp.rb
29
+ Resque::Mcp.configure do |c|
30
+ c.auth_token = Rails.application.credentials.dig(:resque_mcp, :token)
31
+ end
32
+ ```
33
+
34
+ The token is **required** — the endpoint answers `503` until one is configured, and `401` on any request without a matching `Authorization: Bearer` header. The engine talks to whatever `Resque.redis` your app already configured; it never opens its own Redis connection.
35
+
36
+ Connect Claude Code:
37
+
38
+ ```sh
39
+ claude mcp add --transport http resque https://your-app.example.com/resque-mcp \
40
+ --header "Authorization: Bearer <token>"
41
+ ```
42
+
43
+ Then ask, e.g., "How is my Resque doing?"
44
+
45
+ ## Tools
46
+
47
+ The tool surface is currently in progress. Every tool response returns structured JSON alongside a text body and ends in a `meta` footer naming the Rails environment and the Redis target (with any credentials stripped), so you always see what you are talking to.
48
+
49
+ ### `overview` — read-only
50
+
51
+ Global Resque health snapshot; takes no parameters.
52
+
53
+ ```json
54
+ {
55
+ "pending": 87, "processed": 1093421, "failed": 1342,
56
+ "queues": 6, "workers": 12, "working": 3,
57
+ "queue_sizes": { "default": 3, "mailers": 0, "imports": 84 },
58
+ "meta": { "environment": "production", "redis": "redis://prod-redis:6379/0/resque" }
59
+ }
60
+ ```
61
+
62
+ - `pending` and `queue_sizes` come from a single snapshot, so `pending` always equals the sum of `queue_sizes`.
63
+ - `processed` is Resque's lifetime counter; `failed` is the current number of records in the failed list.
64
+ - `workers` counts registered workers, `working` those currently running a job.
65
+
66
+ ## Development
67
+
68
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests and standardrb. You can also run `bin/console` for an interactive prompt.
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jbockler/resque-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/jbockler/resque-mcp/blob/main/CODE_OF_CONDUCT.md).
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resque
4
+ module Mcp
5
+ class EndpointController < ActionController::API
6
+ before_action :require_auth_token, only: :handle
7
+
8
+ def handle
9
+ server = ServerFactory.build(environment: Rails.env.to_s)
10
+ transport = ::MCP::Server::Transports::StreamableHTTPTransport.new(
11
+ server, stateless: true, enable_json_response: true
12
+ )
13
+
14
+ status, headers, body = transport.handle_request(request)
15
+ headers.each { |key, value| response.set_header(key, value) }
16
+
17
+ payload = body.first
18
+ if payload
19
+ render json: payload, status: status
20
+ else
21
+ head status
22
+ end
23
+ end
24
+
25
+ def method_not_allowed
26
+ head :method_not_allowed
27
+ end
28
+
29
+ private
30
+
31
+ # No reliable boot-time hook exists (initializer ordering), so a
32
+ # missing token is caught per request: 503, never silently open.
33
+ def require_auth_token
34
+ configured = Resque::Mcp.config.auth_token
35
+ if configured.blank?
36
+ Rails.logger.error(
37
+ "resque-mcp: refusing to serve — Resque::Mcp.config.auth_token is not set. " \
38
+ "Set it in an initializer via Resque::Mcp.configure."
39
+ )
40
+ return head :service_unavailable
41
+ end
42
+
43
+ provided = request.authorization.to_s[/\ABearer (.+)\z/i, 1]
44
+ unless provided && ActiveSupport::SecurityUtils.secure_compare(provided, configured)
45
+ response.set_header("WWW-Authenticate", "Bearer")
46
+ head :unauthorized
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Resque::Mcp::Engine.routes.draw do
4
+ post "/", to: "endpoint#handle"
5
+ match "/", to: "endpoint#method_not_allowed", via: :all
6
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resque
4
+ module Mcp
5
+ # The only code in the gem that talks to Resque. Rails-free.
6
+ class Adapter
7
+ def initialize(resque: ::Resque)
8
+ @resque = resque
9
+ end
10
+
11
+ # One queue_sizes snapshot, not Resque.info — info reruns the queue
12
+ # sweep, letting pending disagree with queue_sizes in one response.
13
+ def stats
14
+ queue_sizes = @resque.queue_sizes
15
+ {
16
+ pending: queue_sizes.values.sum,
17
+ processed: @resque::Stat[:processed],
18
+ failed: @resque::Failure.count,
19
+ queues: queue_sizes.size,
20
+ workers: @resque.workers.size,
21
+ working: @resque.working.size,
22
+ queue_sizes: queue_sizes
23
+ }
24
+ end
25
+
26
+ # Resque.redis_id can embed user:password@; only this stripped form
27
+ # may reach tool responses.
28
+ def redis_identifier
29
+ strip_userinfo(@resque.redis_id.to_s)
30
+ end
31
+
32
+ private
33
+
34
+ # Greedy to the last "@" — passwords may contain "@", "/", or spaces;
35
+ # over-stripping is acceptable, leaking is not.
36
+ def strip_userinfo(id)
37
+ id.sub(%r{\A(.*?://)?.*@}, '\1')
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resque
4
+ module Mcp
5
+ class Configuration
6
+ attr_accessor :auth_token
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/engine"
4
+
5
+ module Resque
6
+ module Mcp
7
+ class Engine < ::Rails::Engine
8
+ isolate_namespace Resque::Mcp
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resque
4
+ module Mcp
5
+ # Builds a fresh ::MCP::Server per request. The caller passes
6
+ # `environment` (the controller sends Rails.env); this file is Rails-free.
7
+ module ServerFactory
8
+ def self.build(environment: nil)
9
+ ::MCP::Server.new(
10
+ name: "resque-mcp",
11
+ version: Resque::Mcp::VERSION,
12
+ tools: [Tools::Overview],
13
+ server_context: {adapter: Adapter.new, environment: environment}
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resque
4
+ module Mcp
5
+ module Tools
6
+ # Shared tool helpers: adapter access, response envelopes, meta footer.
7
+ class Base < ::MCP::Tool
8
+ class << self
9
+ private
10
+
11
+ def adapter(server_context)
12
+ server_context.fetch(:adapter)
13
+ end
14
+
15
+ def success_response(payload, server_context)
16
+ body = payload.merge(meta: meta_footer(server_context))
17
+ ::MCP::Tool::Response.new(
18
+ [{type: "text", text: JSON.generate(body)}],
19
+ structured_content: body
20
+ )
21
+ end
22
+
23
+ def error_response(message)
24
+ ::MCP::Tool::Response.new([{type: "text", text: message}], error: true)
25
+ end
26
+
27
+ def meta_footer(server_context)
28
+ {
29
+ environment: server_context[:environment],
30
+ redis: adapter(server_context).redis_identifier
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resque
4
+ module Mcp
5
+ module Tools
6
+ class Overview < Base
7
+ tool_name "overview"
8
+ description "Global Resque health snapshot: pending/processed/failed totals, " \
9
+ "queue count, worker counts, Redis server, environment. Cheap; call this first."
10
+ input_schema(properties: {}, required: [])
11
+ annotations(read_only_hint: true)
12
+
13
+ # `**` tolerates unexpected client arguments, which would otherwise
14
+ # surface as opaque JSON-RPC internal errors.
15
+ def self.call(server_context:, **)
16
+ success_response(adapter(server_context).stats, server_context)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resque
4
+ module Mcp
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/resque/mcp.rb ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "resque"
5
+ require "mcp"
6
+ require "zeitwerk"
7
+
8
+ require_relative "mcp/version"
9
+
10
+ module Resque
11
+ module Mcp
12
+ class Error < StandardError; end
13
+
14
+ class << self
15
+ def configure
16
+ yield config
17
+ end
18
+
19
+ def config
20
+ @config ||= Configuration.new
21
+ end
22
+
23
+ def reset_config!
24
+ @config = Configuration.new
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ loader = Zeitwerk::Loader.for_gem_extension(Resque)
31
+ loader.ignore("#{__dir__}/mcp/version.rb")
32
+ loader.ignore("#{__dir__}/mcp/engine.rb")
33
+ loader.setup
34
+
35
+ require_relative "mcp/engine" if defined?(Rails)
@@ -0,0 +1,5 @@
1
+ module Resque
2
+ module Mcp
3
+ VERSION: String
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-mcp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Josch Bockler
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: resque
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '2.7'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '2.7'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '4'
32
+ - !ruby/object:Gem::Dependency
33
+ name: mcp
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '0.22'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '0.22'
46
+ - !ruby/object:Gem::Dependency
47
+ name: railties
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '7.2'
53
+ type: :runtime
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '7.2'
60
+ - !ruby/object:Gem::Dependency
61
+ name: zeitwerk
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '2.6'
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '2.6'
74
+ description: Exposes Resque queues, workers, and failed jobs to MCP clients via a
75
+ Streamable HTTP endpoint mounted in the host Rails app.
76
+ email:
77
+ - 9265647+jbockler@users.noreply.github.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - CHANGELOG.md
83
+ - CODE_OF_CONDUCT.md
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - app/controllers/resque/mcp/endpoint_controller.rb
88
+ - config/routes.rb
89
+ - lib/resque/mcp.rb
90
+ - lib/resque/mcp/adapter.rb
91
+ - lib/resque/mcp/configuration.rb
92
+ - lib/resque/mcp/engine.rb
93
+ - lib/resque/mcp/server_factory.rb
94
+ - lib/resque/mcp/tools/base.rb
95
+ - lib/resque/mcp/tools/overview.rb
96
+ - lib/resque/mcp/version.rb
97
+ - sig/resque/mcp.rbs
98
+ homepage: https://github.com/jbockler/resque-mcp
99
+ licenses:
100
+ - MIT
101
+ metadata:
102
+ allowed_push_host: https://rubygems.org
103
+ homepage_uri: https://github.com/jbockler/resque-mcp
104
+ source_code_uri: https://github.com/jbockler/resque-mcp
105
+ changelog_uri: https://github.com/jbockler/resque-mcp/blob/main/CHANGELOG.md
106
+ rubygems_mfa_required: 'true'
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 3.2.0
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 4.0.3
122
+ specification_version: 4
123
+ summary: MCP server for Resque, mountable as a Rails engine.
124
+ test_files: []