Repository navigation
sdk/js, webapp: a browser lists tools that declare an output schema, and a failed dial names every path - #955
Merged
Conversation
…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.
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Sofind_remote_toolsfailed with anEvalErrorfor any provider whose tools declare anoutputSchema. 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: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_RESERVATIONwas lost. With two routers, libp2p also folds both relays' answers into one "All multiaddr dials failed".connect()now throwscannot 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
find_remote_toolsagainst@modelcontextprotocol/server-everythingbehind agentmesh-node:EvalError: Evaluating a string as JavaScript violates the following Content Security Policy directive because 'unsafe-eval' is not an allowed source of scriptAfter: the tools are listed.
npm testnow runs with--disallow-code-generation-from-strings; the MCP test tool declares an output schema and fails withEvalErrorwithout the validator change.The dial request has no valid addresses for peer: 12D3KooW…After:
cannot reach 12D3KooW…:followed by each router'sNO_RESERVATION, the directory address'sno valid addresses, and the router that refused the member (sdk/js/src/session.test.ts). A directory that answers with an error is reported asdirectory lookup: ….After: Peers 0, Routers 1 (
tests/ui/app.spec.js).make lint,make ui-test(36 passed),sdk/jsnpm 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 plainErrorwhose 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/jshas a new runtime dependency,@cfworker/json-schema. The MCP SDK already lists it as an optional peer.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.