Skip to content

fix(core): show function and reload errors in dev, and real errors over MCP - #602

Merged
jimhoyd merged 8 commits into
mainfrom
claude/dev-mcp-errors
Sep 24, 2026
Merged

jimhoyd merged 8 commits into
mainfrom
claude/dev-mcp-errors

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Closes #580
Closes #582
Refs #590 (protocol-version negotiation only; the naming, structuredContent and skills items need a separate decision)

What changes

Dev diagnostics (#580)

  • urlcode dev writes a function_error JSON line to stderr for a trusted function's generic 502/504: requestId, status, matched route, project-relative source, export, thrown message and stack. A handler's error keeps naming the handler as it bubbles out through middleware; the thrown value is not replaced, so middleware that catches it still sees the original. Shape failures (non-Response, bad status, changed native header, header/body limits, missing export) now carry a reason too.
  • urlcode serve --debug-errors turns on the same diagnostics. It is off by default, allowed only on serve, and rejected elsewhere.
  • The diagnostics use their own channel (ServerOptions.debugErrors / diagnostics, stderr by default). They never reach the response body, the JSON event log or observers, so the documented guarantee that the event log carries no exception text still holds. HttpError now accepts ErrorOptions, so the reason travels as cause.
  • A rejected reload still emits {"event":"reload","status":"rejected"}, and also writes reload_rejected to stderr with the message urlcode validate prints (shared describeError, moved from the CLI into errors.ts).
  • Trusted function load failures now name the file, line, export and the loader's message, for example Function initialization failed in f.mjs:3 (export default): SyntaxError: Unexpected token ';'. Node 26 gives an ESM syntax error no location, so only on that failure path the runtime runs node --check (parse only) on the entry file. A syntax error inside an imported module is reported as , in a module it imports.
  • Env, secret and egress denials caused by a policy pinned to a different projectSha256 now print both revisions and point at urlcode permissions. There is no auto-repin.
  • The sandboxed (sandbox: true) path is untouched. FunctionPool/function-worker.ts did not change, and sandboxed failures still report only the generic answer.

MCP (#582, #590)

  • A failed tool returns the CLI's message (for example the schema location of an invalid route, or the list of valid get_capability names), not Operation failed validation.
  • -32602 now names the unknown tool (and the flag that adds get_extensions or the authoring tools), each unknown, missing or invalid argument (using ajv allErrors), and the arguments the tool accepts.
  • Without a host file, plan_feature leaves get_extensions out of next. The CLI plan-feature follows the same rule.
  • explain_error matches ordered rules against the runtime's error families and returns matched, guidance, nextTools and, for a schema error, the decoded location. Unmatched text gets matched: null and a pointer to search_docs.
  • initialize echoes a requested protocolVersion it supports (2025-11-25, 2025-06-18, 2025-03-26, 2024-11-05) and otherwise answers 2025-11-25.

Docs updated: LOCAL-DEVELOPMENT (troubleshooting), TOOLING (MCP errors/negotiation), OBSERVABILITY and MONITORING (the diagnostics are not events), OPERATIONS (--debug-errors), FUNCTION-SECURITY (stale pin message), the RUNTIME-IMPLEMENTATION RIM-GUEST-001 card, and regenerated llms-full.txt.

Evidence

  • New test/dev-diagnostics.test.ts (7 tests) covers the function_error content and a generic body, handler attribution through middleware, silence without the flag, reload_rejected matching createRuntime's message, the stale-pin message, init failures (syntax line, top-level throw line, missing export, nested syntax error, unresolved package), and CLI validate output plus the --debug-errors guard.
  • test/mcp.test.ts has two new tests: protocol negotiation, and real tool errors, named tools and arguments, next without a host, and explain_error matching.
  • npm run verify passes locally and so does npm run test:package.

Limitations

  • Sandboxed routes get no function_error detail. Adding it would mean changing the worker bridge, which this PR deliberately does not do.
  • In a trusted module, the line for a syntax error inside an imported module is not located; the report names only the entry file.
  • The protocol negotiation was not tested against real clients on older revisions.

🤖 Generated with Claude Code

…er MCP

dev (and serve --debug-errors) now writes a function_error line to stderr
with the route, source file, export, thrown message and stack behind a
trusted function's generic 502/504, and a reload_rejected line carrying the
message validate prints. The response body, JSON event log and observers are
unchanged. Function load failures name the file, line, export and loader
message. A binding or egress denial caused by a policy pinned to an older
projectSha256 says so and points at `urlcode permissions`.

The MCP server returns the CLI's message for failed tools, names unknown
tools and bad or missing arguments in -32602, leaves get_extensions out of
plan_feature's next list without a host file, matches explain_error on the
supplied text, and echoes a supported requested protocol version.

Closes #580
Closes #582
Refs #590

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jimhoyd and others added 4 commits September 23, 2026 17:46
Report project-relative sources with forward slashes, parse node --check
output with CRLF line endings, and call a syntax error nested only when the
entry file itself parses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 24, 2026 01:13
# Conflicts:
#	llms-full.txt
#	packages/core/src/feature-plan.ts
# Conflicts:
#	llms-full.txt
#	packages/core/src/cli.ts
#	packages/core/src/mcp.ts
#	packages/core/src/policy.ts
#	packages/core/src/router.ts
…uard, and update stale test expectations

- router.ts: the pinned-policy binding-denial messages (#602) now combine
  with #607's grantHint wording instead of dropping the pin-specific
  explanation; the pin case takes priority since it fully explains the
  denial on its own.
- config.ts: safeFile no longer names a reference that looks like a path
  traversal attempt (a '..' segment), fixing a regression #607 introduced
  and #602 exposed (issue #610) — MCP's validate tool now surfaces the
  CLI's real error text (#582), which would otherwise turn an escaping
  function/middleware source reference into a filesystem oracle. A plain
  in-project typo is still named, matching #607's own authoring-errors
  test.
- test/dev-diagnostics.test.ts, test/mcp.test.ts: two assertions predated
  #607's route-name and file:line:column prefixes and #581's friendlier
  multiple-handlers message; updated to match the now-current, improved
  text rather than reverting the improvement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd merged commit 37d9a45 into main Sep 24, 2026
61 checks passed
@jimhoyd
jimhoyd deleted the claude/dev-mcp-errors branch September 24, 2026 02:27
jimhoyd added a commit that referenced this pull request Sep 24, 2026
…es (#590) (#633)

Implements the remainder of #590 (protocol negotiation already landed in
#602): rename ambiguous/inconsistent MCP tool names to a verb-first
vocabulary (capabilities->list_capabilities, import_preview->preview_import,
export_preview->preview_export, recipes_list->list_recipes,
recipes_show->get_recipe, review_project->review, matching CLI `urlcode
review`), keeping every pre-#590 name working as a deprecated alias with its
own "Deprecated alias for ..." description in tools/list. Fix the `target`
ambiguity (a route path in `explain` vs. a deployment target elsewhere) by
introducing `deployTarget` as the canonical argument on inspect,
list_capabilities, get_context, plan_feature and review, with the old
`target` argument still accepted (deprecated) on those tools.

get_context is now first in tools/list, matching its documented role as the
first call. Every successful tools/call reply also carries structuredContent
mirroring the JSON already in its text content. Add a read-only run_tests
tool that runs tests/requests.json fixtures the way `urlcode test` does,
reusing runProjectTests against a disposable server/data directory; it never
writes a project file.

list_skills/get_skill now return the real canonical inventory of all three
shipped skills (skills/urlcode, .claude/skills/urlcode-authoring,
.claude/skills/urlcode-operations) with each skill's own SKILL.md frontmatter
description, read at call time so the inventory cannot drift from the skill
it describes. Align llms.txt's skill list and llms-full.txt guidance
(reconciled to: search_docs/get_context first, llms-full.txt only as a
by-heading fallback, never a whole-file read or grep) accordingly, and update
docs/TOOLING.md and docs/RECIPES.md to the canonical names and alias/
structuredContent/run_tests behavior.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[Bug]: MCP tools hide the errors the CLI reports [Bug]: function errors and rejected reloads are invisible during urlcode dev

1 participant