mcp-http-webhook 1.0.28 → 1.0.30
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/dist/server.d.ts.map +1 -1
- package/dist/server.js +15 -1
- package/dist/server.js.map +1 -1
- package/package.json +1 -5
- package/src/server.ts +16 -1
- package/ARCHITECTURE.md +0 -269
- package/BLOG_POST.md +0 -738
- package/COMPLETION_IMPLEMENTATION.md +0 -280
- package/CONTRIBUTING.md +0 -136
- package/GETTING_STARTED.md +0 -310
- package/IMPLEMENTATION.md +0 -294
- package/MIGRATION_TO_SDK.md +0 -263
- package/PAGINATION_IMPLEMENTATION.md +0 -221
- package/SDK_INTEGRATION_COMPLETE.md +0 -300
- package/STANDARD_SUBSCRIPTIONS.md +0 -268
- package/STANDARD_SUBSCRIPTIONS_COMPLETE.md +0 -309
- package/SUMMARY.md +0 -272
- package/examples/GITHUB_LIVE_EXAMPLE.md +0 -308
- package/examples/GITHUB_LIVE_SETUP.md +0 -253
- package/examples/QUICKSTART.md +0 -130
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
# MCP Completion Support Implementation
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
Implemented comprehensive completion (autocomplete) support for MCP resources and prompts. Completions provide intelligent suggestions for prompt arguments and resource URI parameters, enabling better user experience in MCP clients.
|
|
6
|
-
|
|
7
|
-
## Changes Made
|
|
8
|
-
|
|
9
|
-
### 1. Type Definitions (`src/types/index.ts`)
|
|
10
|
-
|
|
11
|
-
#### Added New Types:
|
|
12
|
-
|
|
13
|
-
- **`CompletionItem`**: Individual completion suggestion
|
|
14
|
-
- `value`: The actual value to use
|
|
15
|
-
- `label`: Optional display label
|
|
16
|
-
- `description`: Optional description
|
|
17
|
-
- `type`: Type hint (value, function, variable, constant, other)
|
|
18
|
-
|
|
19
|
-
- **`CompletionRef`**: Reference to what's being completed
|
|
20
|
-
- Prompt reference: `{ type: 'ref/prompt', name, arguments }`
|
|
21
|
-
- Resource reference: `{ type: 'ref/resource', uri }`
|
|
22
|
-
|
|
23
|
-
- **`CompletionHandler`**: Function signature for completion handlers
|
|
24
|
-
```typescript
|
|
25
|
-
(ref: CompletionRef, argument: string, context: AuthContext) => Promise<CompletionItem[]>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
#### Updated Types:
|
|
29
|
-
|
|
30
|
-
- **`PromptDefinition`**: Added optional `completion` handler
|
|
31
|
-
- **`ResourceDefinition`**: Added optional `completion` handler
|
|
32
|
-
- **`MCPServerConfig`**: Added optional global `completions` handler
|
|
33
|
-
|
|
34
|
-
### 2. Server Implementation (`src/server.ts`)
|
|
35
|
-
|
|
36
|
-
#### Imports:
|
|
37
|
-
- Added `completable` from `@modelcontextprotocol/sdk/server/completable.js`
|
|
38
|
-
|
|
39
|
-
#### Prompt Registration:
|
|
40
|
-
- Wraps prompt argument schemas with `completable()` when completion handler is provided
|
|
41
|
-
- Completion callback receives:
|
|
42
|
-
- Current argument value
|
|
43
|
-
- Context with other argument values (for context-aware suggestions)
|
|
44
|
-
- Returns array of completion values
|
|
45
|
-
|
|
46
|
-
#### Completion Flow:
|
|
47
|
-
1. Client requests completions for a specific argument
|
|
48
|
-
2. Server identifies the relevant completion handler:
|
|
49
|
-
- Prompt-specific handler
|
|
50
|
-
- Resource-specific handler
|
|
51
|
-
- Global fallback handler
|
|
52
|
-
3. Handler returns suggestions based on:
|
|
53
|
-
- Current partial value
|
|
54
|
-
- Other argument values (context)
|
|
55
|
-
- User authentication context
|
|
56
|
-
4. Server formats and returns completion items
|
|
57
|
-
|
|
58
|
-
### 3. Documentation
|
|
59
|
-
|
|
60
|
-
#### Updated README.md:
|
|
61
|
-
- Added **Completions** section with:
|
|
62
|
-
- Prompt completion example (context-aware)
|
|
63
|
-
- Resource URI completion example (hierarchical)
|
|
64
|
-
- Global completion handler example
|
|
65
|
-
- Reference to example file
|
|
66
|
-
|
|
67
|
-
### 4. Examples
|
|
68
|
-
|
|
69
|
-
Created `examples/completion-example.ts` demonstrating:
|
|
70
|
-
|
|
71
|
-
1. **Prompt Argument Completion**:
|
|
72
|
-
- Language selection → suggests: python, javascript, typescript, etc.
|
|
73
|
-
- Framework selection → context-aware based on language
|
|
74
|
-
- Feature selection → common features
|
|
75
|
-
|
|
76
|
-
2. **Resource URI Completion**:
|
|
77
|
-
- Owner parameter → suggests GitHub organizations
|
|
78
|
-
- Repo parameter → filtered by selected owner
|
|
79
|
-
- Hierarchical completion
|
|
80
|
-
|
|
81
|
-
3. **Global Completion Handler**:
|
|
82
|
-
- Fallback for arguments without specific handlers
|
|
83
|
-
- Provides default suggestions
|
|
84
|
-
|
|
85
|
-
## Usage
|
|
86
|
-
|
|
87
|
-
### Prompt with Completion
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
const promptDef: PromptDefinition = {
|
|
91
|
-
name: 'generate-code',
|
|
92
|
-
arguments: [
|
|
93
|
-
{ name: 'language', required: true },
|
|
94
|
-
{ name: 'framework', required: false }
|
|
95
|
-
],
|
|
96
|
-
|
|
97
|
-
handler: async (args, context) => {
|
|
98
|
-
// Generate code based on args
|
|
99
|
-
return { messages: [...] };
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
completion: async (ref, argument, context) => {
|
|
103
|
-
if (argument === 'language') {
|
|
104
|
-
return [
|
|
105
|
-
{ value: 'python', label: 'Python' },
|
|
106
|
-
{ value: 'javascript', label: 'JavaScript' }
|
|
107
|
-
];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Context-aware: framework based on language
|
|
111
|
-
if (argument === 'framework' && ref.arguments?.language) {
|
|
112
|
-
const lang = ref.arguments.language;
|
|
113
|
-
return getFrameworksForLanguage(lang);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Resource with Completion
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
const resourceDef: ResourceDefinition = {
|
|
125
|
-
uri: 'github://repos/{owner}/{repo}',
|
|
126
|
-
name: 'github-repos',
|
|
127
|
-
|
|
128
|
-
read: async (uri, context) => { /* ... */ },
|
|
129
|
-
|
|
130
|
-
completion: async (ref, argument, context) => {
|
|
131
|
-
if (argument === 'owner') {
|
|
132
|
-
return await fetchGitHubOrganizations();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (argument === 'repo') {
|
|
136
|
-
// Extract owner from current URI
|
|
137
|
-
const owner = ref.uri.match(/repos\/([^/]+)/)?.[1];
|
|
138
|
-
return await fetchReposForOwner(owner);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Global Completion Handler
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
createMCPServer({
|
|
150
|
-
// ... other config
|
|
151
|
-
completions: async (ref, argument, context) => {
|
|
152
|
-
// Fallback for any argument without specific handler
|
|
153
|
-
if (ref.type === 'ref/prompt') {
|
|
154
|
-
return getPromptCompletions(ref.name, argument);
|
|
155
|
-
}
|
|
156
|
-
if (ref.type === 'ref/resource') {
|
|
157
|
-
return getResourceCompletions(ref.uri, argument);
|
|
158
|
-
}
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## Client Request/Response
|
|
165
|
-
|
|
166
|
-
### Request Completions
|
|
167
|
-
|
|
168
|
-
```json
|
|
169
|
-
{
|
|
170
|
-
"jsonrpc": "2.0",
|
|
171
|
-
"method": "completion/complete",
|
|
172
|
-
"params": {
|
|
173
|
-
"ref": {
|
|
174
|
-
"type": "ref/prompt",
|
|
175
|
-
"name": "generate-code",
|
|
176
|
-
"arguments": {
|
|
177
|
-
"language": "python"
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
"argument": {
|
|
181
|
-
"name": "framework",
|
|
182
|
-
"value": "fla"
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
### Response
|
|
189
|
-
|
|
190
|
-
```json
|
|
191
|
-
{
|
|
192
|
-
"jsonrpc": "2.0",
|
|
193
|
-
"result": {
|
|
194
|
-
"completion": {
|
|
195
|
-
"values": ["flask", "fastapi"],
|
|
196
|
-
"total": 2,
|
|
197
|
-
"hasMore": false
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
## Key Features
|
|
204
|
-
|
|
205
|
-
### 1. Context-Aware Completions
|
|
206
|
-
- Suggestions based on other argument values
|
|
207
|
-
- Example: Framework suggestions filtered by selected language
|
|
208
|
-
|
|
209
|
-
### 2. Hierarchical Completions
|
|
210
|
-
- Step-by-step suggestions for complex URIs
|
|
211
|
-
- Example: Owner → Repo → Branch
|
|
212
|
-
|
|
213
|
-
### 3. Async Data Sources
|
|
214
|
-
- Completion handlers can fetch from databases/APIs
|
|
215
|
-
- Supports dynamic, real-time suggestions
|
|
216
|
-
|
|
217
|
-
### 4. Type Safety
|
|
218
|
-
- Full TypeScript support
|
|
219
|
-
- Strongly typed completion items and handlers
|
|
220
|
-
|
|
221
|
-
### 5. Fallback Support
|
|
222
|
-
- Global handler for arguments without specific handlers
|
|
223
|
-
- Prevents empty completion lists
|
|
224
|
-
|
|
225
|
-
### 6. Performance Optimized
|
|
226
|
-
- Completions use Zod's completable wrapper
|
|
227
|
-
- Efficient MCP SDK integration
|
|
228
|
-
|
|
229
|
-
## Best Practices
|
|
230
|
-
|
|
231
|
-
1. **Fast Handlers**: Keep completion handlers under 100ms for good UX
|
|
232
|
-
2. **Context-Aware**: Use `ref.arguments` to provide relevant suggestions
|
|
233
|
-
3. **Caching**: Cache frequent completions (e.g., language lists)
|
|
234
|
-
4. **Fuzzy Matching**: Implement fuzzy search for better matches
|
|
235
|
-
5. **Async Loading**: Fetch suggestions from APIs/databases as needed
|
|
236
|
-
6. **Graceful Fallback**: Always return empty array instead of throwing errors
|
|
237
|
-
7. **Rich Metadata**: Include labels and descriptions for better UX
|
|
238
|
-
8. **Hierarchical Flow**: For nested parameters, complete in logical order
|
|
239
|
-
|
|
240
|
-
## Examples of Use Cases
|
|
241
|
-
|
|
242
|
-
1. **Code Generation**: Language → Framework → Library completions
|
|
243
|
-
2. **File Browsers**: Drive → Folder → File hierarchical completion
|
|
244
|
-
3. **Database Queries**: Database → Schema → Table → Column completion
|
|
245
|
-
4. **API Endpoints**: Service → Resource → Method completion
|
|
246
|
-
5. **Git Operations**: Remote → Branch → Commit completion
|
|
247
|
-
6. **Cloud Resources**: Provider → Region → Resource type completion
|
|
248
|
-
|
|
249
|
-
## Integration with MCP SDK
|
|
250
|
-
|
|
251
|
-
- Uses `completable()` wrapper from `@modelcontextprotocol/sdk`
|
|
252
|
-
- Integrates seamlessly with Zod schemas
|
|
253
|
-
- Compatible with all MCP clients that support completions capability
|
|
254
|
-
- Follows official MCP completion protocol
|
|
255
|
-
|
|
256
|
-
## Files Modified
|
|
257
|
-
|
|
258
|
-
- `src/types/index.ts` - Type definitions for completions
|
|
259
|
-
- `src/server.ts` - Server-side completion implementation
|
|
260
|
-
- `README.md` - Documentation
|
|
261
|
-
- `examples/completion-example.ts` - Comprehensive examples (NEW)
|
|
262
|
-
|
|
263
|
-
## Testing
|
|
264
|
-
|
|
265
|
-
Build successful:
|
|
266
|
-
```bash
|
|
267
|
-
cd packages/plugins/mcp-proxy
|
|
268
|
-
npm run build # ✓ No errors
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
## Next Steps
|
|
272
|
-
|
|
273
|
-
Consider:
|
|
274
|
-
1. Add fuzzy matching library for better user experience
|
|
275
|
-
2. Implement completion result caching
|
|
276
|
-
3. Add completion metrics/analytics
|
|
277
|
-
4. Support for completion pagination (for large result sets)
|
|
278
|
-
5. Add completion templates/presets
|
|
279
|
-
6. Integration tests with MCP clients
|
|
280
|
-
7. Performance benchmarks for completion handlers
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
# Contributing to MCP HTTP Webhook
|
|
2
|
-
|
|
3
|
-
Thank you for your interest in contributing! This document provides guidelines and instructions for contributing.
|
|
4
|
-
|
|
5
|
-
## Development Setup
|
|
6
|
-
|
|
7
|
-
1. **Fork and Clone**
|
|
8
|
-
```bash
|
|
9
|
-
git clone https://github.com/your-username/mcp-http-webhook.git
|
|
10
|
-
cd mcp-http-webhook
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
2. **Install Dependencies**
|
|
14
|
-
```bash
|
|
15
|
-
npm install
|
|
16
|
-
# or
|
|
17
|
-
pnpm install
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
3. **Build**
|
|
21
|
-
```bash
|
|
22
|
-
npm run build
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
4. **Run Tests**
|
|
26
|
-
```bash
|
|
27
|
-
npm test
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Code Style
|
|
31
|
-
|
|
32
|
-
We use ESLint and Prettier for code formatting:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
# Lint code
|
|
36
|
-
npm run lint
|
|
37
|
-
|
|
38
|
-
# Format code
|
|
39
|
-
npm run format
|
|
40
|
-
|
|
41
|
-
# Type check
|
|
42
|
-
npm run type-check
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### TypeScript Guidelines
|
|
46
|
-
|
|
47
|
-
- Use explicit types for public APIs
|
|
48
|
-
- Prefer `const` over `let`
|
|
49
|
-
- Use async/await over promises
|
|
50
|
-
- Document public APIs with JSDoc comments
|
|
51
|
-
|
|
52
|
-
Example:
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
/**
|
|
56
|
-
* Creates a new MCP server instance
|
|
57
|
-
* @param config - Server configuration
|
|
58
|
-
* @returns Configured MCP server
|
|
59
|
-
*/
|
|
60
|
-
export function createMCPServer(config: MCPServerConfig): MCPServer {
|
|
61
|
-
// ...
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Testing
|
|
66
|
-
|
|
67
|
-
- Write tests for all new features
|
|
68
|
-
- Maintain >80% code coverage
|
|
69
|
-
- Use descriptive test names
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
describe('SubscriptionManager', () => {
|
|
73
|
-
it('should create a new subscription', async () => {
|
|
74
|
-
// Test implementation
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Commit Messages
|
|
80
|
-
|
|
81
|
-
We follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
feat: add webhook retry backoff configuration
|
|
85
|
-
fix: resolve subscription cleanup race condition
|
|
86
|
-
docs: update subscription flow diagram
|
|
87
|
-
test: add tests for webhook signature verification
|
|
88
|
-
chore: update dependencies
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Pull Request Process
|
|
92
|
-
|
|
93
|
-
1. **Create a Branch**
|
|
94
|
-
```bash
|
|
95
|
-
git checkout -b feature/my-new-feature
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
2. **Make Changes**
|
|
99
|
-
- Write code following style guidelines
|
|
100
|
-
- Add/update tests
|
|
101
|
-
- Update documentation
|
|
102
|
-
|
|
103
|
-
3. **Run Quality Checks**
|
|
104
|
-
```bash
|
|
105
|
-
npm run lint
|
|
106
|
-
npm run format
|
|
107
|
-
npm test
|
|
108
|
-
npm run type-check
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
4. **Commit Changes**
|
|
112
|
-
```bash
|
|
113
|
-
git commit -m "feat: add my new feature"
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
5. **Push to Fork**
|
|
117
|
-
```bash
|
|
118
|
-
git push origin feature/my-new-feature
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
6. **Create Pull Request**
|
|
122
|
-
- Provide clear description of changes
|
|
123
|
-
- Link related issues
|
|
124
|
-
- Include screenshots/examples if applicable
|
|
125
|
-
|
|
126
|
-
## Code of Conduct
|
|
127
|
-
|
|
128
|
-
This project follows the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md).
|
|
129
|
-
|
|
130
|
-
## Questions?
|
|
131
|
-
|
|
132
|
-
Feel free to open an issue or ask in our [Discord community](https://discord.gg/mcp-webhook).
|
|
133
|
-
|
|
134
|
-
## License
|
|
135
|
-
|
|
136
|
-
By contributing, you agree that your contributions will be licensed under the MIT License.
|
package/GETTING_STARTED.md
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
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! 🚀
|