@@ -15,6 +15,9 @@ A template repository for building Model Context Protocol (MCP) servers with Typ
15
15
- 📝 Comprehensive documentation and examples
16
16
- 🛠️ Development tools: Biome for linting/formatting, Husky for Git hooks
17
17
- 🎯 Pre-configured for MCP server development
18
+ - 🔐 Built-in validation using Zod schemas
19
+ - ⚡ ES modules with native Node.js support
20
+ - 📊 Code coverage reporting with c8
18
21
19
22
## MCP Servers Built with This Template
20
23
@@ -67,14 +70,26 @@ yarn dev
67
70
src/
68
71
├── index.ts # MCP server entry point
69
72
├── tools/ # Tool implementations
70
- │ └── example.ts # Example tool
73
+ │ ├── example.ts # Example tool
74
+ │ └── *.test.ts # Tool tests
71
75
├── utils/ # Shared utilities
72
- │ └── validation.ts # Input validation helpers
76
+ │ ├── validation.ts # Input validation helpers
77
+ │ └── *.test.ts # Utility tests
73
78
└── types.ts # TypeScript type definitions
79
+
80
+ # Configuration files
81
+ ├── .github/workflows/ # CI/CD pipelines
82
+ ├── .husky/ # Git hooks
83
+ ├── biome.json # Linter/formatter config
84
+ ├── tsconfig.json # TypeScript config
85
+ ├── vitest.config.ts # Test runner config
86
+ └── .releaserc.json # Semantic release config
74
87
```
75
88
76
89
## Development
77
90
91
+ ### Available Commands
92
+
78
93
``` bash
79
94
# Install dependencies
80
95
yarn install
@@ -94,14 +109,26 @@ yarn test
94
109
# Run tests in watch mode
95
110
yarn test:watch
96
111
97
- # Run tests with coverage
98
- yarn test:coverage
112
+ # Run tests with coverage report
113
+ yarn test:ci
99
114
100
- # Lint and format code
115
+ # Lint code
101
116
yarn lint
117
+
118
+ # Auto-fix linting issues
119
+ yarn lint:fix
120
+
121
+ # Format code
102
122
yarn format
103
123
```
104
124
125
+ ### Development Workflow
126
+
127
+ 1 . ** Start development** : ` yarn dev ` - Runs the server with hot reload
128
+ 2 . ** Write tests** : Add ` .test.ts ` files alongside your code
129
+ 3 . ** Run tests** : ` yarn test:watch ` - Keep tests running while you code
130
+ 4 . ** Lint/format** : Automatic on commit via Husky hooks
131
+
105
132
## Creating Your MCP Server
106
133
107
134
### 1. Define Your Tools
@@ -189,9 +216,27 @@ describe('myTool', () => {
189
216
190
217
### NPM Package
191
218
192
- 1 . Update ` package.json ` with your package details
193
- 2 . Build: ` yarn build `
194
- 3 . Publish: ` npm publish `
219
+ 1 . Update ` package.json ` with your package details:
220
+ - ` name ` : Your package name (e.g., ` mcp-your-server ` )
221
+ - ` description ` : Clear description of what your server does
222
+ - ` keywords ` : Add relevant keywords for discoverability
223
+ - ` author ` : Your name or organization
224
+ - ` repository ` : Your GitHub repository URL
225
+
226
+ 2 . Build the project:
227
+ ``` bash
228
+ yarn build
229
+ ```
230
+
231
+ 3 . Test the build locally:
232
+ ``` bash
233
+ yarn start
234
+ ```
235
+
236
+ 4 . Publish to npm:
237
+ ``` bash
238
+ npm publish
239
+ ```
195
240
196
241
### Automated Releases
197
242
@@ -214,6 +259,61 @@ This template includes semantic-release for automated versioning and publishing:
214
259
3 . ** Testing** : Write comprehensive tests for all tools
215
260
4 . ** Documentation** : Document each tool's purpose and usage
216
261
5 . ** Type Safety** : Leverage TypeScript's type system fully
262
+ 6 . ** Modular Design** : Keep tools focused on single responsibilities
263
+ 7 . ** Async/Await** : Use modern async patterns for all I/O operations
264
+ 8 . ** Environment Variables** : Use ` .env ` files for configuration (never commit secrets)
265
+
266
+ ## Adding CLI Support
267
+
268
+ To add CLI functionality to your MCP server (like the Wayback Machine example):
269
+
270
+ 1 . Install Commander.js:
271
+ ``` bash
272
+ yarn add commander chalk ora
273
+ ```
274
+
275
+ 2 . Create ` src/cli.ts ` :
276
+ ``` typescript
277
+ import { Command } from ' commander' ;
278
+ import chalk from ' chalk' ;
279
+
280
+ export function createCLI() {
281
+ const program = new Command ();
282
+
283
+ program
284
+ .name (' your-tool' )
285
+ .description (' Your MCP server as a CLI' )
286
+ .version (' 1.0.0' );
287
+
288
+ // Add commands here
289
+
290
+ return program ;
291
+ }
292
+ ```
293
+
294
+ 3 . Update ` src/index.ts ` to detect CLI mode:
295
+ ``` typescript
296
+ async function main() {
297
+ const isCliMode = process .stdin .isTTY || process .argv .length > 2 ;
298
+
299
+ if (isCliMode && process .argv .length > 2 ) {
300
+ const { createCLI } = await import (' ./cli.js' );
301
+ const program = createCLI ();
302
+ await program .parseAsync (process .argv );
303
+ } else {
304
+ // MCP server mode
305
+ const transport = new StdioServerTransport ();
306
+ await server .connect (transport );
307
+ }
308
+ }
309
+ ```
310
+
311
+ 4 . Add bin entry to ` package.json ` :
312
+ ``` json
313
+ "bin" : {
314
+ "your-tool" : " dist/index.js"
315
+ }
316
+ ```
217
317
218
318
## License
219
319
@@ -225,8 +325,27 @@ This work is licensed under a [Creative Commons Attribution-NonCommercial-ShareA
225
325
226
326
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
227
327
328
+ ## Troubleshooting
329
+
330
+ ### Common Issues
331
+
332
+ 1 . ** Build errors** : Ensure all dependencies are installed with ` yarn install `
333
+ 2 . ** Type errors** : Run ` npx tsc --noEmit ` to check TypeScript types
334
+ 3 . ** Test failures** : Check test files are named ` *.test.ts `
335
+ 4 . ** Claude Desktop connection** : Verify the path in your config is absolute
336
+
337
+ ### Debug Mode
338
+
339
+ To see detailed logs when running as an MCP server:
340
+
341
+ ``` bash
342
+ DEBUG=* node dist/index.js
343
+ ```
344
+
228
345
## Resources
229
346
230
347
- [ Model Context Protocol Documentation] ( https://modelcontextprotocol.io )
231
348
- [ MCP TypeScript SDK] ( https://github.com/modelcontextprotocol/typescript-sdk )
232
- - [ Creating MCP Servers Guide] ( https://modelcontextprotocol.io/tutorials/building-servers )
349
+ - [ Creating MCP Servers Guide] ( https://modelcontextprotocol.io/tutorials/building-servers )
350
+ - [ Awesome MCP Servers] ( https://github.com/modelcontextprotocol/awesome-mcp ) - Community-curated list
351
+ - [ MCP Discord] ( https://discord.gg/mcp ) - Get help and share your servers
0 commit comments