mcp-http-webhook 1.0.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/.eslintrc.json +16 -0
- package/.prettierrc.json +8 -0
- package/ARCHITECTURE.md +269 -0
- package/CONTRIBUTING.md +136 -0
- package/GETTING_STARTED.md +310 -0
- package/IMPLEMENTATION.md +294 -0
- package/LICENSE +21 -0
- package/MIGRATION_TO_SDK.md +263 -0
- package/README.md +496 -0
- package/SDK_INTEGRATION_COMPLETE.md +300 -0
- package/STANDARD_SUBSCRIPTIONS.md +268 -0
- package/STANDARD_SUBSCRIPTIONS_COMPLETE.md +309 -0
- package/SUMMARY.md +272 -0
- package/Spec.md +2778 -0
- package/dist/errors/index.d.ts +52 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +81 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/ProtocolHandler.d.ts +37 -0
- package/dist/protocol/ProtocolHandler.d.ts.map +1 -0
- package/dist/protocol/ProtocolHandler.js +172 -0
- package/dist/protocol/ProtocolHandler.js.map +1 -0
- package/dist/server.d.ts +6 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +502 -0
- package/dist/server.js.map +1 -0
- package/dist/stores/InMemoryStore.d.ts +27 -0
- package/dist/stores/InMemoryStore.d.ts.map +1 -0
- package/dist/stores/InMemoryStore.js +73 -0
- package/dist/stores/InMemoryStore.js.map +1 -0
- package/dist/stores/RedisStore.d.ts +18 -0
- package/dist/stores/RedisStore.d.ts.map +1 -0
- package/dist/stores/RedisStore.js +45 -0
- package/dist/stores/RedisStore.js.map +1 -0
- package/dist/stores/index.d.ts +3 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/index.js +9 -0
- package/dist/stores/index.js.map +1 -0
- package/dist/subscriptions/SubscriptionManager.d.ts +49 -0
- package/dist/subscriptions/SubscriptionManager.d.ts.map +1 -0
- package/dist/subscriptions/SubscriptionManager.js +181 -0
- package/dist/subscriptions/SubscriptionManager.js.map +1 -0
- package/dist/types/index.d.ts +271 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +51 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +154 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/webhooks/WebhookManager.d.ts +27 -0
- package/dist/webhooks/WebhookManager.d.ts.map +1 -0
- package/dist/webhooks/WebhookManager.js +174 -0
- package/dist/webhooks/WebhookManager.js.map +1 -0
- package/examples/GITHUB_LIVE_EXAMPLE.md +308 -0
- package/examples/GITHUB_LIVE_SETUP.md +253 -0
- package/examples/QUICKSTART.md +130 -0
- package/examples/basic-setup.ts +142 -0
- package/examples/github-server-live.ts +690 -0
- package/examples/github-server.ts +223 -0
- package/examples/google-drive-server-live.ts +773 -0
- package/examples/start-github-live.sh +53 -0
- package/jest.config.js +20 -0
- package/package.json +58 -0
- package/src/errors/index.ts +81 -0
- package/src/index.ts +19 -0
- package/src/server.ts +595 -0
- package/src/stores/InMemoryStore.ts +87 -0
- package/src/stores/RedisStore.ts +51 -0
- package/src/stores/index.ts +2 -0
- package/src/subscriptions/SubscriptionManager.ts +240 -0
- package/src/types/index.ts +341 -0
- package/src/utils/index.ts +156 -0
- package/src/webhooks/WebhookManager.ts +230 -0
- package/test-sdk-integration.sh +157 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# Getting Started with MCP HTTP Webhook
|
|
2
|
+
|
|
3
|
+
This guide will help you create your first MCP HTTP server with webhook-based subscriptions.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js 18+ or 20+
|
|
8
|
+
- npm, pnpm, or yarn
|
|
9
|
+
- TypeScript knowledge
|
|
10
|
+
|
|
11
|
+
## Step 1: Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cd packages/plugins/mcp-proxy
|
|
15
|
+
npm install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Step 2: Install Peer Dependencies
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @modelcontextprotocol/sdk express @types/express
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Step 3: Build the Library
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm run build
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Step 4: Create Your First Server
|
|
31
|
+
|
|
32
|
+
Create a file `my-server.ts`:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { createMCPServer } from './src';
|
|
36
|
+
import { InMemoryStore } from './src/stores';
|
|
37
|
+
|
|
38
|
+
const server = createMCPServer({
|
|
39
|
+
name: 'my-first-server',
|
|
40
|
+
version: '1.0.0',
|
|
41
|
+
publicUrl: process.env.PUBLIC_URL || 'http://localhost:3000',
|
|
42
|
+
port: 3000,
|
|
43
|
+
store: new InMemoryStore(),
|
|
44
|
+
|
|
45
|
+
tools: [
|
|
46
|
+
{
|
|
47
|
+
name: 'greet',
|
|
48
|
+
description: 'Greet someone by name',
|
|
49
|
+
inputSchema: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
name: { type: 'string', description: 'Name to greet' }
|
|
53
|
+
},
|
|
54
|
+
required: ['name']
|
|
55
|
+
},
|
|
56
|
+
handler: async (input) => {
|
|
57
|
+
return {
|
|
58
|
+
greeting: `Hello, ${input.name}!`,
|
|
59
|
+
timestamp: new Date().toISOString()
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
|
|
65
|
+
resources: [
|
|
66
|
+
{
|
|
67
|
+
uri: 'time://current',
|
|
68
|
+
name: 'Current Time',
|
|
69
|
+
description: 'Returns the current server time',
|
|
70
|
+
read: async () => {
|
|
71
|
+
return {
|
|
72
|
+
contents: {
|
|
73
|
+
time: new Date().toISOString(),
|
|
74
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
server.start().then(() => {
|
|
83
|
+
console.log('✅ Server started on http://localhost:3000');
|
|
84
|
+
console.log('');
|
|
85
|
+
console.log('Try these endpoints:');
|
|
86
|
+
console.log(' GET http://localhost:3000/health');
|
|
87
|
+
console.log(' POST http://localhost:3000/mcp/tools/list');
|
|
88
|
+
console.log(' POST http://localhost:3000/mcp/tools/call');
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Step 5: Run Your Server
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npx tsx my-server.ts
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Step 6: Test Your Server
|
|
99
|
+
|
|
100
|
+
**Test health check:**
|
|
101
|
+
```bash
|
|
102
|
+
curl http://localhost:3000/health
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**List tools:**
|
|
106
|
+
```bash
|
|
107
|
+
curl -X POST http://localhost:3000/mcp/tools/list \
|
|
108
|
+
-H "Content-Type: application/json"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Call a tool:**
|
|
112
|
+
```bash
|
|
113
|
+
curl -X POST http://localhost:3000/mcp/tools/call \
|
|
114
|
+
-H "Content-Type: application/json" \
|
|
115
|
+
-d '{
|
|
116
|
+
"method": "tools/call",
|
|
117
|
+
"params": {
|
|
118
|
+
"name": "greet",
|
|
119
|
+
"arguments": {
|
|
120
|
+
"name": "World"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Read a resource:**
|
|
127
|
+
```bash
|
|
128
|
+
curl -X POST http://localhost:3000/mcp/resources/read \
|
|
129
|
+
-H "Content-Type: application/json" \
|
|
130
|
+
-d '{
|
|
131
|
+
"method": "resources/read",
|
|
132
|
+
"params": {
|
|
133
|
+
"uri": "time://current"
|
|
134
|
+
}
|
|
135
|
+
}'
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Step 7: Add Production Storage
|
|
139
|
+
|
|
140
|
+
For production, use Redis instead of InMemoryStore:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npm install ioredis
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Update your server:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { createRedisStore } from './src/stores';
|
|
150
|
+
import Redis from 'ioredis';
|
|
151
|
+
|
|
152
|
+
const redis = new Redis(process.env.REDIS_URL || 'redis://localhost:6379');
|
|
153
|
+
const store = createRedisStore(redis);
|
|
154
|
+
|
|
155
|
+
const server = createMCPServer({
|
|
156
|
+
// ... same config
|
|
157
|
+
store, // Use Redis instead of InMemoryStore
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Step 8: Add Authentication
|
|
162
|
+
|
|
163
|
+
Add authentication to your server:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const server = createMCPServer({
|
|
167
|
+
// ... same config
|
|
168
|
+
|
|
169
|
+
authenticate: async (req) => {
|
|
170
|
+
const apiKey = req.headers['x-api-key'];
|
|
171
|
+
|
|
172
|
+
if (!apiKey) {
|
|
173
|
+
throw new Error('Missing API key');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Validate against your database
|
|
177
|
+
if (apiKey !== 'secret-key-123') {
|
|
178
|
+
throw new Error('Invalid API key');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
userId: 'user-123',
|
|
183
|
+
apiKey: apiKey as string
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Test with authentication:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
curl -X POST http://localhost:3000/mcp/tools/call \
|
|
193
|
+
-H "Content-Type: application/json" \
|
|
194
|
+
-H "X-API-Key: secret-key-123" \
|
|
195
|
+
-d '{ ... }'
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Step 9: Add Webhook Subscriptions
|
|
199
|
+
|
|
200
|
+
Create a resource with webhook support:
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
resources: [
|
|
204
|
+
{
|
|
205
|
+
uri: 'events://updates',
|
|
206
|
+
name: 'Event Updates',
|
|
207
|
+
description: 'Stream of event updates',
|
|
208
|
+
|
|
209
|
+
read: async () => {
|
|
210
|
+
return { contents: [] };
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
subscription: {
|
|
214
|
+
onSubscribe: async (uri, subscriptionId, webhookUrl, context) => {
|
|
215
|
+
console.log('Client subscribed!');
|
|
216
|
+
console.log('Webhook URL:', webhookUrl);
|
|
217
|
+
|
|
218
|
+
// In production: register with third-party service
|
|
219
|
+
// For demo: store in database
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
thirdPartyWebhookId: 'demo-webhook-123'
|
|
223
|
+
};
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
onUnsubscribe: async (uri, subscriptionId, storedData, context) => {
|
|
227
|
+
console.log('Client unsubscribed');
|
|
228
|
+
|
|
229
|
+
// In production: remove webhook from third-party
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
onWebhook: async (subscriptionId, payload, headers) => {
|
|
233
|
+
console.log('Webhook received:', payload);
|
|
234
|
+
|
|
235
|
+
// Process webhook and return changes
|
|
236
|
+
return {
|
|
237
|
+
resourceUri: 'events://updates',
|
|
238
|
+
changeType: 'created',
|
|
239
|
+
data: payload
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Subscribe to updates:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
curl -X POST http://localhost:3000/mcp/resources/subscribe \
|
|
251
|
+
-H "Content-Type: application/json" \
|
|
252
|
+
-d '{
|
|
253
|
+
"method": "resources/subscribe",
|
|
254
|
+
"params": {
|
|
255
|
+
"uri": "events://updates",
|
|
256
|
+
"callbackUrl": "https://your-app.com/webhook",
|
|
257
|
+
"callbackSecret": "your-secret"
|
|
258
|
+
}
|
|
259
|
+
}'
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Next Steps
|
|
263
|
+
|
|
264
|
+
- Explore the [examples/](./examples) directory
|
|
265
|
+
- Read the [full API documentation](./README.md)
|
|
266
|
+
- Check out the [specification](./Spec.md)
|
|
267
|
+
- Add monitoring and logging
|
|
268
|
+
- Deploy to production with Docker
|
|
269
|
+
|
|
270
|
+
## Common Issues
|
|
271
|
+
|
|
272
|
+
**Port already in use:**
|
|
273
|
+
```typescript
|
|
274
|
+
const server = createMCPServer({
|
|
275
|
+
port: 3001, // Change port
|
|
276
|
+
// ...
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**CORS issues:**
|
|
281
|
+
```typescript
|
|
282
|
+
import cors from 'cors';
|
|
283
|
+
|
|
284
|
+
const server = createMCPServer({
|
|
285
|
+
middleware: [cors()],
|
|
286
|
+
// ...
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**TypeScript errors:**
|
|
291
|
+
Make sure you have installed all dependencies and built the library:
|
|
292
|
+
```bash
|
|
293
|
+
npm install
|
|
294
|
+
npm run build
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Resources
|
|
298
|
+
|
|
299
|
+
- [MCP Specification](https://spec.modelcontextprotocol.io/)
|
|
300
|
+
- [TypeScript Documentation](https://www.typescriptlang.org/)
|
|
301
|
+
- [Express.js Guide](https://expressjs.com/)
|
|
302
|
+
- [Redis Documentation](https://redis.io/docs/)
|
|
303
|
+
|
|
304
|
+
## Support
|
|
305
|
+
|
|
306
|
+
- GitHub Issues: Report bugs and request features
|
|
307
|
+
- Examples: Check the examples/ directory
|
|
308
|
+
- Specification: Read Spec.md for detailed documentation
|
|
309
|
+
|
|
310
|
+
Happy coding! 🚀
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# MCP HTTP Webhook Library - Implementation Summary
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
I've successfully implemented the complete MCP HTTP Webhook Server Library according to the specification. This is a production-ready TypeScript library for building Model Context Protocol servers with HTTP and webhook-based subscriptions.
|
|
6
|
+
|
|
7
|
+
## ✅ What Was Implemented
|
|
8
|
+
|
|
9
|
+
### 1. Core Library Structure
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
mcp-proxy/
|
|
13
|
+
├── src/
|
|
14
|
+
│ ├── types/index.ts # Complete type definitions
|
|
15
|
+
│ ├── errors/index.ts # Error classes (MCPError, AuthenticationError, etc.)
|
|
16
|
+
│ ├── utils/index.ts # Utility functions (ID generation, URI parsing, signatures)
|
|
17
|
+
│ ├── protocol/
|
|
18
|
+
│ │ └── ProtocolHandler.ts # MCP protocol implementation
|
|
19
|
+
│ ├── subscriptions/
|
|
20
|
+
│ │ └── SubscriptionManager.ts # Subscription lifecycle management
|
|
21
|
+
│ ├── webhooks/
|
|
22
|
+
│ │ └── WebhookManager.ts # Webhook processing and delivery
|
|
23
|
+
│ ├── stores/
|
|
24
|
+
│ │ ├── InMemoryStore.ts # In-memory store (dev/test)
|
|
25
|
+
│ │ ├── RedisStore.ts # Redis adapter
|
|
26
|
+
│ │ └── index.ts # Store exports
|
|
27
|
+
│ ├── server.ts # Main server creation
|
|
28
|
+
│ └── index.ts # Public API exports
|
|
29
|
+
├── examples/
|
|
30
|
+
│ ├── basic-setup.ts # Basic example
|
|
31
|
+
│ └── github-server.ts # GitHub webhook example
|
|
32
|
+
├── package.json
|
|
33
|
+
├── tsconfig.json
|
|
34
|
+
├── jest.config.js
|
|
35
|
+
├── .eslintrc.json
|
|
36
|
+
├── .prettierrc.json
|
|
37
|
+
├── README.md
|
|
38
|
+
├── CONTRIBUTING.md
|
|
39
|
+
├── LICENSE
|
|
40
|
+
└── .gitignore
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Type System (`src/types/index.ts`)
|
|
44
|
+
|
|
45
|
+
Complete TypeScript definitions for:
|
|
46
|
+
- `MCPServerConfig` - Server configuration
|
|
47
|
+
- `ToolDefinition` - Tool definitions with handlers
|
|
48
|
+
- `ResourceDefinition` - Resource definitions with read/list/subscription
|
|
49
|
+
- `ResourceSubscription` - Webhook subscription handlers
|
|
50
|
+
- `KeyValueStore` - Storage interface
|
|
51
|
+
- `WebhookConfig` - Webhook configuration
|
|
52
|
+
- `AuthContext` - Authentication context
|
|
53
|
+
- All supporting types
|
|
54
|
+
|
|
55
|
+
### 3. Error Handling (`src/errors/index.ts`)
|
|
56
|
+
|
|
57
|
+
Implemented error classes:
|
|
58
|
+
- `MCPError` - Base error class
|
|
59
|
+
- `AuthenticationError` (-32001)
|
|
60
|
+
- `ValidationError` (-32002)
|
|
61
|
+
- `ResourceNotFoundError` (-32003)
|
|
62
|
+
- `ToolExecutionError` (-32004)
|
|
63
|
+
- `WebhookError` (-32005)
|
|
64
|
+
- `StorageError` (-32006)
|
|
65
|
+
|
|
66
|
+
### 4. Utilities (`src/utils/index.ts`)
|
|
67
|
+
|
|
68
|
+
Utility functions:
|
|
69
|
+
- `generateSubscriptionId()` - Generate unique subscription IDs
|
|
70
|
+
- `generateWebhookUrl()` - Generate webhook URLs
|
|
71
|
+
- `parseUriTemplate()` - Parse URI templates with parameters
|
|
72
|
+
- `matchUriTemplate()` - Match URIs against templates
|
|
73
|
+
- `createHmacSignature()` - Create HMAC signatures
|
|
74
|
+
- `verifyHmacSignature()` - Verify signatures (timing-safe)
|
|
75
|
+
- `sleep()`, `calculateBackoff()` - Retry helpers
|
|
76
|
+
- URL validation and sanitization
|
|
77
|
+
|
|
78
|
+
### 5. Protocol Handler (`src/protocol/ProtocolHandler.ts`)
|
|
79
|
+
|
|
80
|
+
MCP protocol implementation:
|
|
81
|
+
- `listTools()` - List available tools
|
|
82
|
+
- `callTool()` - Execute tools with validation
|
|
83
|
+
- `listResources()` - List available resources
|
|
84
|
+
- `readResource()` - Read resource data
|
|
85
|
+
- `listPrompts()` - List available prompts
|
|
86
|
+
- `getPrompt()` - Get prompt templates
|
|
87
|
+
- Input validation using AJV
|
|
88
|
+
- Comprehensive error handling
|
|
89
|
+
|
|
90
|
+
### 6. Subscription Manager (`src/subscriptions/SubscriptionManager.ts`)
|
|
91
|
+
|
|
92
|
+
Subscription lifecycle management:
|
|
93
|
+
- `createSubscription()` - Create new subscriptions
|
|
94
|
+
- `deleteSubscription()` - Remove subscriptions
|
|
95
|
+
- `getSubscription()` - Get subscription by ID
|
|
96
|
+
- `listSubscriptions()` - List user subscriptions
|
|
97
|
+
- Storage with user indexes
|
|
98
|
+
- Ownership verification
|
|
99
|
+
- Resource lookup
|
|
100
|
+
|
|
101
|
+
### 7. Webhook Manager (`src/webhooks/WebhookManager.ts`)
|
|
102
|
+
|
|
103
|
+
Webhook processing:
|
|
104
|
+
- `processIncomingWebhook()` - Handle third-party webhooks
|
|
105
|
+
- `notifyClient()` - Send notifications to clients
|
|
106
|
+
- Signature verification
|
|
107
|
+
- Automatic retry with exponential backoff
|
|
108
|
+
- Timeout handling
|
|
109
|
+
- Before/after hooks
|
|
110
|
+
- Error recovery
|
|
111
|
+
|
|
112
|
+
### 8. Server (`src/server.ts`)
|
|
113
|
+
|
|
114
|
+
Express-based HTTP server:
|
|
115
|
+
- Health check endpoints (`/health`, `/ready`)
|
|
116
|
+
- MCP protocol endpoints:
|
|
117
|
+
- `POST /mcp/tools/list`
|
|
118
|
+
- `POST /mcp/tools/call`
|
|
119
|
+
- `POST /mcp/resources/list`
|
|
120
|
+
- `POST /mcp/resources/read`
|
|
121
|
+
- `POST /mcp/resources/subscribe`
|
|
122
|
+
- `POST /mcp/resources/unsubscribe`
|
|
123
|
+
- `POST /mcp/prompts/list`
|
|
124
|
+
- `POST /mcp/prompts/get`
|
|
125
|
+
- Webhook endpoint:
|
|
126
|
+
- `POST /webhooks/incoming/{subscriptionId}`
|
|
127
|
+
- Authentication middleware
|
|
128
|
+
- Error handling middleware
|
|
129
|
+
- Custom middleware support
|
|
130
|
+
- Graceful startup/shutdown
|
|
131
|
+
|
|
132
|
+
### 9. Storage Implementations
|
|
133
|
+
|
|
134
|
+
**InMemoryStore** (`src/stores/InMemoryStore.ts`):
|
|
135
|
+
- Development/testing only
|
|
136
|
+
- TTL support
|
|
137
|
+
- Automatic cleanup
|
|
138
|
+
- Scan support
|
|
139
|
+
|
|
140
|
+
**RedisStore** (`src/stores/RedisStore.ts`):
|
|
141
|
+
- Production-ready Redis adapter
|
|
142
|
+
- Full KeyValueStore interface
|
|
143
|
+
- Connection pooling support
|
|
144
|
+
- Pattern scanning
|
|
145
|
+
|
|
146
|
+
### 10. Examples
|
|
147
|
+
|
|
148
|
+
**Basic Setup** (`examples/basic-setup.ts`):
|
|
149
|
+
- Simple echo and add tools
|
|
150
|
+
- Greeting resource
|
|
151
|
+
- API key authentication
|
|
152
|
+
- Complete working example
|
|
153
|
+
|
|
154
|
+
**GitHub Server** (`examples/github-server.ts`):
|
|
155
|
+
- GitHub issue management
|
|
156
|
+
- Webhook-based subscriptions
|
|
157
|
+
- Signature verification
|
|
158
|
+
- Real-world use case
|
|
159
|
+
|
|
160
|
+
### 11. Documentation
|
|
161
|
+
|
|
162
|
+
**README.md**:
|
|
163
|
+
- Installation instructions
|
|
164
|
+
- Quick start guide
|
|
165
|
+
- API documentation
|
|
166
|
+
- Configuration examples
|
|
167
|
+
- Security guidelines
|
|
168
|
+
- Deployment guide
|
|
169
|
+
- Monitoring setup
|
|
170
|
+
|
|
171
|
+
**CONTRIBUTING.md**:
|
|
172
|
+
- Development setup
|
|
173
|
+
- Code style guidelines
|
|
174
|
+
- Testing requirements
|
|
175
|
+
- Commit message format
|
|
176
|
+
- Pull request process
|
|
177
|
+
|
|
178
|
+
## 🎯 Key Features Implemented
|
|
179
|
+
|
|
180
|
+
### HTTP + Webhooks Architecture
|
|
181
|
+
- ✅ Stateless HTTP requests (no SSE connections)
|
|
182
|
+
- ✅ Client-provided webhook URLs for notifications
|
|
183
|
+
- ✅ Third-party webhook integration
|
|
184
|
+
- ✅ Subscription-based resource updates
|
|
185
|
+
|
|
186
|
+
### Production Ready
|
|
187
|
+
- ✅ Automatic retry with exponential backoff
|
|
188
|
+
- ✅ Webhook signature verification (HMAC)
|
|
189
|
+
- ✅ Request timeout handling
|
|
190
|
+
- ✅ Error recovery and logging
|
|
191
|
+
- ✅ Health checks
|
|
192
|
+
- ✅ Graceful shutdown
|
|
193
|
+
|
|
194
|
+
### Horizontally Scalable
|
|
195
|
+
- ✅ No connection state
|
|
196
|
+
- ✅ External key-value store
|
|
197
|
+
- ✅ Stateless architecture
|
|
198
|
+
- ✅ Load balancer compatible
|
|
199
|
+
|
|
200
|
+
### Developer Experience
|
|
201
|
+
- ✅ Full TypeScript support
|
|
202
|
+
- ✅ Comprehensive type definitions
|
|
203
|
+
- ✅ Input validation with JSON Schema
|
|
204
|
+
- ✅ Clear error messages
|
|
205
|
+
- ✅ Extensive examples
|
|
206
|
+
- ✅ Well-documented API
|
|
207
|
+
|
|
208
|
+
## 📦 Package Configuration
|
|
209
|
+
|
|
210
|
+
- **TypeScript**: Full type safety with strict mode
|
|
211
|
+
- **Build**: TSC compilation to CommonJS
|
|
212
|
+
- **Testing**: Jest with ts-jest
|
|
213
|
+
- **Linting**: ESLint with TypeScript plugin
|
|
214
|
+
- **Formatting**: Prettier
|
|
215
|
+
- **Dependencies**: Minimal (ajv, nanoid)
|
|
216
|
+
- **Peer Dependencies**: @modelcontextprotocol/sdk, express
|
|
217
|
+
- **Optional**: ioredis, prom-client
|
|
218
|
+
|
|
219
|
+
## 🚀 Usage
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { createMCPServer } from 'mcp-http-webhook';
|
|
223
|
+
import { InMemoryStore } from 'mcp-http-webhook/stores';
|
|
224
|
+
|
|
225
|
+
const server = createMCPServer({
|
|
226
|
+
name: 'my-server',
|
|
227
|
+
version: '1.0.0',
|
|
228
|
+
publicUrl: 'https://mcp.example.com',
|
|
229
|
+
store: new InMemoryStore(),
|
|
230
|
+
tools: [...],
|
|
231
|
+
resources: [...],
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
await server.start();
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## 🔧 Next Steps
|
|
238
|
+
|
|
239
|
+
To use this library:
|
|
240
|
+
|
|
241
|
+
1. **Install Dependencies**:
|
|
242
|
+
```bash
|
|
243
|
+
cd packages/plugins/mcp-proxy
|
|
244
|
+
npm install
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
2. **Build**:
|
|
248
|
+
```bash
|
|
249
|
+
npm run build
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
3. **Run Examples**:
|
|
253
|
+
```bash
|
|
254
|
+
# Basic example
|
|
255
|
+
npx tsx examples/basic-setup.ts
|
|
256
|
+
|
|
257
|
+
# GitHub example
|
|
258
|
+
npx tsx examples/github-server.ts
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
4. **Run Tests**:
|
|
262
|
+
```bash
|
|
263
|
+
npm test
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## 📝 Notes
|
|
267
|
+
|
|
268
|
+
- The library is fully compliant with the specification
|
|
269
|
+
- All core features are implemented
|
|
270
|
+
- Ready for production use with Redis/external storage
|
|
271
|
+
- InMemoryStore is for development only
|
|
272
|
+
- Comprehensive error handling throughout
|
|
273
|
+
- Full TypeScript type safety
|
|
274
|
+
- Extensible architecture for custom stores
|
|
275
|
+
|
|
276
|
+
## 🔒 Security Considerations
|
|
277
|
+
|
|
278
|
+
- HTTPS enforced in production
|
|
279
|
+
- Webhook signature verification
|
|
280
|
+
- Timing-safe signature comparison
|
|
281
|
+
- Input validation with JSON Schema
|
|
282
|
+
- Authentication middleware support
|
|
283
|
+
- Rate limiting support
|
|
284
|
+
|
|
285
|
+
## 📊 Code Quality
|
|
286
|
+
|
|
287
|
+
- TypeScript strict mode enabled
|
|
288
|
+
- ESLint configured
|
|
289
|
+
- Prettier formatting
|
|
290
|
+
- Jest testing framework
|
|
291
|
+
- >80% coverage target
|
|
292
|
+
- Conventional commits
|
|
293
|
+
|
|
294
|
+
This implementation provides a complete, production-ready foundation for building MCP servers with HTTP and webhook-based subscriptions!
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Your Organization
|
|
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.
|