|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance for Claude Code when working with this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is the Notion MCP Server - an [MCP (Model Context Protocol)](https://spec.modelcontextprotocol.io/) server that exposes the [Notion API](https://developers.notion.com/reference/intro) as MCP tools. It auto-generates tools from an OpenAPI specification. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +``` |
| 12 | +scripts/notion-openapi.json # OpenAPI spec (source of truth for all tools) |
| 13 | + ↓ |
| 14 | +src/init-server.ts # Loads & validates spec, creates MCPProxy |
| 15 | + ↓ |
| 16 | +src/openapi-mcp-server/ |
| 17 | +├── openapi/parser.ts # Converts OpenAPI → MCP tools |
| 18 | +├── mcp/proxy.ts # Registers tools with MCP server |
| 19 | +└── client/http-client.ts # Executes API calls |
| 20 | +``` |
| 21 | + |
| 22 | +## Key Patterns |
| 23 | + |
| 24 | +### Adding New Endpoints |
| 25 | + |
| 26 | +Only modify `scripts/notion-openapi.json`. Tools are auto-generated from the spec - no code changes needed elsewhere. |
| 27 | + |
| 28 | +### Tool Generation Flow |
| 29 | + |
| 30 | +1. `OpenAPIToMCPConverter.convertToMCPTools()` iterates all paths/operations |
| 31 | +2. Each operation becomes an MCP tool (name = `operationId`) |
| 32 | +3. Parameters + requestBody → `inputSchema` |
| 33 | +4. Response schema → `returnSchema` |
| 34 | +5. `MCPProxy.setupHandlers()` registers tools with the MCP SDK |
| 35 | + |
| 36 | +### Naming Conventions |
| 37 | + |
| 38 | +- Tool names come from OpenAPI `operationId` (e.g., `retrieve-a-database`) |
| 39 | +- Names are truncated to 64 chars and converted to title case for display |
| 40 | + |
| 41 | +## Common Commands |
| 42 | + |
| 43 | +```bash |
| 44 | +npm run build # TypeScript compilation + CLI bundling |
| 45 | +npm test # Run vitest tests |
| 46 | +npm run dev # Start dev server with hot reload |
| 47 | +``` |
| 48 | + |
| 49 | +## File Structure |
| 50 | + |
| 51 | +- `scripts/notion-openapi.json` - OpenAPI 3.1.0 spec defining all Notion API endpoints |
| 52 | +- `scripts/start-server.ts` - Entry point |
| 53 | +- `src/init-server.ts` - Server initialization |
| 54 | +- `src/openapi-mcp-server/` - Core MCP server implementation |
| 55 | + - `openapi/parser.ts` - OpenAPI to MCP conversion (529 lines) |
| 56 | + - `mcp/proxy.ts` - MCP tool registration and execution (209 lines) |
| 57 | + - `client/http-client.ts` - HTTP request execution (198 lines) |
| 58 | + |
| 59 | +## Testing |
| 60 | + |
| 61 | +Tests are in `__tests__` directories adjacent to source files. Run with `npm test`. |
| 62 | + |
| 63 | +## API Version |
| 64 | + |
| 65 | +Uses Notion API version `2025-09-03` (Data Source Edition). The spec includes both: |
| 66 | +- `/v1/databases/{database_id}` - Traditional database endpoints |
| 67 | +- `/v1/data_sources/{data_source_id}` - New data source endpoints |
0 commit comments