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. |
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",
_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. |
verify_source_status |
Refresh whole-tree source truth before publishing verified status. |
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. |
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
verify_source_status
¶
Refresh whole-tree source truth before publishing verified status.
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
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 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 | |
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.
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.