Skip to main content
Connect the Pi coding agent to Context7 to get current library documentation and code examples in your coding sessions. We recommend built-in MCP. The Context7 MCP server receives updates more frequently than the Pi extension. The official 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. Update Pi before you start:
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:
Approve access in your browser. Pi stores and refreshes your OAuth tokens. See Set Up OAuth for more details.

API key

Create an API key in the Context7 dashboard. Export it before you start Pi, then add the remote server:
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:
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:
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 for other options.

Use Context7

Ask Pi to use Context7 in your prompt:
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:
To request documentation lookups by default, add this instruction to your project’s AGENTS.md:
AGENTS.md
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 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:
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 and export it before starting Pi:
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:
You can also provide a Context7 library ID to skip the library search: