Skip to content

Commit f6ab775

Browse files
committed
feat: initial MCP TypeScript template setup
- Add template README with comprehensive documentation - Set up package.json with MCP SDK and development dependencies - Add MIT license - Configure for TypeScript and ES modules
1 parent b1aa764 commit f6ab775

File tree

3 files changed

+293
-0
lines changed

3 files changed

+293
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
# MCP TypeScript Server Template
2+
3+
A template repository for building Model Context Protocol (MCP) servers with TypeScript.
4+
5+
## Features
6+
7+
- 🚀 Full TypeScript support with strict mode
8+
- 🧪 Testing setup with Vitest and coverage reporting
9+
- 📦 Automated releases with semantic-release
10+
- 🔄 CI/CD pipelines with GitHub Actions
11+
- 🏗️ Modular architecture for easy extension
12+
- 📝 Comprehensive documentation and examples
13+
- 🛠️ Development tools: Biome for linting/formatting, Husky for Git hooks
14+
- 🎯 Pre-configured for MCP server development
15+
16+
## Quick Start
17+
18+
### Using GitHub Template
19+
20+
1. Click "Use this template" button on GitHub
21+
2. Clone your new repository
22+
3. Install dependencies: `yarn install`
23+
4. Start development: `yarn dev`
24+
25+
### Manual Setup
26+
27+
```bash
28+
# Clone the template
29+
git clone https://github.com/Mearman/mcp-template.git my-mcp-server
30+
cd my-mcp-server
31+
32+
# Install dependencies
33+
yarn install
34+
35+
# Start development
36+
yarn dev
37+
```
38+
39+
## Project Structure
40+
41+
```
42+
src/
43+
├── index.ts # MCP server entry point
44+
├── tools/ # Tool implementations
45+
│ └── example.ts # Example tool
46+
├── utils/ # Shared utilities
47+
│ └── validation.ts # Input validation helpers
48+
└── types.ts # TypeScript type definitions
49+
```
50+
51+
## Development
52+
53+
```bash
54+
# Install dependencies
55+
yarn install
56+
57+
# Development with hot reload
58+
yarn dev
59+
60+
# Build TypeScript to JavaScript
61+
yarn build
62+
63+
# Run production build
64+
yarn start
65+
66+
# Run tests
67+
yarn test
68+
69+
# Run tests in watch mode
70+
yarn test:watch
71+
72+
# Run tests with coverage
73+
yarn test:coverage
74+
75+
# Lint and format code
76+
yarn lint
77+
yarn format
78+
```
79+
80+
## Creating Your MCP Server
81+
82+
### 1. Define Your Tools
83+
84+
Create tool implementations in `src/tools/`:
85+
86+
```typescript
87+
// src/tools/my-tool.ts
88+
import { z } from 'zod';
89+
90+
const MyToolSchema = z.object({
91+
input: z.string().describe('Tool input'),
92+
});
93+
94+
export async function myTool(args: unknown) {
95+
const { input } = MyToolSchema.parse(args);
96+
97+
// Tool implementation
98+
return {
99+
success: true,
100+
result: `Processed: ${input}`,
101+
};
102+
}
103+
```
104+
105+
### 2. Register Tools in Server
106+
107+
Update `src/index.ts` to register your tools:
108+
109+
```typescript
110+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
111+
tools: [
112+
{
113+
name: 'my_tool',
114+
description: 'Description of what my tool does',
115+
inputSchema: zodToJsonSchema(MyToolSchema),
116+
},
117+
],
118+
}));
119+
120+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
121+
switch (request.params.name) {
122+
case 'my_tool':
123+
return await myTool(request.params.arguments);
124+
default:
125+
throw new Error(`Unknown tool: ${request.params.name}`);
126+
}
127+
});
128+
```
129+
130+
### 3. Configure for Claude Desktop
131+
132+
Add to `claude_desktop_config.json`:
133+
134+
```json
135+
{
136+
"mcpServers": {
137+
"my-mcp-server": {
138+
"command": "node",
139+
"args": ["/path/to/my-mcp-server/dist/index.js"],
140+
"env": {}
141+
}
142+
}
143+
}
144+
```
145+
146+
## Testing
147+
148+
Write tests for your tools in `src/tools/*.test.ts`:
149+
150+
```typescript
151+
import { describe, it, expect } from 'vitest';
152+
import { myTool } from './my-tool';
153+
154+
describe('myTool', () => {
155+
it('should process input correctly', async () => {
156+
const result = await myTool({ input: 'test' });
157+
expect(result.success).toBe(true);
158+
expect(result.result).toBe('Processed: test');
159+
});
160+
});
161+
```
162+
163+
## Publishing
164+
165+
### NPM Package
166+
167+
1. Update `package.json` with your package details
168+
2. Build: `yarn build`
169+
3. Publish: `npm publish`
170+
171+
### Automated Releases
172+
173+
This template includes semantic-release for automated versioning and publishing:
174+
175+
1. Follow [conventional commits](https://www.conventionalcommits.org/)
176+
2. Push to main branch
177+
3. CI/CD will automatically:
178+
- Determine version bump
179+
- Update CHANGELOG.md
180+
- Create GitHub release
181+
- Publish to npm
182+
183+
## Best Practices
184+
185+
1. **Input Validation**: Always validate tool inputs using Zod schemas
186+
2. **Error Handling**: Provide clear error messages for debugging
187+
3. **Testing**: Write comprehensive tests for all tools
188+
4. **Documentation**: Document each tool's purpose and usage
189+
5. **Type Safety**: Leverage TypeScript's type system fully
190+
191+
## License
192+
193+
MIT
194+
195+
## Contributing
196+
197+
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
198+
199+
## Resources
200+
201+
- [Model Context Protocol Documentation](https://modelcontextprotocol.io)
202+
- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
203+
- [Creating MCP Servers Guide](https://modelcontextprotocol.io/tutorials/building-servers)

package.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "mcp-typescript-template",
3+
"version": "0.1.0",
4+
"description": "Template for building MCP (Model Context Protocol) servers with TypeScript",
5+
"main": "dist/index.js",
6+
"type": "module",
7+
"scripts": {
8+
"build": "tsc",
9+
"dev": "tsx watch src/index.ts",
10+
"test": "vitest run --coverage",
11+
"test:watch": "vitest --watch",
12+
"test:ci": "vitest run --coverage --reporter=json --reporter=default",
13+
"lint": "biome check .",
14+
"format": "biome format --write .",
15+
"prepare": "husky",
16+
"start": "node dist/index.js"
17+
},
18+
"keywords": [
19+
"mcp",
20+
"model-context-protocol",
21+
"typescript",
22+
"template",
23+
"mcp-server"
24+
],
25+
"author": "",
26+
"license": "MIT",
27+
"repository": {
28+
"type": "git",
29+
"url": "git+https://github.com/Mearman/mcp-typescript-template.git"
30+
},
31+
"publishConfig": {
32+
"access": "public",
33+
"registry": "https://registry.npmjs.org/"
34+
},
35+
"files": [
36+
"dist/**/*.js",
37+
"dist/**/*.d.ts",
38+
"dist/**/*.map",
39+
"!dist/**/*.test.*",
40+
"LICENSE",
41+
"README.md",
42+
"CHANGELOG.md"
43+
],
44+
"dependencies": {
45+
"@modelcontextprotocol/sdk": "^1.12.1",
46+
"zod": "^3.25.51",
47+
"zod-to-json-schema": "^3.24.1"
48+
},
49+
"devDependencies": {
50+
"@biomejs/biome": "^1.9.4",
51+
"@commitlint/cli": "^19.6.1",
52+
"@commitlint/config-conventional": "^19.6.0",
53+
"@semantic-release/changelog": "^6.0.3",
54+
"@semantic-release/git": "^10.0.1",
55+
"@semantic-release/github": "^11.0.3",
56+
"@semantic-release/npm": "^12.0.1",
57+
"@types/node": "^22.13.2",
58+
"@vitest/coverage-v8": "^2.1.8",
59+
"husky": "^9.1.7",
60+
"semantic-release": "^24.2.5",
61+
"tsx": "^4.19.2",
62+
"typescript": "^5.7.3",
63+
"vitest": "^2.1.8"
64+
},
65+
"engines": {
66+
"node": ">=18"
67+
},
68+
"packageManager": "[email protected]"
69+
}

0 commit comments

Comments
 (0)