mcp-rubber-duck 1.9.3 → 1.9.5

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.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
- import { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
3
+ import { z } from 'zod';
4
4
  import { ConfigManager } from './config/config.js';
5
5
  import { ProviderManager } from './providers/manager.js';
6
6
  import { EnhancedProviderManager } from './providers/enhanced-manager.js';
@@ -34,7 +34,7 @@ import { mcpStatusTool } from './tools/mcp-status.js';
34
34
  // Import usage stats tool
35
35
  import { getUsageStatsTool } from './tools/get-usage-stats.js';
36
36
  // Import prompts
37
- import { getPrompts, getPrompt } from './prompts/index.js';
37
+ import { PROMPTS } from './prompts/index.js';
38
38
  export class RubberDuckServer {
39
39
  server;
40
40
  configManager;
@@ -52,15 +52,10 @@ export class RubberDuckServer {
52
52
  functionBridge;
53
53
  mcpEnabled = false;
54
54
  constructor() {
55
- this.server = new Server({
55
+ this.server = new McpServer({
56
56
  name: 'mcp-rubber-duck',
57
57
  version: '1.0.0',
58
- }, {
59
- capabilities: {
60
- tools: {},
61
- prompts: {},
62
- },
63
- });
58
+ }, {});
64
59
  // Initialize managers
65
60
  this.configManager = new ConfigManager();
66
61
  const config = this.configManager.getConfig();
@@ -78,7 +73,12 @@ export class RubberDuckServer {
78
73
  this.healthMonitor = new HealthMonitor(this.providerManager);
79
74
  // Initialize MCP bridge if enabled
80
75
  this.initializeMCPBridge();
81
- this.setupHandlers();
76
+ this.registerTools();
77
+ this.registerPrompts();
78
+ // Handle errors
79
+ this.server.server.onerror = (error) => {
80
+ logger.error('Server error:', error);
81
+ };
82
82
  }
83
83
  initializeMCPBridge() {
84
84
  const config = this.configManager.getConfig();
@@ -107,107 +107,367 @@ export class RubberDuckServer {
107
107
  this.mcpEnabled = false;
108
108
  }
109
109
  }
110
- setupHandlers() {
111
- // List available tools
112
- this.server.setRequestHandler(ListToolsRequestSchema, () => {
113
- return { tools: this.getTools() };
110
+ // Tool functions return `{ type: 'text' }` where TS infers `string`, not the literal `"text"`.
111
+ // This helper narrows the type to satisfy McpServer's CallToolResult expectation.
112
+ toolResult(result) {
113
+ return result;
114
+ }
115
+ toolErrorResult(error) {
116
+ logger.error('Tool execution error:', error);
117
+ const errorMessage = error instanceof Error ? error.message : String(error);
118
+ return {
119
+ content: [
120
+ {
121
+ type: 'text',
122
+ text: `${getRandomDuckMessage('error')}\n\nError: ${errorMessage}`,
123
+ },
124
+ ],
125
+ isError: true,
126
+ };
127
+ }
128
+ registerTools() {
129
+ // ask_duck
130
+ this.server.registerTool('ask_duck', {
131
+ description: this.mcpEnabled
132
+ ? 'Ask a question to a specific LLM provider (duck) with MCP tool access'
133
+ : 'Ask a question to a specific LLM provider (duck)',
134
+ inputSchema: {
135
+ prompt: z.string().describe('The question or prompt to send to the duck'),
136
+ provider: z.string().optional().describe('The provider name (optional, uses default if not specified)'),
137
+ model: z.string().optional().describe('Specific model to use (optional, uses provider default if not specified)'),
138
+ temperature: z.number().min(0).max(2).optional().describe('Temperature for response generation (0-2)'),
139
+ },
140
+ annotations: {
141
+ readOnlyHint: true,
142
+ openWorldHint: true,
143
+ },
144
+ }, async (args) => {
145
+ try {
146
+ if (this.mcpEnabled && this.enhancedProviderManager) {
147
+ return this.toolResult(await this.handleAskDuckWithMCP(args));
148
+ }
149
+ return this.toolResult(await askDuckTool(this.providerManager, this.cache, args));
150
+ }
151
+ catch (error) {
152
+ return this.toolErrorResult(error);
153
+ }
114
154
  });
115
- // List available prompts
116
- this.server.setRequestHandler(ListPromptsRequestSchema, () => {
117
- return { prompts: getPrompts() };
155
+ // chat_with_duck
156
+ this.server.registerTool('chat_with_duck', {
157
+ description: 'Have a conversation with a duck, maintaining context across messages',
158
+ inputSchema: {
159
+ conversation_id: z.string().describe('Conversation ID (creates new if not exists)'),
160
+ message: z.string().describe('Your message to the duck'),
161
+ provider: z.string().optional().describe('Provider to use (can switch mid-conversation)'),
162
+ model: z.string().optional().describe('Specific model to use (optional)'),
163
+ },
164
+ annotations: {
165
+ openWorldHint: true,
166
+ },
167
+ }, async (args) => {
168
+ try {
169
+ return this.toolResult(await chatDuckTool(this.providerManager, this.conversationManager, args));
170
+ }
171
+ catch (error) {
172
+ return this.toolErrorResult(error);
173
+ }
118
174
  });
119
- // Get specific prompt
120
- this.server.setRequestHandler(GetPromptRequestSchema, (request) => {
121
- const { name, arguments: args } = request.params;
175
+ // clear_conversations
176
+ this.server.registerTool('clear_conversations', {
177
+ description: 'Clear all conversation history and start fresh',
178
+ annotations: {
179
+ destructiveHint: true,
180
+ idempotentHint: true,
181
+ openWorldHint: false,
182
+ },
183
+ }, () => {
122
184
  try {
123
- return getPrompt(name, args || {});
185
+ return this.toolResult(clearConversationsTool(this.conversationManager, {}));
124
186
  }
125
187
  catch (error) {
126
- const errorMessage = error instanceof Error ? error.message : String(error);
127
- logger.error(`Prompt error for ${name}:`, errorMessage);
128
- throw error;
188
+ return this.toolErrorResult(error);
129
189
  }
130
190
  });
131
- // Handle tool calls
132
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
133
- const { name, arguments: args } = request.params;
191
+ // list_ducks
192
+ this.server.registerTool('list_ducks', {
193
+ description: 'List all available LLM providers (ducks) and their status',
194
+ inputSchema: {
195
+ check_health: z.boolean().default(false).describe('Perform health check on all providers'),
196
+ },
197
+ annotations: {
198
+ readOnlyHint: true,
199
+ openWorldHint: true,
200
+ },
201
+ }, async (args) => {
202
+ try {
203
+ return this.toolResult(await listDucksTool(this.providerManager, this.healthMonitor, args));
204
+ }
205
+ catch (error) {
206
+ return this.toolErrorResult(error);
207
+ }
208
+ });
209
+ // list_models
210
+ this.server.registerTool('list_models', {
211
+ description: 'List available models for LLM providers',
212
+ inputSchema: {
213
+ provider: z.string().optional().describe('Provider name (optional, lists all if not specified)'),
214
+ fetch_latest: z.boolean().default(false).describe('Fetch latest models from API vs using cached/configured'),
215
+ },
216
+ annotations: {
217
+ readOnlyHint: true,
218
+ openWorldHint: true,
219
+ },
220
+ }, async (args) => {
221
+ try {
222
+ return this.toolResult(await listModelsTool(this.providerManager, args));
223
+ }
224
+ catch (error) {
225
+ return this.toolErrorResult(error);
226
+ }
227
+ });
228
+ // compare_ducks
229
+ this.server.registerTool('compare_ducks', {
230
+ description: 'Ask the same question to multiple ducks simultaneously',
231
+ inputSchema: {
232
+ prompt: z.string().describe('The question to ask all ducks'),
233
+ providers: z.array(z.string()).optional().describe('List of provider names to query (optional, uses all if not specified)'),
234
+ model: z.string().optional().describe('Specific model to use for all providers (optional)'),
235
+ },
236
+ annotations: {
237
+ readOnlyHint: true,
238
+ openWorldHint: true,
239
+ },
240
+ }, async (args) => {
134
241
  try {
135
- switch (name) {
136
- case 'ask_duck':
137
- // Use enhanced provider manager if MCP is enabled
138
- if (this.mcpEnabled && this.enhancedProviderManager) {
139
- return await this.handleAskDuckWithMCP(args || {});
140
- }
141
- return await askDuckTool(this.providerManager, this.cache, args || {});
142
- case 'chat_with_duck':
143
- return await chatDuckTool(this.providerManager, this.conversationManager, args || {});
144
- case 'clear_conversations':
145
- return clearConversationsTool(this.conversationManager, args || {});
146
- case 'list_ducks':
147
- return await listDucksTool(this.providerManager, this.healthMonitor, args || {});
148
- case 'list_models':
149
- return await listModelsTool(this.providerManager, args || {});
150
- case 'compare_ducks':
151
- // Use enhanced provider manager if MCP is enabled
152
- if (this.mcpEnabled && this.enhancedProviderManager) {
153
- return await this.handleCompareDucksWithMCP(args || {});
154
- }
155
- return await compareDucksTool(this.providerManager, args || {});
156
- case 'duck_council':
157
- // Use enhanced provider manager if MCP is enabled
158
- if (this.mcpEnabled && this.enhancedProviderManager) {
159
- return await this.handleDuckCouncilWithMCP(args || {});
160
- }
161
- return await duckCouncilTool(this.providerManager, args || {});
162
- case 'duck_vote':
163
- return await duckVoteTool(this.providerManager, args || {});
164
- case 'duck_judge':
165
- return await duckJudgeTool(this.providerManager, args || {});
166
- case 'duck_iterate':
167
- return await duckIterateTool(this.providerManager, args || {});
168
- case 'duck_debate':
169
- return await duckDebateTool(this.providerManager, args || {});
170
- // Usage stats tool
171
- case 'get_usage_stats':
172
- return getUsageStatsTool(this.usageService, args || {});
173
- // MCP-specific tools
174
- case 'get_pending_approvals':
175
- if (!this.approvalService) {
176
- throw new Error('MCP bridge not enabled');
177
- }
178
- return getPendingApprovalsTool(this.approvalService, args || {});
179
- case 'approve_mcp_request':
180
- if (!this.approvalService) {
181
- throw new Error('MCP bridge not enabled');
182
- }
183
- return approveMCPRequestTool(this.approvalService, args || {});
184
- case 'mcp_status':
185
- if (!this.mcpClientManager || !this.approvalService || !this.functionBridge) {
186
- throw new Error('MCP bridge not enabled');
187
- }
188
- return await mcpStatusTool(this.mcpClientManager, this.approvalService, this.functionBridge, args || {});
189
- default:
190
- throw new Error(`Unknown tool: ${name}`);
242
+ if (this.mcpEnabled && this.enhancedProviderManager) {
243
+ return this.toolResult(await this.handleCompareDucksWithMCP(args));
191
244
  }
245
+ return this.toolResult(await compareDucksTool(this.providerManager, args));
192
246
  }
193
247
  catch (error) {
194
- logger.error(`Tool execution error for ${name}:`, error);
195
- const errorMessage = error instanceof Error ? error.message : String(error);
196
- return {
197
- content: [
198
- {
199
- type: 'text',
200
- text: `${getRandomDuckMessage('error')}\n\nError: ${errorMessage}`,
201
- },
202
- ],
203
- isError: true,
204
- };
248
+ return this.toolErrorResult(error);
205
249
  }
206
250
  });
207
- // Handle errors
208
- this.server.onerror = (error) => {
209
- logger.error('Server error:', error);
210
- };
251
+ // duck_council
252
+ this.server.registerTool('duck_council', {
253
+ description: 'Get responses from all configured ducks (like a panel discussion)',
254
+ inputSchema: {
255
+ prompt: z.string().describe('The question for the duck council'),
256
+ model: z.string().optional().describe('Specific model to use for all ducks (optional)'),
257
+ },
258
+ annotations: {
259
+ readOnlyHint: true,
260
+ openWorldHint: true,
261
+ },
262
+ }, async (args) => {
263
+ try {
264
+ if (this.mcpEnabled && this.enhancedProviderManager) {
265
+ return this.toolResult(await this.handleDuckCouncilWithMCP(args));
266
+ }
267
+ return this.toolResult(await duckCouncilTool(this.providerManager, args));
268
+ }
269
+ catch (error) {
270
+ return this.toolErrorResult(error);
271
+ }
272
+ });
273
+ // duck_vote
274
+ this.server.registerTool('duck_vote', {
275
+ description: 'Have multiple ducks vote on options with reasoning. Returns vote tally, confidence scores, and consensus level.',
276
+ inputSchema: {
277
+ question: z.string().describe('The question to vote on (e.g., "Best approach for error handling?")'),
278
+ options: z.array(z.string()).min(2).max(10).describe('The options to vote on (2-10 options)'),
279
+ voters: z.array(z.string()).optional().describe('List of provider names to vote (optional, uses all if not specified)'),
280
+ require_reasoning: z.boolean().default(true).describe('Require ducks to explain their vote (default: true)'),
281
+ },
282
+ annotations: {
283
+ readOnlyHint: true,
284
+ openWorldHint: true,
285
+ },
286
+ }, async (args) => {
287
+ try {
288
+ return this.toolResult(await duckVoteTool(this.providerManager, args));
289
+ }
290
+ catch (error) {
291
+ return this.toolErrorResult(error);
292
+ }
293
+ });
294
+ // duck_judge
295
+ this.server.registerTool('duck_judge', {
296
+ description: 'Have one duck evaluate and rank other ducks\' responses. Use after duck_council to get a comparative evaluation.',
297
+ inputSchema: {
298
+ responses: z.array(z.object({
299
+ provider: z.string(),
300
+ nickname: z.string(),
301
+ model: z.string().optional(),
302
+ content: z.string(),
303
+ })).min(2).describe('Array of duck responses to evaluate (from duck_council output)'),
304
+ judge: z.string().optional().describe('Provider name of the judge duck (optional, uses first available)'),
305
+ criteria: z.array(z.string()).optional().describe('Evaluation criteria (default: ["accuracy", "completeness", "clarity"])'),
306
+ persona: z.string().optional().describe('Judge persona (e.g., "senior engineer", "security expert")'),
307
+ },
308
+ annotations: {
309
+ readOnlyHint: true,
310
+ openWorldHint: true,
311
+ },
312
+ }, async (args) => {
313
+ try {
314
+ return this.toolResult(await duckJudgeTool(this.providerManager, args));
315
+ }
316
+ catch (error) {
317
+ return this.toolErrorResult(error);
318
+ }
319
+ });
320
+ // duck_iterate
321
+ this.server.registerTool('duck_iterate', {
322
+ description: 'Iteratively refine a response between two ducks. One generates, the other critiques/improves, alternating for multiple rounds.',
323
+ inputSchema: {
324
+ prompt: z.string().describe('The initial prompt/task to iterate on'),
325
+ iterations: z.number().min(1).max(10).default(3).describe('Number of iteration rounds (default: 3, max: 10)'),
326
+ providers: z.array(z.string()).min(2).max(2).describe('Exactly 2 provider names for the ping-pong iteration'),
327
+ mode: z.enum(['refine', 'critique-improve']).describe('refine: each duck improves the previous response. critique-improve: alternates between critiquing and improving.'),
328
+ },
329
+ annotations: {
330
+ readOnlyHint: true,
331
+ openWorldHint: true,
332
+ },
333
+ }, async (args) => {
334
+ try {
335
+ return this.toolResult(await duckIterateTool(this.providerManager, args));
336
+ }
337
+ catch (error) {
338
+ return this.toolErrorResult(error);
339
+ }
340
+ });
341
+ // duck_debate
342
+ this.server.registerTool('duck_debate', {
343
+ description: 'Structured multi-round debate between ducks. Supports oxford (pro/con), socratic (questioning), and adversarial (attack/defend) formats.',
344
+ inputSchema: {
345
+ prompt: z.string().describe('The debate topic or proposition'),
346
+ rounds: z.number().min(1).max(10).default(3).describe('Number of debate rounds (default: 3)'),
347
+ providers: z.array(z.string()).min(2).optional().describe('Provider names to participate (min 2, uses all if not specified)'),
348
+ format: z.enum(['oxford', 'socratic', 'adversarial']).describe('Debate format: oxford (pro/con), socratic (questioning), adversarial (attack/defend)'),
349
+ synthesizer: z.string().optional().describe('Provider to synthesize the debate (optional, uses first provider)'),
350
+ },
351
+ annotations: {
352
+ readOnlyHint: true,
353
+ openWorldHint: true,
354
+ },
355
+ }, async (args) => {
356
+ try {
357
+ return this.toolResult(await duckDebateTool(this.providerManager, args));
358
+ }
359
+ catch (error) {
360
+ return this.toolErrorResult(error);
361
+ }
362
+ });
363
+ // get_usage_stats
364
+ this.server.registerTool('get_usage_stats', {
365
+ description: 'Get usage statistics for a time period. Shows token counts and costs (when pricing configured).',
366
+ inputSchema: {
367
+ period: z.enum(['today', '7d', '30d', 'all']).default('today').describe('Time period for stats'),
368
+ },
369
+ annotations: {
370
+ readOnlyHint: true,
371
+ openWorldHint: false,
372
+ },
373
+ }, (args) => {
374
+ try {
375
+ return this.toolResult(getUsageStatsTool(this.usageService, args));
376
+ }
377
+ catch (error) {
378
+ return this.toolErrorResult(error);
379
+ }
380
+ });
381
+ // Conditionally register MCP tools
382
+ if (this.mcpEnabled) {
383
+ // get_pending_approvals
384
+ this.server.registerTool('get_pending_approvals', {
385
+ description: 'Get list of pending MCP tool approvals from ducks',
386
+ inputSchema: {
387
+ duck: z.string().optional().describe('Filter by duck name (optional)'),
388
+ },
389
+ annotations: {
390
+ readOnlyHint: true,
391
+ openWorldHint: false,
392
+ },
393
+ }, (args) => {
394
+ try {
395
+ if (!this.approvalService) {
396
+ throw new Error('MCP bridge not enabled');
397
+ }
398
+ return this.toolResult(getPendingApprovalsTool(this.approvalService, args));
399
+ }
400
+ catch (error) {
401
+ return this.toolErrorResult(error);
402
+ }
403
+ });
404
+ // approve_mcp_request
405
+ this.server.registerTool('approve_mcp_request', {
406
+ description: "Approve or deny a duck's MCP tool request",
407
+ inputSchema: {
408
+ approval_id: z.string().describe('The approval request ID'),
409
+ decision: z.enum(['approve', 'deny']).describe('Whether to approve or deny the request'),
410
+ reason: z.string().optional().describe('Reason for denial (optional)'),
411
+ },
412
+ annotations: {
413
+ idempotentHint: true,
414
+ openWorldHint: false,
415
+ },
416
+ }, (args) => {
417
+ try {
418
+ if (!this.approvalService) {
419
+ throw new Error('MCP bridge not enabled');
420
+ }
421
+ return this.toolResult(approveMCPRequestTool(this.approvalService, args));
422
+ }
423
+ catch (error) {
424
+ return this.toolErrorResult(error);
425
+ }
426
+ });
427
+ // mcp_status
428
+ this.server.registerTool('mcp_status', {
429
+ description: 'Get status of MCP bridge, servers, and pending approvals',
430
+ annotations: {
431
+ readOnlyHint: true,
432
+ openWorldHint: true,
433
+ },
434
+ }, async () => {
435
+ try {
436
+ if (!this.mcpClientManager || !this.approvalService || !this.functionBridge) {
437
+ throw new Error('MCP bridge not enabled');
438
+ }
439
+ return this.toolResult(await mcpStatusTool(this.mcpClientManager, this.approvalService, this.functionBridge, {}));
440
+ }
441
+ catch (error) {
442
+ return this.toolErrorResult(error);
443
+ }
444
+ });
445
+ }
446
+ }
447
+ registerPrompts() {
448
+ for (const [name, prompt] of Object.entries(PROMPTS)) {
449
+ // Convert prompt.arguments array to Zod schema
450
+ const argsSchema = {};
451
+ for (const arg of prompt.arguments || []) {
452
+ argsSchema[arg.name] = arg.required
453
+ ? z.string().describe(arg.description || '')
454
+ : z.string().optional().describe(arg.description || '');
455
+ }
456
+ this.server.registerPrompt(name, {
457
+ description: prompt.description,
458
+ argsSchema,
459
+ }, (args) => {
460
+ try {
461
+ const messages = prompt.buildMessages((args || {}));
462
+ return { messages };
463
+ }
464
+ catch (error) {
465
+ const errorMessage = error instanceof Error ? error.message : String(error);
466
+ logger.error(`Prompt error for ${name}:`, errorMessage);
467
+ throw error;
468
+ }
469
+ });
470
+ }
211
471
  }
212
472
  // MCP-enhanced tool handlers
213
473
  async handleAskDuckWithMCP(args) {
@@ -309,408 +569,6 @@ export class RubberDuckServer {
309
569
  }
310
570
  return formatted;
311
571
  }
312
- getTools() {
313
- const baseTools = [
314
- {
315
- name: 'ask_duck',
316
- description: this.mcpEnabled
317
- ? 'Ask a question to a specific LLM provider (duck) with MCP tool access'
318
- : 'Ask a question to a specific LLM provider (duck)',
319
- inputSchema: {
320
- type: 'object',
321
- properties: {
322
- prompt: {
323
- type: 'string',
324
- description: 'The question or prompt to send to the duck',
325
- },
326
- provider: {
327
- type: 'string',
328
- description: 'The provider name (optional, uses default if not specified)',
329
- },
330
- model: {
331
- type: 'string',
332
- description: 'Specific model to use (optional, uses provider default if not specified)',
333
- },
334
- temperature: {
335
- type: 'number',
336
- description: 'Temperature for response generation (0-2)',
337
- minimum: 0,
338
- maximum: 2,
339
- },
340
- },
341
- required: ['prompt'],
342
- },
343
- annotations: {
344
- readOnlyHint: true,
345
- openWorldHint: true,
346
- },
347
- },
348
- {
349
- name: 'chat_with_duck',
350
- description: 'Have a conversation with a duck, maintaining context across messages',
351
- inputSchema: {
352
- type: 'object',
353
- properties: {
354
- conversation_id: {
355
- type: 'string',
356
- description: 'Conversation ID (creates new if not exists)',
357
- },
358
- message: {
359
- type: 'string',
360
- description: 'Your message to the duck',
361
- },
362
- provider: {
363
- type: 'string',
364
- description: 'Provider to use (can switch mid-conversation)',
365
- },
366
- model: {
367
- type: 'string',
368
- description: 'Specific model to use (optional)',
369
- },
370
- },
371
- required: ['conversation_id', 'message'],
372
- },
373
- annotations: {
374
- openWorldHint: true,
375
- },
376
- },
377
- {
378
- name: 'clear_conversations',
379
- description: 'Clear all conversation history and start fresh',
380
- inputSchema: {
381
- type: 'object',
382
- properties: {},
383
- },
384
- annotations: {
385
- destructiveHint: true,
386
- idempotentHint: true,
387
- openWorldHint: false,
388
- },
389
- },
390
- {
391
- name: 'list_ducks',
392
- description: 'List all available LLM providers (ducks) and their status',
393
- inputSchema: {
394
- type: 'object',
395
- properties: {
396
- check_health: {
397
- type: 'boolean',
398
- description: 'Perform health check on all providers',
399
- default: false,
400
- },
401
- },
402
- },
403
- annotations: {
404
- readOnlyHint: true,
405
- openWorldHint: true,
406
- },
407
- },
408
- {
409
- name: 'list_models',
410
- description: 'List available models for LLM providers',
411
- inputSchema: {
412
- type: 'object',
413
- properties: {
414
- provider: {
415
- type: 'string',
416
- description: 'Provider name (optional, lists all if not specified)',
417
- },
418
- fetch_latest: {
419
- type: 'boolean',
420
- description: 'Fetch latest models from API vs using cached/configured',
421
- default: false,
422
- },
423
- },
424
- },
425
- annotations: {
426
- readOnlyHint: true,
427
- openWorldHint: true,
428
- },
429
- },
430
- {
431
- name: 'compare_ducks',
432
- description: 'Ask the same question to multiple ducks simultaneously',
433
- inputSchema: {
434
- type: 'object',
435
- properties: {
436
- prompt: {
437
- type: 'string',
438
- description: 'The question to ask all ducks',
439
- },
440
- providers: {
441
- type: 'array',
442
- items: {
443
- type: 'string',
444
- },
445
- description: 'List of provider names to query (optional, uses all if not specified)',
446
- },
447
- model: {
448
- type: 'string',
449
- description: 'Specific model to use for all providers (optional)',
450
- },
451
- },
452
- required: ['prompt'],
453
- },
454
- annotations: {
455
- readOnlyHint: true,
456
- openWorldHint: true,
457
- },
458
- },
459
- {
460
- name: 'duck_council',
461
- description: 'Get responses from all configured ducks (like a panel discussion)',
462
- inputSchema: {
463
- type: 'object',
464
- properties: {
465
- prompt: {
466
- type: 'string',
467
- description: 'The question for the duck council',
468
- },
469
- model: {
470
- type: 'string',
471
- description: 'Specific model to use for all ducks (optional)',
472
- },
473
- },
474
- required: ['prompt'],
475
- },
476
- annotations: {
477
- readOnlyHint: true,
478
- openWorldHint: true,
479
- },
480
- },
481
- {
482
- name: 'duck_vote',
483
- description: 'Have multiple ducks vote on options with reasoning. Returns vote tally, confidence scores, and consensus level.',
484
- inputSchema: {
485
- type: 'object',
486
- properties: {
487
- question: {
488
- type: 'string',
489
- description: 'The question to vote on (e.g., "Best approach for error handling?")',
490
- },
491
- options: {
492
- type: 'array',
493
- items: { type: 'string' },
494
- minItems: 2,
495
- maxItems: 10,
496
- description: 'The options to vote on (2-10 options)',
497
- },
498
- voters: {
499
- type: 'array',
500
- items: { type: 'string' },
501
- description: 'List of provider names to vote (optional, uses all if not specified)',
502
- },
503
- require_reasoning: {
504
- type: 'boolean',
505
- default: true,
506
- description: 'Require ducks to explain their vote (default: true)',
507
- },
508
- },
509
- required: ['question', 'options'],
510
- },
511
- annotations: {
512
- readOnlyHint: true,
513
- openWorldHint: true,
514
- },
515
- },
516
- {
517
- name: 'duck_judge',
518
- description: 'Have one duck evaluate and rank other ducks\' responses. Use after duck_council to get a comparative evaluation.',
519
- inputSchema: {
520
- type: 'object',
521
- properties: {
522
- responses: {
523
- type: 'array',
524
- items: {
525
- type: 'object',
526
- properties: {
527
- provider: { type: 'string' },
528
- nickname: { type: 'string' },
529
- model: { type: 'string' },
530
- content: { type: 'string' },
531
- },
532
- required: ['provider', 'nickname', 'content'],
533
- },
534
- minItems: 2,
535
- description: 'Array of duck responses to evaluate (from duck_council output)',
536
- },
537
- judge: {
538
- type: 'string',
539
- description: 'Provider name of the judge duck (optional, uses first available)',
540
- },
541
- criteria: {
542
- type: 'array',
543
- items: { type: 'string' },
544
- description: 'Evaluation criteria (default: ["accuracy", "completeness", "clarity"])',
545
- },
546
- persona: {
547
- type: 'string',
548
- description: 'Judge persona (e.g., "senior engineer", "security expert")',
549
- },
550
- },
551
- required: ['responses'],
552
- },
553
- annotations: {
554
- readOnlyHint: true,
555
- openWorldHint: true,
556
- },
557
- },
558
- {
559
- name: 'duck_iterate',
560
- description: 'Iteratively refine a response between two ducks. One generates, the other critiques/improves, alternating for multiple rounds.',
561
- inputSchema: {
562
- type: 'object',
563
- properties: {
564
- prompt: {
565
- type: 'string',
566
- description: 'The initial prompt/task to iterate on',
567
- },
568
- iterations: {
569
- type: 'number',
570
- minimum: 1,
571
- maximum: 10,
572
- default: 3,
573
- description: 'Number of iteration rounds (default: 3, max: 10)',
574
- },
575
- providers: {
576
- type: 'array',
577
- items: { type: 'string' },
578
- minItems: 2,
579
- maxItems: 2,
580
- description: 'Exactly 2 provider names for the ping-pong iteration',
581
- },
582
- mode: {
583
- type: 'string',
584
- enum: ['refine', 'critique-improve'],
585
- description: 'refine: each duck improves the previous response. critique-improve: alternates between critiquing and improving.',
586
- },
587
- },
588
- required: ['prompt', 'providers', 'mode'],
589
- },
590
- annotations: {
591
- readOnlyHint: true,
592
- openWorldHint: true,
593
- },
594
- },
595
- {
596
- name: 'duck_debate',
597
- description: 'Structured multi-round debate between ducks. Supports oxford (pro/con), socratic (questioning), and adversarial (attack/defend) formats.',
598
- inputSchema: {
599
- type: 'object',
600
- properties: {
601
- prompt: {
602
- type: 'string',
603
- description: 'The debate topic or proposition',
604
- },
605
- rounds: {
606
- type: 'number',
607
- minimum: 1,
608
- maximum: 10,
609
- default: 3,
610
- description: 'Number of debate rounds (default: 3)',
611
- },
612
- providers: {
613
- type: 'array',
614
- items: { type: 'string' },
615
- minItems: 2,
616
- description: 'Provider names to participate (min 2, uses all if not specified)',
617
- },
618
- format: {
619
- type: 'string',
620
- enum: ['oxford', 'socratic', 'adversarial'],
621
- description: 'Debate format: oxford (pro/con), socratic (questioning), adversarial (attack/defend)',
622
- },
623
- synthesizer: {
624
- type: 'string',
625
- description: 'Provider to synthesize the debate (optional, uses first provider)',
626
- },
627
- },
628
- required: ['prompt', 'format'],
629
- },
630
- annotations: {
631
- readOnlyHint: true,
632
- openWorldHint: true,
633
- },
634
- },
635
- {
636
- name: 'get_usage_stats',
637
- description: 'Get usage statistics for a time period. Shows token counts and costs (when pricing configured).',
638
- inputSchema: {
639
- type: 'object',
640
- properties: {
641
- period: {
642
- type: 'string',
643
- enum: ['today', '7d', '30d', 'all'],
644
- default: 'today',
645
- description: 'Time period for stats',
646
- },
647
- },
648
- },
649
- annotations: {
650
- readOnlyHint: true,
651
- openWorldHint: false,
652
- },
653
- },
654
- ];
655
- // Add MCP-specific tools if enabled
656
- if (this.mcpEnabled) {
657
- baseTools.push({
658
- name: 'get_pending_approvals',
659
- description: 'Get list of pending MCP tool approvals from ducks',
660
- inputSchema: {
661
- type: 'object',
662
- properties: {
663
- duck: {
664
- type: 'string',
665
- description: 'Filter by duck name (optional)',
666
- },
667
- },
668
- },
669
- annotations: {
670
- readOnlyHint: true,
671
- openWorldHint: false,
672
- },
673
- }, {
674
- name: 'approve_mcp_request',
675
- description: "Approve or deny a duck's MCP tool request",
676
- inputSchema: {
677
- type: 'object',
678
- properties: {
679
- approval_id: {
680
- type: 'string',
681
- description: 'The approval request ID',
682
- },
683
- decision: {
684
- type: 'string',
685
- enum: ['approve', 'deny'],
686
- description: 'Whether to approve or deny the request',
687
- },
688
- reason: {
689
- type: 'string',
690
- description: 'Reason for denial (optional)',
691
- },
692
- },
693
- required: ['approval_id', 'decision'],
694
- },
695
- annotations: {
696
- idempotentHint: true,
697
- openWorldHint: false,
698
- },
699
- }, {
700
- name: 'mcp_status',
701
- description: 'Get status of MCP bridge, servers, and pending approvals',
702
- inputSchema: {
703
- type: 'object',
704
- properties: {},
705
- },
706
- annotations: {
707
- readOnlyHint: true,
708
- openWorldHint: true,
709
- },
710
- });
711
- }
712
- return baseTools;
713
- }
714
572
  async start() {
715
573
  // Only show welcome message when not running as MCP server
716
574
  const isMCP = process.env.MCP_SERVER === 'true' || process.argv.includes('--mcp');