|
| 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 | +### Building and Development |
| 8 | +```bash |
| 9 | +npm run build # Compile TypeScript to dist/ |
| 10 | +npm run dev # Watch mode with tsx for development |
| 11 | +npm start # Run compiled server from dist/ |
| 12 | +``` |
| 13 | + |
| 14 | +### Code Quality |
| 15 | +```bash |
| 16 | +npm run lint # ESLint on src/**/*.ts |
| 17 | +npm run format # Prettier formatting on src/**/*.ts |
| 18 | +npm test # Run test file |
| 19 | +``` |
| 20 | + |
| 21 | +## Architecture |
| 22 | + |
| 23 | +### MCP Server Pattern |
| 24 | +This is a Model Context Protocol (MCP) server for Toggl Track time tracking: |
| 25 | +- Main server entry point at `src/index.ts` sets up StdioServerTransport |
| 26 | +- Tools are defined with JSON schemas and registered via `setRequestHandler` |
| 27 | +- Each tool maps to a Toggl Track API operation |
| 28 | + |
| 29 | +### File Structure |
| 30 | +- `src/index.ts` - MCP server entry point, tool definitions |
| 31 | +- `src/toggl-api.ts` - Toggl Track API client wrapper |
| 32 | +- `src/cache-manager.ts` - Caching layer for API responses |
| 33 | +- `src/types.ts` - TypeScript type definitions |
| 34 | +- `src/utils.ts` - Utility functions |
| 35 | + |
| 36 | +### Toggl API Integration |
| 37 | +The `TogglAPI` class (`src/toggl-api.ts`) wraps the Toggl Track API: |
| 38 | +- Uses API token authentication |
| 39 | +- Supports time entries, projects, clients, and reports |
| 40 | +- Caching layer reduces API calls for frequently accessed data |
| 41 | + |
| 42 | +### TypeScript Configuration |
| 43 | +- ES2022 modules with strict mode enabled |
| 44 | +- Compiles to ES modules (not CommonJS) |
| 45 | +- All imports require `.js` extensions (even for `.ts` files) |
| 46 | + |
| 47 | +## Environment Variables |
| 48 | + |
| 49 | +Required: |
| 50 | +- `TOGGL_API_TOKEN`: Your Toggl Track API token (get from https://track.toggl.com/profile) |
| 51 | + |
| 52 | +Optional: |
| 53 | +- `TOGGL_WORKSPACE_ID`: Default workspace ID |
| 54 | + |
| 55 | +## Key Implementation Patterns |
| 56 | + |
| 57 | +### Caching Strategy |
| 58 | +- `cache-manager.ts` provides TTL-based caching |
| 59 | +- Reduces API rate limiting issues |
| 60 | +- Cache invalidation on write operations |
| 61 | + |
| 62 | +### Error Handling |
| 63 | +- API errors wrapped with descriptive messages |
| 64 | +- Rate limiting handled with retry logic |
| 65 | +- Missing resources return clear error states |
0 commit comments