Skip to content

fix(core): let a client register .mcp.json before urlcode init runs (#542) - #634

Merged
jimhoyd merged 2 commits into
mainfrom
claude/mcp-pre-session-bootstrap-542
Sep 24, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/mcp-pre-session-bootstrap-542

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

urlcode init writes .mcp.json only after the agent's session has started, so a project-scoped MCP client (Claude Code, Codex, and similar clients that load .mcp.json at session start) never sees the local urlcode mcp tools on the very first agent turn that creates the project — contradicting the first-attempt guidance in llms.txt/docs/AI-AUTHORING.md/the generated AGENTS.md, which lead with MCP get_context when available.

This implements a supported pre-session bootstrap path (option 1 from the issue): urlcode mcp print-config [project] [--global] prints the same .mcp.json JSON init writes, 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.

  • The urlcode mcp server now starts fine against an empty directory (no urlcode.yaml yet): tools/list answers immediately, and a project-reading tool such as get_context fails 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 init no longer refuses an in-place init over a pre-existing .mcp.json, and no longer regenerates one that's already there (.mcp.json joins the allowed pre-existing entries alongside package.json/package-lock.json/node_modules/.git). So once the agent runs init, no client restart is needed — the same session's next MCP call against the same project root succeeds.
  • print-config defaults to the portable npx --no --package @jimhoyd/urlcode form (works whether or not the runtime ends up pinned in a package.json); --global prints the bare urlcode command for a global install.

This covers urlcode init <existing-or-empty-dir>. init --with always creates a brand-new site directory (its parent mkdir refuses 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, and skills/urlcode/SKILL.md, each with an explicit fallback (run the first turn's init as 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.json is now an allowed pre-existing entry for in-place init, and init never overwrites one that's already there.
  • packages/core/src/ecosystem-cli.ts, packages/core/src/cli.ts: new urlcode 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 after initProject with no restart.
  • test/cli.test.ts: mcp print-config output shape/flags, and the init + pre-registered .mcp.json interplay (preserved byte-for-byte, context succeeds after init).

Test plan

  • npm run typecheck
  • npm run lint
  • npm 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.txt freshness, 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)
  • Manual end-to-end walkthrough: wrote mcp print-config output as .mcp.json into an empty directory, confirmed the MCP server answers tools/list/get_context against it, ran init in the same directory, confirmed .mcp.json was preserved byte-for-byte and the next get_context call succeeded

Closes #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

jimhoyd and others added 2 commits September 23, 2026 22:29
…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]>
@jimhoyd
jimhoyd merged commit 6f2dc56 into main Sep 24, 2026
22 checks passed
@jimhoyd
jimhoyd deleted the claude/mcp-pre-session-bootstrap-542 branch September 24, 2026 04:47
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.

[Gap]: local MCP is unavailable to the agent that creates a fresh URLCode project

1 participant