This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Build:
pnpm build- Compiles TypeScript to JavaScript indist/directory - Development:
pnpm dev- Runs the server directly from source using tsx - Type checking:
pnpm typecheck- Runs TypeScript compiler without emitting files - Start production:
pnpm start- Runs the compiled server fromdist/index.js
This is a Model Context Protocol (MCP) server that wraps the SlimContext library to provide AI chat history compression tools. The architecture follows a modular design:
-
src/index.ts- Main server entry point using@modelcontextprotocol/sdkSlimContextMCPServerclass manages the MCP server lifecycle- Handles tool registration and request routing
- Implements proper error handling and graceful shutdown
-
src/types/index.ts- Type definitions and Zod schemas- Defines message schemas compatible with SlimContext format
- Contains validation schemas for tool arguments
- Custom error classes:
SlimContextErrorandOpenAIError
-
src/tools/trim.ts- Token-based trimming compression- Uses
TrimCompressorfrom slimcontext library - Removes oldest non-system messages when token threshold exceeded
- Fast, deterministic, no external dependencies
- Uses
-
src/tools/summarize.ts- AI-powered summarization compression- Uses
SummarizeCompressorfrom slimcontext library - Custom
OpenAISlimContextModeladapter for OpenAI API integration - Creates summaries of older messages while preserving recent context
- Requires OpenAI API key via parameter or
OPENAI_API_KEYenvironment variable
- Uses
All tools work with SlimContext message format:
{
role: 'system' | 'user' | 'assistant' | 'tool' | 'human',
content: string
}The codebase handles role normalization (e.g., 'human' → 'user') when interfacing with external APIs.
- Tools return structured JSON responses with success/error states
- Custom error types allow for specific error handling
- MCP server wraps tool errors in standardized format
- All async operations are properly handled with try/catch blocks
@modelcontextprotocol/sdk- MCP protocol implementationslimcontext- Core compression algorithmsopenai- OpenAI API client for summarizationzod- Runtime type validation and parsing
Uses strict TypeScript configuration with:
- ES2022 target with ESNext modules
- Strict type checking enabled (
noImplicitAny,strictNullChecks, etc.) - Source maps and declarations generated
- Output to
dist/directory