Skip to content

feat(mcp): add update and embed tools#632

Open
estrenuo wants to merge 15 commits into
tobi:mainfrom
estrenuo:feat/mcp-update-embed-tools
Open

feat(mcp): add update and embed tools#632
estrenuo wants to merge 15 commits into
tobi:mainfrom
estrenuo:feat/mcp-update-embed-tools

Conversation

@estrenuo
Copy link
Copy Markdown

@estrenuo estrenuo commented May 7, 2026

Summary

  • New MCP tools update and embed so an agent can re-index collections and generate vector embeddings without shelling out to the CLI.
  • update accepts optional collection (scope to one) and runUpdateCommand (opt-in git pull etc.); failing update_command marks that collection skipped and continues.
  • embed is incremental by default; opt-in force: true wipes and regenerates all vectors.
  • buildInstructions updated: existing qmd embed CLI hints replaced with tool-style Call the \embed` tool` plus a new "Maintenance:" tool list.

Implementation notes

  • Both handlers reuse the existing pure-logic functions reindexCollection and generateEmbeddings from src/store.ts via store.internal.
  • Synchronous return only, no MCP progressNotification — the agent flow is short by design.
  • EmbedResult.docsProcessed is mapped to docsEmbedded at the tool boundary so the public MCP shape is stable independent of the internal field name.
  • runShellCommand (private helper) executes the YAML-configured update_command via sh -c. Documented as trusted-source-only.

Test plan

  • npx vitest run test/mcp.test.ts — 65/65 passing.
  • Manual end-to-end through Claude Code (qmd-feat MCP server registered locally):
    • tools/list shows update and embed alongside existing tools.
    • update with no args re-indexed myrag (2 new, 5 updated, 454 unchanged, 5 orphaned cleaned, 133ms; surfaced needsEmbedding: 7).
    • embed with no args embedded the 7 pending docs (120 chunks, 0 errors, 14.2s, force=false).
  • Reviewer: spot-check runShellCommand security note (src/mcp/server.ts, JSDoc above the helper) — confirm the trusted-source-only wording is acceptable.
  • Reviewer: confirm field-name mapping docsProcesseddocsEmbedded is acceptable as the public MCP shape.

🤖 Generated with Claude Code

estrenuo and others added 15 commits May 7, 2026 12:48
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a new describe block with a real on-disk collection (alpha.md +
beta.md), isolated SQLite DB, and YAML config for upcoming update/embed
tool tests. Includes mcpRequest helper and initSession() per-test helper.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces the stub handler with real re-indexing logic using
listCollections + reindexCollection. Adds runShellCommand helper
for optional pre-index shell commands. Updates fixture beforeAll
to use createStore schema initialization instead of initTestDatabase
to ensure documents_fts schema is compatible with reindexCollection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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