# Recommended Context7 Prompt Structure for Accurate Documentation

> Learn the recommended Context7 prompt structure for accurate, version-specific documentation. Follow the three-step pattern for best results. Optimize your queries now.

- Repository: [Upstash/context7](https://github.com/upstash/context7)
- Tags: how-to-guide
- Published: 2026-02-16

---

**To retrieve accurate, version-specific documentation using Context7, structure your prompt using a three-step pattern: write a natural language request, append the trigger token `use context7`, and optionally specify a library ID or version.**

Context7, developed by Upstash, is an MCP server that fetches up-to-date documentation directly into your LLM's context window. Following the recommended **Context7 prompt structure** ensures the system resolves the correct library and eliminates hallucinations caused by outdated training data. This guide explains the exact pattern implemented in the `upstash/context7` repository.

## The Three-Step Context7 Prompt Pattern

According to the project documentation in `docs/overview.mdx` (lines 32-34), Context7 operates on a simple three-step prompt pattern. This structure ensures the MCP client recognizes when to invoke the documentation retrieval tool and which library to target.

### Step 1: Write Your Request in Natural Language

Begin by describing your task or question exactly as you would ask a human developer. The [`packages/mcp/README.md`](https://github.com/upstash/context7/blob/main/packages/mcp/README.md) (lines 37-40) emphasizes that you should write your prompt naturally without trying to force specific keywords or syntax at the beginning.

```text
How do I implement middleware in Next.js that validates JWT tokens from cookies?

```

### Step 2: Add the Trigger Token

Append the specific trigger token `use context7` to your prompt. This token signals the MCP client to invoke the Context7 server and inject the retrieved documentation into the LLM's context. The main [`README.md`](https://github.com/upstash/context7/blob/main/README.md) (lines 23-27) demonstrates this pattern with a concrete example showing the token placement at the end of the prompt.

```text
Create a React hook for data fetching with error handling. use context7

```

### Step 3: Specify Library ID or Version (Optional)

For precise control, specify the exact library using slash syntax (`/owner/repo` or `/library/id`) or mention a specific version number. The `docs/tips.mdx` file (lines 6-38) details these advanced options for skipping automatic library matching and pinning documentation to specific releases.

```text
Set up Supabase authentication in a Next.js 14 project. use library /supabase/supabase for API and docs.

```

```text
How do I configure Tailwind CSS v3.4 with custom themes? use context7

```

## Context7 Prompt Examples

The following examples from the repository documentation illustrate the complete prompt structure in action:

**Basic natural language request with trigger:**

```text
Create a Next.js middleware that checks for a valid JWT in cookies
and redirects unauthenticated users to `/login`. use context7

```

**With explicit library ID (skips auto-matching):**

```text
Implement basic authentication with Supabase. use library /supabase/supabase for API and docs.

```

**With version specification:**

```text
How do I set up Next.js 14 middleware? use context7

```

## Source File Implementation Details

The prompt structure is explicitly defined in the following source files:

- **`docs/overview.mdx`** (lines 32-34): Summarizes the three-step pattern and explains how Context7 resolves libraries and versions.
- **`docs/tips.mdx`** (lines 6-38): Provides advanced guidance on library ID syntax (`/owner/repo`), version pinning, and troubleshooting prompt formatting.
- **[`README.md`](https://github.com/upstash/context7/blob/main/README.md)** (lines 23-27): Contains the minimal working example demonstrating the `use context7` trigger token placement.
- **[`packages/mcp/README.md`](https://github.com/upstash/context7/blob/main/packages/mcp/README.md)** (lines 37-40): Emphasizes writing prompts in natural language without forced syntax.

## Summary

- **Context7** injects up-to-date documentation directly into your LLM's prompt window via an MCP server.
- The **recommended prompt structure** follows three steps: write naturally, append `use context7`, and optionally specify library IDs or versions.
- Use **slash syntax** (`/owner/repo`) to bypass automatic library matching when you know the exact repository.
- Reference the **`docs/overview.mdx`** and **`docs/tips.mdx`** files for the canonical implementation details.

## Frequently Asked Questions

### What is the exact trigger token for Context7?

The trigger token is **`use context7`**. According to the [`README.md`](https://github.com/upstash/context7/blob/main/README.md) (lines 23-27), appending this exact phrase to your prompt signals the MCP client to invoke the Context7 server and inject retrieved documentation into the context window.

### How do I specify a specific library version in a Context7 prompt?

Mention the version number naturally in your request, such as "Next.js 14" or "Tailwind CSS v3.4". The `docs/tips.mdx` file (lines 6-38) explains that Context7 parses version mentions to fetch documentation for specific releases rather than the latest version.

### Can I use Context7 without specifying a library ID?

Yes. If you omit the library ID, Context7 attempts to **auto-resolve** the library based on the content of your natural language request. However, as noted in `docs/tips.mdx`, explicitly specifying the library ID using slash syntax (`/owner/repo`) eliminates ambiguity and ensures faster, more accurate retrieval.

### Where is the official prompt structure documented in the source code?

The canonical three-step pattern is documented in **`docs/overview.mdx`** (lines 32-34), with additional implementation details in **`docs/tips.mdx`** (lines 6-38). The [`README.md`](https://github.com/upstash/context7/blob/main/README.md) (lines 23-27) and [`packages/mcp/README.md`](https://github.com/upstash/context7/blob/main/packages/mcp/README.md) (lines 37-40) provide practical examples and emphasize natural language prompt writing.