> ## Documentation Index
> Fetch the complete documentation index at: https://doc.askmydocs.padosoft.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP server

> Expose the canonical knowledge base as Model Context Protocol tools — the enterprise-kb server (25 tools) consumable by Claude Desktop, Claude Code, Cursor and any MCP client, plus token-gated access.

## Motivation

Retrieval is most useful when an *agent* can reach it. AskMyDocs exposes its
knowledge base as **MCP (Model Context Protocol) tools**, so Claude Desktop,
Claude Code, Cursor, or any custom agent can search, navigate the graph, and
surface promotion candidates — over the same retrieval stack the chat UI uses.

## The `enterprise-kb` server

The MCP server (`app/Mcp/Servers/KnowledgeBaseServer.php`, registered name
`enterprise-kb`) exposes **25 tools** across four categories:

* **Read-only retrieval** (hybrid search, document/chunk reads, recent changes,
  project-scoped search).
* **Graph navigation** (neighbours, subgraph, canonical lookups by slug/type,
  the multi-hop `KbWikiNavigateTool` — primary agentic surface, see [Auto-Wiki](/auto-wiki)).
* **Write surfaces** for auto-wiki operations: evidence tier (`KbSetEvidenceTierTool`),
  graph link rebuild (`KbRebuildWikiLinksTool`), concept synthesis
  (`KbSynthesizeConceptsTool`), index build (`KbBuildWikiIndexTool`), page review
  (`KbWikiReviewTool`), suggestion apply (`KbApplySuggestionTool`), wiki
  maintenance (`KbWikiMaintainTool`), and auto→human-vouched tier promotion
  (`KbWikiPromoteTool`).
* **Write-nothing propose/suggest** tools that surface candidate artifacts for
  human review — the **canonical promotion pipeline** (suggest → candidates →
  promote via `CanonicalWriter`) stays human-gated
  (see [canonical & promotion](/canonical-and-promotion)).

```mermaid theme={null}
flowchart LR
    CLIENT[Claude Desktop / Code / Cursor] -->|MCP stdio / HTTP| SRV[enterprise-kb server]
    SRV --> RET[retrieval tools<br/>read-only]
    SRV --> NAV["graph navigation<br/>(KbWikiNavigateTool — primary agentic surface)"]
    SRV --> WRITE["auto-wiki write tools<br/>(evidence tier, graph, synthesis…)"]
    SRV --> SUG["canonical-promote suggest tools<br/>write NOTHING"]
    RET & NAV & WRITE --> KB[(canonical KB)]
```

New capabilities land tri-surface (R44): every Auto-Wiki and KB capability is
also an MCP tool.

## Connecting a client

Expose the server and point your MCP client at it. The host ships an
`askmydocs:mcp:connect` Artisan helper that prints the bootstrap snippet for a
consumer client. Access is **token-gated** — mint a personal access token (Sanctum) or an
MCP token in the admin (`/app/admin/mcp/tokens`) and the per-tool authorizer
enforces the caller's RBAC on every invocation.

## The MCP pack

The transport, multi-turn tool-calling orchestrator, hash-only audit, and RBAC
hooks are factored into the standalone **`padosoft/askmydocs-mcp-pack`** package
(framework-agnostic; AskMyDocs pins `^1.5`). The host binds three adapters
(`McpHostBridge`, server registry, tool authorizer) so the pack drives the real
AskMyDocs retrieval + Spatie RBAC + Eloquent audit. The host admin SPA
(`/app/admin/mcp-tools`) surfaces server CRUD, the tool catalogue, and the audit
log; the optional standalone `padosoft/askmydocs-mcp-pack-admin` panel (default
`/admin/mcp-pack`) adds the circuit-breaker dashboard and the OpenAPI explorer.

## Gotchas & operations

* The **canonical promotion pipeline** (suggest → candidates → promote via
  `CanonicalWriter`) is human-gated and no MCP tool triggers it. Auto-wiki write
  tools (evidence tier, graph rebuild, concept synthesis, etc.) DO write to storage
  — they are RBAC-authorized and audited.
* Every tool invocation is RBAC-authorized + audited (hash-only) — bypassing the
  authorizer is a defect.
* Adding a new MCP tool: extend `Laravel\Mcp\Server\Tool`, register it on
  `KnowledgeBaseServer::$tools`, and bump the registration-count test.

<CardGroup cols={2}>
  <Card title="Auto-Wiki" icon="wand-magic-sparkles" href="/auto-wiki">
    The agentic navigation surface MCP exposes.
  </Card>

  <Card title="Sister packages" icon="cubes" href="/sister-packages">
    The padosoft/\* ecosystem, including the MCP pack.
  </Card>
</CardGroup>
