Fixed feat(mcp): register get_contract_status tool - #234
Conversation
Expose contract TTL health as an MCP tool by extracting status mapping into core and wiring a stdio MCP server that queries SQLite for per-entry lifespans. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@bigjoe-io Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📜 Recent review details🔇 Additional comments (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR adds contract TTL status computation, updates the ChangesContract status and MCP wiring
Sequence Diagram(s)sequenceDiagram
participant MCPClient
participant StdioServerTransport
participant McpServer
participant GetContractStatusTool
participant getContractStatus
participant Database
MCPClient->>StdioServerTransport: send get_contract_status call
StdioServerTransport->>McpServer: dispatch tool request
McpServer->>GetContractStatusTool: invoke handler with contractId
GetContractStatusTool->>getContractStatus: fetch ContractStatus
getContractStatus->>Database: load contract and entries
Database-->>getContractStatus: contract data
getContractStatus-->>GetContractStatusTool: ContractStatus
GetContractStatusTool-->>McpServer: CallToolResult
McpServer-->>StdioServerTransport: response
StdioServerTransport-->>MCPClient: text content and structuredContent
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/status.ts`:
- Around line 43-60: The `ContractEntry` type is out of sync with the database
schema for `live_until_ledger`, which makes the null-handling path in
`mapEntryStatus` unreachable. Update the `ContractEntry` definition in
`repositories.ts` so `live_until_ledger` is `number | null`, then keep the
existing `mapEntryStatus` logic in `status.ts` using `entry.live_until_ledger ??
null` and the `liveUntilLedger == null` check so rows with NULL can correctly
fall back to status "unknown".
In `@src/mcp/index.ts`:
- Around line 6-15: The MCP entrypoint currently connects StdioServerTransport
while the logger path still defaults to stdout and even uses console.log in
src/logging/logger.ts, which can corrupt JSON-RPC frames. Update the logger
setup used by createMcpServer/main so all runtime logs go to stderr or a file,
and remove any stdout writes from error formatting in the logger implementation.
Make sure the logger configuration and any initialization paths referenced by
getDatabase, tool execution, and contract status checks never emit to stdout on
the MCP stdio transport path.
In `@src/mcp/server.ts`:
- Around line 5-14: The server version in createMcpServer is hardcoded and can
drift from the package manifest; update McpServer initialization to source
version from package metadata instead of the literal "0.1.2". Use the
createMcpServer symbol as the fix point and ensure the reported MCP version
always matches the package.json version, either by importing the package JSON or
wiring the version in at build time.
In `@src/mcp/tools/get_contract_status.ts`:
- Around line 29-52: The get_contract_status tool registration is missing an
outputSchema, so its structuredContent is not validated at runtime. Add a Zod
schema that matches the ContractStatus shape used by formatContractStatusResult
and pass it into server.registerTool in registerGetContractStatusTool so clients
can rely on typed output.
In `@stdout`:
- Around line 53-78: The stdout fixture is capturing volatile machine-specific
fields that should be normalized before snapshotting. Update the logger/test
harness that produces this MonitorCycle output so PID, hostname, and absolute
checkout paths are redacted or replaced with stable placeholders, and keep the
rest of the threshold/error messages unchanged.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 301a166b-b211-4b2f-92d8-5af90a401a28
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (9)
package.jsonsrc/commands/status.tssrc/core/status.tssrc/mcp/index.tssrc/mcp/server.tssrc/mcp/tools/get_contract_status.tsstdouttests/core/status.test.tstests/mcp/get_contract_status.test.ts
📜 Review details
🔇 Additional comments (6)
src/core/status.ts (1)
76-95: LGTM!src/commands/status.ts (1)
17-61: LGTM!package.json (1)
6-19: LGTM!Also applies to: 40-49
src/mcp/tools/get_contract_status.ts (1)
11-27: LGTM!tests/core/status.test.ts (1)
19-150: LGTM!tests/mcp/get_contract_status.test.ts (1)
16-69: LGTM!
# Conflicts: # package-lock.json # package.json # stdout
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| - | - | Generic High Entropy Secret | 7efd589 | tests/commands/channels.test.ts | View secret |
| - | - | Generic High Entropy Secret | 617e5cd | tests/rpc/client.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Closes #174 Core status logic (src/core/status.ts)
TTL mapping from status.ts is now in core/ as getContractStatus(), returning structured JSON:
Contract metadata (contractId, name, network, lastCheckedLedger)
Per-entry TTL data (label, entryType, liveUntilLedger, remainingTTL, approximateTimeRemaining, status)
MCP server (src/mcp/)
get_contract_status tool — accepts contractId, queries SQLite, returns JSON
Stdio transport — run via npm run mcp or sorokeep-mcp after build
Errors for unregistered contracts return MCP isError: true
CLI refactor (src/commands/status.ts)
The status command now uses getContractStatus() so CLI and MCP stay in sync.
Tests (TDD)
tests/core/status.test.ts — 6 tests for mapping, edge cases, TTL classification
tests/mcp/get_contract_status.test.ts — 2 tests for JSON output and error handling
All 235 tests pass (with Node 22+).
Usage