DEV Community

vedanth bora
vedanth bora

Posted on

I Built a CLI That Gives Your LLM Accurate Library Docs — No MCP Server Needed

The Problem

You're building with Next.js 15 and ask your AI assistant to write an API route. It gives you the Pages Router pattern from Next.js 12. You paste React docs into the prompt, but they're already outdated by the time you copy them.

Context7 solved this by indexing documentation directly from source repos and serving it through an MCP server. Cursor, Claude Code, and other AI editors use it to get real, version-specific docs instead of hallucinated APIs.

But MCP has a constraint: you need an MCP-compatible client. If you're working in the terminal, running a script, or using a local LLM — you're out of luck.

The Solution

I built c7 — a CLI that pulls from the same Context7 database and outputs docs as plain text to stdout.

c7 react hooks
c7 express middleware
c7 nextjs "app router"
Enter fullscreen mode Exit fullscreen mode

That's it. No server, no configuration, no IDE integration. Just text you can pipe anywhere.

How It Works

The CLI does two things:

  1. Resolves a library name to a Context7 ID (e.g., react/websites/react_dev)
  2. Fetches documentation for that library, filtered by topic

Under the hood it's two API calls using Node.js built-in fetch against Context7's v2 API. The entire project is ~220 lines across two files with zero dependencies.

bin/c7.js   — 136 lines (CLI parsing + output formatting)
lib/api.js  —  87 lines (Context7 v2 API client)
Enter fullscreen mode Exit fullscreen mode

No axios. No commander. No chalk. Just process.argv and fetch.

The Real Power: Pipes

Because c7 outputs plain text to stdout, it composes with everything:

Pipe into LLMs

# Claude
c7 react hooks | claude "summarize the key patterns and show examples"

# Ollama (local models)
c7 express middleware | ollama run codellama "explain this middleware pattern"

# Any LLM CLI
c7 nextjs "api routes" | llm "write an API route based on these docs"
Enter fullscreen mode Exit fullscreen mode

Pipe into Unix tools

# Search docs
c7 nextjs "api routes" | grep "export"

# Page through docs
c7 prisma "schema" | less

# Copy to clipboard
c7 react "useEffect" | pbcopy

# Build context files
c7 nextjs "app router" >> context.txt
c7 react "server components" >> context.txt
Enter fullscreen mode Exit fullscreen mode

Use in scripts

# Pre-load context for a coding agent
DOCS=$(c7 nextjs "app router middleware")
claude "Build a Next.js middleware that handles auth. Use these docs:\n$DOCS"
Enter fullscreen mode Exit fullscreen mode

c7 vs MCP Server

MCP Server c7 CLI
Setup Install server, configure MCP client, restart editor npx @vedanth/context7
Works in MCP-compatible editors Terminal, scripts, CI, anywhere
Composable Limited to MCP protocol Pipes, redirects, subshells
Dependencies Several npm packages Zero
Lines of code ~1000+ ~220

They're complementary. Use the MCP server in your editor, use c7 everywhere else.

Getting Started

# Run without installing
npx @vedanth/context7 react hooks

# Or install globally
npm install -g @vedanth/context7
c7 react hooks
c7 express middleware
c7 nextjs "app router" | claude "summarize"
Enter fullscreen mode Exit fullscreen mode

No API key required for basic usage. For higher rate limits, get a free key at context7.com/dashboard.

Links


Built by Vedanth Bora. If this saves you from one hallucinated API, it was worth building.

Top comments (0)