Skip to content

sdk/js, webapp: a browser lists tools that declare an output schema, and a failed dial names every path - #955

Merged
aojea merged 1 commit into
google:mainfrom
kaisoz:kaisoz/webapp-mcp-fixes
Nov 26, 2026
Merged

aojea merged 1 commit into
google:mainfrom
kaisoz:kaisoz/webapp-mcp-fixes

Conversation

@kaisoz

@kaisoz kaisoz commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes three problems found in one testnet session with agentmesh-webapp. They ship together because each is small, and all three are about what the browser shows an agent or a person.

Remote tools with an output schema did not load in the browser. The MCP SDK's client checks tool results with ajv. ajv compiles each output schema with new Function, and the page's Content Security Policy allows no eval. So find_remote_tools failed with an EvalError for any provider whose tools declare an outputSchema. The SDK's MCP client now uses the MCP SDK's own eval-free checker, CfWorkerJsonSchemaValidator, in Node and in the browser.

A failed connection showed the wrong reason. connect() tries three paths in turn:

  1. the peer's own addresses and the relays of the routers it holds;
  2. the addresses the directory knows for the peer;
  3. the routers it has not joined.

It reported only the last path's error. For an offline peer that was "no valid addresses", a directory address the browser cannot dial, and the relay's NO_RESERVATION was lost. With two routers, libp2p also folds both relays' answers into one "All multiaddr dials failed". connect() now throws cannot reach <peer>: with one line per path and its reason, as the Python SDK already does. It also reports a router that refuses the member and a failed directory lookup, which were skipped without a trace.

The dashboard counted routers as peers. "Connected Peers" counted every open connection, so a page that talked to no member showed one peer per router. The two counts now sit under Connections. Peers leaves the routers out. Routers is unchanged, because the page's timer for a lost router is timed on that count.

Evidence

  • Before: find_remote_tools against @modelcontextprotocol/server-everything behind agentmesh-node:
    EvalError: Evaluating a string as JavaScript violates the following Content Security Policy directive because 'unsafe-eval' is not an allowed source of script
    After: the tools are listed. npm test now runs with --disallow-code-generation-from-strings; the MCP test tool declares an output schema and fails with EvalError without the validator change.
  • Before: an offline peer reached through two routers: The dial request has no valid addresses for peer: 12D3KooW…
    After: cannot reach 12D3KooW…: followed by each router's NO_RESERVATION, the directory address's no valid addresses, and the router that refused the member (sdk/js/src/session.test.ts). A directory that answers with an error is reported as directory lookup: ….
  • Before: a page that talks to no member shows Connected Peers 1 with one router.
    After: Peers 0, Routers 1 (tests/ui/app.spec.js).
  • make lint, make ui-test (36 passed), sdk/js npm test (170 passed).

Risk

The change is easy to revert. It stores no data and changes no wire format.

Three things change for code that uses the JS SDK:

  • connect() and everything built on it now fail with a plain Error whose message lists each path. Before, they threw the libp2p error of the last path. Nothing in this repository checks the type of that error.
  • sdk/js has a new runtime dependency, @cfworker/json-schema. The MCP SDK already lists it as an optional peer.
  • The SDK tests now run with eval switched off. A future change that needs eval fails the tests, as it would fail in the web app.

On the dashboard, only the Peers number changes, and the labels move under a new heading. The Routers number and the lost-router timer behave as before.

…and a failed dial names every path

On a testnet, find_remote_tools from agentmesh-webapp failed in two ways,
and its dashboard counted routers as peers:

- A provider whose tools declare an outputSchema (server-everything) failed
  with "EvalError: ... 'unsafe-eval' is not an allowed source of script".
  The MCP SDK's client compiles each output schema with ajv, which builds
  validators with new Function, and the page's CSP allows no eval.
- Offline providers were reported as "NoValidAddressesError: The dial
  request has no valid addresses". connect() kept only the error of its last
  path, a directory address the browser has no transport for, and dropped
  the relay's NO_RESERVATION. With two held routers libp2p also folds the
  relays' answers into one "All multiaddr dials failed".
- "Connected Peers" counted every connection, so a page that talked to no
  member showed one peer per router, next to a Routers count of the same
  routers.

Now:

- The SDK's MCP client checks schemas with the MCP SDK's eval-free
  CfWorkerJsonSchemaValidator (@cfworker/json-schema, the MCP SDK's optional
  peer), in Node and in the browser.
- connect() throws "cannot reach <peer>:" with each path it tried and why it
  failed, as the Python SDK does. Errors libp2p aggregates are expanded, and
  a router that refuses the member or a failed directory lookup is reported
  instead of skipped.
- The dashboard groups its counts under Connections. Peers leaves the
  routers out. Routers is unchanged, the SDK's admitted routers, because the
  lost-session timer is timed on that count.

Tests:

- npm test runs the SDK suite with eval switched off
  (--disallow-code-generation-from-strings). The MCP test tool declares an
  output schema; without the validator change it fails with EvalError.
- Two session tests: one holds two routers, a directory address with no
  transport and a router that refuses the member; one gets an error from the
  directory. On the parent commit both get only the last path's error.
- The UI journey expects 0 peers after join; on the parent commit it shows 1.
@kaisoz
kaisoz requested a review from aojea as a code owner November 26, 2026 22:46

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the web application UI to separate routers from peers under a new 'Connections' section, updating the documentation and UI tests accordingly. In the JS SDK, it integrates @cfworker/json-schema as the JSON schema validator to comply with environments that disallow unsafe-eval in their Content Security Policy. Additionally, the SDK now aggregates and reports detailed failure reasons from all attempted paths when a peer connection fails, which is verified by new integration tests. No review comments were provided, so there is no feedback to evaluate.

@aojea
aojea merged commit f92adad into google:main Nov 26, 2026
22 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.

2 participants