summaryrefslogtreecommitdiff
path: root/mcp-servers/simple-mcp-server/README.md
blob: ad653584ba63540f2803353a995b879627383417 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# Simple MCP Server Claude Code Configuration ๐Ÿš€

A clean, focused Claude Code configuration for building standard MCP (Model Context Protocol) servers. Perfect for developers who want to create MCP servers without the complexity of specialized features like databases or authentication.

## โœจ Features

This configuration provides comprehensive support for:

- **MCP Protocol Implementation** - Complete server setup with tools, resources, and prompts
- **Type-Safe Development** - TypeScript with Zod validation
- **Multiple Transport Options** - stdio, HTTP+SSE, WebSocket
- **Testing & Debugging** - Integration with MCP Inspector
- **Production Ready** - Docker support, logging, error handling

## ๐Ÿ“ฆ Installation

1. Copy the configuration to your MCP server project:

```bash
cp -r simple-mcp-server/.claude your-mcp-project/
cp simple-mcp-server/CLAUDE.md your-mcp-project/

# Make hook scripts executable
chmod +x your-mcp-project/.claude/hooks/*.sh
```

2. The configuration will be automatically loaded when you start Claude Code.

## ๐Ÿค– Specialized Agents (6 total)

### Core MCP Development

| Agent | Description | Use Cases |
|-------|-------------|-----------|
| `mcp-architect` | MCP server architecture expert | Server structure, capability design, protocol patterns |
| `tool-builder` | Tool implementation specialist | Creating tools, parameter schemas, response formats |
| `resource-manager` | Resource system expert | URI schemes, content types, dynamic resources |

### Development & Operations

| Agent | Description | Use Cases |
|-------|-------------|-----------|
| `error-handler` | Error handling and debugging | Error codes, validation, troubleshooting |
| `test-writer` | Testing strategy expert | Unit tests, integration tests, MCP Inspector |
| `deployment-expert` | Deployment and packaging | Docker, npm publishing, Claude integration |

## ๐Ÿ› ๏ธ Commands (7 total)

### Setup & Initialization

```bash
/init basic         # Basic MCP server with one tool
/init standard      # Standard server with tools and resources
/init full          # Complete server with all capabilities
```

### Development Workflow

```bash
/add-tool           # Add a new tool to the server
/add-resource       # Add a new resource endpoint
/add-prompt         # Add a new prompt template
```

### Testing & Deployment

```bash
/test              # Run tests and validate protocol compliance
/debug             # Debug server issues with detailed logging
/build             # Build and prepare for deployment
/deploy            # Deploy to npm or Docker registry
```

## ๐Ÿช Automation Hooks

### Development Hook (`dev-watch.sh`)

Automatically triggered on TypeScript file changes:

- โœ… Type checking with `tsc --noEmit`
- ๐ŸŽจ Prettier formatting
- ๐Ÿ” ESLint linting
- ๐Ÿงช Test execution for changed files
- ๐Ÿ“ Update tool/resource counts

### Build Hook (`pre-build.sh`)

Runs before building:

- ๐Ÿ” Lint check
- โœ… Type validation
- ๐Ÿงช Test suite execution
- ๐Ÿ“ฆ Dependency audit
- ๐Ÿท๏ธ Version validation

### Test Hook (`test-runner.sh`)

Enhances test execution:

- ๐Ÿงช Run appropriate test suite
- ๐Ÿ“Š Coverage reporting
- ๐Ÿ” MCP protocol validation
- ๐Ÿ“ Test results summary

## โš™๏ธ Configuration Details

### Security Permissions

```json
{
  "permissions": {
    "allow": [
      "Read", "Write", "Edit", "MultiEdit",
      "Grep", "Glob", "LS",
      "Bash(npm run:*)",
      "Bash(npx @modelcontextprotocol/inspector)",
      "Bash(node dist/*.js)",
      "Bash(tsx src/*.ts)"
    ],
    "deny": [
      "Bash(rm -rf)",
      "Bash(sudo:*)",
      "Read(**/*secret*)",
      "Write(**/*secret*)"
    ]
  }
}
```

### Environment Variables

Pre-configured for MCP development:

- `NODE_ENV` - Environment mode
- `LOG_LEVEL` - Logging verbosity
- `MCP_SERVER_NAME` - Server identifier
- `MCP_SERVER_VERSION` - Server version
- `DEBUG` - Debug mode flag

## ๐Ÿš€ Usage Examples

### Creating a Basic MCP Server

```bash
# 1. Initialize the project
> /init standard

# 2. Add a custom tool
> /add-tool calculate "Performs calculations"

# 3. Add a resource
> /add-resource config "Server configuration"

# 4. Test the implementation
> /test

# 5. Build for production
> /build
```

### Quick Server Setup

```typescript
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server({
  name: 'my-server',
  version: '1.0.0',
}, {
  capabilities: {
    tools: {},
    resources: {},
  },
});

// Add your tools
server.addTool({
  name: 'hello',
  description: 'Say hello',
  inputSchema: {
    type: 'object',
    properties: {
      name: { type: 'string' },
    },
  },
  handler: async (args) => ({
    content: [{
      type: 'text',
      text: `Hello, ${args.name}!`,
    }],
  }),
});

// Connect transport
const transport = new StdioServerTransport();
await server.connect(transport);
```

### Testing with MCP Inspector

```bash
# Launch the MCP Inspector
> npx @modelcontextprotocol/inspector

# The inspector will:
# - Connect to your server
# - Display available tools/resources
# - Allow interactive testing
# - Show protocol messages
```

## ๐Ÿ“Š Technology Stack

Optimized for:

- **TypeScript** - Type-safe development
- **Node.js** - JavaScript runtime
- **@modelcontextprotocol/sdk** - Official MCP SDK
- **Zod** - Runtime validation
- **Vitest** - Fast unit testing
- **Docker** - Containerization

## ๐ŸŽฏ Key Features

### MCP Protocol Support

- Tools, Resources, and Prompts
- Multiple transport options
- Progress notifications
- Error handling with proper codes

### Developer Experience

- Type-safe with TypeScript
- Automatic validation with Zod
- Hot reload in development
- Comprehensive testing

### Production Ready

- Docker containerization
- Structured logging
- Error monitoring
- Rate limiting support

## ๐Ÿ”ง Customization

Edit `.claude/settings.json` to customize:

- Tool and resource definitions
- Environment variables
- Hook configurations
- Permission settings

## ๐Ÿ“ Best Practices

This configuration enforces:

1. **Protocol Compliance** - Strict MCP specification adherence
2. **Type Safety** - Full TypeScript with runtime validation
3. **Error Handling** - Proper error codes and messages
4. **Testing** - Comprehensive test coverage
5. **Documentation** - Clear code comments and API docs
6. **Security** - Input validation and sanitization

## ๐Ÿ› Troubleshooting

### Common Issues

**Server not starting:**

```bash
# Check TypeScript compilation
npm run typecheck

# Check for missing dependencies
npm install

# Verify Node.js version
node --version  # Should be >= 18
```

**Tools not appearing:**

```bash
# Validate tool registration
/debug

# Check MCP Inspector
npx @modelcontextprotocol/inspector
```

**Transport issues:**

```bash
# Test with stdio transport first
node dist/index.js

# For HTTP transport, check port
lsof -i :3000
```

## ๐ŸŒŸ Example Projects

### Weather Tool Server

```typescript
server.addTool({
  name: 'get_weather',
  description: 'Get weather for a location',
  inputSchema: {
    type: 'object',
    properties: {
      location: { type: 'string' },
    },
    required: ['location'],
  },
  handler: async ({ location }) => {
    const weather = await fetchWeather(location);
    return {
      content: [{
        type: 'text',
        text: `Weather in ${location}: ${weather}`,
      }],
    };
  },
});
```

### File System Resource Server

```typescript
server.addResource({
  uri: 'file:///{path}',
  name: 'File System',
  handler: async ({ path }) => {
    const content = await fs.readFile(path, 'utf-8');
    return {
      contents: [{
        uri: `file:///${path}`,
        mimeType: 'text/plain',
        text: content,
      }],
    };
  },
});
```

## ๐Ÿ“š Resources

- [MCP Specification](https://spec.modelcontextprotocol.io)
- [MCP SDK Documentation](https://github.com/modelcontextprotocol/typescript-sdk)
- [MCP Inspector](https://github.com/modelcontextprotocol/inspector)
- [Example MCP Servers](https://github.com/modelcontextprotocol/servers)
- [Claude Code MCP Guide](https://docs.anthropic.com/claude-code/mcp)

## ๐ŸŽ‰ Quick Start

```bash
# 1. Create a new MCP server project
mkdir my-mcp-server && cd my-mcp-server
npm init -y

# 2. Install dependencies
npm install @modelcontextprotocol/sdk zod
npm install -D typescript tsx @types/node vitest

# 3. Copy this configuration
cp -r path/to/simple-mcp-server/.claude .
cp path/to/simple-mcp-server/CLAUDE.md .

# 4. Initialize TypeScript
npx tsc --init

# 5. Create your server
touch src/index.ts

# 6. Start development
npm run dev
```

## ๐ŸŽฏ What Makes This Configuration Special

### Focused on Fundamentals

- **No complexity** - Just pure MCP server development
- **No dependencies** - No databases, no authentication, no external services
- **Clean architecture** - Clear separation of concerns
- **Best practices** - Industry-standard patterns and conventions

### Perfect For

- Building your first MCP server
- Creating utility servers for Claude Code
- Learning MCP protocol implementation
- Prototyping new MCP capabilities
- Building production-ready MCP servers

---

**Built for clean, simple MCP server development** ๐Ÿš€

*Create robust MCP servers with best practices and minimal complexity.*

**Configuration Version:** 1.0.0 | **Compatible with:** @modelcontextprotocol/sdk >=1.0.0