MCP Integration¶
Pali ships an MCP server over stdio, launched from the unified CLI at cmd/pali/main.go using pali mcp serve.
Runtime Wiring¶
Server implementation:
- internal/mcp/server.go
- internal/mcp/tools/registry.go
Startup path (pali mcp serve):
1. Load config (pali.yaml)
2. Open SQLite and run migrations
3. Build services:
- memory service (repo + vectorstore + embedder + scorer)
- tenant service (repo)
4. Create MCP server and register tools
5. Run via stdio transport
Production command pattern:
- pali mcp serve -config /etc/pali/pali.yaml
- This is the stable command to reference from MCP hosts (Claude Desktop/Cursor/etc.).
- Config reference: docs/configuration.md
Built-In Agent Guidance¶
Pali exposes memory-first guidance through standard MCP surfaces so hosts can adopt defaults without per-user instruction files:
initialize.instructions: tells agents to callmemory_searchbefore history-dependent answers and write durable facts withmemory_store/memory_store_preference.- prompt
pali_memory_autopilot: a reusable prompt snippet hosts can inject automatically for memory-first behavior.
Note: this improves default tool usage, but MCP servers cannot force tool calls when the host ignores prompts/instructions.
Tool Catalog (11 common tools)¶
memory_storememory_store_preferencememory_searchmemory_listmemory_deletetenant_createtenant_listtenant_statstenant_existshealth_checkpali_capabilities
All tools return structured output and use MCP isError for tool-level failures.
Memory tool highlights:
- memory_store supports optional provenance fields: source, created_by (auto|user|system)
- memory_search supports optional retrieval filters: min_score (0..1) and tiers (working|episodic|semantic)
- memory item outputs include source, created_by, recall_count, last_accessed_at, last_recalled_at
Tenant-aware tools (memory_*, tenant_stats, tenant_exists) resolve tenant in this order:
tenant_idin tool input (explicit)- JWT tenant claim (when auth is enabled and token metadata is available)
- MCP session default tenant (if available)
default_tenant_idfrom config- else tool returns clear
isError=true
This is a resolution contract, not a guarantee that every MCP host is forwarding auth metadata the same way. If your deployment requires strict tenant-bound bearer auth, validate the REST API path separately and treat MCP host integration as an additional trust boundary.
Protocol Layout Used¶
Pali follows the standard MCP flow:
- initialize
- prompts/list
- prompts/get
- tools/list
- tools/call
Tool input schemas are derived from typed Go structs in internal/mcp/tools/registry.go.
Automated Testing¶
Code tests:
- internal/mcp/server_test.go
- validates tool registry contains expected tools
- runs end-to-end tool calls via in-memory MCP transports
- executes tenant + memory flow (tenant_create, memory_store, memory_search)
Run:
- Start MCP server:
go run ./cmd/pali mcp serve -config pali.yaml- Connect an MCP client (Claude Desktop / Cursor / another MCP host) to the
pali mcp servestdio command. - Verify
tools/listreturns the 11 tools above. - Call:
pali_capabilitiestenant_creatememory_storememory_searchtenant_stats- Validate error behavior:
memory_storewith missingtenant_idand no fallback configured -> toolisError=truememory_deletewrong tenant -> toolisError=true- Confirm memory lifecycle:
- store memory
- search memory
- delete memory
- search again returns empty