|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with |
| 4 | +code in this repository. |
| 5 | + |
| 6 | +## Project Overview |
| 7 | + |
| 8 | +This is a Model Context Protocol (MCP) server that provides JMAP (JSON Meta |
| 9 | +Application Protocol) email management tools. It's built with Deno and |
| 10 | +integrates with JMAP-compliant email servers like FastMail, Cyrus IMAP, and |
| 11 | +Stalwart Mail Server. |
| 12 | + |
| 13 | +## Development Commands |
| 14 | + |
| 15 | +### Building and Running |
| 16 | + |
| 17 | +- `deno task start` - Run the MCP server in development |
| 18 | +- `deno task watch` - Run with file watching for development |
| 19 | + |
| 20 | +### Testing Connection |
| 21 | + |
| 22 | +- `deno run --allow-env --allow-net src/mod.ts` - Test JMAP server connection |
| 23 | + |
| 24 | +### Required Environment Variables |
| 25 | + |
| 26 | +```bash |
| 27 | +JMAP_SESSION_URL="https://your-jmap-server.com/.well-known/jmap" |
| 28 | +JMAP_BEARER_TOKEN="your-bearer-token" |
| 29 | +JMAP_ACCOUNT_ID="account-id" # Optional, auto-detected if not provided |
| 30 | +``` |
| 31 | + |
| 32 | +## Architecture |
| 33 | + |
| 34 | +### Core Structure |
| 35 | + |
| 36 | +- **Entry point**: `src/mod.ts` - MCP server setup, JMAP client initialization, |
| 37 | + and tool registration |
| 38 | +- **Tool modules**: `src/tools/` - Modular tool implementations |
| 39 | + - `email.ts` - Email search, retrieval, mailbox management, and basic |
| 40 | + operations |
| 41 | + - `submission.ts` - Email composition and sending (when JMAP submission |
| 42 | + capability is available) |
| 43 | +- **Utilities**: `src/utils.ts` - Common utilities like error formatting |
| 44 | + |
| 45 | +### Key Design Patterns |
| 46 | + |
| 47 | +- **Functional programming style** - Functions are pure where possible, side |
| 48 | + effects are contained |
| 49 | +- **Runtime validation** - All inputs validated with Zod schemas before |
| 50 | + processing |
| 51 | +- **Capability-based registration** - Tools are registered based on JMAP server |
| 52 | + capabilities |
| 53 | +- **Graceful degradation** - Server adapts to read-only accounts and limited |
| 54 | + JMAP capabilities |
| 55 | + |
| 56 | +### JMAP Integration |
| 57 | + |
| 58 | +- Uses `jmap-jam` client library for JMAP RFC 8620/8621 compliance |
| 59 | +- Automatically detects account capabilities and registers appropriate tools |
| 60 | +- Supports both read-only and full-access JMAP accounts |
| 61 | +- Handles JMAP mail (`urn:ietf:params:jmap:mail`) and submission |
| 62 | + (`urn:ietf:params:jmap:submission`) capabilities |
| 63 | + |
| 64 | +### Tool Categories |
| 65 | + |
| 66 | +1. **Email Search & Retrieval**: `search_emails`, `get_emails`, `get_threads` |
| 67 | +2. **Mailbox Management**: `get_mailboxes` |
| 68 | +3. **Email Actions** (non-read-only): `mark_emails`, `move_emails`, |
| 69 | + `delete_emails` |
| 70 | +4. **Email Composition** (submission capability): `send_email`, `reply_to_email` |
| 71 | + |
| 72 | +## Development Guidelines |
| 73 | + |
| 74 | +### Adding New Tools |
| 75 | + |
| 76 | +1. Create Zod validation schemas for input parameters |
| 77 | +2. Implement tool logic with proper error handling using `formatError()` |
| 78 | +3. Register tools in appropriate module (`email.ts` vs `submission.ts`) |
| 79 | +4. Tools should be registered conditionally based on JMAP capabilities |
| 80 | + |
| 81 | +### Code Style |
| 82 | + |
| 83 | +- Follow functional programming patterns throughout the codebase |
| 84 | +- Use TypeScript types imported from `jmap-jam` for JMAP objects |
| 85 | +- All external inputs must be validated with Zod schemas |
| 86 | +- Error handling should use the `formatError()` utility |
| 87 | +- Console output uses `console.warn()` for server status messages |
| 88 | + |
| 89 | +### JMAP Considerations |
| 90 | + |
| 91 | +- Email IDs and thread IDs are server-specific strings, not UUIDs |
| 92 | +- Mailbox hierarchies use parent-child relationships via `parentId` |
| 93 | +- Keywords like `$seen`, `$flagged`, `$draft` control email state |
| 94 | +- Date filters must use ISO 8601 format |
| 95 | +- Pagination is handled via `position` and `limit` parameters |
| 96 | + |
| 97 | +## Security Notes |
| 98 | + |
| 99 | +- Bearer tokens are provided via environment variables, never hardcoded |
| 100 | +- No secrets are logged or exposed in MCP responses |
| 101 | +- Input validation prevents injection attacks |
| 102 | +- JMAP protocol provides built-in security through proper authentication |
0 commit comments