You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
2
4
3
5
## Build & Test Commands
4
6
5
7
```sh
6
8
npm run build # Build ESM and CJS versions
7
-
npm run lint # Run ESLint
8
-
npm test# Run all tests
9
-
npx jest path/to/file.test.ts # Run specific test file
10
-
npx jest -t "test name"# Run tests matching pattern
9
+
npm run lint # Run ESLint and Prettier check
10
+
npm run lint:fix # Auto-fix lint and formatting issues
11
+
npm test# Run all tests (vitest)
12
+
npm run test:watch # Run tests in watch mode
13
+
npx vitest path/to/file.test.ts # Run specific test file
14
+
npx vitest -t "test name"# Run tests matching pattern
15
+
npm run typecheck # Type-check without emitting
11
16
```
12
17
13
18
## Code Style Guidelines
@@ -16,13 +21,206 @@ npx jest -t "test name" # Run tests matching pattern
16
21
-**Naming**: PascalCase for classes/types, camelCase for functions/variables
17
22
-**Files**: Lowercase with hyphens, test files with `.test.ts` suffix
18
23
-**Imports**: ES module style, include `.js` extension, group imports logically
19
-
-**Error Handling**: Use TypeScript's strict mode, explicit error checking in tests
20
24
-**Formatting**: 2-space indentation, semicolons required, single quotes preferred
21
25
-**Testing**: Co-locate tests with source files, use descriptive test names
22
26
-**Comments**: JSDoc for public APIs, inline comments for complex logic
23
27
24
-
## Project Structure
28
+
## Architecture Overview
29
+
30
+
### Core Layers
31
+
32
+
The SDK is organized into three main layers:
33
+
34
+
1.**Types Layer** (`src/types.ts`) - Protocol types generated from the MCP specification. All JSON-RPC message types, schemas, and protocol constants are defined here using Zod v4.
35
+
36
+
2.**Protocol Layer** (`src/shared/protocol.ts`) - The abstract `Protocol` class that handles JSON-RPC message routing, request/response correlation, capability negotiation, and transport management. Both `Client` and `Server` extend this class.
37
+
38
+
3.**High-Level APIs**:
39
+
-`Client` (`src/client/index.ts`) - Low-level client extending Protocol with typed methods for all MCP operations
40
+
-`Server` (`src/server/index.ts`) - Low-level server extending Protocol with request handler registration
41
+
-`McpServer` (`src/server/mcp.ts`) - High-level server API with simplified resource/tool/prompt registration
42
+
43
+
### Transport System
44
+
45
+
Transports (`src/shared/transport.ts`) provide the communication layer:
46
+
47
+
-**Streamable HTTP** (`src/server/streamableHttp.ts`, `src/client/streamableHttp.ts`) - Recommended transport for remote servers, supports SSE for streaming
48
+
-**SSE** (`src/server/sse.ts`, `src/client/sse.ts`) - Legacy HTTP+SSE transport for backwards compatibility
49
+
-**stdio** (`src/server/stdio.ts`, `src/client/stdio.ts`) - For local process-spawned integrations
50
+
51
+
### Server-Side Features
52
+
53
+
-**Tools/Resources/Prompts**: Registered via `McpServer.tool()`, `.resource()`, `.prompt()` methods
54
+
-**OAuth/Auth**: Full OAuth 2.0 server implementation in `src/server/auth/`
55
+
-**Completions**: Auto-completion support via `src/server/completable.ts`
56
+
57
+
### Client-Side Features
58
+
59
+
-**Auth**: OAuth client support in `src/client/auth.ts` and `src/client/auth-extensions.ts`
60
+
-**Middleware**: Request middleware in `src/client/middleware.ts`
61
+
-**Sampling**: Clients can handle `sampling/createMessage` requests from servers (LLM completions)
62
+
-**Elicitation**: Clients can handle `elicitation/create` requests for user input (form or URL mode)
63
+
-**Roots**: Clients can expose filesystem roots to servers via `roots/list`
64
+
65
+
### Experimental Features
66
+
67
+
Located in `src/experimental/`:
68
+
69
+
-**Tasks**: Long-running task support with polling/resumption (`src/experimental/tasks/`)
70
+
71
+
### Zod Compatibility
72
+
73
+
The SDK uses `zod/v4` internally but supports both v3 and v4 APIs. Compatibility utilities:
74
+
75
+
-`src/server/zod-compat.ts` - Schema parsing helpers that work across versions
76
+
-`src/server/zod-json-schema-compat.ts` - Converts Zod schemas to JSON Schema
0 commit comments