Skip to content

codenib.mcp

CodeNib MCP server - exposes backbone capabilities over stdio.

Provides MCP tools for semantic indexing, CodeGraph, and hybrid retrieval (vector, BM25, regex, Zoekt trigram) for external agent frameworks.

Modules:

Name Description
context

ServerContext - loads a RepoManifest and available index objects from disk.

prompts

MCP prompt resource - guidance for calling agents.

server

CodeNib MCP server - stdio transport.

tools

MCP tool implementations.

Classes:

Name Description
ServerContext

Runtime context for the MCP server.

ServerContext dataclass

ServerContext(
    manifest: RepoManifest,
    symbol_graph: CodeGraph | None = None,
    bm25: BM25CodeIndexer | None = None,
    regex_index: RegexNodeIndex | None = None,
    zoekt: ZoektSearcher | None = None,
    vector: CodeVectorStore | None = None,
    errors: dict[str, str] = dict(),
)

Runtime context for the MCP server.

Holds the loaded manifest and runtime-loaded index objects. Missing or failed indexes stay None; tools check at call time and return descriptive errors.

Methods:

Name Description
load

Load a manifest and all available indexes.

load classmethod

load(manifest_path: str | Path) -> ServerContext

Load a manifest and all available indexes.

Each index is loaded independently; a failure in one does not block the others. Failed indexes are recorded in errors.

Source code in codenib/mcp/context.py
@classmethod
def load(cls, manifest_path: str | Path) -> ServerContext:
    """Load a manifest and all available indexes.

    Each index is loaded independently; a failure in one does not
    block the others. Failed indexes are recorded in ``errors``.
    """
    manifest = RepoManifest.load(manifest_path)
    ctx = cls(manifest=manifest)

    ctx._load_symbol_graph()
    ctx._load_bm25()
    ctx._load_regex_index()
    ctx._load_zoekt()
    ctx._load_vector()

    cap_summary = {k: v for k, v in manifest.capabilities.items() if v}
    logger.info(
        "ServerContext ready  repo=%s  commit=%s  capabilities=%s  errors=%s",
        manifest.repo_path,
        manifest.commit[:8] if manifest.commit else "N/A",
        cap_summary or "none",
        list(ctx.errors) or "none",
    )
    return ctx