Skip to content

refactor(mcp): register service-backed tools through one contract binding loop - #11264

Merged
morluto merged 3 commits into
mainfrom
refactor/mcp-contract-tool-bindings
Nov 15, 2026
Merged

morluto merged 3 commits into
mainfrom
refactor/mcp-contract-tool-bindings

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of plan W1 (one owner for adding a tool). Every service-backed MCP tool had its own src/server/register*.ts file: about 25 lines that resolved toolContract(name), wrapped one service method in createEvidenceToolHandler or createRetainedSummaryToolHandler, picked toolRegistrationOptions or applicationToolRegistrationOptions, and called server.registerTool. Adding a tool meant adding another copy and wiring it into createServer.

registerContractTools in src/server/contractToolBindings.ts is now the single registration loop for those tools. createServer declares one binding per contract name, and the loop registers each bound contract from the registry through the shared handler its binding selects. 41 register files are deleted.

Refs #10583

Problem and expected behavior

Expected: adding a service-backed MCP tool touches its contract and one binding entry, with the handler and registration options chosen by one owner. Before: a new register*.ts file, an import and a call in createServer, and a per-file choice of handler and registration options that could drift (for example, inspect_byte_entropy and inspect_native_exports both use the retained-summary handler but different admission).

Change and scope

  • src/server/contractToolBindings.ts (new owner):
    • ContractToolBindings is keyed by exact catalog contract name. Each binding declares admission: "sdk" | "application" (who validates the raw request: the SDK through the contract request frame, or the application workflow) and either run (Evidence handler) or summary (retained-summary handler).
    • summary is only accepted for contracts whose input selects detail; this is checked at compile time, and a test pins it with @ts-expect-error.
    • contractServiceBindings(service, names) binds the named operations of a ContractToolService (ADB, JEB, Apktool, firmware, Flutter, pcap).
    • registerContractTools(server, bindings, dependencies, contracts = TOOL_CONTRACTS) iterates the registry, registers every bound contract, and throws at startup when a binding names no registered contract.
    • A binding selects exactly one handler: run and summary exclude each other in the type.
  • src/server/serviceToolBindings.ts (new): SERVICE_TOOL_BINDINGS is the one table of these bindings, keyed by the service that runs them, with each entry's production admission, handler kind and retention. registerServiceTools(server, services, dependencies) registers the supplied services. createServer and the MCP tests both bind from it, so a test covers the production wiring.
  • src/server/createServer.ts: the families keep their call sites and order. Each run of simple registrations is now one registerServiceTools call naming its services. inspect_byte_entropy moves out of registerBinaryDiagnosticsTools, which keeps only the bespoke inspect_binary_layout.
  • Deleted (41): the register files for the V8 code cache, PE resources/certificates/imports/load config, SQLite, Apple IPS, binary hardening, ELF notes and unwind ranges, kernel module and build config, native initializers and exports, release exposure, Windows shortcut, recorded crash, web module and source location, JavaScript recovery, IL2CPP, APK signature, Go, Rust, GPU code objects, model artifact, desktop application, devicetree, Erlang, Python pyc, byte entropy, EVM, packet capture, signal recording, Wasm, firmware, JEB, Apktool, ADB, pcap and Flutter.
  • scripts/ci/scopes.mjs: the deleted paths are removed from their scopes; the new owners stay unscoped, so changing them takes the full-suite fallback. .github/workflows/real-go-binary.yml watches the new owners instead of the deleted registerGoTools.ts. tests/evaluation/ciTestSelection.test.ts uses the new owner as its MCP-implementation sample.

Not included (named exceptions that keep their own register files, because their registration is not one service call per contract): sessions, session status and records, guidance, prompts, analysis settings and views, evidence, investigation, enhanced and official proxy tools, reverse-engineering, Cutter, GDB, Rizin, Frida, browser, electron, web runtime and network capture, JavaScript runtime observation, Android, managed, application, desktop build, comparisons, close lifecycle, web script, native function matching. Moving their simple members onto the loop is follow-up work. Capability availability (CapabilityInventory) and toolEffects.ts are separate W1 items.

Contract and boundary impact

  • Semantic owner and earliest changed stage: registerContractTools owns MCP registration for bound contracts. The handlers (createEvidenceToolHandler, createRetainedSummaryToolHandler) and registration options are unchanged and are now chosen in one place. The superseded per-tool files are deleted.
  • Contribution scope fit and linked maintainer decision: not applicable (internal refactor within existing boundaries).
  • CLI and MCP/tool-catalog contract: unchanged. Every migrated tool keeps its contract, handler kind and admission. npm run verify:advertised-schemas reports the committed summary current.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none. Recording, lookup and admission are passed through as before.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • tests/boundary/mcp/contractToolBindings.test.ts (new):
      • A synthetic contract appended to the registry is listed by tools/list and dispatched to its binding from the binding alone, with no register file.
      • A binding that names no registered contract is refused at startup.
      • At compile time, summary is refused for a contract without detail, and a binding with both run and summary is refused.
    • The MCP tests that called the deleted register functions directly now register through the production table with registerServiceTools: binaryDiagnosticsMcp, devicetreeMcp, erlangBeamMcp, evmInterfaceMcp (including its duplicate-registration refusal), modelArtifactPartialReadFailure and process-global/modelHostReadFailure.
  • Base reproduction or other evidence: refactor; the existing MCP workflow tests of every migrated tool pass unchanged.
  • User-visible CLI/MCP output (if applicable): none changed.
  • Remaining proof gaps: optional providers that are not installed locally (skipped files listed below) were not exercised end to end.

Validation performed

  • npm run test:focused -- with the new test, the six migrated test files, tests/evaluation/ciTestSelection.test.ts, toolSchemaValidity, toolFamiliesMcp, clientCapabilities, advertisedCatalogSummary and the MCP tests of the migrated tools (apktool, appleIps, binaryHardening, desktopApplication, elfNotes, elfUnwindRanges, firmware, flutter, goBinary, javascriptRecovery, jeb, kernelBuildConfig, kernelModule, packetCapture, pcap, peCertificates, peImports, peLoadConfig, pythonPyc, recordedCrash, releaseExposure, adb, nativeInitializers, rustBinary, signalRecording, v8CodeCache, wasmArtifact, webModuleTrace, webSourceLocation, windowsShortcut): 40 files passed and 2 skipped; 222 tests passed and 4 skipped.
  • npx oxfmt --check .: passed.
  • npm run check:fast (typecheck and lint): passed.
  • node scripts/verify/architecture-guards.mjs: passed.
  • npm run verify:advertised-schemas: passed (summary current).
  • After the review fixes (2b2cadf), the same focused run, check:fast, the guards and verify:advertised-schemas were repeated: all passed (40 files passed and 2 skipped; 222 tests).

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; no provider behaviour changed.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none. Registration options and admission are preserved per tool.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

…ding loop

registerContractTools registers every bound contract from the registry through the shared Evidence or retained-summary handler its binding selects, and refuses a binding that names no registered contract. createServer declares the bindings by exact contract name; 41 per-tool register files are deleted.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T15:10:10.815287Z
We couldn’t complete this review. Comment @codex review to try again.
f6e1118 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no blocking issue remains.

Summary

Moves service-backed MCP registration into serviceToolBindings.ts and the shared registerContractTools loop.

  • Service-backed MCP tools now register from a shared contract-binding path.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["createServer: supplied services"] --> B["serviceToolBindings: named bindings"]
  B --> C["registerContractTools"]
  D["TOOL_CONTRACTS"] --> C
  C --> E["Choose registration options"]
  E --> F{"Binding handler"}
  F --> G["createEvidenceToolHandler"]
  F --> H["createRetainedSummaryToolHandler"]
  G --> I["server.registerTool"]
  H --> I
Loading

Reviews (3) · Last reviewed commit: "test(mcp): assert binding exclusivity wi..." · Reviewed by Greptile

Comment thread src/server/contractToolBindings.ts Resolved
Comment thread src/server/createServer.ts Resolved
…ke each binding select one handler

serviceToolBindings owns the binding of every service-backed contract, keyed by its service; createServer and the MCP tests bind from it, so tests exercise the production handler kind, admission and dependencies. A binding can no longer carry both run and summary. The Go real-binary workflow follows the new registration owners.
@morluto
morluto merged commit 7aea984 into main Nov 15, 2026
8 checks passed
@morluto
morluto deleted the refactor/mcp-contract-tool-bindings branch November 15, 2026 15:55
mvanhorn added a commit to mvanhorn/rea that referenced this pull request Nov 15, 2026
Main replaced the per-tool register files with the service binding table
(morluto#11264) and declares standalone availability on contracts (morluto#11262), so
inspect_deb_package now binds through serviceToolBindings, declares
availability "standalone", and registerDebPackageTool.ts is removed.

The default MCP profile no longer lists output schemas (morluto#10693), so the
deb MCP test validates the canonical contract output schema instead.
Plastic-time added a commit to Plastic-time/rea that referenced this pull request Nov 15, 2026
Main morluto#11264 registers service-backed MCP tools through one binding table,
and morluto#11270 declares tool availability on the contract. The merge takes
main's createServer.ts and CapabilityInventory.ts, then:

- binds inspect_pe_rich_header in serviceToolBindings.ts and passes the
  service to registerServiceTools, like inspect_pe_imports;
- marks the contract "standalone";
- removes registerPeRichHeaderTool.ts, as main removed its siblings.
@morluto morluto added the area: mcp MCP server, transport, and tool registration label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant