npm package: @aaronmaturen/pi-context7
Description: Context7 extension for pi - fetches up-to-date library documentation via context7.com
Latest version: 1.0.1

# pi-context7

A [pi](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent) extension that brings [Context7](https://context7.com) library documentation into your coding sessions.

Instead of relying on potentially stale training data, the LLM can pull real, up-to-date documentation snippets directly from a library's official docs at query time.

## How it works

The extension registers two tools that the LLM can call:

| Tool                 | Purpose                                                                                                    |
| -------------------- | ---------------------------------------------------------------------------------------------------------- |
| `resolve_library_id` | Search context7.com for a library by name; returns ranked matches with IDs, trust scores, and token counts |
| `get_library_docs`   | Fetch documentation snippets for a resolved library ID, optionally focused on a topic                      |

**Typical flow:**

1. You ask about a library (e.g. "how do I use Drizzle ORM with Postgres?")
2. LLM calls `resolve_library_id("drizzle-orm")` → picks the best match
3. LLM calls `get_library_docs("/drizzle-team/drizzle-orm", { topic: "postgres" })` → gets real docs
4. LLM answers using current, accurate documentation

## Installation

### Via npm (recommended)

```bash
# Global — available in all projects
pi install npm:@aaronmaturen/pi-context7

# Project-local — saved to .pi/settings.json, shared with your team
pi install -l npm:@aaronmaturen/pi-context7
```

Then restart pi or run `/reload`.

### From source

```bash
# Clone and symlink globally
git clone https://github.com/aaronmaturen/pi-context7
ln -s $(pwd)/pi-context7 ~/.pi/agent/extensions/pi-context7

# Or for a quick one-off test without installing
pi -e ./src/index.ts
```

## Usage

Just ask pi about any library — the LLM will use the tools automatically when it needs current docs:

```
you: how do I do server-side rendering with Next.js 15 App Router?
you: show me the zustand persist middleware API
you: what's the correct way to use Drizzle transactions?
```

Or be explicit:

```
you: use context7 to look up the latest Hono docs on routing
```

## Configuration

No API key required — Context7 has a generous free tier (200 requests/day for anonymous use). The extension sets a `X-User-Agent: pi-context7/1.0` header so usage is identifiable.

If you have a Context7 account and want to use a higher quota, the API currently uses session cookies (browser-based auth). Anonymous access is sufficient for typical development use.

### Tuning token budgets

The default `tokens` value is `10,000`. For complex topics or large APIs you can ask for more:

```
you: fetch 25000 tokens of the React Server Components docs from context7
```

The LLM will pass the appropriate `tokens` value to `get_library_docs`.

## No npm dependencies

The extension uses only Node.js built-ins (`fetch`) and pi's own utilities. No `npm install` required.

## Files

```
pi-context7/
├── README.md
├── package.json        # pi extension entry point declaration
└── src/
    └── index.ts        # Extension — two tools + session status indicator
```

## Context7 API

- `GET https://context7.com/api/v1/search?query=<name>` — search libraries
- `GET https://context7.com/api/v1/<library-id>?tokens=<n>&topic=<t>` — fetch docs

See [context7.com](https://context7.com) and the [Context7 MCP server](https://github.com/upstash/context7) for more details.