Context Book README

The full upstream README, mirrored for reference. Install config, tool schemas, adoption signals and our own overview live on the Context Book listing page.

ContextBook

smithery badge License: MIT

ContextBook - Stop re-explaining. Give agents the right context | Product Hunt

Stop re-explaining yourself to Agents. Give it the right context, right when needed.

LLMs are stateless β€” each conversation starts from scratch. ContextBook gives your AI tools a persistent, searchable knowledge library to draw the right context when they need it. No bloatware, no pre-loaded junk. Just the right information, at the right time.

How It Works

mermaid
flowchart LR
    AI["πŸ€– AI Clients\nClaude Β· Cursor Β· Windsurf"]
    Browser["🌐 Browser Dashboard"]
    MCP["πŸ”Œ MCP Server :8081\n8 Bearer-authenticated tools"]
    API["βš™οΈ REST API :8080\nOAuth 2.0 Β· Books Β· Pages Β· Search"]
    DB["πŸ—„οΈ PostgreSQL\npgvector Β· pg_trgm"]
    VOYAGE["🧠 Voyage AI\nvoyage-4 (1024-dim)"]

    AI -- "MCP Β· Bearer Token" --> MCP
    Browser -- "Session Β· HTTP JSON" --> API
    MCP --- DB
    API --- DB
    API -- "OAuth 2.0 PKCE" --> AI
    DB --- VOYAGE

Two Go binaries share a PostgreSQL database:

  • API server (cmd/api) β€” the control plane: user login, OAuth 2.0, dashboard, book/page CRUD
  • MCP server (cmd/mcp) β€” the data plane: 8 MCP tools for AI agents, protected by Bearer tokens

MCP Tools

All tools require a valid Bearer token and are scoped to the authenticated user.

ToolDescription
book_create_or_updateCreate a Book or update its metadata
book_listPaginated list of Book metadata
book_getRetrieve all pages of a Book
page_insertPush an atomic page into a Book; embeds immediately
page_updateReplace a page's content; re-embeds
page_deleteRemove a page (indices not re-numbered)
page_searchSemantic search across all Books
readmeReturns the usage guide (call once per session)

Quick Start

Prerequisites

1. Set up the database

sql
CREATE DATABASE contextbook_db;
\c contextbook_db
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS pg_trgm;

Migrations run automatically on API server startup.

2. Configure environment

bash
cp .env.example backend/.env
# Edit backend/.env β€” set DATABASE_URL, API_KEY_SALT, VOYAGE_API_KEY

3. Run the backend

bash
cd backend
go run ./cmd/api/main.go    # API + dashboard (:8080)
go run ./cmd/mcp/main.go     # MCP server (:8081)

4. Run the frontend (optional)

bash
cd frontend
npm install && npm run dev    # Vite dev server on :5173

5. Connect an AI client

For Cursor (.cursor/mcp.json):

config.json
{
  "mcpServers": {
    "contextbook": {
      "url": "http://localhost:8081/mcp"
    }
  }
}

For any MCP-compatible client, point the server URL to http://localhost:8081/mcp.

Documentation

  • Backend README β€” API routes, auth flows, database schema, MCP tools, configuration
  • Frontend README β€” components, routing, design system, development setup
  • Architecture β€” full system overview with Mermaid diagrams

Project Structure

Code
context-book/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ cmd/api/main.go          REST API + auth server
β”‚   β”œβ”€β”€ cmd/mcp/main.go          MCP tool server
β”‚   └── internal/
β”‚       β”œβ”€β”€ api/                  REST handlers + routes
β”‚       β”œβ”€β”€ auth/                 OAuth 2.0 PKCE, sessions, SSO
β”‚       β”œβ”€β”€ context/              Book/Page business logic
β”‚       β”œβ”€β”€ db/                  pgx queries + migrations
β”‚       β”œβ”€β”€ embedding/            Voyage AI client
β”‚       β”œβ”€β”€ logger/               slog + HTTP access logging
β”‚       └── mcp/                  8 MCP tool handlers
β”œβ”€β”€ frontend/                     React 19 + Vite + TypeScript SPA
β”‚   └── src/
β”‚       β”œβ”€β”€ App.tsx               Router + app shell
β”‚       β”œβ”€β”€ lib/api.ts            HTTP client
β”‚       └── components/           UI components
β”œβ”€β”€ Dockerfile                    API server container
β”œβ”€β”€ Dockerfile.mcp                MCP server container
└── go.work                       Go workspace

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Make your changes
  4. Ensure the backend compiles (cd backend && go build ./cmd/api ./cmd/mcp)
  5. Ensure the frontend builds (cd frontend && npm run build)
  6. Commit and push
  7. Open a Pull Request

License

MIT β€” see the LICENSE file for details.