sidekiq-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: 28a6841ac7244a9e2dbbacec82c6d68c8b6aad63577cfc5b8708a37979563b94
4
+ data.tar.gz: ba2b4d0631956b7542c5c908889fd97c27c125fb6d22158935107b966cd88bf7
5
+ SHA512:
6
+ metadata.gz: '04795cdcb429dc3e0bc3e6cf1f2871edbb7fe71358cabb0616bfc46734c8676bfcbd1ca2c7f600dc98f0d52080489ba422febe57864768559a4c8452f2945c60'
7
+ data.tar.gz: a86fe4850fb9ebc357ccdd07cc2c130f7570835a44e75dea40171254db0a909db53379a99be241b6cd8a7a7fc0775aeef04f65d4389c8f548383a553554e54cd
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-08-04
4
+
5
+ - Initial release
@@ -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/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # Sidekiq MCP
2
+
3
+ A Sidekiq plugin that provides an MCP (Model Context Protocol) server, enabling LLMs to interact with Sidekiq queues, statistics, and failed jobs through a standardized interface.
4
+
5
+ ## Available Tools
6
+
7
+ The MCP server provides the following tools:
8
+
9
+ ### Statistics & Monitoring
10
+ - `sidekiq_stats` - Get general Sidekiq statistics (processed, failed, busy, enqueued counts)
11
+ - `job_class_stats` - Breakdown of job counts, retries, and error rates by class
12
+ - `workers_count` - Show how many workers are running and busy
13
+ - `queue_health` - Heuristics on whether queues are backed up or healthy
14
+
15
+ ### Queue Inspection
16
+ - `list_queues` - List all queues with sizes and latency
17
+ - `queue_details` - Get detailed info about a specific queue including jobs
18
+ - `busy_workers` - List currently busy workers and their job details
19
+
20
+ ### Job Management
21
+ - `failed_jobs` - List failed jobs with error details
22
+ - `list_retry_jobs` - List jobs in the retry set (jobs that failed but will be retried)
23
+ - `list_scheduled_jobs` - List jobs in the scheduled set
24
+ - `dead_jobs` - Show jobs in the dead set (jobs that have exhausted all retries)
25
+ - `job_details` - Show args, error message, and history for a job by JID
26
+
27
+ ### Job Actions
28
+ - `retry_job` - Retry a failed job by JID
29
+ - `delete_failed_job` - Delete a failed job by JID
30
+ - `remove_job` - Remove a job from any set (queue/schedule/retry/dead) by JID
31
+ - `reschedule_job` - Reschedule a job in the scheduled set to a new time
32
+ - `kill_job` - Move a job from retry/scheduled set to the dead set
33
+ - `clear_queue` - Clear all jobs from a specific queue (destructive operation)
34
+
35
+ ### Real-time Monitoring
36
+ - `stream_stats` - Start streaming real-time Sidekiq statistics (use with SSE)
37
+ - `process_set` - Get detailed information about all Sidekiq processes/workers
38
+
39
+
40
+ ## Example Prompts
41
+
42
+ Once configured, you can ask your LLM:
43
+
44
+ - "What's the current status of Sidekiq?"
45
+ - "Show me the failed jobs and their error messages"
46
+ - "List all queues and their health status"
47
+ - "Which job classes have the highest error rates?"
48
+ - "Show me details for job abc123"
49
+ - "Retry the job with JID abc123"
50
+ - "What jobs are currently running?"
51
+ - "Are any queues backed up or unhealthy?"
52
+ - "How many workers are busy right now?"
53
+ - "Clear all jobs from the 'low_priority' queue"
54
+ - "Reschedule job abc123 to run tomorrow at 9 AM"
55
+ - "Move this failed job to the dead set"
56
+ - "Start streaming live stats updates"
57
+
58
+ ## Installation
59
+
60
+ Add this line to your application's Gemfile:
61
+
62
+ ```ruby
63
+ gem 'sidekiq-mcp'
64
+ ```
65
+
66
+ And then execute:
67
+ ```bash
68
+ bundle install
69
+ ```
70
+
71
+ ## Usage
72
+
73
+ ### Rails Integration
74
+
75
+ The gem automatically integrates with Rails applications. Configure it in an initializer:
76
+
77
+ ```ruby
78
+ # config/initializers/sidekiq_mcp.rb
79
+ Sidekiq::Mcp.configure do |config|
80
+ config.enabled = true
81
+ config.path = "/sidekiq-mcp"
82
+ config.auth_token = Rails.application.credentials.sidekiq_mcp_token
83
+ config.sse_enabled = true # Enable Server-Sent Events for real-time updates
84
+ end
85
+ ```
86
+
87
+ The MCP server will be available at the configured path (default: `/sidekiq-mcp`).
88
+
89
+ ### Manual Setup (Non-Rails)
90
+
91
+ For non-Rails applications, add the middleware to your Rack stack:
92
+
93
+ ```ruby
94
+ require 'sidekiq/mcp'
95
+
96
+ # Configure
97
+ Sidekiq::Mcp.configure do |config|
98
+ config.auth_token = "your-secret-token"
99
+ end
100
+
101
+ # Add to your config.ru or middleware stack
102
+ use Sidekiq::Mcp::Middleware
103
+ ```
104
+
105
+ ### Authentication
106
+
107
+ The MCP server supports two authentication methods:
108
+
109
+ 1. **Bearer Token**: Include `Authorization: Bearer your-token` header
110
+ 2. **HTTP Basic Auth**: Use any username with your token as the password
111
+
112
+ Example configuration for different MCP clients:
113
+
114
+ #### Claude Desktop
115
+
116
+ Add to your `claude_desktop_config.json`:
117
+
118
+ ```json
119
+ {
120
+ "mcpServers": {
121
+ "sidekiq": {
122
+ "command": "curl",
123
+ "args": [
124
+ "-X", "POST",
125
+ "-H", "Content-Type: application/json",
126
+ "-H", "Authorization: Bearer your-secret-token",
127
+ "http://localhost:3000/sidekiq-mcp"
128
+ ]
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ #### VS Code with Claude Extension
135
+
136
+ Configure in your VS Code settings:
137
+
138
+ ```json
139
+ {
140
+ "claude.mcpServers": {
141
+ "sidekiq": {
142
+ "url": "http://localhost:3000/sidekiq-mcp",
143
+ "headers": {
144
+ "Authorization": "Bearer your-secret-token"
145
+ }
146
+ }
147
+ }
148
+ }
149
+ ```
150
+
151
+ #### Cursor
152
+
153
+ Add to your Cursor configuration:
154
+
155
+ ```json
156
+ {
157
+ "mcp": {
158
+ "servers": {
159
+ "sidekiq": {
160
+ "command": ["curl"],
161
+ "args": [
162
+ "-X", "POST",
163
+ "-H", "Content-Type: application/json",
164
+ "-H", "Authorization: Bearer your-secret-token",
165
+ "http://localhost:3000/sidekiq-mcp"
166
+ ]
167
+ }
168
+ }
169
+ }
170
+ }
171
+ ```
172
+
173
+ #### Claude Code
174
+
175
+ Configure via CLI:
176
+
177
+ ```bash
178
+ claude mcp add --transport http sidekiq-mcp-server http://localhost:3000/sidekiq-mcp
179
+ ```
180
+
181
+ Or add to your MCP configuration:
182
+
183
+ ```json
184
+ {
185
+ "sidekiq-mcp": {
186
+ "endpoint": "http://localhost:3000/sidekiq-mcp",
187
+ "auth": {
188
+ "type": "bearer",
189
+ "token": "your-secret-token"
190
+ }
191
+ }
192
+ }
193
+ ```
194
+
195
+ ## Development
196
+
197
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
198
+
199
+ The `example/` directory contains a sample Rails application demonstrating the integration.
200
+
201
+ ## Contributing
202
+
203
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andrew/sidekiq-mcp.
204
+
205
+ ## License
206
+
207
+ The gem is available as open source under the terms of the MIT License.
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,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rack"
4
+ require "base64"
5
+
6
+ module Sidekiq
7
+ module Mcp
8
+ class Middleware
9
+ def initialize(app)
10
+ @app = app
11
+ @server = Server.new
12
+ end
13
+
14
+ def call(env)
15
+ request = Rack::Request.new(env)
16
+
17
+ return @app.call(env) unless mcp_request?(request)
18
+ return unauthorized_response unless authorized?(request)
19
+
20
+ if request.post?
21
+ handle_mcp_request(request)
22
+ else
23
+ method_not_allowed_response
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def mcp_request?(request)
30
+ config = Sidekiq::Mcp.configuration || Sidekiq::Mcp::Configuration.new
31
+ request.path == config.path
32
+ end
33
+
34
+ def authorized?(request)
35
+ config = Sidekiq::Mcp.configuration || Sidekiq::Mcp::Configuration.new
36
+
37
+ return true unless config.auth_token
38
+
39
+ auth_header = request.env["HTTP_AUTHORIZATION"]
40
+ return false unless auth_header
41
+
42
+ if auth_header.start_with?("Bearer ")
43
+ token = auth_header.split(" ", 2).last
44
+ token == config.auth_token
45
+ elsif auth_header.start_with?("Basic ")
46
+ # For Basic auth, expect username to be anything and password to be the token
47
+ encoded = auth_header.split(" ", 2).last
48
+ decoded = Base64.decode64(encoded)
49
+ _username, password = decoded.split(":", 2)
50
+ password == config.auth_token
51
+ else
52
+ false
53
+ end
54
+ end
55
+
56
+ def handle_mcp_request(request)
57
+ body = request.body.read
58
+ response = @server.handle_request(body)
59
+
60
+ return no_content_response if response.nil?
61
+
62
+ [
63
+ 200,
64
+ {
65
+ "Content-Type" => "application/json",
66
+ "Access-Control-Allow-Origin" => "*",
67
+ "Access-Control-Allow-Methods" => "POST, OPTIONS",
68
+ "Access-Control-Allow-Headers" => "Content-Type, Authorization"
69
+ },
70
+ [response.to_json]
71
+ ]
72
+ rescue => e
73
+ error_response(e.message)
74
+ end
75
+
76
+ def unauthorized_response
77
+ [
78
+ 401,
79
+ { "Content-Type" => "application/json" },
80
+ [{ error: "Unauthorized" }.to_json]
81
+ ]
82
+ end
83
+
84
+ def method_not_allowed_response
85
+ [
86
+ 405,
87
+ { "Content-Type" => "application/json" },
88
+ [{ error: "Method not allowed" }.to_json]
89
+ ]
90
+ end
91
+
92
+ def no_content_response
93
+ [204, {}, []]
94
+ end
95
+
96
+ def error_response(message)
97
+ [
98
+ 500,
99
+ { "Content-Type" => "application/json" },
100
+ [{ error: "Internal server error: #{message}" }.to_json]
101
+ ]
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/railtie"
4
+
5
+ module Sidekiq
6
+ module Mcp
7
+ class Railtie < Rails::Railtie
8
+ railtie_name :sidekiq_mcp
9
+
10
+ config.after_initialize do
11
+ # Auto-configure if in Rails environment
12
+ Rails.application.config.middleware.use Sidekiq::Mcp::Middleware
13
+
14
+ # Add SSE middleware if enabled
15
+ if Sidekiq::Mcp.configuration&.sse_enabled != false
16
+ Rails.application.config.middleware.use Sidekiq::Mcp::SseMiddleware
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq
4
+ module Mcp
5
+ class Routes
6
+ def self.mount(app, path: "/sidekiq-mcp")
7
+ # Configure the MCP path
8
+ Sidekiq::Mcp.configure do |config|
9
+ config.path = path
10
+ end
11
+
12
+ # Add the middleware to the Rack stack
13
+ app.use Sidekiq::Mcp::Middleware
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Sidekiq
6
+ module Mcp
7
+ class Server
8
+ PROTOCOL_VERSION = "2025-06-18"
9
+
10
+ def initialize
11
+ @tools = ToolsRegistry.new
12
+ end
13
+
14
+ def handle_request(body)
15
+ request = JSON.parse(body)
16
+
17
+ case request["method"]
18
+ when "initialize"
19
+ handle_initialize(request)
20
+ when "tools/list"
21
+ handle_tools_list(request)
22
+ when "tools/call"
23
+ handle_tools_call(request)
24
+ when "notifications/initialized"
25
+ handle_initialized(request)
26
+ else
27
+ error_response(request["id"], -32601, "Method not found")
28
+ end
29
+ rescue JSON::ParserError
30
+ error_response(nil, -32700, "Parse error")
31
+ rescue => e
32
+ error_response(request&.dig("id"), -32603, "Internal error: #{e.message}")
33
+ end
34
+
35
+ private
36
+
37
+ def handle_initialize(request)
38
+ {
39
+ jsonrpc: "2.0",
40
+ id: request["id"],
41
+ result: {
42
+ protocolVersion: PROTOCOL_VERSION,
43
+ capabilities: {
44
+ tools: {}
45
+ },
46
+ serverInfo: {
47
+ name: "sidekiq-mcp",
48
+ version: Sidekiq::Mcp::VERSION
49
+ }
50
+ }
51
+ }
52
+ end
53
+
54
+ def handle_tools_list(request)
55
+ {
56
+ jsonrpc: "2.0",
57
+ id: request["id"],
58
+ result: {
59
+ tools: @tools.list
60
+ }
61
+ }
62
+ end
63
+
64
+ def handle_tools_call(request)
65
+ tool_name = request.dig("params", "name")
66
+ arguments = request.dig("params", "arguments") || {}
67
+
68
+ result = @tools.call(tool_name, arguments)
69
+
70
+ {
71
+ jsonrpc: "2.0",
72
+ id: request["id"],
73
+ result: {
74
+ content: [
75
+ {
76
+ type: "text",
77
+ text: result
78
+ }
79
+ ]
80
+ }
81
+ }
82
+ end
83
+
84
+ def handle_initialized(request)
85
+ # No response needed for notifications
86
+ nil
87
+ end
88
+
89
+ def error_response(id, code, message)
90
+ {
91
+ jsonrpc: "2.0",
92
+ id: id,
93
+ error: {
94
+ code: code,
95
+ message: message
96
+ }
97
+ }
98
+ end
99
+ end
100
+ end
101
+ end