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 selected index objects from disk. |
explore_bounds |
Deterministic byte bounds for composed MCP exploration responses. |
explore_session |
Bounded, fingerprint-safe context deduplication for stdio MCP sessions. |
grep_jev |
The source-only grep/Jev vertical shared by the CLI and MCP tool. |
prompts |
MCP prompt resource - guidance for calling agents. |
server |
CodeNib MCP server - stdio transport. |
tool_surface |
Configurable MCP tool visibility for agent-surface experiments. |
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,
lsp_provider: Any | None = None,
lsp_provider_selection: dict[str, Any] = dict(),
errors: dict[str, str] = dict(),
artifact: Mapping[str, Any] | None = None,
source_error: str | None = "source binding has not been verified",
grep_jev: GrepJevConfig | None = None,
_native_index_authorization: NativeIndexAuthorization | None = None,
_artifact_binding: ContextArtifactBinding | None = None,
_source_binding: RepositorySourceBinding | None = None,
)
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 |
|---|---|
read_source_bytes |
Read one repository file through the retained source authority. |
borrow_source_reader |
Borrow the exact source reader retained by this context owner. |
search_grep_jev |
Run the explicit remote route only against this context's source. |
verify_source_status |
Refresh whole-tree source truth before publishing verified status. |
indexed_query |
Deliver local indexed facts only while their source remains current. |
load |
Load a manifest and the selected runtime views. |
load_views |
Load additional manifest views without disturbing loaded resources. |
close |
Release runtime resources owned by this context. |
enable_source_definition_provider |
Select a lazy candidate worker only for a verified local Python source. |
close_source_definition_provider |
Reap the owned worker before graph compilation or source release. |
begin_explore_session |
Create fresh state for one stdio connection. |
ensure_explore_session |
Return the connection runtime, creating one for direct embeddings. |
end_explore_session |
Discard one connection's ledger without clearing a newer runtime. |
configure_lsp_provider |
Bind a runtime-only provider without mutating persisted artifacts. |
validate_views |
Open selected artifacts without initializing a vector query model. |
Attributes:
| Name | Type | Description |
|---|---|---|
source_verified |
bool
|
Return whether live reads retain exact content-byte authority. |
source_verification_scope |
str | None
|
M1 authenticates v2 content bytes, never mutable Git HEAD state. |
commit_verified |
bool
|
Mutable checkout commit provenance requires an M2 source snapshot. |
loaded_views |
frozenset[str]
|
Return the runtime views currently available in this context. |
source_verified
property
¶
Return whether live reads retain exact content-byte authority.
source_verification_scope
property
¶
M1 authenticates v2 content bytes, never mutable Git HEAD state.
commit_verified
property
¶
Mutable checkout commit provenance requires an M2 source snapshot.
loaded_views
property
¶
Return the runtime views currently available in this context.
read_source_bytes
¶
Read one repository file through the retained source authority.
Source code in codenib/mcp/context.py
borrow_source_reader
¶
Borrow the exact source reader retained by this context owner.
Source code in codenib/mcp/context.py
search_grep_jev
¶
Run the explicit remote route only against this context's source.
Source code in codenib/mcp/context.py
verify_source_status
¶
Refresh whole-tree source truth before publishing verified status.
Source code in codenib/mcp/context.py
indexed_query
¶
Deliver local indexed facts only while their source remains current.
A query owns runtime resources until its final source check accepts the result; close waits on the same query lock. Lock order is query, then view (when needed), then source verification. Session bookkeeping uses only the view lock, so workers must not retain it while calling providers: that would block the MCP event loop on session lookup. A mid-query edit discards the result. Portable artifacts retain snapshot semantics; grep/Jev captures current source independently on each request.
Source code in codenib/mcp/context.py
load
classmethod
¶
load(
manifest_path: RepoManifest | str | Path,
*,
views: Iterable[str] | None = None,
artifact: Mapping[str, Any] | None = None,
artifact_binding: ContextArtifactBinding | None = None,
artifact_reader: PublicationDirectoryReader | None = None,
native_index_authorization: NativeIndexAuthorization | None = None,
source_binding: RepositorySourceBinding | None = None,
_context_owner: Callable[[ServerContext], None] | None = None
) -> ServerContext
Load a manifest and the selected runtime views.
views=None preserves the MCP server's load-all behavior. Explicit
selections avoid importing or starting unrelated view runtimes. Each
selected view is loaded independently; a failure in one does not block
the others. Failed views are recorded in errors.
Source code in codenib/mcp/context.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | |
load_views
¶
load_views(
views: Iterable[str],
*,
native_index_authorization: NativeIndexAuthorization | None = None,
artifact_reader: PublicationDirectoryReader | None = None
) -> dict[str, str]
Load additional manifest views without disturbing loaded resources.
View dependencies are resolved in the same way as :meth:load. The
operation is idempotent and serialized so query-time planners can
safely request only the backends selected for a query. The returned
mapping contains requested views that remain unavailable.
Source code in codenib/mcp/context.py
close
¶
Release runtime resources owned by this context.
Only the serialized MCP reloader preserves a connection runtime; it transfers that ledger/barrier to the replacement after cleanup succeeds. Normal close still ends the session and releases every resource.
Source code in codenib/mcp/context.py
enable_source_definition_provider
¶
Select a lazy candidate worker only for a verified local Python source.
The serialized MCP preparer calls this before a positional definition. Missing software simply keeps the existing complete-graph route; no install or provider network request occurs inside a source lease.
Source code in codenib/mcp/context.py
close_source_definition_provider
¶
Reap the owned worker before graph compilation or source release.
Lock order is the caller's MCP context lock, then this query lock, then bounded worker I/O. No source lease is held during shutdown. A failed close keeps this field and the source binding for retry.
Source code in codenib/mcp/context.py
begin_explore_session
¶
Create fresh state for one stdio connection.
Stdio normally has one live connection per process. Replacing any
previous runtime keeps reconnects fail-closed even when an embedding
application reuses the same :class:ServerContext.
Source code in codenib/mcp/context.py
ensure_explore_session
¶
Return the connection runtime, creating one for direct embeddings.
Source code in codenib/mcp/context.py
end_explore_session
¶
Discard one connection's ledger without clearing a newer runtime.
Source code in codenib/mcp/context.py
configure_lsp_provider
¶
configure_lsp_provider(
*,
allow_native: bool,
native_disabled_reason: str = "native_provider_not_authorized"
) -> dict[str, Any]
Bind a runtime-only provider without mutating persisted artifacts.
Source code in codenib/mcp/context.py
validate_views
classmethod
¶
validate_views(
manifest: RepoManifest | str | Path,
*,
views: Iterable[str],
native_index_authorization: NativeIndexAuthorization | None = None
) -> dict[str, str]
Open selected artifacts without initializing a vector query model.
The returned mapping contains only unavailable views. Vector indexes follow the normal FAISS/document load path with a fixed-dimension embedding probe. Temporary vector and Zoekt resources are released before returning.