feat(mcp): expose knowledge-base tools to all MCP clients - #295
Merged
Conversation
Register add_knowledge_base, list_knowledge_bases, and remove_knowledge_base as MCP tools so codex, claude, jcode, and other MCP hosts can manage knowledge bases. The operations already exist for the OpenCode plugin and the Pi extension; this wires them into the MCP server. - tool-names: define MCP_TOOL_NAMES as its own array extending PORTABLE_TOOL_NAMES with the three KB tools. KB tools stay out of PORTABLE_TOOL_NAMES because that set is a Pi contract (tests/pi-package.test.ts asserts Pi exposes every portable name; Pi uses the knowledge_base_* aliases). - register-tools: append three server.tool registrations that call addKnowledgeBase/listKnowledgeBases/removeKnowledgeBase with the MCP runtime project root and host. Returns prefixed with "Error:" are surfaced with isError so clients can distinguish refusals (missing dir, blocked sensitive dir) from success; informational results such as "already configured" and "not found" stay successful. - docs: reclassify the KB tools from OpenCode-only to shared by MCP and OpenCode (Pi uses aliases); correct the portable-tool count to 15 and the host totals; document the worktree limitation, multi-host config divergence, and KB indexing/config semantics (project-local write, union list, repo-only blame). - tests: update the MCP tool-count test to 18; add tests/mcp-knowledge-bases.test.ts covering add/list/remove through the MCP client, host-specific config persistence (claude, codex), indexer refresh, the missing-path isError failure path, the not-found success case, and missing-required-arg schema rejection.
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
Registers add_knowledge_base, list_knowledge_bases, and remove_knowledge_base as MCP server tools so every MCP client (Codex, Claude Code, Jcode, and other MCP hosts) can manage knowledge bases.
Previously these operations were exposed only to the OpenCode plugin and the Pi extension (under host-native names); MCP clients had no way to add, list, or remove knowledge bases through the MCP
server.
Implements #298
Background
The knowledge-base operations (addKnowledgeBase, listKnowledgeBase, removeKnowledgeBase in src/tools/operations.ts) were deliberately scoped to OpenCode and Pi, not overlooked: KB management
mutates persistent per-host config and rebuilds the shared indexer, and OpenCode/Pi pass a per-call worktree so KB edits land in worktree-local config. The MCP server, however, runs at a fixed
project root (process.cwd() / --project) for its lifetime, and all existing MCP tools already operate on that fixed root. Exposing KB tools on the startup root is therefore consistent with the
existing MCP model, not a new behavior.
Changes
is a Pi contract (tests/pi-package.test.ts asserts Pi exposes every portable name, and Pi exposes KB tools only under its knowledge_base_* aliases).
so a response whose text starts with "Error: " is reported with MCP isError: true; informational returns ("already configured", "not found") are not flagged as errors.
reclassifies the KB tools as shared by MCP + OpenCode, and documents the worktree, multi-host, config-layering, and repo-only-blame semantics.
(.claude/codebase-index.json for claude, .codebase-index/config.json for codex) and refreshes the indexer; list shows Exists; remove clears it; non-existent path returns isError: true with
"Error: Directory does not exist" and writes no config / triggers no refresh; remove of an unconfigured path returns "Knowledge base not found" without isError; missing required path is rejected
by Zod with isError: true.
Behavior notes
codex/jcode/pi) and refreshes the index. It is not a user-global change.
retrieval tools.
config returns "Knowledge base not found" and is not removed.
blameAuthor/blameSha/blameSince filters match only in-repo files.
Tests
Manual verification
Installed and driven over stdio with raw JSON-RPC (--project --host claude, embeddings via OLLAMA_HOST → nomic-embed-text):
codebase_peek → json-c lh_table_lookup/json_object_object_add alongside repo hits (union confirmed), with repo hits carrying git blame and json-c hits carrying none — matching the documented
blame semantics.
Checklist