Setup and context: When AI Generates Code That Doesn't Work
If you've been using AI-powered IDEs like Antigravity for a while, you've probably run into something like this:
"I asked for a Next.js routing example and got Pages Router syntax — but I'm using App Router." Or: "The Supabase auth code the AI generated uses an API that was deprecated months ago." Or simply: "The generated code looks right but fails immediately."
In most cases, the culprit is the AI's training data cutoff. Libraries evolve constantly, but AI models can only draw from what they learned at training time. That's a fundamental limitation — until Context7 MCP enters the picture.
Context7 is an open-source MCP server built by Upstash. When Antigravity generates code, Context7 fetches the latest documentation in real time for the relevant library and injects it directly into the AI's context, ensuring you always get code that matches the current API.
What Is Context7 MCP?
Context7 operates on a simple but powerful idea. When you tell the AI to "use context7," it queries the Context7 server via the MCP protocol, retrieves up-to-date documentation for the target library, and prepends that documentation to your prompt automatically.
Before and After Context7
Without Context7, AI-assisted code generation looks like this:
- You ask: "Help me implement authentication with Supabase"
- The AI draws from its training data (which may be months or years old)
- You get code that might use a deprecated API or an outdated pattern
With Context7 in the mix:
- You ask: "Help me implement authentication with Supabase use context7"
- Context7 fetches the latest Supabase documentation
- The AI incorporates that documentation as live context
- You get code that reflects current best practices and API shapes
Supported Libraries
Context7 covers a wide range of popular open-source libraries, including:
- Frontend frameworks: React, Next.js, Vue.js, Nuxt, Svelte, Remix, Astro
- Backend: Express, Fastify, Hono, NestJS, Django
- Databases & BaaS: Prisma, Drizzle ORM, Supabase, Firebase
- UI toolkits: Tailwind CSS, shadcn/ui, Radix UI
- Testing: Vitest, Jest, Playwright, Cypress
- Utilities: Zod, tRPC, Zustand, Jotai
Setting Up Context7 in Antigravity
Prerequisites
- Latest version of Antigravity IDE installed
- Node.js 18 or higher
- Antigravity agent mode enabled
Step 1: Open MCP Configuration
To add an MCP server in Antigravity, you'll edit mcp.json. Open the Settings panel and navigate to Settings → MCP Servers → Edit JSON, or directly edit .antigravity/mcp.json in your project root.
Step 2: Add Context7 to Your MCP Config
Add the following entry to your mcp.json:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"],
"env": {}
}
}
}Save the file. Antigravity will automatically spin up the Context7 server. On first run, npx will install the @upstash/context7-mcp package (requires an internet connection).
Step 3: Verify the Setup
Once configured, try this prompt in agent mode:
How do I create an API route in Next.js App Router? use context7
Adding use context7 to your prompt signals Antigravity to invoke the Context7 MCP tool. You should see Context7 fetch the relevant Next.js documentation before generating a response.
Practical Usage Patterns
The Basics: Adding "use context7"
The core mechanism is simple — append use context7 to your prompt whenever you want real-time library docs injected:
# Pattern 1: Server Actions in Next.js 15
Implement form validation and database writes using
Next.js 15 Server Actions use context7
# Pattern 2: Supabase Auth
Set up email and Google OAuth authentication
with Supabase use context7
# Pattern 3: Vitest configuration
Help me configure Vitest for a React + TypeScript
project from scratch use context7
Specifying Library Versions
When you need to target a specific version, just be explicit:
Show me how to use the new `use` hook for data fetching
in React 19 use context7
Context7 interprets version hints and retrieves the matching documentation.
Embedding Context7 in AGENTS.md or Rules Files
For team projects, you can make Context7 the default behavior by adding instructions to your AGENTS.md or project rules file:
# AGENTS.md
## Documentation Policy
- Always use "use context7" when generating or reviewing library-specific code
- For Next.js, React, Supabase, and Prisma, always verify against the latest docs
- Specify version explicitly when targeting a non-latest releaseWith this in place, agents will automatically invoke Context7 whenever they work with library code.
Real-World Code Examples
Example 1: Next.js 15 Data Fetching
Without Context7, you might get Pages Router patterns even when App Router is what you need. With Context7:
// Generated with Context7 referencing current Next.js docs
// app/users/page.tsx — React Server Component pattern
import { Suspense } from 'react'
import { UserList } from '@/components/user-list'
export default function UsersPage() {
return (
<Suspense fallback={<p>Loading users...</p>}>
<UserList />
</Suspense>
)
}
// app/users/actions.ts
'use server'
import { revalidatePath } from 'next/cache'
export async function createUser(formData: FormData) {
const name = formData.get('name') as string
// Database operation here
revalidatePath('/users')
// Expected: page refetches and shows the new user
}Example 2: Supabase v2 Auth
Supabase's API has evolved significantly. Context7 makes sure you're using the current client interface:
// Context7-informed code using Supabase v2 patterns
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
)
// Sign in with email and password
const { data, error } = await supabase.auth.signInWithPassword({
email: 'user@example.com',
password: 'securepassword',
})
// Retrieve session (v2 API)
const { data: { session } } = await supabase.auth.getSession()
// Expected output: session.user.id and session.access_token are availableSummary
Context7 MCP is one of the simplest and highest-impact upgrades you can make to your Antigravity workflow. Setup takes under five minutes — a few lines in mcp.json — and the benefit is immediate: every prompt that includes use context7 gets backed by live library documentation instead of potentially stale training data.
If you work regularly with any fast-moving library (Next.js, React, Supabase, Prisma), Context7 is a no-brainer addition to your toolbelt.
Ready to explore more MCP servers? Check out the Antigravity MCP Store Guide to discover a curated marketplace of servers you can add with a single click.
If you'd like to go deeper and build your own MCP server, the Antigravity Custom MCP Server Build Guide walks you through a full TypeScript implementation from scratch.