# pi-codebase-memory-bridge

A [pi](https://pi.dev) extension that bridges the
[`codebase-memory-mcp`](https://github.com/) knowledge graph into pi as native tools.

pi **intentionally ships without MCP support** (see pi's `docs/usage.md`: _"It
intentionally does not include built-in MCP..."_). A Kiro/Claude-Desktop-style
`mcpServers` block in `settings.json` is silently ignored — pi never spawns the
server. This extension is the supported way to get those tools into pi: it talks
to `codebase-memory-mcp` and registers each of its tools as a real pi tool.

## How it works

- On `session_start`, it does a one-time MCP handshake over stdio to fetch the
  server's tool list **with input schemas** (so it stays correct across
  `codebase-memory-mcp` versions — no hardcoded schemas to drift).
- It registers one pi tool per server tool: `search_graph`, `query_graph`,
  `trace_path`, `get_architecture`, `get_code_snippet`, `search_code`,
  `list_projects`, `index_status`, `detect_changes`, `manage_adr`, and the rest.
- Each call shells out to `codebase-memory-mcp cli <tool> <json>`, which returns
  JSON synchronously — no long-lived connection to manage.
- When a tool takes a `project` and you omit it, the extension injects a project
  id derived from the current working directory (abs path with `/` → `-`), which
  matches `codebase-memory-mcp`'s default naming. Pass `project` explicitly to
  override, or call `list_projects` to see what's indexed.

## Prerequisites

1. Install the `codebase-memory-mcp` binary (its own installer/README).
2. Index your repo at least once: `codebase-memory-mcp cli index_repository '{"repo_path":"."}'`.

## Install

```bash
# from npm
pi install npm:pi-codebase-memory-bridge

# from GitHub (pinned ref recommended)
pi install git:github.com/yanralapdy/pi-codebase-memory-bridge

# or during development, from a local checkout
pi install /path/to/pi-codebase-memory-bridge
```

## Configuration

The binary is resolved in this order:

1. `CODEBASE_MEMORY_MCP_BIN` env var (if the path exists)
2. `~/.local/bin/codebase-memory-mcp`
3. `codebase-memory-mcp` on `PATH`

## Development

```bash
npm test   # runs unit tests for the pure helpers via tsx
```

## License

MIT
