converse-mcp-server 1.0.1
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/.env.example +177 -0
- package/README.md +425 -0
- package/bin/converse.js +45 -0
- package/docs/API.md +897 -0
- package/docs/ARCHITECTURE.md +552 -0
- package/docs/EXAMPLES.md +736 -0
- package/package.json +101 -0
- package/src/config.js +521 -0
- package/src/continuationStore.js +340 -0
- package/src/index.js +216 -0
- package/src/providers/google.js +441 -0
- package/src/providers/index.js +87 -0
- package/src/providers/openai.js +348 -0
- package/src/providers/xai.js +305 -0
- package/src/router.js +497 -0
- package/src/systemPrompts.js +90 -0
- package/src/tools/chat.js +336 -0
- package/src/tools/consensus.js +478 -0
- package/src/tools/index.js +156 -0
- package/src/transport/httpTransport.js +548 -0
- package/src/utils/console.js +64 -0
- package/src/utils/contextProcessor.js +475 -0
- package/src/utils/errorHandler.js +555 -0
- package/src/utils/logger.js +450 -0
- package/src/utils/tokenLimiter.js +217 -0
package/docs/API.md
ADDED
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
# Converse MCP Server - API Reference
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Converse MCP Server provides two main tools through the Model Context Protocol (MCP):
|
|
6
|
+
|
|
7
|
+
1. **Chat Tool** - Single-provider conversational AI with context support
|
|
8
|
+
2. **Consensus Tool** - Multi-provider parallel execution with response aggregation
|
|
9
|
+
|
|
10
|
+
## Transport Protocols
|
|
11
|
+
|
|
12
|
+
The server supports two transport modes:
|
|
13
|
+
|
|
14
|
+
### HTTP Transport (Default)
|
|
15
|
+
- **Endpoint**: `http://localhost:3000/mcp`
|
|
16
|
+
- **Protocol**: HTTP streaming with JSON-RPC 2.0
|
|
17
|
+
- **Usage**: Best for development, debugging, and web integrations
|
|
18
|
+
- **Features**: Health endpoints, CORS support, session management
|
|
19
|
+
|
|
20
|
+
### Stdio Transport (Legacy)
|
|
21
|
+
- **Protocol**: Standard input/output with JSON-RPC 2.0
|
|
22
|
+
- **Usage**: Traditional MCP client integrations
|
|
23
|
+
- **Features**: Process-based communication, lower latency
|
|
24
|
+
|
|
25
|
+
**Transport Selection:**
|
|
26
|
+
```bash
|
|
27
|
+
# Default (HTTP)
|
|
28
|
+
npm start
|
|
29
|
+
|
|
30
|
+
# Explicit HTTP
|
|
31
|
+
npm start -- --transport=http
|
|
32
|
+
|
|
33
|
+
# Stdio transport
|
|
34
|
+
npm start -- --transport=stdio
|
|
35
|
+
|
|
36
|
+
# Environment variable
|
|
37
|
+
MCP_TRANSPORT=stdio npm start
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Tool Schemas
|
|
41
|
+
|
|
42
|
+
### Chat Tool
|
|
43
|
+
|
|
44
|
+
**Description**: General conversational AI with context and continuation support.
|
|
45
|
+
|
|
46
|
+
#### Request Schema
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"type": "object",
|
|
51
|
+
"properties": {
|
|
52
|
+
"prompt": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"description": "Your question or topic with relevant context. Example: 'How should I structure the authentication module for this Express.js API?'"
|
|
55
|
+
},
|
|
56
|
+
"model": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"description": "AI model to use. Examples: 'auto' (recommended), 'gemini-2.5-flash', 'o3', 'grok-4-0709'. Default: 'auto'"
|
|
59
|
+
},
|
|
60
|
+
"files": {
|
|
61
|
+
"type": "array",
|
|
62
|
+
"items": {"type": "string"},
|
|
63
|
+
"description": "File paths to include as context (absolute paths required). Example: ['/path/to/src/auth.js', '/path/to/config.json']"
|
|
64
|
+
},
|
|
65
|
+
"images": {
|
|
66
|
+
"type": "array",
|
|
67
|
+
"items": {"type": "string"},
|
|
68
|
+
"description": "Image paths for visual context (absolute paths or base64). Example: ['/path/to/diagram.png', 'data:image/jpeg;base64,...']"
|
|
69
|
+
},
|
|
70
|
+
"continuation_id": {
|
|
71
|
+
"type": "string",
|
|
72
|
+
"description": "Continuation ID for persistent conversation. Example: 'chat_1703123456789_abc123'"
|
|
73
|
+
},
|
|
74
|
+
"temperature": {
|
|
75
|
+
"type": "number",
|
|
76
|
+
"minimum": 0.0,
|
|
77
|
+
"maximum": 1.0,
|
|
78
|
+
"default": 0.5,
|
|
79
|
+
"description": "Response randomness (0.0-1.0). Examples: 0.2 (focused), 0.5 (balanced), 0.8 (creative)"
|
|
80
|
+
},
|
|
81
|
+
"reasoning_effort": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"enum": ["minimal", "low", "medium", "high", "max"],
|
|
84
|
+
"default": "medium",
|
|
85
|
+
"description": "Reasoning depth for thinking models. Examples: 'minimal' (quick), 'medium' (balanced), 'high' (complex analysis)"
|
|
86
|
+
},
|
|
87
|
+
"use_websearch": {
|
|
88
|
+
"type": "boolean",
|
|
89
|
+
"default": false,
|
|
90
|
+
"description": "Enable web search for current information. Example: true for framework docs, false for private code analysis"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"required": ["prompt"]
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### Response Format
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"content": "AI response text",
|
|
102
|
+
"continuation": {
|
|
103
|
+
"id": "conv_d6a6a5ec-6900-4fd8-a4e0-1fa4f75dfc42",
|
|
104
|
+
"provider": "openai",
|
|
105
|
+
"model": "gpt-4o-mini",
|
|
106
|
+
"messageCount": 3
|
|
107
|
+
},
|
|
108
|
+
"metadata": {
|
|
109
|
+
"model": "gpt-4o-mini",
|
|
110
|
+
"usage": {
|
|
111
|
+
"input_tokens": 150,
|
|
112
|
+
"output_tokens": 85,
|
|
113
|
+
"total_tokens": 235
|
|
114
|
+
},
|
|
115
|
+
"response_time_ms": 1247,
|
|
116
|
+
"provider": "openai"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### Example Usage
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"prompt": "Review this authentication function for security issues",
|
|
126
|
+
"model": "o3",
|
|
127
|
+
"files": ["/project/src/auth.js", "/project/config/security.json"],
|
|
128
|
+
"temperature": 0.2,
|
|
129
|
+
"reasoning_effort": "high"
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Consensus Tool
|
|
134
|
+
|
|
135
|
+
**Description**: Multi-provider parallel execution with cross-model feedback for gathering perspectives from multiple AI models.
|
|
136
|
+
|
|
137
|
+
#### Request Schema
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"type": "object",
|
|
142
|
+
"properties": {
|
|
143
|
+
"prompt": {
|
|
144
|
+
"type": "string",
|
|
145
|
+
"description": "The problem or proposal to gather consensus on. Example: 'Should we use microservices or monolith architecture for our e-commerce platform?'"
|
|
146
|
+
},
|
|
147
|
+
"models": {
|
|
148
|
+
"type": "array",
|
|
149
|
+
"items": {
|
|
150
|
+
"type": "object",
|
|
151
|
+
"properties": {
|
|
152
|
+
"model": {"type": "string"}
|
|
153
|
+
},
|
|
154
|
+
"required": ["model"]
|
|
155
|
+
},
|
|
156
|
+
"description": "List of models to consult. Example: [{'model': 'o3'}, {'model': 'gemini-2.5-flash'}, {'model': 'grok-4-0709'}]"
|
|
157
|
+
},
|
|
158
|
+
"relevant_files": {
|
|
159
|
+
"type": "array",
|
|
160
|
+
"items": {"type": "string"},
|
|
161
|
+
"description": "File paths for additional context. Example: ['/path/to/architecture.md', '/path/to/requirements.txt']"
|
|
162
|
+
},
|
|
163
|
+
"images": {
|
|
164
|
+
"type": "array",
|
|
165
|
+
"items": {"type": "string"},
|
|
166
|
+
"description": "Image paths for visual context. Example: ['/path/to/architecture.png', '/path/to/user_flow.jpg']"
|
|
167
|
+
},
|
|
168
|
+
"continuation_id": {
|
|
169
|
+
"type": "string",
|
|
170
|
+
"description": "Thread continuation ID for multi-turn conversations. Example: 'consensus_1703123456789_xyz789'"
|
|
171
|
+
},
|
|
172
|
+
"enable_cross_feedback": {
|
|
173
|
+
"type": "boolean",
|
|
174
|
+
"default": true,
|
|
175
|
+
"description": "Enable refinement phase where models see others' responses. Example: true (recommended), false (faster)"
|
|
176
|
+
},
|
|
177
|
+
"cross_feedback_prompt": {
|
|
178
|
+
"type": "string",
|
|
179
|
+
"description": "Custom prompt for refinement phase. Example: 'Focus on scalability trade-offs in your refinement'"
|
|
180
|
+
},
|
|
181
|
+
"temperature": {
|
|
182
|
+
"type": "number",
|
|
183
|
+
"minimum": 0.0,
|
|
184
|
+
"maximum": 1.0,
|
|
185
|
+
"default": 0.2,
|
|
186
|
+
"description": "Response randomness. Examples: 0.1 (very focused), 0.2 (analytical), 0.5 (balanced)"
|
|
187
|
+
},
|
|
188
|
+
"reasoning_effort": {
|
|
189
|
+
"type": "string",
|
|
190
|
+
"enum": ["minimal", "low", "medium", "high", "max"],
|
|
191
|
+
"default": "medium",
|
|
192
|
+
"description": "Reasoning depth. Examples: 'medium' (balanced), 'high' (complex analysis), 'max' (thorough evaluation)"
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"required": ["prompt", "models"]
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### Response Format
|
|
200
|
+
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"status": "consensus_complete",
|
|
204
|
+
"models_consulted": 3,
|
|
205
|
+
"successful_initial_responses": 3,
|
|
206
|
+
"failed_responses": 0,
|
|
207
|
+
"refined_responses": 3,
|
|
208
|
+
"phases": {
|
|
209
|
+
"initial": [
|
|
210
|
+
{
|
|
211
|
+
"model": "o3",
|
|
212
|
+
"status": "success",
|
|
213
|
+
"response": "Initial analysis from O3...",
|
|
214
|
+
"metadata": {
|
|
215
|
+
"provider": "openai",
|
|
216
|
+
"input_tokens": 200,
|
|
217
|
+
"output_tokens": 150,
|
|
218
|
+
"response_time": 2500
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
"refined": [
|
|
223
|
+
{
|
|
224
|
+
"model": "o3",
|
|
225
|
+
"status": "success",
|
|
226
|
+
"initial_response": "Initial analysis...",
|
|
227
|
+
"refined_response": "After considering other perspectives...",
|
|
228
|
+
"metadata": {
|
|
229
|
+
"total_response_time": 4800,
|
|
230
|
+
"total_input_tokens": 450,
|
|
231
|
+
"total_output_tokens": 320
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
],
|
|
235
|
+
"failed": []
|
|
236
|
+
},
|
|
237
|
+
"continuation": {
|
|
238
|
+
"id": "consensus_xyz789",
|
|
239
|
+
"messageCount": 2
|
|
240
|
+
},
|
|
241
|
+
"settings": {
|
|
242
|
+
"enable_cross_feedback": true,
|
|
243
|
+
"temperature": 0.2,
|
|
244
|
+
"models_requested": ["o3", "gemini-2.5-flash", "grok-4-0709"]
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Example Usage
|
|
250
|
+
|
|
251
|
+
```json
|
|
252
|
+
{
|
|
253
|
+
"prompt": "What's the best database solution for a high-traffic social media platform?",
|
|
254
|
+
"models": [
|
|
255
|
+
{"model": "o3"},
|
|
256
|
+
{"model": "gemini-2.5-pro"},
|
|
257
|
+
{"model": "grok-4-0709"}
|
|
258
|
+
],
|
|
259
|
+
"relevant_files": ["/docs/requirements.md", "/docs/current_architecture.md"],
|
|
260
|
+
"enable_cross_feedback": true,
|
|
261
|
+
"temperature": 0.1,
|
|
262
|
+
"reasoning_effort": "high"
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Supported Models
|
|
267
|
+
|
|
268
|
+
### OpenAI Models
|
|
269
|
+
|
|
270
|
+
| Model | Context | Tokens | Features | Use Cases |
|
|
271
|
+
|-------|---------|--------|----------|-----------|
|
|
272
|
+
| `o3` | 200K | 100K | Reasoning | Logic, analysis, complex problems |
|
|
273
|
+
| `o3-mini` | 200K | 100K | Fast reasoning | Balanced performance/speed |
|
|
274
|
+
| `o4-mini` | 200K | 100K | Latest | General purpose, rapid reasoning |
|
|
275
|
+
| `gpt-4o` | 128K | 16K | Multimodal | Vision, general chat |
|
|
276
|
+
| `gpt-4o-mini` | 128K | 16K | Fast multimodal | Quick responses, images |
|
|
277
|
+
|
|
278
|
+
### Google/Gemini Models
|
|
279
|
+
|
|
280
|
+
| Model | Alias | Context | Tokens | Features | Use Cases |
|
|
281
|
+
|-------|-------|---------|--------|----------|-----------|
|
|
282
|
+
| `gemini-2.5-flash` | `flash` | 1M | 65K | Ultra-fast | Quick analysis, simple queries |
|
|
283
|
+
| `gemini-2.5-pro` | `pro` | 1M | 65K | Thinking mode | Deep reasoning, architecture |
|
|
284
|
+
| `gemini-2.0-flash` | `flash2` | 1M | 65K | Latest | Experimental thinking |
|
|
285
|
+
|
|
286
|
+
### X.AI/Grok Models
|
|
287
|
+
|
|
288
|
+
| Model | Alias | Context | Tokens | Features | Use Cases |
|
|
289
|
+
|-------|-------|---------|--------|----------|-----------|
|
|
290
|
+
| `grok-4-0709` | `grok` | 256K | 256K | Advanced | Latest capabilities |
|
|
291
|
+
| `grok-3` | `grok3` | 131K | 131K | Previous gen | Stable reasoning |
|
|
292
|
+
| `grok-3-fast` | - | 131K | 131K | High perf | Faster processing |
|
|
293
|
+
|
|
294
|
+
### Model Selection
|
|
295
|
+
|
|
296
|
+
Use `"auto"` for automatic selection or specify exact models:
|
|
297
|
+
|
|
298
|
+
```json
|
|
299
|
+
// Automatic selection (recommended)
|
|
300
|
+
{"model": "auto"}
|
|
301
|
+
|
|
302
|
+
// Specific models
|
|
303
|
+
{"model": "gemini-2.5-flash"}
|
|
304
|
+
{"model": "o3"}
|
|
305
|
+
{"model": "grok-4-0709"}
|
|
306
|
+
|
|
307
|
+
// Using aliases
|
|
308
|
+
{"model": "flash"} // -> gemini-2.5-flash
|
|
309
|
+
{"model": "pro"} // -> gemini-2.5-pro
|
|
310
|
+
{"model": "grok"} // -> grok-4-0709
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Context Processing
|
|
314
|
+
|
|
315
|
+
### File Support
|
|
316
|
+
|
|
317
|
+
**Supported Text Formats:**
|
|
318
|
+
- `.txt`, `.md`, `.js`, `.ts`, `.json`, `.yaml`, `.yml`
|
|
319
|
+
- `.py`, `.java`, `.c`, `.cpp`, `.h`, `.css`, `.html`
|
|
320
|
+
- `.xml`, `.csv`, `.sql`, `.sh`, `.bat`, `.log`
|
|
321
|
+
|
|
322
|
+
**Supported Image Formats:**
|
|
323
|
+
- `.jpg`, `.jpeg`, `.png`, `.gif`, `.webp`, `.bmp`
|
|
324
|
+
|
|
325
|
+
**Size Limits:**
|
|
326
|
+
- Text files: 1MB default
|
|
327
|
+
- Image files: 10MB default
|
|
328
|
+
|
|
329
|
+
### File Processing
|
|
330
|
+
|
|
331
|
+
```json
|
|
332
|
+
{
|
|
333
|
+
"files": [
|
|
334
|
+
"/absolute/path/to/file.js",
|
|
335
|
+
"./relative/path/to/file.md"
|
|
336
|
+
]
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Response includes:**
|
|
341
|
+
- File content with line numbers
|
|
342
|
+
- Metadata (size, last modified)
|
|
343
|
+
- Error handling for inaccessible files
|
|
344
|
+
|
|
345
|
+
### Image Processing
|
|
346
|
+
|
|
347
|
+
```json
|
|
348
|
+
{
|
|
349
|
+
"images": [
|
|
350
|
+
"/path/to/diagram.png",
|
|
351
|
+
"data:image/jpeg;base64,/9j/4AAQ..."
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Features:**
|
|
357
|
+
- Base64 encoding for AI processing
|
|
358
|
+
- MIME type detection
|
|
359
|
+
- Size validation
|
|
360
|
+
- Security path checking
|
|
361
|
+
|
|
362
|
+
## Continuation System
|
|
363
|
+
|
|
364
|
+
### Creating Conversations
|
|
365
|
+
|
|
366
|
+
First request creates a continuation automatically:
|
|
367
|
+
|
|
368
|
+
```json
|
|
369
|
+
{
|
|
370
|
+
"prompt": "Start a conversation about architecture",
|
|
371
|
+
"model": "auto"
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Response includes continuation ID:
|
|
376
|
+
|
|
377
|
+
```json
|
|
378
|
+
{
|
|
379
|
+
"content": "Let's discuss architecture...",
|
|
380
|
+
"continuation": {
|
|
381
|
+
"id": "conv_abc123",
|
|
382
|
+
"provider": "openai",
|
|
383
|
+
"model": "gpt-4o-mini",
|
|
384
|
+
"messageCount": 2
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Continuing Conversations
|
|
390
|
+
|
|
391
|
+
Use the continuation ID in subsequent requests:
|
|
392
|
+
|
|
393
|
+
```json
|
|
394
|
+
{
|
|
395
|
+
"prompt": "What about microservices?",
|
|
396
|
+
"continuation_id": "conv_abc123"
|
|
397
|
+
}
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
**Features:**
|
|
401
|
+
- Persistent conversation history
|
|
402
|
+
- Provider and model consistency
|
|
403
|
+
- Message count tracking
|
|
404
|
+
- Automatic expiration
|
|
405
|
+
|
|
406
|
+
### ⚠️ Known Issues
|
|
407
|
+
|
|
408
|
+
**Continuation ID Missing (Critical):**
|
|
409
|
+
```json
|
|
410
|
+
// Some responses may not include continuation metadata
|
|
411
|
+
{
|
|
412
|
+
"content": "Response without continuation...",
|
|
413
|
+
// Missing: continuation field
|
|
414
|
+
}
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
**Workaround:** Use single-turn interactions until fixed. Track conversation manually if needed.
|
|
418
|
+
|
|
419
|
+
**Status:** Implementation gap identified in integration testing. High priority fix planned.
|
|
420
|
+
|
|
421
|
+
## Error Handling
|
|
422
|
+
|
|
423
|
+
### Common Error Responses
|
|
424
|
+
|
|
425
|
+
**Missing API Key:**
|
|
426
|
+
```json
|
|
427
|
+
{
|
|
428
|
+
"error": "Provider not available. Check API key configuration.",
|
|
429
|
+
"code": "PROVIDER_UNAVAILABLE",
|
|
430
|
+
"provider": "openai"
|
|
431
|
+
}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
**Invalid Model:**
|
|
435
|
+
```json
|
|
436
|
+
{
|
|
437
|
+
"error": "Model not found: invalid-model",
|
|
438
|
+
"code": "MODEL_NOT_FOUND",
|
|
439
|
+
"provider": "openai"
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
**Rate Limiting:**
|
|
444
|
+
```json
|
|
445
|
+
{
|
|
446
|
+
"error": "OpenAI rate limit exceeded",
|
|
447
|
+
"code": "RATE_LIMIT_EXCEEDED",
|
|
448
|
+
"provider": "openai",
|
|
449
|
+
"retry_after": 60
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
**Context Too Large:**
|
|
454
|
+
```json
|
|
455
|
+
{
|
|
456
|
+
"error": "Context length exceeded for model",
|
|
457
|
+
"code": "CONTEXT_LENGTH_EXCEEDED",
|
|
458
|
+
"max_tokens": 128000,
|
|
459
|
+
"provided_tokens": 150000
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## Rate Limits & Quotas
|
|
464
|
+
|
|
465
|
+
### Provider Limits
|
|
466
|
+
|
|
467
|
+
**OpenAI:**
|
|
468
|
+
- Rate limits vary by model and tier
|
|
469
|
+
- Automatic retry with exponential backoff
|
|
470
|
+
- Error codes: `rate_limit_error`, `insufficient_quota`
|
|
471
|
+
|
|
472
|
+
**Google:**
|
|
473
|
+
- Free tier: 50 requests/day
|
|
474
|
+
- Paid: Based on quota settings
|
|
475
|
+
- Automatic retry for temporary failures
|
|
476
|
+
|
|
477
|
+
**X.AI:**
|
|
478
|
+
- Based on account tier
|
|
479
|
+
- Higher limits for paid accounts
|
|
480
|
+
- Standard HTTP 429 handling
|
|
481
|
+
|
|
482
|
+
### Server Limits
|
|
483
|
+
|
|
484
|
+
**Default Limits:**
|
|
485
|
+
- Max output tokens: 25,000 (configurable to 200,000)
|
|
486
|
+
- Request timeout: 5 minutes
|
|
487
|
+
- Concurrent requests: Unlimited
|
|
488
|
+
|
|
489
|
+
**Configuration:**
|
|
490
|
+
```bash
|
|
491
|
+
MAX_MCP_OUTPUT_TOKENS=200000
|
|
492
|
+
REQUEST_TIMEOUT_MS=300000
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
## Authentication
|
|
496
|
+
|
|
497
|
+
### API Key Management
|
|
498
|
+
|
|
499
|
+
**Environment Variables:**
|
|
500
|
+
```bash
|
|
501
|
+
OPENAI_API_KEY=sk-proj-...
|
|
502
|
+
GOOGLE_API_KEY=AIzaSy...
|
|
503
|
+
XAI_API_KEY=xai-...
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
**MCP Client Configuration:**
|
|
507
|
+
```json
|
|
508
|
+
{
|
|
509
|
+
"env": {
|
|
510
|
+
"OPENAI_API_KEY": "sk-proj-...",
|
|
511
|
+
"GOOGLE_API_KEY": "AIzaSy...",
|
|
512
|
+
"XAI_API_KEY": "xai-..."
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
### Security
|
|
518
|
+
|
|
519
|
+
**Features:**
|
|
520
|
+
- API keys never logged or exposed
|
|
521
|
+
- Path traversal protection for files
|
|
522
|
+
- File access limited to allowed directories
|
|
523
|
+
- Input validation on all parameters
|
|
524
|
+
|
|
525
|
+
## Performance
|
|
526
|
+
|
|
527
|
+
### Response Times
|
|
528
|
+
|
|
529
|
+
**Typical Performance:**
|
|
530
|
+
- Simple chat: 500-2000ms
|
|
531
|
+
- Complex reasoning: 2-10 seconds
|
|
532
|
+
- Consensus (3 models): 3-15 seconds
|
|
533
|
+
- File processing: <100ms per file
|
|
534
|
+
|
|
535
|
+
**Optimization:**
|
|
536
|
+
- Parallel consensus execution
|
|
537
|
+
- Efficient context processing
|
|
538
|
+
- Connection pooling
|
|
539
|
+
- Response caching for repeated requests
|
|
540
|
+
|
|
541
|
+
### Monitoring
|
|
542
|
+
|
|
543
|
+
**Metrics Available:**
|
|
544
|
+
- Response times per provider
|
|
545
|
+
- Token usage statistics
|
|
546
|
+
- Error rates and types
|
|
547
|
+
- Request concurrency
|
|
548
|
+
|
|
549
|
+
**Logging:**
|
|
550
|
+
```bash
|
|
551
|
+
LOG_LEVEL=debug # Detailed operation logs
|
|
552
|
+
LOG_LEVEL=info # Standard operation logs
|
|
553
|
+
LOG_LEVEL=error # Errors only
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
## Examples
|
|
557
|
+
|
|
558
|
+
### Basic Chat
|
|
559
|
+
|
|
560
|
+
```json
|
|
561
|
+
{
|
|
562
|
+
"tool": "chat",
|
|
563
|
+
"arguments": {
|
|
564
|
+
"prompt": "Explain the benefits of TypeScript over JavaScript",
|
|
565
|
+
"model": "gemini-2.5-flash",
|
|
566
|
+
"temperature": 0.3
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### Chat with Context
|
|
572
|
+
|
|
573
|
+
```json
|
|
574
|
+
{
|
|
575
|
+
"tool": "chat",
|
|
576
|
+
"arguments": {
|
|
577
|
+
"prompt": "Review this code for potential security vulnerabilities",
|
|
578
|
+
"model": "o3",
|
|
579
|
+
"files": ["/project/src/auth.js", "/project/src/middleware.js"],
|
|
580
|
+
"reasoning_effort": "high",
|
|
581
|
+
"temperature": 0.1
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### Simple Consensus
|
|
587
|
+
|
|
588
|
+
```json
|
|
589
|
+
{
|
|
590
|
+
"tool": "consensus",
|
|
591
|
+
"arguments": {
|
|
592
|
+
"prompt": "What's the best approach for implementing real-time notifications?",
|
|
593
|
+
"models": [
|
|
594
|
+
{"model": "o3"},
|
|
595
|
+
{"model": "flash"},
|
|
596
|
+
{"model": "grok"}
|
|
597
|
+
],
|
|
598
|
+
"enable_cross_feedback": false,
|
|
599
|
+
"temperature": 0.2
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### Advanced Consensus
|
|
605
|
+
|
|
606
|
+
```json
|
|
607
|
+
{
|
|
608
|
+
"tool": "consensus",
|
|
609
|
+
"arguments": {
|
|
610
|
+
"prompt": "Design a scalable architecture for a video streaming platform",
|
|
611
|
+
"models": [
|
|
612
|
+
{"model": "o3"},
|
|
613
|
+
{"model": "gemini-2.5-pro"},
|
|
614
|
+
{"model": "grok-4-0709"}
|
|
615
|
+
],
|
|
616
|
+
"relevant_files": [
|
|
617
|
+
"/docs/requirements.md",
|
|
618
|
+
"/docs/current_architecture.md",
|
|
619
|
+
"/docs/performance_goals.md"
|
|
620
|
+
],
|
|
621
|
+
"images": ["/diagrams/current_system.png"],
|
|
622
|
+
"enable_cross_feedback": true,
|
|
623
|
+
"cross_feedback_prompt": "Focus on scalability and cost optimization in your refinement",
|
|
624
|
+
"temperature": 0.15,
|
|
625
|
+
"reasoning_effort": "max"
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
## Troubleshooting
|
|
631
|
+
|
|
632
|
+
### Debug Mode
|
|
633
|
+
|
|
634
|
+
Enable detailed logging:
|
|
635
|
+
|
|
636
|
+
```bash
|
|
637
|
+
LOG_LEVEL=debug npx converse-mcp-server
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
### Test API Keys
|
|
641
|
+
|
|
642
|
+
```bash
|
|
643
|
+
# Test OpenAI
|
|
644
|
+
curl -H "Authorization: Bearer $OPENAI_API_KEY" https://api.openai.com/v1/models
|
|
645
|
+
|
|
646
|
+
# Test Google (replace YOUR_KEY)
|
|
647
|
+
curl "https://generativelanguage.googleapis.com/v1beta/models?key=YOUR_KEY"
|
|
648
|
+
|
|
649
|
+
# Test X.AI
|
|
650
|
+
curl -H "Authorization: Bearer $XAI_API_KEY" https://api.x.ai/v1/models
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
### Common Issues
|
|
654
|
+
|
|
655
|
+
**"No providers available":**
|
|
656
|
+
- Check API key environment variables
|
|
657
|
+
- Verify API key format and validity
|
|
658
|
+
- Ensure at least one provider is configured
|
|
659
|
+
|
|
660
|
+
**"Context length exceeded":**
|
|
661
|
+
- Reduce file content or prompt length
|
|
662
|
+
- Use shorter conversation history
|
|
663
|
+
- Switch to model with larger context window
|
|
664
|
+
|
|
665
|
+
**Slow responses:**
|
|
666
|
+
- Check network connectivity
|
|
667
|
+
- Verify API service status
|
|
668
|
+
- Consider using faster models (flash, mini variants)
|
|
669
|
+
|
|
670
|
+
### 🔍 Integration Test Results & Known Issues
|
|
671
|
+
|
|
672
|
+
**Provider-Specific Issues:**
|
|
673
|
+
|
|
674
|
+
**Google Provider:**
|
|
675
|
+
```json
|
|
676
|
+
{
|
|
677
|
+
"error": "genAI.getGenerativeModel is not a function",
|
|
678
|
+
"status": "connected_with_issues",
|
|
679
|
+
"workaround": "Provider handles gracefully, requests still processed"
|
|
680
|
+
}
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
**XAI Provider:**
|
|
684
|
+
```json
|
|
685
|
+
{
|
|
686
|
+
"error": "grok-beta does not exist or your team does not have access",
|
|
687
|
+
"status": "api_key_limitations",
|
|
688
|
+
"workaround": "Try different model names or contact XAI support"
|
|
689
|
+
}
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
**Input Validation:**
|
|
693
|
+
```json
|
|
694
|
+
{
|
|
695
|
+
"issue": "Missing required parameters may not be rejected",
|
|
696
|
+
"impact": "Some invalid requests may be processed",
|
|
697
|
+
"workaround": "Always provide required parameters like 'prompt'"
|
|
698
|
+
}
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
**Performance Benchmarks (From Integration Testing):**
|
|
702
|
+
- **Chat Tool**: 581ms average (OpenAI), excellent performance
|
|
703
|
+
- **Consensus Tool**: 496ms parallel execution (3 providers), excellent
|
|
704
|
+
- **File Processing**: 1779ms for analysis, good performance
|
|
705
|
+
- **Auto Selection**: 1900ms, acceptable for complex selection
|
|
706
|
+
- **Success Rate**: 75% (6/8 tests passing), core functionality working
|
|
707
|
+
|
|
708
|
+
**Validated Functionality:**
|
|
709
|
+
- ✅ Real API connectivity to all three providers
|
|
710
|
+
- ✅ Chat tool with actual AI responses
|
|
711
|
+
- ✅ Consensus tool with parallel execution
|
|
712
|
+
- ✅ File context processing and analysis
|
|
713
|
+
- ✅ HTTP transport for MCP protocol
|
|
714
|
+
- ✅ Automatic provider selection
|
|
715
|
+
- ✅ Graceful error handling for provider issues
|
|
716
|
+
|
|
717
|
+
## 🔧 Extension Guide
|
|
718
|
+
|
|
719
|
+
### Adding New Providers
|
|
720
|
+
|
|
721
|
+
Create a new provider by implementing the standard interface:
|
|
722
|
+
|
|
723
|
+
```javascript
|
|
724
|
+
// src/providers/newprovider.js
|
|
725
|
+
export async function invoke(messages, options = {}) {
|
|
726
|
+
// Validate API key availability
|
|
727
|
+
if (!process.env.NEWPROVIDER_API_KEY) {
|
|
728
|
+
throw new Error('NEWPROVIDER_API_KEY not configured');
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
try {
|
|
732
|
+
// Implement API call logic
|
|
733
|
+
const response = await apiCall(messages, options);
|
|
734
|
+
|
|
735
|
+
return {
|
|
736
|
+
content: response.text,
|
|
737
|
+
stop_reason: response.stop_reason || 'stop',
|
|
738
|
+
rawResponse: response
|
|
739
|
+
};
|
|
740
|
+
} catch (error) {
|
|
741
|
+
throw new Error(`New Provider error: ${error.message}`);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
export function isAvailable() {
|
|
746
|
+
return Boolean(process.env.NEWPROVIDER_API_KEY);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
export const supportedModels = ['model-1', 'model-2'];
|
|
750
|
+
export const name = 'newprovider';
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
**Registration:**
|
|
754
|
+
Add to `src/providers/index.js`:
|
|
755
|
+
```javascript
|
|
756
|
+
import * as newprovider from './newprovider.js';
|
|
757
|
+
|
|
758
|
+
export const providers = {
|
|
759
|
+
// ... existing providers
|
|
760
|
+
newprovider: newprovider
|
|
761
|
+
};
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
### Adding New Tools
|
|
765
|
+
|
|
766
|
+
Create a new tool following the MCP tool pattern:
|
|
767
|
+
|
|
768
|
+
```javascript
|
|
769
|
+
// src/tools/newtool.js
|
|
770
|
+
import { createToolResponse, createToolError } from './index.js';
|
|
771
|
+
|
|
772
|
+
export async function newTool(args, dependencies) {
|
|
773
|
+
const { config, providers, continuationStore } = dependencies;
|
|
774
|
+
|
|
775
|
+
try {
|
|
776
|
+
// Validate required arguments
|
|
777
|
+
if (!args.requiredParam) {
|
|
778
|
+
return createToolError('requiredParam is required');
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// Implement tool logic
|
|
782
|
+
const result = await processToolLogic(args, dependencies);
|
|
783
|
+
|
|
784
|
+
return createToolResponse(result);
|
|
785
|
+
} catch (error) {
|
|
786
|
+
return createToolError(`Tool execution failed: ${error.message}`);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// Tool definition for MCP registration
|
|
791
|
+
export const newToolDefinition = {
|
|
792
|
+
name: 'newtool',
|
|
793
|
+
description: 'Description of what the new tool does',
|
|
794
|
+
inputSchema: {
|
|
795
|
+
type: 'object',
|
|
796
|
+
properties: {
|
|
797
|
+
requiredParam: {
|
|
798
|
+
type: 'string',
|
|
799
|
+
description: 'Description of required parameter'
|
|
800
|
+
},
|
|
801
|
+
optionalParam: {
|
|
802
|
+
type: 'boolean',
|
|
803
|
+
default: false,
|
|
804
|
+
description: 'Description of optional parameter'
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
required: ['requiredParam']
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
**Registration:**
|
|
813
|
+
Add to `src/tools/index.js`:
|
|
814
|
+
```javascript
|
|
815
|
+
import { newTool, newToolDefinition } from './newtool.js';
|
|
816
|
+
|
|
817
|
+
export const tools = {
|
|
818
|
+
// ... existing tools
|
|
819
|
+
newtool: newTool
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
export const toolDefinitions = {
|
|
823
|
+
// ... existing definitions
|
|
824
|
+
newtool: newToolDefinition
|
|
825
|
+
};
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
### Configuration Extensions
|
|
829
|
+
|
|
830
|
+
Add new configuration options:
|
|
831
|
+
|
|
832
|
+
```javascript
|
|
833
|
+
// src/config.js
|
|
834
|
+
export const config = {
|
|
835
|
+
// ... existing config
|
|
836
|
+
|
|
837
|
+
newFeature: {
|
|
838
|
+
enabled: process.env.NEW_FEATURE_ENABLED === 'true',
|
|
839
|
+
timeout: parseInt(process.env.NEW_FEATURE_TIMEOUT) || 30000,
|
|
840
|
+
customOption: process.env.NEW_FEATURE_OPTION || 'default'
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
### Testing Extensions
|
|
846
|
+
|
|
847
|
+
Create tests for new components:
|
|
848
|
+
|
|
849
|
+
```javascript
|
|
850
|
+
// tests/providers/newprovider.test.js
|
|
851
|
+
import { describe, it, expect } from 'vitest';
|
|
852
|
+
import * as newProvider from '../../src/providers/newprovider.js';
|
|
853
|
+
|
|
854
|
+
describe('New Provider', () => {
|
|
855
|
+
it('should implement required interface', () => {
|
|
856
|
+
expect(newProvider.invoke).toBeDefined();
|
|
857
|
+
expect(newProvider.isAvailable).toBeDefined();
|
|
858
|
+
expect(newProvider.name).toBe('newprovider');
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it('should handle API calls correctly', async () => {
|
|
862
|
+
// Test implementation
|
|
863
|
+
});
|
|
864
|
+
});
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
### Best Practices
|
|
868
|
+
|
|
869
|
+
**Provider Development:**
|
|
870
|
+
- Always check API key availability in `isAvailable()`
|
|
871
|
+
- Implement consistent error handling
|
|
872
|
+
- Follow the standard response format
|
|
873
|
+
- Add comprehensive logging
|
|
874
|
+
- Handle rate limiting gracefully
|
|
875
|
+
|
|
876
|
+
**Tool Development:**
|
|
877
|
+
- Validate all input parameters
|
|
878
|
+
- Use dependency injection pattern
|
|
879
|
+
- Return standardized responses
|
|
880
|
+
- Implement proper error handling
|
|
881
|
+
- Add detailed input schema
|
|
882
|
+
|
|
883
|
+
**Testing:**
|
|
884
|
+
- Write unit tests for core logic
|
|
885
|
+
- Add integration tests with mocked APIs
|
|
886
|
+
- Test error conditions thoroughly
|
|
887
|
+
- Validate input/output formats
|
|
888
|
+
|
|
889
|
+
**Documentation:**
|
|
890
|
+
- Update API documentation with new tools/providers
|
|
891
|
+
- Add usage examples
|
|
892
|
+
- Document configuration options
|
|
893
|
+
- Include troubleshooting guides
|
|
894
|
+
|
|
895
|
+
---
|
|
896
|
+
|
|
897
|
+
For more examples and integration patterns, see [EXAMPLES.md](EXAMPLES.md).
|