Skip to content

Add MCP job inspection capabilities - #239

Merged
kentcdodds merged 4 commits into
mainfrom
cursor/mcp-job-inspection-ab5e
Apr 21, 2026
Merged

kentcdodds merged 4 commits into
mainfrom
cursor/mcp-job-inspection-ab5e

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Apr 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add signed-in job_list and job_get jobs-domain capabilities so MCP callers can inspect scheduled jobs without direct DB access
  • expose persisted debugging fields for each job, including schedule details, counters, last run status/error, recent run history, and whether a job is currently due
  • surface per-user JobManager alarm debug state through the jobs service and update jobs-domain metadata/instructions so the new inspection capabilities are discoverable
  • fix CI regressions by moving the new inspection capability service imports behind handler execution and centralizing the JobManager debug types in the manager client module
  • address AI reviewer feedback by normalizing alarm timestamp comparison, making due_now assertions deterministic, and tightening public numeric schemas for non-negative counters/durations

Testing

  • npm run typecheck
  • npm run test -- packages/worker/src/jobs/manager-do.node.test.ts packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts packages/worker/src/jobs/service.node.test.ts packages/worker/src/mcp/capabilities/build-capability-registry.workers.test.ts packages/worker/src/mcp/capabilities/meta/meta-list-capabilities.node.test.ts
  • npm run test:mcp -- packages/worker/src/mcp/mcp-server.mcp-e2e.test.ts
  • npm run build
Open in Web Open in Cursor 

Summary by CodeRabbit

Release Notes

  • New Features
    • Added job inspection capabilities to view all scheduled jobs with execution history and status
    • Added job manager debug state tracking to monitor scheduling health
    • New tools to list jobs and retrieve individual job details with run history and alarm status

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Apr 20, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@cursor[bot] has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 2 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 47 minutes and 2 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9a98c911-da07-481b-a9c2-1bd09bf19830

📥 Commits

Reviewing files that changed from the base of the PR and between 47a9d53 and f5859ba.

📒 Files selected for processing (10)
  • packages/worker/src/jobs/manager-client.ts
  • packages/worker/src/jobs/manager-do.node.test.ts
  • packages/worker/src/jobs/manager-do.ts
  • packages/worker/src/jobs/manager-state.ts
  • packages/worker/src/jobs/service.ts
  • packages/worker/src/mcp/capabilities/jobs/domain.ts
  • packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts
  • packages/worker/src/mcp/capabilities/jobs/shared.ts
  • packages/worker/src/mcp/jobs-embed.ts
  • packages/worker/src/mcp/server-instructions.ts
📝 Walkthrough

Walkthrough

This PR extends the job manager system with debugging and inspection capabilities. It introduces new APIs to retrieve debug state (binding availability, alarm scheduling status, next runnable job details) from the job manager, combines this with job data via new service functions, and exposes them through two new MCP capabilities (job_list and job_get) with corresponding schemas and output builders.

Changes

Cohort / File(s) Summary
Core Manager Debug APIs
packages/worker/src/jobs/manager-client.ts, packages/worker/src/jobs/manager-do.ts
Added JobManagerDebugStatus and JobManagerDebugState types. Implemented getDebugState() method in the Durable Object and exported getJobManagerDebugState() function that returns debug state (binding availability, alarm timestamp, next runnable job, sync status) or a default missing-binding state.
Service Inspection APIs
packages/worker/src/jobs/service.ts, packages/worker/src/jobs/service.node.test.ts
Added inspectJobsForUser() and getJobInspection() functions that concurrently fetch jobs and debug state. Added tests verifying inspection outputs include persisted job fields and alarm debug information.
MCP Job Capabilities
packages/worker/src/mcp/capabilities/jobs/job-list.ts, packages/worker/src/mcp/capabilities/jobs/job-get.ts, packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts
Created jobListCapability and jobGetCapability MCP handlers to expose job inspection endpoints. Updated test suite to mock new service functions and verify handler behavior for listing and retrieving jobs with inspection data.
MCP Domain & Shared Utilities
packages/worker/src/mcp/capabilities/jobs/domain.ts, packages/worker/src/mcp/capabilities/jobs/shared.ts
Updated domain metadata to include new list/get capabilities and expanded keywords. Added schemas and builders (jobInspectionSchema, jobManagerDebugSchema, buildJobInspectionOutput(), buildJobManagerDebugOutput()) for job inspection and debug state serialization.
Documentation & UI
packages/worker/src/mcp/jobs-embed.ts, packages/worker/src/mcp/server-instructions.ts
Updated usage instructions to recommend job_list and job_get for inspection workflows. Added tool documentation for debugging scheduling issues.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MCP as MCP Handler
    participant Service as Job Service
    participant JobStore as Job Store
    participant JobManager as JobManager DO
    
    User->>MCP: job_get(jobId)
    activate MCP
    MCP->>Service: getJobInspection({userId, jobId})
    activate Service
    par
        Service->>JobStore: getJob(jobId)
        activate JobStore
        JobStore-->>Service: job data
        deactivate JobStore
    and
        Service->>JobManager: getDebugState({userId})
        activate JobManager
        JobManager->>JobManager: read stored userId, alarm, next job
        JobManager-->>Service: debug state
        deactivate JobManager
    end
    Service-->>MCP: {job, alarm}
    deactivate Service
    MCP->>MCP: build inspection output
    MCP-->>User: job + alarm details
    deactivate MCP
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #237: Adds scheduling capabilities to the jobs MCP domain; directly related as this PR extends the same domain with inspection capabilities.
  • PR #170: Introduces the jobs system and JobManager infrastructure; directly related as this PR builds inspection features on top of that foundation by adding debug state APIs and service functions.

Poem

🐰 A curious rabbit peeks at the manager's mind,
Debug states and alarms of every kind,
List jobs, inspect one, see what's running near,
The inspection tools are crystal clear! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add MCP job inspection capabilities' directly and clearly describes the main change: introducing new job inspection capabilities to the MCP domain.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/mcp-job-inspection-ab5e

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kentcdodds
kentcdodds marked this pull request as ready for review April 20, 2026 22:08
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@github-actions

github-actions Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-239.kentcdodds.workers.dev

Worker: kody-pr-239
D1: kody-pr-239-db
KV: kody-pr-239-oauth-kv

Mocks:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/worker/src/jobs/service.ts (1)

11-21: Consolidate duplicate import from ./manager-client.ts.

syncJobManagerAlarm is imported on Line 11 and getJobManagerDebugState is imported again from the same module on Line 21. Merge them into a single import statement.

♻️ Proposed fix
-import { syncJobManagerAlarm } from './manager-client.ts'
 import {
 	deleteJobRow,
 	getJobRowById,
 	listDueJobRows,
 	listJobRowsByUserId,
 	getNextRunnableJobRow,
 	insertJobRow,
 	updateJobRow,
 } from './repo.ts'
-import { getJobManagerDebugState } from './manager-client.ts'
+import {
+	getJobManagerDebugState,
+	syncJobManagerAlarm,
+} from './manager-client.ts'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/worker/src/jobs/service.ts` around lines 11 - 21, The two imports
from the same module should be consolidated: replace the separate imports of
syncJobManagerAlarm and getJobManagerDebugState from './manager-client.ts' with
a single import statement that imports both symbols together; locate the import
declarations referencing syncJobManagerAlarm and getJobManagerDebugState in
service.ts and merge them into one import { syncJobManagerAlarm,
getJobManagerDebugState } from './manager-client.ts'.
packages/worker/src/mcp/capabilities/jobs/shared.ts (1)

83-113: Constrain counters and durations to non-negative integers.

run_count, success_count, error_count, duration_ms, and last_duration_ms are counters and durations that should never be negative. Tighten the schemas to z.number().int().min(0) to strengthen output validation and catch corrupted persisted debug data.

Proposed schema tightening
+const nonNegativeIntegerSchema = z.number().int().min(0)
+
 const jobRunHistoryEntrySchema = z.object({
 	started_at: z.string(),
 	finished_at: z.string(),
 	status: z.enum(['success', 'error']),
-	duration_ms: z.number(),
+	duration_ms: nonNegativeIntegerSchema,
 	error: z.string().nullable(),
 })
@@
-	last_duration_ms: z.number().nullable(),
-	run_count: z.number(),
-	success_count: z.number(),
-	error_count: z.number(),
+	last_duration_ms: nonNegativeIntegerSchema.nullable(),
+	run_count: nonNegativeIntegerSchema,
+	success_count: nonNegativeIntegerSchema,
+	error_count: nonNegativeIntegerSchema,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/worker/src/mcp/capabilities/jobs/shared.ts` around lines 83 - 113,
Update numeric counter and duration fields to enforce non-negative integers:
change jobRunHistoryEntrySchema.duration_ms to z.number().int().min(0), change
jobInspectionSchema.run_count, success_count, and error_count to
z.number().int().min(0), and change jobInspectionSchema.last_duration_ms to
z.number().int().min(0).nullable(); keep existing nullability on
published_commit/last_run_at/last_run_status/last_run_error as-is. These changes
should be applied on the jobRunHistoryEntrySchema and jobInspectionSchema
definitions referenced above.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/worker/src/jobs/manager-do.ts`:
- Around line 56-72: alarmInSync and status currently compare alarmScheduledFor
and nextRunnableRunAt as strings which can differ in formatting; change the
comparison to use normalized timestamps instead: convert alarmTimestamp/
alarmScheduledFor and nextJob.nextRunAt into numeric epochs (e.g., via new
Date(...).getTime()) or normalize both with new Date(...).toISOString() before
comparing, handling null/undefined the same way as now; update the logic that
sets alarmInSync and status to use these normalized values (symbols:
alarmScheduledFor, nextRunnableRunAt, alarmInSync, status) so equivalent
instants compare equal.

In `@packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts`:
- Around line 535-537: The object literal for the test job has inconsistent
indentation for the due_now key; align the indentation of "due_now" with its
sibling keys (next_run_at and last_run_at) in the job object (in this test
file's job literal) so it matches the surrounding spacing/indentation style,
then re-run the formatter or linter to ensure consistency.
- Around line 347-446: Test relies on the real clock so due_now is flaky; in the
test for job_list (which calls jobListCapability.handler and uses
buildJobInspectionOutput from shared.ts), enable fake timers and set the system
time to the expected moment (e.g., vi.useFakeTimers(); vi.setSystemTime(new
Date('2026-04-20T18:30:00.000Z'))) before invoking handler, then restore real
timers after the assertion with vi.useRealTimers(); insert these calls at the
start/end of the test so the due_now calculation is deterministic.

---

Nitpick comments:
In `@packages/worker/src/jobs/service.ts`:
- Around line 11-21: The two imports from the same module should be
consolidated: replace the separate imports of syncJobManagerAlarm and
getJobManagerDebugState from './manager-client.ts' with a single import
statement that imports both symbols together; locate the import declarations
referencing syncJobManagerAlarm and getJobManagerDebugState in service.ts and
merge them into one import { syncJobManagerAlarm, getJobManagerDebugState } from
'./manager-client.ts'.

In `@packages/worker/src/mcp/capabilities/jobs/shared.ts`:
- Around line 83-113: Update numeric counter and duration fields to enforce
non-negative integers: change jobRunHistoryEntrySchema.duration_ms to
z.number().int().min(0), change jobInspectionSchema.run_count, success_count,
and error_count to z.number().int().min(0), and change
jobInspectionSchema.last_duration_ms to z.number().int().min(0).nullable(); keep
existing nullability on
published_commit/last_run_at/last_run_status/last_run_error as-is. These changes
should be applied on the jobRunHistoryEntrySchema and jobInspectionSchema
definitions referenced above.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 42c81ca1-1488-4650-996c-ee09da5e13ee

📥 Commits

Reviewing files that changed from the base of the PR and between 6e650bf and 47a9d53.

📒 Files selected for processing (11)
  • packages/worker/src/jobs/manager-client.ts
  • packages/worker/src/jobs/manager-do.ts
  • packages/worker/src/jobs/service.node.test.ts
  • packages/worker/src/jobs/service.ts
  • packages/worker/src/mcp/capabilities/jobs/domain.ts
  • packages/worker/src/mcp/capabilities/jobs/job-get.ts
  • packages/worker/src/mcp/capabilities/jobs/job-list.ts
  • packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts
  • packages/worker/src/mcp/capabilities/jobs/shared.ts
  • packages/worker/src/mcp/jobs-embed.ts
  • packages/worker/src/mcp/server-instructions.ts

Comment thread packages/worker/src/jobs/manager-do.ts Outdated
Comment thread packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts
Comment thread packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 47a9d53. Configure here.

Comment thread packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts Outdated
cursoragent and others added 2 commits April 20, 2026 22:49
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds
kentcdodds merged commit e80230c into main Apr 21, 2026
9 checks passed
@kentcdodds
kentcdodds deleted the cursor/mcp-job-inspection-ab5e branch April 21, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants