@prmichaelsen/acp-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +5 -0
- package/AGENT.md +1279 -0
- package/README.md +78 -0
- package/agent/commands/acp.command-create.md +372 -0
- package/agent/commands/acp.design-create.md +224 -0
- package/agent/commands/acp.init.md +410 -0
- package/agent/commands/acp.package-create.md +894 -0
- package/agent/commands/acp.package-info.md +211 -0
- package/agent/commands/acp.package-install.md +461 -0
- package/agent/commands/acp.package-list.md +279 -0
- package/agent/commands/acp.package-publish.md +540 -0
- package/agent/commands/acp.package-remove.md +292 -0
- package/agent/commands/acp.package-search.md +306 -0
- package/agent/commands/acp.package-update.md +310 -0
- package/agent/commands/acp.package-validate.md +535 -0
- package/agent/commands/acp.pattern-create.md +326 -0
- package/agent/commands/acp.plan.md +552 -0
- package/agent/commands/acp.proceed.md +336 -0
- package/agent/commands/acp.project-create.md +672 -0
- package/agent/commands/acp.report.md +394 -0
- package/agent/commands/acp.resume.md +237 -0
- package/agent/commands/acp.status.md +280 -0
- package/agent/commands/acp.sync.md +363 -0
- package/agent/commands/acp.task-create.md +390 -0
- package/agent/commands/acp.update.md +301 -0
- package/agent/commands/acp.validate.md +436 -0
- package/agent/commands/acp.version-check-for-updates.md +275 -0
- package/agent/commands/acp.version-check.md +190 -0
- package/agent/commands/acp.version-update.md +288 -0
- package/agent/commands/command.template.md +316 -0
- package/agent/commands/git.commit.md +513 -0
- package/agent/commands/git.init.md +513 -0
- package/agent/commands/mcp-server-starter.add-tool.md +677 -0
- package/agent/commands/mcp-server-starter.init.md +894 -0
- package/agent/design/.gitkeep +0 -0
- package/agent/design/design.template.md +136 -0
- package/agent/design/remember-mcp-analysis.md +987 -0
- package/agent/design/requirements.template.md +387 -0
- package/agent/manifest.template.yaml +13 -0
- package/agent/manifest.yaml +109 -0
- package/agent/milestones/.gitkeep +0 -0
- package/agent/milestones/milestone-1-{title}.template.md +206 -0
- package/agent/package.template.yaml +36 -0
- package/agent/patterns/.gitkeep +0 -0
- package/agent/patterns/bootstrap.template.md +1237 -0
- package/agent/patterns/mcp-server-starter.bootstrap.md +597 -0
- package/agent/patterns/mcp-server-starter.build-config.md +554 -0
- package/agent/patterns/mcp-server-starter.config-management.md +525 -0
- package/agent/patterns/mcp-server-starter.server-factory.md +616 -0
- package/agent/patterns/mcp-server-starter.server-standalone.md +642 -0
- package/agent/patterns/mcp-server-starter.test-config.md +558 -0
- package/agent/patterns/mcp-server-starter.tool-creation.md +653 -0
- package/agent/patterns/pattern.template.md +364 -0
- package/agent/progress.template.yaml +161 -0
- package/agent/progress.yaml +33 -0
- package/agent/schemas/package.schema.yaml +161 -0
- package/agent/scripts/acp.common.sh +1362 -0
- package/agent/scripts/acp.install.sh +213 -0
- package/agent/scripts/acp.package-create.sh +925 -0
- package/agent/scripts/acp.package-info.sh +270 -0
- package/agent/scripts/acp.package-install.sh +550 -0
- package/agent/scripts/acp.package-list.sh +263 -0
- package/agent/scripts/acp.package-publish.sh +420 -0
- package/agent/scripts/acp.package-remove.sh +272 -0
- package/agent/scripts/acp.package-search.sh +156 -0
- package/agent/scripts/acp.package-update.sh +356 -0
- package/agent/scripts/acp.package-validate.sh +766 -0
- package/agent/scripts/acp.uninstall.sh +85 -0
- package/agent/scripts/acp.version-check-for-updates.sh +98 -0
- package/agent/scripts/acp.version-check.sh +47 -0
- package/agent/scripts/acp.version-update.sh +158 -0
- package/agent/scripts/acp.yaml-parser.sh +736 -0
- package/agent/scripts/acp.yaml-validate.sh +205 -0
- package/agent/tasks/.gitkeep +0 -0
- package/agent/tasks/task-1-{title}.template.md +225 -0
- package/dist/config.d.ts +4 -0
- package/dist/server-factory.d.ts +9 -0
- package/dist/server-factory.js +99 -0
- package/dist/server-factory.js.map +7 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +106 -0
- package/dist/server.js.map +7 -0
- package/dist/tools/acp-remote-list-files.d.ts +15 -0
- package/dist/types/ssh-config.d.ts +16 -0
- package/esbuild.build.js +34 -0
- package/esbuild.watch.js +31 -0
- package/jest.config.js +31 -0
- package/package.json +54 -0
- package/src/config.ts +16 -0
- package/src/server-factory.ts +43 -0
- package/src/server.ts +46 -0
- package/src/tools/acp-remote-list-files.ts +89 -0
- package/src/types/ssh-config.ts +17 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
# Bootstrap Pattern
|
|
2
|
+
|
|
3
|
+
**Pattern**: Project Initialization and Directory Structure
|
|
4
|
+
**Category**: Setup
|
|
5
|
+
**Complexity**: Beginner
|
|
6
|
+
**Last Updated**: 2026-02-22
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
The Bootstrap Pattern provides a standardized approach to initializing TypeScript MCP server projects with the correct directory structure, configuration files, and dependencies. This pattern ensures consistency across projects and sets up a solid foundation for development.
|
|
13
|
+
|
|
14
|
+
**When to use this pattern**:
|
|
15
|
+
- Starting a new MCP server project
|
|
16
|
+
- Converting an existing project to MCP
|
|
17
|
+
- Setting up a development environment for MCP servers
|
|
18
|
+
- Creating a template for team projects
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Core Principles
|
|
23
|
+
|
|
24
|
+
### 1. ES Modules (ESM) First
|
|
25
|
+
Modern JavaScript/TypeScript projects should use ESM syntax (`import`/`export`) rather than CommonJS (`require`/`module.exports`). MCP SDK is built for ESM.
|
|
26
|
+
|
|
27
|
+
### 2. TypeScript for Type Safety
|
|
28
|
+
TypeScript provides compile-time type checking, better IDE support, and improved maintainability for MCP servers.
|
|
29
|
+
|
|
30
|
+
### 3. Dual Build Support
|
|
31
|
+
Projects should support both standalone execution (stdio transport) and library usage (factory pattern for mcp-auth).
|
|
32
|
+
|
|
33
|
+
### 4. Development Workflow
|
|
34
|
+
Fast iteration with watch mode, hot reload, and immediate feedback during development.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Directory Structure
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
my-mcp-server/
|
|
42
|
+
├── src/ # Source code
|
|
43
|
+
│ ├── server.ts # Standalone server entry point
|
|
44
|
+
│ ├── server-factory.ts # Factory for mcp-auth (optional)
|
|
45
|
+
│ ├── config.ts # Configuration management
|
|
46
|
+
│ ├── tools/ # MCP tool implementations
|
|
47
|
+
│ │ └── example-tool.ts
|
|
48
|
+
│ ├── utils/ # Utility functions
|
|
49
|
+
│ │ ├── logger.ts
|
|
50
|
+
│ │ └── error-handler.ts
|
|
51
|
+
│ └── types/ # TypeScript type definitions
|
|
52
|
+
│ └── index.ts
|
|
53
|
+
├── dist/ # Compiled JavaScript (generated)
|
|
54
|
+
│ ├── server.js
|
|
55
|
+
│ └── server-factory.js
|
|
56
|
+
├── tests/ # Test files (optional)
|
|
57
|
+
│ └── server.spec.ts
|
|
58
|
+
├── node_modules/ # Dependencies (generated)
|
|
59
|
+
├── package.json # Project manifest
|
|
60
|
+
├── tsconfig.json # TypeScript configuration
|
|
61
|
+
├── esbuild.build.js # Build script
|
|
62
|
+
├── esbuild.watch.js # Watch mode script (optional)
|
|
63
|
+
├── jest.config.js # Test configuration (optional)
|
|
64
|
+
├── .env.example # Environment variable template
|
|
65
|
+
├── .gitignore # Git ignore rules
|
|
66
|
+
├── README.md # Project documentation
|
|
67
|
+
└── LICENSE # License file
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Directory Purposes
|
|
71
|
+
|
|
72
|
+
**`src/`** - All TypeScript source code
|
|
73
|
+
- Organized by feature/function
|
|
74
|
+
- Tools in `tools/` subdirectory
|
|
75
|
+
- Utilities in `utils/` subdirectory
|
|
76
|
+
- Types in `types/` subdirectory
|
|
77
|
+
|
|
78
|
+
**`dist/`** - Compiled JavaScript output
|
|
79
|
+
- Generated by build process
|
|
80
|
+
- Not committed to git
|
|
81
|
+
- Contains bundled, executable code
|
|
82
|
+
|
|
83
|
+
**`tests/`** - Test files
|
|
84
|
+
- Can be colocated (`*.spec.ts`) or separate
|
|
85
|
+
- Mirrors `src/` structure if separate
|
|
86
|
+
|
|
87
|
+
**`node_modules/`** - npm dependencies
|
|
88
|
+
- Generated by `npm install`
|
|
89
|
+
- Not committed to git
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Configuration Files
|
|
94
|
+
|
|
95
|
+
### package.json
|
|
96
|
+
|
|
97
|
+
Complete example with all necessary fields:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"name": "@username/my-mcp-server",
|
|
102
|
+
"version": "0.1.0",
|
|
103
|
+
"description": "MCP server for [purpose]",
|
|
104
|
+
"type": "module",
|
|
105
|
+
"main": "dist/server.js",
|
|
106
|
+
"exports": {
|
|
107
|
+
".": {
|
|
108
|
+
"types": "./dist/server.d.ts",
|
|
109
|
+
"import": "./dist/server.js"
|
|
110
|
+
},
|
|
111
|
+
"./factory": {
|
|
112
|
+
"types": "./dist/server-factory.d.ts",
|
|
113
|
+
"import": "./dist/server-factory.js"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"bin": {
|
|
117
|
+
"my-mcp-server": "./dist/server.js"
|
|
118
|
+
},
|
|
119
|
+
"scripts": {
|
|
120
|
+
"build": "node esbuild.build.js",
|
|
121
|
+
"build:watch": "node esbuild.watch.js",
|
|
122
|
+
"dev": "tsx watch src/server.ts",
|
|
123
|
+
"start": "node dist/server.js",
|
|
124
|
+
"test": "jest",
|
|
125
|
+
"test:watch": "jest --watch",
|
|
126
|
+
"typecheck": "tsc --noEmit",
|
|
127
|
+
"clean": "rm -rf dist",
|
|
128
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
129
|
+
},
|
|
130
|
+
"keywords": [
|
|
131
|
+
"mcp",
|
|
132
|
+
"model-context-protocol",
|
|
133
|
+
"typescript"
|
|
134
|
+
],
|
|
135
|
+
"author": "Your Name",
|
|
136
|
+
"license": "MIT",
|
|
137
|
+
"dependencies": {
|
|
138
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
139
|
+
"dotenv": "^16.4.5"
|
|
140
|
+
},
|
|
141
|
+
"devDependencies": {
|
|
142
|
+
"@types/node": "^20.11.19",
|
|
143
|
+
"esbuild": "^0.20.0",
|
|
144
|
+
"tsx": "^4.7.1",
|
|
145
|
+
"typescript": "^5.3.3"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Key Fields**:
|
|
151
|
+
- `"type": "module"` - Enables ESM
|
|
152
|
+
- `"main"` - Entry point for standalone usage
|
|
153
|
+
- `"exports"` - Dual export (server + factory)
|
|
154
|
+
- `"bin"` - CLI executable
|
|
155
|
+
- `"scripts"` - Development workflow commands
|
|
156
|
+
|
|
157
|
+
### tsconfig.json
|
|
158
|
+
|
|
159
|
+
TypeScript configuration for ESM + modern features:
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"compilerOptions": {
|
|
164
|
+
"target": "ES2022",
|
|
165
|
+
"module": "ES2022",
|
|
166
|
+
"lib": ["ES2022"],
|
|
167
|
+
"moduleResolution": "node",
|
|
168
|
+
"esModuleInterop": true,
|
|
169
|
+
"allowSyntheticDefaultImports": true,
|
|
170
|
+
"strict": true,
|
|
171
|
+
"skipLibCheck": true,
|
|
172
|
+
"forceConsistentCasingInFileNames": true,
|
|
173
|
+
"resolveJsonModule": true,
|
|
174
|
+
"outDir": "./dist",
|
|
175
|
+
"rootDir": "./src",
|
|
176
|
+
"declaration": true,
|
|
177
|
+
"declarationMap": true,
|
|
178
|
+
"sourceMap": true,
|
|
179
|
+
"types": ["node"],
|
|
180
|
+
"baseUrl": ".",
|
|
181
|
+
"paths": {
|
|
182
|
+
"@/*": ["src/*"]
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
"include": ["src/**/*"],
|
|
186
|
+
"exclude": ["node_modules", "dist", "tests"]
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Key Settings**:
|
|
191
|
+
- `ES2022` target for modern JavaScript
|
|
192
|
+
- `strict: true` for maximum type safety
|
|
193
|
+
- `declaration: true` for `.d.ts` files
|
|
194
|
+
- Path aliases (`@/*`) for clean imports
|
|
195
|
+
|
|
196
|
+
### .env.example
|
|
197
|
+
|
|
198
|
+
Environment variable template:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# Service Configuration
|
|
202
|
+
SERVICE_URL=http://localhost:8080
|
|
203
|
+
SERVICE_API_KEY=
|
|
204
|
+
|
|
205
|
+
# Server Configuration
|
|
206
|
+
PORT=3000
|
|
207
|
+
NODE_ENV=development
|
|
208
|
+
LOG_LEVEL=info
|
|
209
|
+
|
|
210
|
+
# MCP Configuration
|
|
211
|
+
MCP_TRANSPORT=stdio
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Purpose**: Documents required environment variables without exposing secrets.
|
|
215
|
+
|
|
216
|
+
### .gitignore
|
|
217
|
+
|
|
218
|
+
Git ignore rules for MCP projects:
|
|
219
|
+
|
|
220
|
+
```gitignore
|
|
221
|
+
# Dependencies
|
|
222
|
+
node_modules/
|
|
223
|
+
|
|
224
|
+
# Build output
|
|
225
|
+
dist/
|
|
226
|
+
*.js
|
|
227
|
+
*.d.ts
|
|
228
|
+
*.js.map
|
|
229
|
+
!esbuild.*.js
|
|
230
|
+
!jest.config.js
|
|
231
|
+
|
|
232
|
+
# Environment
|
|
233
|
+
.env
|
|
234
|
+
.env.local
|
|
235
|
+
|
|
236
|
+
# IDE
|
|
237
|
+
.vscode/
|
|
238
|
+
.idea/
|
|
239
|
+
*.swp
|
|
240
|
+
*.swo
|
|
241
|
+
|
|
242
|
+
# OS
|
|
243
|
+
.DS_Store
|
|
244
|
+
Thumbs.db
|
|
245
|
+
|
|
246
|
+
# Logs
|
|
247
|
+
*.log
|
|
248
|
+
npm-debug.log*
|
|
249
|
+
|
|
250
|
+
# Testing
|
|
251
|
+
coverage/
|
|
252
|
+
.nyc_output/
|
|
253
|
+
|
|
254
|
+
# Temporary
|
|
255
|
+
*.tmp
|
|
256
|
+
.cache/
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Dependencies
|
|
262
|
+
|
|
263
|
+
### Core Dependencies
|
|
264
|
+
|
|
265
|
+
**@modelcontextprotocol/sdk** (^1.0.4)
|
|
266
|
+
- Purpose: MCP protocol implementation
|
|
267
|
+
- Required: Yes
|
|
268
|
+
- Why: Provides Server, transport, and types
|
|
269
|
+
|
|
270
|
+
**dotenv** (^16.4.5)
|
|
271
|
+
- Purpose: Load environment variables from `.env`
|
|
272
|
+
- Required: Recommended
|
|
273
|
+
- Why: Simplifies configuration management
|
|
274
|
+
|
|
275
|
+
### Development Dependencies
|
|
276
|
+
|
|
277
|
+
**typescript** (^5.3.3)
|
|
278
|
+
- Purpose: TypeScript compiler
|
|
279
|
+
- Required: Yes
|
|
280
|
+
- Why: Compiles TypeScript to JavaScript
|
|
281
|
+
|
|
282
|
+
**esbuild** (^0.20.0)
|
|
283
|
+
- Purpose: Fast JavaScript bundler
|
|
284
|
+
- Required: Yes
|
|
285
|
+
- Why: Bundles code for distribution
|
|
286
|
+
|
|
287
|
+
**tsx** (^4.7.1)
|
|
288
|
+
- Purpose: TypeScript execution with watch mode
|
|
289
|
+
- Required: Recommended
|
|
290
|
+
- Why: Enables `npm run dev` with hot reload
|
|
291
|
+
|
|
292
|
+
**@types/node** (^20.11.19)
|
|
293
|
+
- Purpose: Node.js type definitions
|
|
294
|
+
- Required: Yes
|
|
295
|
+
- Why: Provides types for Node.js APIs
|
|
296
|
+
|
|
297
|
+
### Optional Dependencies
|
|
298
|
+
|
|
299
|
+
**jest** + **ts-jest** + **@types/jest**
|
|
300
|
+
- Purpose: Testing framework
|
|
301
|
+
- When: If writing tests
|
|
302
|
+
|
|
303
|
+
**@prmichaelsen/mcp-auth**
|
|
304
|
+
- Purpose: Multi-tenant authentication
|
|
305
|
+
- When: If building production multi-tenant server
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Implementation
|
|
310
|
+
|
|
311
|
+
### Step-by-Step Setup
|
|
312
|
+
|
|
313
|
+
#### 1. Initialize Project
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
mkdir my-mcp-server
|
|
317
|
+
cd my-mcp-server
|
|
318
|
+
npm init -y
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### 2. Configure package.json
|
|
322
|
+
|
|
323
|
+
Add `"type": "module"` and update scripts:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
npm pkg set type="module"
|
|
327
|
+
npm pkg set scripts.build="node esbuild.build.js"
|
|
328
|
+
npm pkg set scripts.dev="tsx watch src/server.ts"
|
|
329
|
+
npm pkg set scripts.start="node dist/server.js"
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### 3. Install Dependencies
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
# Core dependencies
|
|
336
|
+
npm install @modelcontextprotocol/sdk dotenv
|
|
337
|
+
|
|
338
|
+
# Dev dependencies
|
|
339
|
+
npm install -D typescript esbuild tsx @types/node
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### 4. Create Directory Structure
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
mkdir -p src/tools src/utils src/types
|
|
346
|
+
mkdir -p dist tests
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### 5. Create Configuration Files
|
|
350
|
+
|
|
351
|
+
Create `tsconfig.json`, `.env.example`, `.gitignore` (see examples above).
|
|
352
|
+
|
|
353
|
+
#### 6. Create Build Script
|
|
354
|
+
|
|
355
|
+
Create `esbuild.build.js`:
|
|
356
|
+
|
|
357
|
+
```javascript
|
|
358
|
+
import * as esbuild from 'esbuild';
|
|
359
|
+
|
|
360
|
+
await esbuild.build({
|
|
361
|
+
entryPoints: ['src/server.ts'],
|
|
362
|
+
bundle: true,
|
|
363
|
+
platform: 'node',
|
|
364
|
+
target: 'node20',
|
|
365
|
+
format: 'esm',
|
|
366
|
+
outfile: 'dist/server.js',
|
|
367
|
+
sourcemap: true,
|
|
368
|
+
external: ['@modelcontextprotocol/sdk'],
|
|
369
|
+
banner: {
|
|
370
|
+
js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);"
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
console.log('✓ Build complete');
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
#### 7. Initialize Git
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
git init
|
|
381
|
+
git add .
|
|
382
|
+
git commit -m "chore: initial project setup"
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### 8. Create README.md
|
|
386
|
+
|
|
387
|
+
Document your project's purpose, installation, and usage.
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
## Examples
|
|
392
|
+
|
|
393
|
+
### Minimal Server Setup
|
|
394
|
+
|
|
395
|
+
After bootstrapping, create a minimal server:
|
|
396
|
+
|
|
397
|
+
**src/server.ts**:
|
|
398
|
+
```typescript
|
|
399
|
+
#!/usr/bin/env node
|
|
400
|
+
|
|
401
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
402
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
403
|
+
|
|
404
|
+
const server = new Server(
|
|
405
|
+
{ name: 'my-mcp-server', version: '0.1.0' },
|
|
406
|
+
{ capabilities: { tools: {} } }
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
const transport = new StdioServerTransport();
|
|
410
|
+
await server.connect(transport);
|
|
411
|
+
|
|
412
|
+
console.error('Server running on stdio');
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Build and run:
|
|
416
|
+
```bash
|
|
417
|
+
npm run build
|
|
418
|
+
npm start
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## Benefits
|
|
424
|
+
|
|
425
|
+
### 1. Consistency
|
|
426
|
+
- Standard structure across all MCP projects
|
|
427
|
+
- Familiar layout for team members
|
|
428
|
+
- Easy onboarding for new developers
|
|
429
|
+
|
|
430
|
+
### 2. Best Practices
|
|
431
|
+
- ESM for modern JavaScript
|
|
432
|
+
- TypeScript for type safety
|
|
433
|
+
- Proper separation of concerns
|
|
434
|
+
|
|
435
|
+
### 3. Development Speed
|
|
436
|
+
- Fast builds with esbuild
|
|
437
|
+
- Hot reload with tsx watch
|
|
438
|
+
- Immediate feedback loop
|
|
439
|
+
|
|
440
|
+
### 4. Production Ready
|
|
441
|
+
- Dual build (standalone + factory)
|
|
442
|
+
- Proper error handling setup
|
|
443
|
+
- Configuration management
|
|
444
|
+
|
|
445
|
+
### 5. Maintainability
|
|
446
|
+
- Clear directory structure
|
|
447
|
+
- Documented configuration
|
|
448
|
+
- Type-safe codebase
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
## Anti-Patterns
|
|
453
|
+
|
|
454
|
+
### ❌ Don't: Use CommonJS
|
|
455
|
+
|
|
456
|
+
```javascript
|
|
457
|
+
// ❌ Wrong
|
|
458
|
+
const { Server } = require('@modelcontextprotocol/sdk/server');
|
|
459
|
+
module.exports = server;
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
```javascript
|
|
463
|
+
// ✅ Correct
|
|
464
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
465
|
+
export { server };
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
**Why**: MCP SDK is built for ESM. CommonJS causes compatibility issues.
|
|
469
|
+
|
|
470
|
+
### ❌ Don't: Skip TypeScript
|
|
471
|
+
|
|
472
|
+
```javascript
|
|
473
|
+
// ❌ Wrong - Plain JavaScript
|
|
474
|
+
const server = new Server({ name: 'server' });
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
// ✅ Correct - TypeScript
|
|
479
|
+
const server = new Server(
|
|
480
|
+
{ name: 'server', version: '0.1.0' },
|
|
481
|
+
{ capabilities: { tools: {} } }
|
|
482
|
+
);
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
**Why**: TypeScript catches errors at compile time and improves IDE support.
|
|
486
|
+
|
|
487
|
+
### ❌ Don't: Commit dist/ or node_modules/
|
|
488
|
+
|
|
489
|
+
```gitignore
|
|
490
|
+
# ❌ Wrong - Missing from .gitignore
|
|
491
|
+
# (no entries)
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
```gitignore
|
|
495
|
+
# ✅ Correct
|
|
496
|
+
node_modules/
|
|
497
|
+
dist/
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
**Why**: Generated files should not be in version control.
|
|
501
|
+
|
|
502
|
+
### ❌ Don't: Hardcode Configuration
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
// ❌ Wrong
|
|
506
|
+
const apiKey = 'sk-1234567890';
|
|
507
|
+
const dbUrl = 'mongodb://localhost:27017';
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
```typescript
|
|
511
|
+
// ✅ Correct
|
|
512
|
+
import dotenv from 'dotenv';
|
|
513
|
+
dotenv.config();
|
|
514
|
+
|
|
515
|
+
const apiKey = process.env.API_KEY;
|
|
516
|
+
const dbUrl = process.env.DATABASE_URL;
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
**Why**: Configuration should be environment-specific and not committed to git.
|
|
520
|
+
|
|
521
|
+
### ❌ Don't: Mix Concerns in Root Directory
|
|
522
|
+
|
|
523
|
+
```
|
|
524
|
+
# ❌ Wrong
|
|
525
|
+
my-mcp-server/
|
|
526
|
+
├── tool1.ts
|
|
527
|
+
├── tool2.ts
|
|
528
|
+
├── utils.ts
|
|
529
|
+
├── server.ts
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
```
|
|
533
|
+
# ✅ Correct
|
|
534
|
+
my-mcp-server/
|
|
535
|
+
├── src/
|
|
536
|
+
│ ├── server.ts
|
|
537
|
+
│ ├── tools/
|
|
538
|
+
│ │ ├── tool1.ts
|
|
539
|
+
│ │ └── tool2.ts
|
|
540
|
+
│ └── utils/
|
|
541
|
+
│ └── utils.ts
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
**Why**: Organized structure improves maintainability and scalability.
|
|
545
|
+
|
|
546
|
+
---
|
|
547
|
+
|
|
548
|
+
## Related Patterns
|
|
549
|
+
|
|
550
|
+
- [Server Standalone Pattern](mcp-server-starter.server-standalone.md) - Uses this bootstrap structure
|
|
551
|
+
- [Server Factory Pattern](mcp-server-starter.server-factory.md) - Builds on this foundation
|
|
552
|
+
- [Build Config Pattern](mcp-server-starter.build-config.md) - Detailed build configuration
|
|
553
|
+
- [Config Management Pattern](mcp-server-starter.config-management.md) - Environment variable handling
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
## Troubleshooting
|
|
558
|
+
|
|
559
|
+
**Problem**: `Cannot find module` errors
|
|
560
|
+
|
|
561
|
+
**Solution**: Ensure `"type": "module"` in package.json and use `.js` extensions in imports:
|
|
562
|
+
```typescript
|
|
563
|
+
import { tool } from './tools/tool.js'; // ✅ Include .js
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
**Problem**: TypeScript compilation errors
|
|
567
|
+
|
|
568
|
+
**Solution**: Check `tsconfig.json` has correct `target` and `module` settings (ES2022).
|
|
569
|
+
|
|
570
|
+
**Problem**: esbuild fails to bundle
|
|
571
|
+
|
|
572
|
+
**Solution**: Verify `esbuild.build.js` exists and has correct entry points.
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
## Checklist
|
|
577
|
+
|
|
578
|
+
- [ ] Created project directory
|
|
579
|
+
- [ ] Initialized npm (`npm init -y`)
|
|
580
|
+
- [ ] Set `"type": "module"` in package.json
|
|
581
|
+
- [ ] Installed core dependencies (@modelcontextprotocol/sdk, dotenv)
|
|
582
|
+
- [ ] Installed dev dependencies (typescript, esbuild, tsx, @types/node)
|
|
583
|
+
- [ ] Created directory structure (src/, dist/, tests/)
|
|
584
|
+
- [ ] Created tsconfig.json
|
|
585
|
+
- [ ] Created esbuild.build.js
|
|
586
|
+
- [ ] Created .env.example
|
|
587
|
+
- [ ] Created .gitignore
|
|
588
|
+
- [ ] Initialized git repository
|
|
589
|
+
- [ ] Created README.md
|
|
590
|
+
- [ ] Verified build works (`npm run build`)
|
|
591
|
+
- [ ] Verified dev mode works (`npm run dev`)
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
**Pattern**: Bootstrap
|
|
596
|
+
**Status**: Production Ready
|
|
597
|
+
**Last Updated**: 2026-02-22
|