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

# Pi

> Use Context7 in Pi with built-in MCP support or the official extension

Connect the [Pi coding agent](https://pi.dev) to Context7 to get current library documentation and code examples in your coding sessions.

We recommend [built-in MCP](#built-in-mcp-setup). The Context7 MCP server receives updates more frequently than the Pi extension. The [official extension](#context7-extension) remains an alternative with a documentation skill and the `/c7-docs` prompt.

## Built-in MCP setup

Pi includes MCP support from [version 0.99.0](https://github.com/earendil-works/pi/releases/tag/v0.99.0). Update Pi before you start:

```bash theme={null}
pi update
```

### Quick setup

Run the Context7 setup command:

```bash theme={null}
npx ctx7 setup --pi
```

The command signs you in, creates an API key, and writes these files:

* The MCP server goes in `~/.pi/agent/mcp.json`, with `direct` exposure.
* A Context7 rule goes in `~/.pi/agent/AGENTS.md`.
* The `context7-mcp` skill goes in `~/.agents/skills`.

Pi reads only one context file in each folder. If `AGENTS.override.md` or `CLAUDE.md` exists there, setup adds the rule to that file and does not create `AGENTS.md`. Setup also uses `PI_CODING_AGENT_DIR` when you set it.

Add `--project` to write `.pi/mcp.json`, the project's `AGENTS.md`, and `.agents/skills` instead. With `--oauth`, setup writes an OAuth entry without an API key. Then run `pi mcp login context7` to sign in. To undo the setup, run `npx ctx7 remove --pi`.

For manual setup, choose one of the following connection methods. These commands save the server in `~/.pi/agent/mcp.json`. Add `--local` to `pi mcp add` to save it in your project's `.pi/mcp.json` instead. Pi loads project configuration only after you trust the project.

### OAuth

Add the remote server and sign in:

```bash theme={null}
pi mcp add context7 --url https://mcp.context7.com/mcp --exposure direct
pi mcp login context7
```

Approve access in your browser. Pi stores and refreshes your OAuth tokens. See [Set Up OAuth](https://context7.com/docs/howto/oauth.md) for more details.

### API key

Create an API key in the [Context7 dashboard](https://context7.com/dashboard?tab=settings). Export it before you start Pi, then add the remote server:

```bash theme={null}
export CONTEXT7_API_KEY="YOUR_API_KEY"
pi mcp add context7 --url https://mcp.context7.com/mcp \
  --bearer-token-env-var CONTEXT7_API_KEY --exposure direct
```

Add the export to your shell profile to make the key available in future sessions. Pi saves an environment variable reference in its configuration.

### Local server

To run the Context7 MCP server locally over stdio, use this option. It requires Node.js and `npx`:

```bash theme={null}
export CONTEXT7_API_KEY="YOUR_API_KEY"
pi mcp add context7 --exposure direct \
  --env CONTEXT7_API_KEY='${CONTEXT7_API_KEY}' \
  -- npx -y @upstash/context7-mcp
```

The single quotes keep the environment variable reference in the configuration. Pi resolves it when it starts the server.

### Check the connection

Run this command to check the server connection and list its tools:

```bash theme={null}
pi mcp list
```

In an open Pi session, run `/reload` to load the new configuration. Use `/mcp` to inspect the connection, sign in, or reconnect.

The examples use `--exposure direct` so the model can see Context7's tools immediately. Without this option, Pi uses `codemode` by default and discovers tools through tool search. See [Pi's MCP documentation](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/mcp.md) for other options.

### Use Context7

Ask Pi to use Context7 in your prompt:

```text theme={null}
Use Context7 to show me how to configure caching in Next.js 16.
```

Context7 provides two tools:

* `resolve-library-id` finds the Context7 library ID for a package or product.
* `query-docs` retrieves documentation and code examples for that library ID.

If you know the library ID, include it in your prompt to skip the search:

```text theme={null}
Use Context7 with /vercel/next.js for Cache Components documentation.
```

To request documentation lookups by default, add this instruction to your project's `AGENTS.md`:

```markdown AGENTS.md theme={null}
Use Context7 for library documentation and code examples. Resolve the library ID first,
then query its documentation. Skip resolution when the prompt includes a library ID.
```

Ask for one documentation topic at a time. Include the library version when it matters. For questions about separate topics, request a separate lookup for each topic.

## Context7 extension

The official [`@upstash/context7-pi`](https://github.com/upstash/context7/tree/master/packages/pi) extension registers documentation tools directly in Pi and calls the hosted Context7 HTTP API. It does not connect to the remote MCP server. Choose either the extension or the MCP setup above to avoid duplicate documentation tools.

Install it with Pi's package command:

```bash theme={null}
pi install npm:@upstash/context7-pi
```

Start a new Pi session, or run `/reload` in an open session to load the extension.

The extension works without an API key at the anonymous rate limit. For higher limits, create a key in the [Context7 dashboard](https://context7.com/dashboard?tab=settings) and export it before starting Pi:

```bash theme={null}
export CONTEXT7_API_KEY="YOUR_API_KEY"
```

Add the export to your shell profile for future sessions. The extension uses this key independently of the built-in MCP OAuth sign-in.

The package includes the `resolve-library-id` and `query-docs` tools, the `context7-docs` skill, and the `/c7-docs` prompt template. The skill instructs Pi to look up documentation when you ask about a library. For an explicit lookup, use:

```text theme={null}
/c7-docs next.js How do I enable Cache Components?
```

You can also provide a Context7 library ID to skip the library search:

```text theme={null}
/c7-docs /vercel/next.js How do I enable Cache Components?
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.