Skip to main content
Experimental API - Context Engine SDK is experimental and subject to breaking changes.

Available Examples


Getting the Examples

All example code is available in the Auggie repository. To access the examples:
git clone https://github.com/augmentcode/auggie.git
cd auggie/examples/typescript-sdk/context
Each example is a complete, runnable application demonstrating different use cases of the Auggie SDK.

Prerequisites

Before running the examples:
  1. Node.js 18+ - Required to run the examples
  2. Auggie CLI - Required for FileSystem Context examples
    npm install -g @augmentcode/auggie
    
  3. Authentication - Required for all examples
    auggie login
    
    This creates a session file at ~/.augment/session.json with your API token. Alternatively, you can set environment variables:
    export AUGMENT_API_TOKEN="your-api-token"
    export AUGMENT_API_URL="https://your-tenant.api.augmentcode.com"
    

Setup

Install dependencies:
cd examples/typescript-sdk/context
npm install

Simple Examples

Get started quickly with these basic examples that demonstrate core SDK functionality.

Direct Context

Demonstrates indexing files from any source and performing semantic searches with AI-powered question answering. Quick Start:
npm run direct-context
Or run directly:
npx tsx direct-context/index.ts

FileSystem Context

Shows how to search a local directory using automatic file discovery via the MCP protocol. Prerequisites:
  • Auggie CLI must be installed and in your PATH
  • Authentication via auggie login or AUGMENT_API_TOKEN environment variable
  • A .gitignore or .augmentignore file in the workspace directory to exclude node_modules/ and other large directories
Important: The FileSystem Context indexes all files in the workspace directory. To avoid timeouts when indexing large directories (like node_modules/), make sure you have a .gitignore or .augmentignore file that excludes them. Quick Start:
npm run filesystem-context
Or run directly:
npx tsx filesystem-context/index.ts

Developer Tools

Build production-ready applications with these server examples.

File Search Server

A REST API server that provides semantic file search with AI-powered summarization. Prerequisites: Auggie CLI must be installed and in your PATH. Quick Start:
npm run file-search-server [workspace-directory]
Then query the API:
curl "http://localhost:3000/search?q=typescript"
Or run directly:
npx tsx file-search-server/index.ts .

Prompt Enhancer Server

An HTTP server that automatically enriches user prompts with relevant codebase context. Prerequisites: Auggie CLI must be installed and in your PATH. Quick Start:
npm run prompt-enhancer-server [workspace-directory]
Then enhance prompts:
curl -X POST http://localhost:3001/enhance \
  -H "Content-Type: application/json" \
  -d '{"prompt": "fix the login bug"}'
Or run directly:
npx tsx prompt-enhancer-server/index.ts .

CI/CD Integration

Integrate the SDK into your continuous integration workflows.

GitHub Action Indexer

Automatically index your GitHub repositories with zero-question setup and incremental updates. Perfect for CI/CD workflows and keeping your codebase searchable. Key Features:
  • πŸ”„ Incremental indexing - Only processes changed files for efficiency
  • πŸ’Ύ Smart caching - Persists index state between runs
  • πŸš€ 30-second setup - From zero to running GitHub Action
One-Command Installation:
# Install directly into your repository
cd /path/to/your/repository
npx @augment-samples/github-action-indexer install

# Add your API secrets to GitHub repository settings
# Push to trigger automatic indexing on every commit
What It Does:
  1. Installs a GitHub Action workflow in your repository
  2. Indexes your codebase automatically on every push
  3. Updates incrementally using GitHub’s Compare API
  4. Caches index state for fast subsequent runs
  5. Handles large repositories with optimized performance settings
Perfect For:
  • Keeping your codebase searchable and up-to-date
  • CI/CD workflows that need codebase understanding
  • Teams wanting automatic repository indexing
  • Projects with frequent commits (incremental updates are fast)
Try It Locally First:
cd github-action-indexer
npm install
export AUGMENT_API_TOKEN="your-token"
export AUGMENT_API_URL="https://your-tenant.api.augmentcode.com/"
export GITHUB_TOKEN="your-github-token"
export GITHUB_REPOSITORY="owner/repo"
export GITHUB_SHA="$(git rev-parse HEAD)"
npm run index
npm run search "authentication functions"
πŸ“– Complete Setup Guide β†’ - Detailed instructions, troubleshooting, and customization options.

File Search Server

Location: file-search-server/ Description: REST API for semantic file search with AI-powered summarization and code explanation. Quick Start:
npm run file-search-server
Features:
  • REST API endpoints for semantic search
  • AI-powered code summarization
  • Real-time file indexing
  • HTTP server with JSON responses
API Endpoints:
  • POST /search - Semantic search with optional AI summarization
  • GET /health - Health check endpoint
Prerequisites:
  • Auggie CLI installed and in PATH
  • Authentication via auggie login or environment variables

Prompt Enhancer Server

Location: prompt-enhancer-server/ Description: HTTP server that enhances vague prompts using AI with codebase context. Quick Start:
npm run prompt-enhancer-server
Features:
  • Enhances vague prompts with codebase context
  • HTTP API for prompt enhancement
  • AI-powered prompt improvement
  • Real-time codebase analysis
API Endpoints:
  • POST /enhance - Enhance a prompt with codebase context
  • GET /health - Health check endpoint
Use Cases:
  • Improving user queries for better search results
  • Building intelligent code assistance tools
  • Creating context-aware development workflows

Running Examples Directly with tsx

You can also run examples directly without installing dependencies:
npx tsx direct-context/index.ts
npx tsx filesystem-context/index.ts
npx tsx file-search-server/index.ts .
npx tsx prompt-enhancer-server/index.ts .
Note: This will download dependencies on each run. For better performance, use npm install first.

Troubleshooting

MCP Timeout in FileSystem Context

Problem: The FileSystem Context example times out during indexing. Cause: The workspace directory contains too many files (e.g., node_modules/ with 45,000+ files). Solution: Create a .gitignore or .augmentignore file in the workspace directory to exclude large directories:
# .gitignore or .augmentignore
node_modules/
dist/
*.log
.DS_Store
The auggie CLI respects both .gitignore and .augmentignore patterns and will skip excluded files during indexing.

Authentication Errors

Problem: Error: API key is required for searchAndAsk() Cause: The SDK cannot find your authentication credentials. Solution: Run auggie login to authenticate, or set the AUGMENT_API_TOKEN and AUGMENT_API_URL environment variables.

Next Steps