Repository navigation
fix(core): let a client register .mcp.json before urlcode init runs (#542) - #634
Merged
Merged
Conversation
…542) A project-scoped MCP client (Claude Code, Codex) loads .mcp.json only at session start, but `urlcode init` only writes that file — so the agent's very first turn, which typically runs init itself, never sees the local `urlcode` MCP tools llms.txt/AI-AUTHORING.md/AGENTS.md lead with. Add `urlcode mcp print-config [project] [--global]`, which prints the same .mcp.json JSON `init` writes but works in an empty/not-yet-initialized directory. A human registers its output before starting the agent session, so the server is already loaded on that session's first turn; the server answers project-reading tools with the same actionable "run urlcode init" message the CLI prints instead of failing to start against an empty directory. `init` now keeps an already-present .mcp.json exactly as written (it no longer refuses an in-place init over it, and no longer regenerates it), so no client restart is needed once init runs. Document the bootstrap path in docs/TOOLING.md, llms.txt, docs/AI-AUTHORING.md and skills/urlcode/SKILL.md, with an explicit fallback (run the first turn's init as a plain CLI call) for clients that cannot be bootstrapped this way. Add end-to-end coverage: an MCP session against an empty directory before init, and the CLI init/print-config interplay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reconciles the pre-session MCP bootstrap (#542) with upstream's MCP tool rename/legacy-alias work and CLI --help restructuring (grouped per-command help entries) that landed on main while this branch was in review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
urlcode initwrites.mcp.jsononly after the agent's session has started, so a project-scoped MCP client (Claude Code, Codex, and similar clients that load.mcp.jsonat session start) never sees the localurlcode mcptools on the very first agent turn that creates the project — contradicting the first-attempt guidance inllms.txt/docs/AI-AUTHORING.md/the generatedAGENTS.md, which lead with MCPget_contextwhen available.This implements a supported pre-session bootstrap path (option 1 from the issue):
urlcode mcp print-config [project] [--global]prints the same.mcp.jsonJSONinitwrites, but works from an empty/not-yet-initialized directory. A human (or setup script) registers its output before starting the agent session there, so the client's project-scoped server is already loaded on that session's first turn.urlcode mcpserver now starts fine against an empty directory (nourlcode.yamlyet):tools/listanswers immediately, and a project-reading tool such asget_contextfails closed with the same actionable"run urlcode init there to create a project"message the CLI already prints — never a crash or a refusal to start.urlcode initno longer refuses an in-placeinitover a pre-existing.mcp.json, and no longer regenerates one that's already there (.mcp.jsonjoins the allowed pre-existing entries alongsidepackage.json/package-lock.json/node_modules/.git). So once the agent runsinit, no client restart is needed — the same session's next MCP call against the same project root succeeds.print-configdefaults to the portablenpx --no --package @jimhoyd/urlcodeform (works whether or not the runtime ends up pinned in apackage.json);--globalprints the bareurlcodecommand for a global install.This covers
urlcode init <existing-or-empty-dir>.init --withalways creates a brand-new site directory (its parentmkdirrefuses an existing destination), so nothing can be pre-registered inside it before that directory exists — documented as a scope limit rather than worked around.Documented every agent-facing surface named in the issue:
docs/TOOLING.md(new "Registering before init runs" section),llms.txt,docs/AI-AUTHORING.md, andskills/urlcode/SKILL.md, each with an explicit fallback (run the first turn'sinitas a plain CLI call, then continue with MCP registered) for a client that can't be bootstrapped this way.Changes
packages/core/src/authoring.ts:.mcp.jsonis now an allowed pre-existing entry for in-placeinit, andinitnever overwrites one that's already there.packages/core/src/ecosystem-cli.ts,packages/core/src/cli.ts: newurlcode mcp print-config [project] [--global]subcommand.docs/TOOLING.md,llms.txt,docs/AI-AUTHORING.md,skills/urlcode/SKILL.md,llms-full.txt(regenerated): document the bootstrap path and its fallback.test/mcp.test.ts: end-to-end test — a fresh MCP session against an empty directory sees the server, gets an actionable no-project error, then succeeds against the same directory afterinitProjectwith no restart.test/cli.test.ts:mcp print-configoutput shape/flags, and theinit+ pre-registered.mcp.jsoninterplay (preserved byte-for-byte,contextsucceeds afterinit).Test plan
npm run typechecknpm run lintnpm run check:code(includes core-boundary, release-tag, workspace-link, issue-label checks)npm run check:docs(trust-model prose, version statements, local links, guidance claims, agent facts, YAML reference,llms-full.txtfreshness, cookbook index, Claude plugin)npm run verify(full suite, 840 tests: 835 pass, 1 skipped by design; the 4 initial failures — a SKILL.md line-budget overshoot from my own first draft, and 3 timing-sensitive tests unrelated to this change — were fixed/reconfirmed as pre-existing flakiness under concurrent load on this machine, each passing cleanly in isolated reruns)mcp print-configoutput as.mcp.jsoninto an empty directory, confirmed the MCP server answerstools/list/get_contextagainst it, raninitin the same directory, confirmed.mcp.jsonwas preserved byte-for-byte and the nextget_contextcall succeededCloses #542 — this lands the pre-session bootstrap the issue asks for as its most-implementable option, not the guidance-only fallback.
🤖 Generated with Claude Code