Skip to content

feat(mcp): load MCP tool schemas on demand; persist proposed plans - #409

Open
raymondginger2018-sudo wants to merge 1 commit into
lessweb:mainfrom
raymondginger2018-sudo:pr/deferred-mcp-tools-and-plan-persist
Open

raymondginger2018-sudo wants to merge 1 commit into
lessweb:mainfrom
raymondginger2018-sudo:pr/deferred-mcp-tools-and-plan-persist

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown

Summary

Two prompt/context-economy improvements plus two tool-doc tightenings.

1. Deferred MCP tool schemas (opt-in). MCP servers contribute tool definitions that are all advertised up front. With a large fleet that is the biggest fixed cost in the system prompt. Behind DEEPCODE_DEFERRED_MCP_TOOLS=1, the system prompt lists MCP tool names only and a new SearchMcpTools tool returns the full schema for the tools the model actually needs.

Execution is unaffected: executeMcpTool() resolves tools by namespacedName in this.tools, independent of what was advertised. Default is off, so behaviour is unchanged unless the env knob is set.

2. Plan persistence. A finished <proposed_plan> is written to .deepcode/plans/<timestamp>-plan.md before the implementation chooser opens, so the plan survives a compaction, an undo, or a later session. Persistence is best-effort and never fails a turn — the approval flow is untouched.

3. Tool-doc discipline in bash.md: git commit/push rules (only when asked; branch first on the default branch) and the "coverage — silence is not success" rule for background jobs.

Changes

File What
packages/core/src/prompt.ts PromptToolOptions.deferredMcpTools; advertise SearchMcpTools; only inject its doc when enabled
packages/core/templates/tools/search-mcp-tools.md New tool doc
packages/core/src/mcp/mcp-manager.ts listMcpToolNames() + searchMcpTools(query, limit)
packages/core/src/tools/executor.ts SearchMcpTools handler (limit clamped to 1..25)
packages/core/src/session.ts isDeferredMcpToolsEnabled(), refreshMcpToolDefinitions(), buildSystemPromptWithToolCatalog()
packages/core/src/common/plan-implementation.ts persistProposedPlan()
packages/cli/src/ui/views/App.tsx Persist before opening the chooser
packages/core/src/tests/plan-implementation.test.ts 2 new tests
packages/core/templates/tools/bash.md Git discipline + background coverage

Tests

  • npm run check (typecheck + eslint + prettier): pass
  • npm run build: pass (bundle assets copied)
  • npm test: 696 pass / 5 fail (cli) + 673 pass / 2 fail (core). All 7 are pre-existing on main:
    • the 2 model-settings failures reproduce identically on a clean origin/main tree (verified by stashing my changes and re-running the same file);
    • the 5 image-preview/attachment tests pass 31/31 when run in isolation and only fail under full-suite concurrency.
  • New tests: plan persistence writes the expected file; empty root/plan returns null instead of throwing.

Dependency note

No new dependencies. Default behaviour is unchanged; the only runtime switch is the DEEPCODE_DEFERRED_MCP_TOOLS env var.

MCP servers can contribute many tool definitions, and every one of them is
advertised up front before the conversation starts. With a large MCP fleet
that is the single biggest fixed cost in the system prompt.

Add an opt-in deferred mode (DEEPCODE_DEFERRED_MCP_TOOLS=1): the system
prompt lists MCP tool names only, and a new SearchMcpTools tool returns the
full schema for the tools the model actually needs. Execution is unchanged
because executeMcpTool resolves tools by name, not by what was advertised.

Also persist a finished plan to .deepcode/plans/<timestamp>-plan.md before
opening the implementation chooser, so the plan survives a compaction, an
undo or a later session. Persistence is best-effort and never fails a turn.

And tighten two tool docs: git commit/push discipline in bash.md, and the
'coverage - silence is not success' rule for background jobs.
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.

1 participant