Skip to content

feat: run admitted MCP tools on the worker node that hosts them - #191387

Merged
stevenlee-oai merged 26 commits into
mainfrom
dev/stevenlee/same-node-mcp
Nov 3, 2026
Merged

stevenlee-oai merged 26 commits into
mainfrom
dev/stevenlee/same-node-mcp

Conversation

@stevenlee-oai

@stevenlee-oai stevenlee-oai commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Builds on the Gateway question flow merged in #191589. This PR targets main and adds same-node execution.

What Problem This Solves

A dedicated worker can run the model turn on the same node that owns an MCP client. Sending that call through the Gateway serializes the projected result and loses the metadata Code Mode needs to expose it to the model.

User Impact

A compatible worker calls its node's existing MCP client through its supervisor and projects the result in the model process. The MCP server can run on the node or at a remote HTTPS endpoint. In the Slack test, OCE handled OAuth and the worker used a bearer placeholder for Slack’s hosted MCP server. Known timeouts, authentication failures, and incompatible responses reach the model with a bounded, redacted diagnostic. Unexpected exceptions get a generic message.

Why This Change Was Made

The Gateway applies the turn's tool policy and grants a handle only for eligible tools on the selected node. Older workers, tools on other nodes, and tools requiring Gateway hooks retain Gateway dispatch. The node captures permission when the launch arrives. Once the node processes a withdrawal or connection replacement, an old grant cannot start another MCP call. Restoring permission requires a fresh grant for a later turn. The model turn can continue.

When a local tool asks the user for input, the worker presents its Gateway-issued grant from this turn. Only the question and answer use the Gateway. A tool with execution permission alone receives a local decline. Workers using the earlier preview protocol fall back to Gateway dispatch.

Evidence

Question routing. A real HTTP MCP server received engineering through either execution route. After the user answered, retiring the grant or replacing the pairing prevented delivery on both routes. Ending the originating turn also blocked delivery to a worker that was still waiting. With tool execution alone, the worker declined locally and sent zero Gateway requests. The test controls the paired transport and the answering user. Server-side checks

Transport compatibility. The direct node runner can receive the Gateway's local execution policy. The macOS app's private bridge keeps MCP calls on Gateway dispatch. The stdio regression test checks that a configured app worker offers the routed MCP command, omits local execution from its inventory and dispatches a routed invocation. The test uses a stub invocation handler. Older preview workers advertising worker-local-mcp-v1 also use Gateway dispatch.

Earlier live Console run on a dedicated worker. With a real Slack account, the first turn of revision 1 returned the exact clickable thread permalink in Slack's MCP result, including its thread timestamp. The Gateway trace covered one worker launch and 17 worker control frames. It recorded one admitted search handle, zero worker-to-Gateway invocations for that handle, and zero Gateway-to-node MCP invocations. This run used the OCE runtime backport at e38c4e63 before the diagnostic and launch-race fixes below.

What reaches the MCP server. The integration test uses the production Gateway registry, worker supervisor and node MCP client, and sends requests to a real loopback HTTP MCP server. The Gateway socket, worker process, journal and turn descriptors are controlled test fixtures. The server counts incoming tools/call frames before it dispatches them. Each successful control also executes the tool.

Request Incoming tools/call
Admitted handle 1
Ungranted handle 0
After withdrawal 0
Same grant after permission is restored 0
Previous turn's frame, or its handle sent by the current turn 0 each
Current turn's admitted handle 1
Old connection after replacement 0
Newly admitted handle on the replacement connection 1

Run node scripts/test-projects.mts src/node-host/node-worker-mcp.authority.integration.test.ts to reproduce the server request counts. Other tests exercise turn admission, remote or older workers, live pairing changes, Code Mode result projection, cancellation, and Linux supervisor process ownership.

Launch race. On the previously reviewed head f04d03a9, withdrawing and restoring permission while workspace admission was paused let a queued launch invoke the MCP client once, for both a fresh and a retained child. With this fix, both reject the old handle before invoking the client. Separate ingress coverage checks that the model turn's cancellation signal stays live.

The local upstream tests used an existing dependency installation because the registry's package-age rule deferred one dependency in a clean install.

The test allocation covers 1,019 net lines for worker admission, permission withdrawal on retained workers, server request counts, pending answers, result projection and transport fallback. The routed and same-node Gateway event suite passed all 28 tests.

CI

On 5f93758e1fa, all 28 Gateway event tests and all three worker-local MCP tests passed. The repository's test-line check passed after incorporating the baseline reconciliation from main (6,444,905 lines against a ceiling of 6,444,915). Upstream correction · CI for this head

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 5f93758e1fa7683a68fb02f144b2d15a0edb6eb5
  • Maintainer: @stevenlee-oai
  • Repository role: maintain

These security sensitive changes were made:

  • src/gateway/node-command-policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/server/ws-connection/connect-hello.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 2, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets compatible workers execute admitted MCP tools through their node’s existing MCP client and project results inside the model process.

Example: A worker calls documents.search and receives structuredContent containing document: 7.

  • Before: Gateway serialization loses the process-local metadata that exposes the raw MCP result to Code Mode.
  • After: The worker projects the result locally, so Code Mode receives document: 7.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent implementation with resolved prior findings and meaningful transport-boundary authority evidence; upgrade coverage remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Code Mode on a dedicated worker loses MCP result metadata when a same-node call is projected and serialized through the Gateway.
Reason: The maintainer-authored direction restores useful model-visible results while retaining existing policy-sensitive and incompatible-worker routes.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: it provides useful same-node MCP execution, preserves Gateway fallback, and has no identified code defect.

Priority: P2
Reviewed head: 5f93758e1fa7683a68fb02f144b2d15a0edb6eb5

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply the previously requested v2026.10.10 upgrade run covering same-node execution and legacy fallback with existing settings and data preserved; redact credentials and non-public endpoints.
Agent review details

How this fits together

The Gateway admits the tool surface and issues turn-scoped handles; the node supervisor resolves those handles through its MCP client and returns raw results for worker-side projection.

flowchart LR
  A[Gateway tool admission] --> B[Worker turn grant]
  B --> C[Model worker]
  C --> D[Node supervisor]
  D --> E[Existing MCP client]
  E --> F[MCP server]
  F --> C
  C --> G[Code Mode result]
Loading

Technical review

Best possible solution:

Use the existing node MCP client for eligible same-node tools, project results in the worker, and preserve Gateway execution wherever its policies or transport are required.

Do we have a high-confidence way to reproduce the issue?

Current-main Gateway proxies reconstruct serialized results, while Code Mode MCP metadata lives in a process-local WeakMap; source inspection establishes the boundary without executing target code.

Is this the best way to solve the issue?

The implementation addresses that boundary through existing admission, supervisor, MCP-client, and projection owners; the extracted tool-surface module and reused retained-worker fixture support a coherent same-node stage after the separately merged question flow.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a12e3ae8d85d.

Provenance checked

  • Node-hosted MCP execution changes intended behavior with a stated reason (49b5b86: Let paired nodes publish MCP tools and execute calls through their canonical node-host client.)
  • Prepared worker tool execution keeps the original intent (62e0b2b: Keep admitted tools bound to their prepared plugin generation until the turn finishes.)
  • Retained worker lifetime keeps the original intent (e4d602c: Retain physical workers for background processes while giving each turn fresh admission and authority.)
  • MCP question authority keeps the original intent (e0ac337: Bind node-hosted questions to the originating session, paired connection, permission, and cancellation lifetime.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned scope and current state: Reviewed the introduced main-to-head diff at 5f93758; GitHub reports the same head as open, non-draft, and mergeable, with CI still pending. (5f93758e1fa7)
  • Admission preserves existing policy owners: Local placement requires matching node identity, negotiated support, action-independent permission, and absence of Gateway-only hooks or loop detection; other tools retain their Gateway executor. (src/gateway/worker-environments/worker-turn-tool-surface.ts:41, 5f93758e1fa7)
  • Authority reaches the transport boundary: The integration test uses the production registry, supervisor, and MCP client against real HTTP transport, counting incoming tools/call frames before server dispatch; admitted controls receive requests while ungranted, revoked, restored-old, stale-turn, and replaced-connection attempts receive none. (src/node-host/node-worker-mcp.authority.integration.test.ts:87, 5f93758e1fa7)
  • Prior findings resolved: Recognized MCP failures now retain bounded, redacted diagnostics, and local execution is advertised only by transports that receive policy updates; the private app bridge retains routed MCP invocation. (src/node-host/runtime.ts:264, 5f93758e1fa7)
  • Merged prerequisite remains distinct: The merged Gateway question flow in feat: let node-hosted MCP tools ask questions through the Gateway #191589 supplies elicitation ownership and stable-frame compatibility evidence, but does not implement this PR’s same-node result path. (src/gateway/node-mcp-elicitation.ts:22, e0ac3370bbe3)
  • Proof inspection and remaining coverage: The full current body and non-review discussion report server observations and an earlier live Slack result; the prepared image is only a Blacksmith button, and no supplied evidence shows the previously requested stable upgrade exercising this same-node path. (5f93758e1fa7)

Likely related people:

  • Peter Steinberger: Raw commit 49b5b86 adds src/node-host/mcp.ts:393 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 49b5b862acf3; files: src/node-host/mcp.ts)

PR surface

Source +795, Tests +1019, Docs +11, Other +5. Total +1830 across 52 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 33 931 136 +795
Tests 16 1327 308 +1019
Docs 1 16 5 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 2 5 0 +5
Total 52 2279 449 +1830

Review metrics

Metric Value Why it matters
Production versus test growth Production +931/-136 lines; tests and support +1327/-308 lines. Growth implements negotiated cross-process execution and its authority lifecycle; substantial test scaffolding is moved from the existing retained-worker suite and reused.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Useful worker MCP capability with limited scope and no demonstrated urgent availability or delivery regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (8 earlier review cycles)
  • reviewed 2026-11-02T19:30:03.261Z sha f04d03a :: needs real behavior proof before merge. :: [P2] Preserve recognized MCP failure details on local calls
  • reviewed 2026-11-02T19:53:55.447Z sha fb214e2 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-02T20:07:16.508Z sha 2a553f4 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-03T00:03:54.199Z sha 55a9b86 :: needs changes before merge. :: [P2] Advertise local MCP only on transports that deliver policy events
  • reviewed 2026-11-03T18:21:03.832Z sha fb5fc27 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-03T18:41:04.964Z sha ea75692 :: blocked before merge. :: none
  • reviewed 2026-11-03T18:55:26.371Z sha ea75692 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-03T21:51:54.582Z sha dd3b4e7 :: needs maintainer review before merge. :: none

Reviewed November 3, 2026, 5:40 PM ET / 22:40 UTC (Revision 9).

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Nov 2, 2026
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

Codex follow-up for fb214e292fb8a70189aead5b0923f090c9393dc5.

The worker now preserves recognized MCP error codes and bounded, redacted diagnostics, including the sign-in action for a 401. The Gateway error path keeps its existing behavior. I also reproduced a pending launch inheriting permission after withdrawal and restoration. The node now binds the grant when it receives the launch, before any wait for the workspace or journal. The model turn keeps its own cancellation signal.

The updated PR description includes the live Console trace and the server-observed request counts from the controlled HTTP MCP test. The server saw all three admitted controls and zero requests for the ungranted, revoked, replaced-connection and previous-turn cases. The test counts incoming frames before the MCP server dispatches a tool.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 3, 2026
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

Codex CI attribution for the remaining item on ea75692076e. Scheduled CI on main checked out 2813b78ac9f71a2963502c242c7e6e45c3bde99d. Its two suites fail with the same selectors and assertions as this PR.

  • The settings layout times out waiting for .settings-section__heading. PR log · main log
  • The native embed gets profile: expected false to be true on mobile and times out waiting for .settings-table--stacked tbody td[data-label] on desktop. PR log · main log

Both tests install their own mock Gateway. Their settings implementation and fixtures are unchanged in this PR. I classified these as inherited failures and added the comparison to the PR description.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 3, 2026
@blacksmith-sh

This comment has been minimized.

Base automatically changed from dev/stevenlee/node-mcp-elicitation to main November 3, 2026 21:33
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

Codex follow-up for dd3b4e76982. #191589 has landed and the PR now targets main directly. The merge preserves the same-node changes across the 52 files and incorporates main's fixes for the two inherited settings E2E failures. The three worker-local MCP tests passed on this head. Current CI

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 3, 2026
@stevenlee-oai

Copy link
Copy Markdown
Contributor Author

Codex follow-up for 411995bf04f. This merge incorporates main’s corrected 820px Memory layout test. Its CI shard and the Android 16 KiB native tests now pass. The repository’s test-line check still reports the 294-line deficit inherited from main. The same-node change adds 1,019 lines of tests and a matching allocation. Current CI · Test-line check

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 3, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 3, 2026
@stevenlee-oai
stevenlee-oai merged commit e7f19b1 into main Nov 3, 2026
265 of 268 checks passed
@stevenlee-oai
stevenlee-oai deleted the dev/stevenlee/same-node-mcp branch November 3, 2026 23:49
vincentkoc added a commit that referenced this pull request Nov 4, 2026
…elease-test-budget-20261104

* commit 'd27139b2b220327d6f65b659c6fba0b0110fad97':
  fix(ci): reconcile remaining unallocated test lines
  feat: run admitted MCP tools on the worker node that hosts them (#191387)
  fix(agents): use canonical MCP catalog metadata type
  fix(ci): preserve injected CLI fetch mock identity
  fix(models): avoid revalidating trusted remote catalog snapshots (#192363)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 4, 2026
…claw#191387)

* feat: run admitted MCP tools on the worker node that hosts them

* fix: preserve MCP result compatibility for local worker calls

* fix: type the node MCP client method for unbound use

* fix: bind local MCP permission at launch receipt and preserve tool diagnostics

* test: count local MCP calls at the HTTP request boundary

* docs: distinguish node-owned MCP clients from remote OAuth servers

* feat: let node-hosted MCP tools ask questions through the gateway

* fix: return an explicit empty result for unbound MCP calls

* fix: forward worker MCP questions only for a granted tool handle

* fix: advertise local MCP only on nodes that receive policy updates

* test: check pending MCP answers at the server after revocation

* test: refuse stale MCP answers on a dedicated worker

* refactor: reuse the worker MCP wire feature for node negotiation

* fix: await MCP questions across the private app bridge

* test: account for same-node MCP security and compatibility coverage

* fix: preserve the MCP work budget while the native host waits for an answer

* fix: advertise MCP elicitation without growing the Control UI bundle

---------

Co-authored-by: Codex <[email protected]>
vincentkoc added a commit that referenced this pull request Nov 4, 2026
* commit 'b4ebd3673fea4932296b92bbc07b7abc4bdc792d':
  fix(ci): allow serial SDK API reports to finish (#192196)
  fix(ci): run PostgreSQL checks when its shard planner changes (#191963)
  fix(ci): model native Linux updater asset entry
  improve(test): speed up config and device binding browser tests (#192404)
  improve(ui): show arrivals top right with a contextual session status (#192016)
  improve(ui): mark error toasts and split two-sentence copy (#192015)
  fix(sandbox): give dependency builders a writable home (#192390)
  fix(worktrees): keep archive manifest checks off the main thread (#192358)
  fix(cron): preserve admitted runs and pacing across unrelated MCP reloads (#192399)
  improve(ui): stack toasts in a center lane and an arrivals lane (#192014)
  fix: reclaim abandoned read-only database snapshots (#192368)
  improve(ui): rebuild the toast on one component with variants and a hover dismiss (#192013)
  docs: consolidate team server and team setup into one Multiplayer page
  fix(ci): reconcile remaining unallocated test lines
  feat: run admitted MCP tools on the worker node that hosts them (#191387)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants