Skip to content

Fixed feat(mcp): register get_contract_status tool - #234

Merged
AbdulmalikAlayande merged 3 commits into
TegoLabs:mainfrom
bigjoe-io:main
Jun 26, 2026
Merged

AbdulmalikAlayande merged 3 commits into
TegoLabs:mainfrom
bigjoe-io:main

Conversation

@bigjoe-io

Copy link
Copy Markdown

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

Bigjoe and others added 2 commits June 25, 2026 02:36
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>
@drips-wave

drips-wave Bot commented Jun 25, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3a7395d4-eda8-4cd5-8bf4-8f9ae902f011

📥 Commits

Reviewing files that changed from the base of the PR and between 3d43399 and d4c3e19.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json
📜 Recent review details
🔇 Additional comments (1)
package.json (1)

17-20: LGTM!


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a new command-line entry for viewing contract status through the MCP interface.
    • Introduced a status lookup that returns contract details, entry TTLs, and human-readable time remaining.
    • Added a new MCP tool for retrieving contract status in both plain text and structured formats.
  • Bug Fixes

    • Improved handling for missing contracts and incomplete ledger data by showing clear error or unknown states instead of failing.

Walkthrough

This PR adds contract TTL status computation, updates the status command to consume it, and exposes the same status result through a new MCP server and get_contract_status tool. Tests cover the core status logic and MCP tool responses.

Changes

Contract status and MCP wiring

Layer / File(s) Summary
Status core computation
src/core/status.ts, tests/core/status.test.ts
Contract and entry status types are added, TTL values are derived from contract and ledger data, and the core status suite covers missing contracts, missing TTL fields, expired entries, and empty entry lists.
Status command rendering
src/commands/status.ts
The status command now reads the structured status object, handles ContractNotFoundError, and renders contract and entry fields from returned status data.
MCP tool response
src/mcp/tools/get_contract_status.ts, tests/mcp/get_contract_status.test.ts
The get_contract_status tool validates contractId, formats JSON text plus structuredContent, and tests success and not-found responses.
MCP server and CLI exposure
package.json, src/mcp/server.ts, src/mcp/index.ts
The MCP server factory, stdio CLI entrypoint, executable script, and runtime dependencies are added to expose the tool.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • Issue 175: The MCP server and tool wiring in this PR is adjacent to another MCP tool registration path and shares the same server extension surface.

Possibly related PRs

  • AbdulmalikAlayande/sorokeep#7: Touches src/commands/status.ts, which is the same command path this PR refactors around structured contract status output.

Poem

A rabbit hopped by ledger light,
and found the TTLs shining bright.
The MCP wind went clickety-click,
with JSON carrots, neat and quick. 🐰🥕
Now status speaks in tidy sight.

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed Specific and matches the main change: adding the get_contract_status MCP tool.
Description check ✅ Passed The description is clearly about the MCP tool, core status refactor, and tests, so it matches the changeset.
Linked Issues check ✅ Passed The PR implements the MCP tool, accepts contractId, returns JSON status data, reuses status logic, and adds tests for success and error cases.
Out of Scope Changes check ✅ Passed The package.json and CLI updates support the MCP tool and shared status flow, so no unrelated changes are evident.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between c465cc7 and 3d43399.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (9)
  • package.json
  • src/commands/status.ts
  • src/core/status.ts
  • src/mcp/index.ts
  • src/mcp/server.ts
  • src/mcp/tools/get_contract_status.ts
  • stdout
  • tests/core/status.test.ts
  • tests/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!

Comment thread src/core/status.ts
Comment thread src/mcp/index.ts
Comment thread src/mcp/server.ts
Comment thread src/mcp/tools/get_contract_status.ts
Comment thread stdout Outdated
# Conflicts:
#	package-lock.json
#	package.json
#	stdout
@gitguardian

gitguardian Bot commented Jun 26, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
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
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. 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


🦉 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.

@AbdulmalikAlayande
AbdulmalikAlayande merged commit b75ba09 into TegoLabs:main Jun 26, 2026
2 checks passed
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.

feat(mcp): register get_contract_status tool

2 participants