Skip to content

Add per-project MCP server for domain-context retrieval - #4

Merged
josix merged 2 commits into
mainfrom
feat/mcp-server
Oct 24, 2026
Merged

josix merged 2 commits into
mainfrom
feat/mcp-server

Conversation

@josix

@josix josix commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a per-project MCP server so the agent can look up the repo's own existing code and patterns before it implements anything.

  • Server (engine/retrieval/mcp_server.py), stdio via FastMCP:
    • tools: search_domain_context, index_project, index_status
    • a ground_implementation(task) prompt
    • server instructions
    • a retrieval://index/status resource
  • Code reuse: builds on the existing CLI query and index code. Stdout carries only MCP protocol messages.
  • When indexes get built:
    • The keyword (lexical) index is built on the first query.
    • Heavier strategies (turbovec, pi-serini, hybrid, treesitter) are used only after index_project builds them.
    • The LLM-enriched lexical+ctx index is never built or overwritten implicitly. Building it still requires an explicit CLI run.
  • Agent-facing behaviour:
    • Tool descriptions tell the agent to use search first.
    • Search never raises. Skipped strategies come back with a reason and the fix.
    • top_k is clamped to 25, and snippets are size-capped with a truncated flag.
  • Performance:
    • Loaded indexes are cached in memory.
    • Each request walks the project files once.
    • Builds use a separate lock, so index_status and searches don't wait on a long build. While a build runs, pi-serini is skipped with a retry hint.
  • Packaging:
    • retrieval mcp subcommand and retrieval-mcp script.
    • Optional mcp extra.
    • Registered through plugin.json mcpServers and scripts/retrieval-mcp.sh. There is no root .mcp.json, so opening this repo doesn't create a broken project-scope server.
  • Skill: new domain-context-retrieval skill so agents check these tools on their own while working in a repo. It falls back to the CLI when the server is unavailable.
  • Docs:
    • Updated the README, SETUP, USAGE, the CLI and environment-variable reference pages, the coding-agents how-to, and the changelog (Unreleased section).
    • Shell snippets now use set -- … "$@", so they work in zsh as well as bash.

Notes

  • The engine/uv.lock diff is large mainly because a newer uv rewrote the lock format (revision 3 → 5). No dependency versions were bumped.
  • No version bump; the changelog entry is under Unreleased.

Test plan

  • uv run --directory engine python -m unittest discover -s tests: 582 tests, OK (18 skipped)
  • ruff check and isort --check are clean on the changed Python files
  • uv build produces the sdist and wheel
  • A manual stdio initialize handshake through scripts/retrieval-mcp.sh succeeds
  • After merging, reinstall the plugin and confirm plugin:agentic-retrieval:retrieval shows as connected in /mcp

🤖 Generated with Claude Code

https://claude.ai/code/session_019qtBjPUTJs57FUt6JJRk6K

josix and others added 2 commits October 25, 2026 00:23
Expose the retrieval engine as a stdio MCP server (FastMCP) that the
plugin starts for every opened project, so the agent can ground new
work in the repo's existing implementations before writing code.

- engine/retrieval/mcp_server.py: search_domain_context, index_project,
  index_status tools, a ground_implementation prompt, server
  instructions and a retrieval://index/status resource. Reuses the
  CLI query/index paths; stdout is reserved for the protocol.
- Lazy builds: lexical is built on first query; heavier strategies are
  used only once index_project builds them. lexical+ctx is never built
  or overwritten implicitly (cost opt-in stays on the CLI).
- Search never raises: skipped strategies come back with actionable
  reasons, top_k is clamped and snippets are byte-capped.
- In-process retriever cache, one fingerprint walk per request, and a
  separate build lock so status/search stay responsive during builds.
- `retrieval mcp` subcommand, `retrieval-mcp` script, optional `mcp`
  extra; registered via plugin.json mcpServers + scripts/retrieval-mcp.sh.
- New domain-context-retrieval skill; docs updated, shell snippets made
  zsh-safe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019qtBjPUTJs57FUt6JJRk6K
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019qtBjPUTJs57FUt6JJRk6K
@josix
josix merged commit ab01d51 into main Oct 24, 2026
4 checks passed
@josix
josix deleted the feat/mcp-server branch October 24, 2026 16:49
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