|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +This is a Svelte MCP (Model Context Protocol) server implementation that includes both SvelteKit web interface and MCP server functionality. |
| 8 | + |
| 9 | +### Setup |
| 10 | + |
| 11 | +```bash |
| 12 | +pnpm i |
| 13 | +cp .env.example .env |
| 14 | +# Set the VOYAGE_API_KEY for embeddings support in .env |
| 15 | +pnpm dev |
| 16 | +``` |
| 17 | + |
| 18 | +### Common Commands |
| 19 | + |
| 20 | +- `pnpm dev` - Start SvelteKit development server |
| 21 | +- `pnpm build` - Build the application for production |
| 22 | +- `pnpm start` - Run the MCP server (Node.js entry point) |
| 23 | +- `pnpm check` - Run Svelte type checking |
| 24 | +- `pnpm check:watch` - Run type checking in watch mode |
| 25 | +- `pnpm lint` - Run prettier check and eslint |
| 26 | +- `pnpm format` - Format code with prettier |
| 27 | +- `pnpm test` - Run unit tests with vitest |
| 28 | +- `pnpm test:watch` - Run tests in watch mode |
| 29 | + |
| 30 | +### Database Commands (Drizzle ORM) |
| 31 | + |
| 32 | +- `pnpm db:push` - Push schema changes to database |
| 33 | +- `pnpm db:generate` - Generate migration files |
| 34 | +- `pnpm db:migrate` - Run migrations |
| 35 | +- `pnpm db:studio` - Open Drizzle Studio |
| 36 | + |
| 37 | +## Architecture |
| 38 | + |
| 39 | +### MCP Server Implementation |
| 40 | + |
| 41 | +The core MCP server is implemented in `src/lib/mcp/index.ts` using the `tmcp` library with: |
| 42 | + |
| 43 | +- **Transport Layers**: Both HTTP (`HttpTransport`) and STDIO (`StdioTransport`) support |
| 44 | +- **Schema Validation**: Uses Valibot with `ValibotJsonSchemaAdapter` |
| 45 | +- **Main Tool**: `svelte-autofixer` - analyzes Svelte code and provides suggestions/fixes |
| 46 | + |
| 47 | +### Code Analysis Engine |
| 48 | + |
| 49 | +Located in `src/lib/server/analyze/`: |
| 50 | + |
| 51 | +- **Parser** (`parse.ts`): Uses `svelte-eslint-parser` and TypeScript parser to analyze Svelte components |
| 52 | +- **Scope Analysis**: Tracks variables, references, and scopes across the AST |
| 53 | +- **Rune Detection**: Identifies Svelte 5 runes (`$state`, `$effect`, `$derived`, etc.) |
| 54 | + |
| 55 | +### Autofixer System |
| 56 | + |
| 57 | +- **Autofixers** (`src/lib/mcp/autofixers.ts`): Visitor pattern implementations for code analysis |
| 58 | +- **Walker Utility** (`src/lib/index.ts`): Enhanced AST walking with visitor mixing capabilities |
| 59 | +- **Current Autofixer**: `assign_in_effect` - detects assignments to `$state` variables inside `$effect` blocks |
| 60 | + |
| 61 | +### Database Layer |
| 62 | + |
| 63 | +- **ORM**: Drizzle with SQLite backend |
| 64 | +- **Schema** (`src/lib/server/db/schema.ts`): Vector table for embeddings support |
| 65 | +- **Utils** (`src/lib/server/db/utils.ts`): Custom float32 array type for vectors |
| 66 | + |
| 67 | +### SvelteKit Integration |
| 68 | + |
| 69 | +- **Hooks** (`src/hooks.server.ts`): Integrates MCP HTTP transport with SvelteKit requests |
| 70 | +- **Routes**: Basic web interface for the MCP server |
| 71 | + |
| 72 | +## Key Dependencies |
| 73 | + |
| 74 | +- **tmcp**: Core MCP server implementation |
| 75 | +- **@tmcp/transport-http** & **@tmcp/transport-stdio**: Transport layers |
| 76 | +- **@tmcp/adapter-valibot**: Schema validation adapter |
| 77 | +- **svelte-eslint-parser**: Svelte component parsing |
| 78 | +- **zimmerframe**: AST walking utilities |
| 79 | +- **drizzle-orm**: Database ORM with SQLite |
| 80 | +- **valibot**: Schema validation library |
| 81 | + |
| 82 | +## Environment Configuration |
| 83 | + |
| 84 | +Required environment variables: |
| 85 | + |
| 86 | +- `DATABASE_URL`: SQLite database path (default: `file:test.db`) |
| 87 | +- `VOYAGE_API_KEY`: API key for embeddings support (optional) |
| 88 | + |
| 89 | +When connected to the svelte-llm MCP server, you have access to comprehensive Svelte 5 and SvelteKit documentation. Here's how to use the available tools effectively: |
| 90 | + |
| 91 | +## Available MCP Tools: |
| 92 | + |
| 93 | +### 1. list_sections |
| 94 | + |
| 95 | +Use this FIRST to discover all available documentation sections. Returns a structured list with titles and paths. |
| 96 | +When asked about Svelte or SvelteKit topics, ALWAYS use this tool at the start of the chat to find relevant sections. |
| 97 | + |
| 98 | +### 2. get_documentation |
| 99 | + |
| 100 | +Retrieves full documentation content for specific sections. Accepts single or multiple sections. |
| 101 | +After calling the list_sections tool, you MUST analyze the returned documentation sections and then use the get_documentation tool to fetch ALL documentation sections that are relevant for the users task. |
0 commit comments