@arikusi/deepseek-mcp-server 1.1.0 → 1.2.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/README.md +72 -18
  3. package/dist/config.d.ts +7 -1
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +16 -11
  6. package/dist/config.js.map +1 -1
  7. package/dist/cost.d.ts +30 -13
  8. package/dist/cost.d.ts.map +1 -1
  9. package/dist/cost.js +58 -19
  10. package/dist/cost.js.map +1 -1
  11. package/dist/deepseek-client.d.ts +8 -0
  12. package/dist/deepseek-client.d.ts.map +1 -1
  13. package/dist/deepseek-client.js +90 -48
  14. package/dist/deepseek-client.js.map +1 -1
  15. package/dist/errors.d.ts +71 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +74 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/index.d.ts +0 -3
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +33 -614
  22. package/dist/index.js.map +1 -1
  23. package/dist/prompts/advanced.d.ts +8 -0
  24. package/dist/prompts/advanced.d.ts.map +1 -0
  25. package/dist/prompts/advanced.js +187 -0
  26. package/dist/prompts/advanced.js.map +1 -0
  27. package/dist/prompts/core.d.ts +8 -0
  28. package/dist/prompts/core.d.ts.map +1 -0
  29. package/dist/prompts/core.js +188 -0
  30. package/dist/prompts/core.js.map +1 -0
  31. package/dist/prompts/function-calling.d.ts +7 -0
  32. package/dist/prompts/function-calling.d.ts.map +1 -0
  33. package/dist/prompts/function-calling.js +87 -0
  34. package/dist/prompts/function-calling.js.map +1 -0
  35. package/dist/prompts/index.d.ts +7 -0
  36. package/dist/prompts/index.d.ts.map +1 -0
  37. package/dist/prompts/index.js +13 -0
  38. package/dist/prompts/index.js.map +1 -0
  39. package/dist/schemas.d.ts +59 -20
  40. package/dist/schemas.d.ts.map +1 -1
  41. package/dist/schemas.js +9 -2
  42. package/dist/schemas.js.map +1 -1
  43. package/dist/server.d.ts +9 -0
  44. package/dist/server.d.ts.map +1 -0
  45. package/dist/server.js +16 -0
  46. package/dist/server.js.map +1 -0
  47. package/dist/tools/deepseek-chat.d.ts +8 -0
  48. package/dist/tools/deepseek-chat.d.ts.map +1 -0
  49. package/dist/tools/deepseek-chat.js +184 -0
  50. package/dist/tools/deepseek-chat.js.map +1 -0
  51. package/dist/tools/index.d.ts +8 -0
  52. package/dist/tools/index.d.ts.map +1 -0
  53. package/dist/tools/index.js +9 -0
  54. package/dist/tools/index.js.map +1 -0
  55. package/dist/types.d.ts +94 -0
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/types.js +20 -1
  58. package/dist/types.js.map +1 -1
  59. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2,627 +2,46 @@
2
2
  /**
3
3
  * DeepSeek MCP Server
4
4
  * Model Context Protocol server for DeepSeek API integration
5
- *
6
- * This server exposes DeepSeek's chat and reasoning models as MCP tools
7
- * that can be used by Claude Code and other MCP clients.
8
5
  */
9
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
10
6
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
11
- import { z } from 'zod';
12
- import { loadConfig, getConfig } from './config.js';
13
- import { calculateCost, formatCost } from './cost.js';
14
- import { ExtendedMessageSchema, ChatInputWithToolsSchema, ToolDefinitionSchema, ToolChoiceSchema, } from './schemas.js';
7
+ import { loadConfig } from './config.js';
8
+ import { ConfigError } from './errors.js';
15
9
  import { DeepSeekClient } from './deepseek-client.js';
16
- // Load and validate configuration
17
- const config = loadConfig();
18
- // Initialize DeepSeek client (uses getConfig() internally)
19
- const deepseek = new DeepSeekClient();
20
- // Create MCP server
21
- const server = new McpServer({
22
- name: 'deepseek-mcp-server',
23
- version: '1.1.0',
24
- });
25
- /**
26
- * Tool: deepseek_chat
27
- *
28
- * Chat completion with DeepSeek models.
29
- * Supports both deepseek-chat and deepseek-reasoner (R1) models.
30
- * Supports function calling via the tools parameter.
31
- */
32
- server.registerTool('deepseek_chat', {
33
- title: 'DeepSeek Chat Completion',
34
- description: 'Chat with DeepSeek AI models. Supports deepseek-chat for general conversations and ' +
35
- 'deepseek-reasoner (R1) for complex reasoning tasks with chain-of-thought explanations. ' +
36
- 'Supports function calling via the tools parameter for structured tool use. ' +
37
- 'The reasoner model provides both reasoning_content (thinking process) and content (final answer).',
38
- inputSchema: {
39
- messages: z
40
- .array(ExtendedMessageSchema)
41
- .min(1)
42
- .describe('Array of conversation messages. Each message has role (system/user/assistant/tool) and content. Tool messages require tool_call_id.'),
43
- model: z
44
- .enum(['deepseek-chat', 'deepseek-reasoner'])
45
- .default('deepseek-chat')
46
- .describe('Model to use. deepseek-chat for general tasks, deepseek-reasoner for complex reasoning'),
47
- temperature: z
48
- .number()
49
- .min(0)
50
- .max(2)
51
- .optional()
52
- .describe('Sampling temperature (0-2). Higher = more random. Default: 1.0'),
53
- max_tokens: z
54
- .number()
55
- .min(1)
56
- .max(32768)
57
- .optional()
58
- .describe('Maximum tokens to generate. Default: model maximum'),
59
- stream: z
60
- .boolean()
61
- .optional()
62
- .default(false)
63
- .describe('Enable streaming mode. Returns full response after streaming completes.'),
64
- tools: z
65
- .array(ToolDefinitionSchema)
66
- .max(128)
67
- .optional()
68
- .describe('Array of tool definitions for function calling. Each tool has type "function" and a function object with name, description, and parameters (JSON Schema).'),
69
- tool_choice: ToolChoiceSchema.optional().describe('Controls which tool the model calls. "auto" (default), "none", "required", or {type:"function",function:{name:"..."}}'),
70
- },
71
- outputSchema: {
72
- content: z.string(),
73
- reasoning_content: z.string().optional(),
74
- model: z.string(),
75
- usage: z.object({
76
- prompt_tokens: z.number(),
77
- completion_tokens: z.number(),
78
- total_tokens: z.number(),
79
- }),
80
- finish_reason: z.string(),
81
- tool_calls: z
82
- .array(z.object({
83
- id: z.string(),
84
- type: z.literal('function'),
85
- function: z.object({
86
- name: z.string(),
87
- arguments: z.string(),
88
- }),
89
- }))
90
- .optional(),
91
- },
92
- }, async (input) => {
10
+ import { createServer, version } from './server.js';
11
+ import { registerAllTools } from './tools/index.js';
12
+ import { registerAllPrompts } from './prompts/index.js';
13
+ async function main() {
14
+ // Load and validate configuration
93
15
  try {
94
- // Validate input with extended schema (supports tools)
95
- const validated = ChatInputWithToolsSchema.parse(input);
96
- console.error(`[DeepSeek MCP] Request: model=${validated.model}, messages=${validated.messages.length}, stream=${validated.stream}${validated.tools ? `, tools=${validated.tools.length}` : ''}`);
97
- // Call appropriate method based on stream parameter
98
- const response = validated.stream
99
- ? await deepseek.createStreamingChatCompletion({
100
- model: validated.model,
101
- messages: validated.messages,
102
- temperature: validated.temperature,
103
- max_tokens: validated.max_tokens,
104
- tools: validated.tools,
105
- tool_choice: validated.tool_choice,
106
- })
107
- : await deepseek.createChatCompletion({
108
- model: validated.model,
109
- messages: validated.messages,
110
- temperature: validated.temperature,
111
- max_tokens: validated.max_tokens,
112
- tools: validated.tools,
113
- tool_choice: validated.tool_choice,
114
- });
115
- console.error(`[DeepSeek MCP] Response: tokens=${response.usage.total_tokens}, finish_reason=${response.finish_reason}${response.tool_calls ? `, tool_calls=${response.tool_calls.length}` : ''}`);
116
- // Format response
117
- let responseText = '';
118
- // Add reasoning content if available (for deepseek-reasoner)
119
- if (response.reasoning_content) {
120
- responseText += `<thinking>\n${response.reasoning_content}\n</thinking>\n\n`;
121
- }
122
- responseText += response.content;
123
- // Format tool calls if present
124
- if (response.tool_calls?.length) {
125
- responseText += '\n\n**Function Calls:**\n';
126
- for (const tc of response.tool_calls) {
127
- responseText += `\`${tc.function.name}\`\n`;
128
- responseText += `- Call ID: ${tc.id}\n`;
129
- responseText += `- Arguments: ${tc.function.arguments}\n\n`;
130
- }
131
- }
132
- // Calculate cost
133
- const cost = calculateCost(response.usage.prompt_tokens, response.usage.completion_tokens, response.model);
134
- // Add usage stats with cost information (controlled by config)
135
- if (getConfig().showCostInfo) {
136
- responseText += `\n---\n**Request Information:**\n`;
137
- responseText += `- **Tokens:** ${response.usage.total_tokens} (${response.usage.prompt_tokens} prompt + ${response.usage.completion_tokens} completion)\n`;
138
- responseText += `- **Model:** ${response.model}\n`;
139
- responseText += `- **Cost:** ${formatCost(cost)}`;
140
- if (response.tool_calls?.length) {
141
- responseText += `\n- **Tool Calls:** ${response.tool_calls.length}`;
142
- }
143
- }
144
- return {
145
- content: [
146
- {
147
- type: 'text',
148
- text: responseText,
149
- },
150
- ],
151
- structuredContent: {
152
- ...response,
153
- cost_usd: parseFloat(cost.toFixed(6)),
154
- },
155
- };
16
+ loadConfig();
156
17
  }
157
18
  catch (error) {
158
- console.error('[DeepSeek MCP] Error:', error);
159
- const errorMessage = error?.message || 'Unknown error occurred';
160
- return {
161
- content: [
162
- {
163
- type: 'text',
164
- text: `Error: ${errorMessage}`,
165
- },
166
- ],
167
- isError: true,
168
- };
169
- }
170
- });
171
- /**
172
- * Register MCP Prompts
173
- * Pre-built prompt templates for common reasoning tasks
174
- */
175
- // Core Reasoning Prompts
176
- server.registerPrompt('debug_with_reasoning', {
177
- title: 'Debug Code with Reasoning',
178
- description: 'Debug code issues using DeepSeek R1 reasoning model with step-by-step analysis',
179
- argsSchema: {
180
- code: z.string().describe('Code to debug'),
181
- error: z
182
- .string()
183
- .optional()
184
- .describe('Error message or description of the issue'),
185
- language: z.string().optional().describe('Programming language'),
186
- },
187
- }, ({ code, error, language }, _extra) => ({
188
- messages: [
189
- {
190
- role: 'user',
191
- content: {
192
- type: 'text',
193
- text: `You are an expert debugging assistant. Analyze this code using deep reasoning.
194
-
195
- ${language ? `Language: ${language}` : ''}
196
- ${error ? `Error/Issue: ${error}` : ''}
197
-
198
- Code:
199
- \`\`\`
200
- ${code}
201
- \`\`\`
202
-
203
- Please:
204
- 1. Identify the bug or issue
205
- 2. Explain your reasoning process step-by-step
206
- 3. Suggest a fix with explanation
207
- 4. Provide the corrected code
208
-
209
- Use the deepseek_chat tool with model: "deepseek-reasoner" for detailed reasoning.`,
210
- },
211
- },
212
- ],
213
- }));
214
- server.registerPrompt('code_review_deep', {
215
- title: 'Deep Code Review',
216
- description: 'Comprehensive code review analyzing quality, security, performance, and best practices',
217
- argsSchema: {
218
- code: z.string().describe('Code to review'),
219
- language: z.string().optional().describe('Programming language'),
220
- focus: z
221
- .enum(['security', 'performance', 'quality', 'all'])
222
- .default('all')
223
- .describe('Review focus area'),
224
- },
225
- }, ({ code, language, focus }, _extra) => ({
226
- messages: [
227
- {
228
- role: 'user',
229
- content: {
230
- type: 'text',
231
- text: `You are an expert code reviewer. Perform a comprehensive code review.
232
-
233
- ${language ? `Language: ${language}` : ''}
234
- Focus: ${focus === 'all' ? 'Security, Performance, Code Quality, Best Practices' : focus}
235
-
236
- Code:
237
- \`\`\`
238
- ${code}
239
- \`\`\`
240
-
241
- For each issue found, provide:
242
- 1. **Issue**: What's wrong
243
- 2. **Reasoning**: Why it's a problem
244
- 3. **Severity**: Critical/High/Medium/Low
245
- 4. **Fix**: How to resolve it
246
-
247
- Use the deepseek_chat tool with model: "deepseek-reasoner" for thorough analysis.`,
248
- },
249
- },
250
- ],
251
- }));
252
- server.registerPrompt('research_synthesis', {
253
- title: 'Research & Synthesis',
254
- description: 'Research a topic and synthesize information into a structured report',
255
- argsSchema: {
256
- topic: z.string().describe('Topic to research'),
257
- context: z
258
- .string()
259
- .optional()
260
- .describe('Additional context or specific questions'),
261
- depth: z
262
- .enum(['brief', 'moderate', 'comprehensive'])
263
- .default('moderate')
264
- .describe('Research depth'),
265
- },
266
- }, ({ topic, context, depth }, _extra) => ({
267
- messages: [
268
- {
269
- role: 'user',
270
- content: {
271
- type: 'text',
272
- text: `You are a research assistant. Research and synthesize information about this topic.
273
-
274
- Topic: ${topic}
275
- ${context ? `Context: ${context}` : ''}
276
- Depth: ${depth}
277
-
278
- Please provide:
279
- 1. **Overview**: Brief summary
280
- 2. **Key Findings**: Main points with reasoning
281
- 3. **Analysis**: Deep dive with reasoning process
282
- 4. **Conclusion**: Synthesis and implications
283
- 5. **Sources**: Cite reasoning steps
284
-
285
- Use the deepseek_chat tool with model: "deepseek-reasoner" for comprehensive analysis.`,
286
- },
287
- },
288
- ],
289
- }));
290
- server.registerPrompt('strategic_planning', {
291
- title: 'Strategic Planning',
292
- description: 'Analyze options and create strategic plans with reasoning for each decision',
293
- argsSchema: {
294
- goal: z.string().describe('Goal or objective'),
295
- context: z.string().optional().describe('Situational context'),
296
- constraints: z.string().optional().describe('Constraints or limitations'),
297
- },
298
- }, ({ goal, context, constraints }, _extra) => ({
299
- messages: [
300
- {
301
- role: 'user',
302
- content: {
303
- type: 'text',
304
- text: `You are a strategic planning expert. Create a detailed plan with reasoning.
305
-
306
- Goal: ${goal}
307
- ${context ? `Context: ${context}` : ''}
308
- ${constraints ? `Constraints: ${constraints}` : ''}
309
-
310
- Please provide:
311
- 1. **Situation Analysis**: Current state with reasoning
312
- 2. **Options**: List possible approaches
313
- 3. **Evaluation**: Pros/cons of each option with reasoning
314
- 4. **Recommendation**: Best approach with detailed reasoning
315
- 5. **Action Plan**: Step-by-step plan with rationale
316
-
317
- Use the deepseek_chat tool with model: "deepseek-reasoner" for thorough strategic thinking.`,
318
- },
319
- },
320
- ],
321
- }));
322
- server.registerPrompt('explain_like_im_five', {
323
- title: "Explain Like I'm Five",
324
- description: 'Explain complex topics in simple terms using analogies and reasoning',
325
- argsSchema: {
326
- topic: z.string().describe('Complex topic to explain'),
327
- audience: z
328
- .enum(['child', 'beginner', 'intermediate'])
329
- .default('beginner')
330
- .describe('Target audience level'),
331
- },
332
- }, ({ topic, audience }, _extra) => ({
333
- messages: [
334
- {
335
- role: 'user',
336
- content: {
337
- type: 'text',
338
- text: `You are an expert explainer. Make complex topics simple and understandable.
339
-
340
- Topic: ${topic}
341
- Audience: ${audience}
342
-
343
- Please:
344
- 1. Start with a simple analogy or metaphor
345
- 2. Break down the concept step-by-step
346
- 3. Use everyday examples
347
- 4. Show your reasoning for why this explanation works
348
- 5. Build up complexity gradually if needed
349
-
350
- Use the deepseek_chat tool with model: "deepseek-reasoner" to ensure logical explanations.`,
351
- },
352
- },
353
- ],
354
- }));
355
- // Advanced Prompts
356
- server.registerPrompt('mathematical_proof', {
357
- title: 'Mathematical Proof',
358
- description: 'Prove mathematical statements with rigorous step-by-step reasoning',
359
- argsSchema: {
360
- statement: z.string().describe('Mathematical statement to prove'),
361
- context: z.string().optional().describe('Mathematical context or axioms'),
362
- },
363
- }, ({ statement, context }, _extra) => ({
364
- messages: [
365
- {
366
- role: 'user',
367
- content: {
368
- type: 'text',
369
- text: `You are a mathematician. Provide a rigorous proof.
370
-
371
- Statement to prove: ${statement}
372
- ${context ? `Context/Axioms: ${context}` : ''}
373
-
374
- Provide:
375
- 1. **Given**: What we know
376
- 2. **To Prove**: What we're proving
377
- 3. **Proof**: Step-by-step logical reasoning
378
- 4. **Conclusion**: QED statement
379
-
380
- Use the deepseek_chat tool with model: "deepseek-reasoner" for strict logical reasoning.`,
381
- },
382
- },
383
- ],
384
- }));
385
- server.registerPrompt('argument_validation', {
386
- title: 'Argument Validation',
387
- description: 'Analyze arguments for logical fallacies and reasoning errors',
388
- argsSchema: {
389
- argument: z.string().describe('Argument to validate'),
390
- type: z
391
- .enum(['informal', 'formal', 'both'])
392
- .default('informal')
393
- .describe('Analysis type'),
394
- },
395
- }, ({ argument, type }, _extra) => ({
396
- messages: [
397
- {
398
- role: 'user',
399
- content: {
400
- type: 'text',
401
- text: `You are a logic expert. Analyze this argument for validity.
402
-
403
- Argument:
404
- ${argument}
405
-
406
- Analysis type: ${type}
407
-
408
- Please identify:
409
- 1. **Structure**: Break down the argument's structure
410
- 2. **Premises**: List all premises and assumptions
411
- 3. **Conclusion**: What's being claimed
412
- 4. **Reasoning**: Analyze the logical flow
413
- 5. **Fallacies**: Any logical fallacies or errors
414
- 6. **Validity**: Is the reasoning sound?
415
- 7. **Improvements**: How to strengthen the argument
416
-
417
- Use the deepseek_chat tool with model: "deepseek-reasoner" for thorough logical analysis.`,
418
- },
419
- },
420
- ],
421
- }));
422
- server.registerPrompt('creative_ideation', {
423
- title: 'Creative Ideation',
424
- description: 'Generate creative ideas with reasoning for feasibility and value',
425
- argsSchema: {
426
- challenge: z.string().describe('Problem or challenge to solve'),
427
- constraints: z
428
- .string()
429
- .optional()
430
- .describe('Constraints or requirements'),
431
- quantity: z
432
- .number()
433
- .min(1)
434
- .max(20)
435
- .default(5)
436
- .describe('Number of ideas to generate'),
437
- },
438
- }, ({ challenge, constraints, quantity }, _extra) => ({
439
- messages: [
440
- {
441
- role: 'user',
442
- content: {
443
- type: 'text',
444
- text: `You are a creative problem solver. Generate innovative ideas with reasoning.
445
-
446
- Challenge: ${challenge}
447
- ${constraints ? `Constraints: ${constraints}` : ''}
448
- Ideas needed: ${quantity}
449
-
450
- For each idea, provide:
451
- 1. **Idea**: The concept
452
- 2. **Reasoning**: Why this could work
453
- 3. **Feasibility**: How realistic it is (High/Medium/Low)
454
- 4. **Value**: Potential impact
455
- 5. **Next Steps**: How to validate/implement
456
-
457
- Use the deepseek_chat tool with model: "deepseek-reasoner" for reasoned creativity.`,
458
- },
459
- },
460
- ],
461
- }));
462
- server.registerPrompt('cost_comparison', {
463
- title: 'LLM Cost Comparison',
464
- description: 'Compare costs of different LLMs for a task and show savings with DeepSeek',
465
- argsSchema: {
466
- task: z.string().describe('Task description'),
467
- estimated_tokens: z
468
- .number()
469
- .min(100)
470
- .describe('Estimated token count (prompt + completion)'),
471
- },
472
- }, ({ task, estimated_tokens }, _extra) => ({
473
- messages: [
474
- {
475
- role: 'user',
476
- content: {
477
- type: 'text',
478
- text: `You are a cost analysis expert. Compare LLM costs for this task.
479
-
480
- Task: ${task}
481
- Estimated tokens: ${estimated_tokens} (prompt + completion)
482
-
483
- Calculate costs for:
484
- 1. **DeepSeek Chat**: $0.14/1M prompt + $0.28/1M completion
485
- 2. **DeepSeek Reasoner**: $0.42/1M prompt + $0.42/1M completion
486
- 3. **Claude Sonnet**: $3/1M prompt + $15/1M completion
487
- 4. **GPT-4**: $2.50/1M prompt + $10/1M completion
488
-
489
- Show:
490
- - Cost breakdown per model
491
- - Savings percentage with DeepSeek
492
- - When to use which model (cost vs quality)
493
-
494
- Use the deepseek_chat tool with model: "deepseek-chat" for this analysis.`,
495
- },
496
- },
497
- ],
498
- }));
499
- server.registerPrompt('pair_programming', {
500
- title: 'Pair Programming',
501
- description: 'Interactive coding assistant that explains reasoning for code decisions',
502
- argsSchema: {
503
- task: z.string().describe('Coding task'),
504
- language: z.string().describe('Programming language'),
505
- style: z
506
- .enum(['beginner', 'intermediate', 'expert'])
507
- .default('intermediate')
508
- .describe('Code complexity level'),
509
- },
510
- }, ({ task, language, style }, _extra) => ({
511
- messages: [
512
- {
513
- role: 'user',
514
- content: {
515
- type: 'text',
516
- text: `You are a pair programming partner. Help me write code with clear reasoning.
517
-
518
- Task: ${task}
519
- Language: ${language}
520
- Level: ${style}
521
-
522
- Please:
523
- 1. **Plan**: Break down the task with reasoning
524
- 2. **Code**: Write clean, commented code
525
- 3. **Explain**: Explain each major decision
526
- 4. **Test**: Suggest test cases with reasoning
527
- 5. **Optimize**: Mention potential improvements
528
-
529
- Use the deepseek_chat tool with model: "deepseek-reasoner" for thoughtful code generation.`,
530
- },
531
- },
532
- ],
533
- }));
534
- // Function Calling Prompts
535
- server.registerPrompt('function_call_debug', {
536
- title: 'Function Calling Debug',
537
- description: 'Debug function calling issues with DeepSeek models',
538
- argsSchema: {
539
- tools_json: z.string().describe('JSON string of tool definitions'),
540
- messages_json: z
541
- .string()
542
- .describe('JSON string of conversation messages'),
543
- error: z
544
- .string()
545
- .optional()
546
- .describe('Error message or unexpected behavior'),
547
- },
548
- }, ({ tools_json, messages_json, error }, _extra) => ({
549
- messages: [
550
- {
551
- role: 'user',
552
- content: {
553
- type: 'text',
554
- text: `You are a function calling expert. Debug this function calling setup.
555
-
556
- Tool Definitions:
557
- \`\`\`json
558
- ${tools_json}
559
- \`\`\`
560
-
561
- Messages:
562
- \`\`\`json
563
- ${messages_json}
564
- \`\`\`
565
-
566
- ${error ? `Error/Issue: ${error}` : 'The model is not calling the expected function.'}
567
-
568
- Please analyze:
569
- 1. **Tool Schema**: Are the tool definitions valid and well-structured?
570
- 2. **Messages**: Are messages properly formatted for function calling?
571
- 3. **Issue**: What might be causing the problem?
572
- 4. **Fix**: Suggest corrected tool definitions and/or messages
573
- 5. **Best Practices**: Tips for reliable function calling
574
-
575
- Use the deepseek_chat tool with model: "deepseek-reasoner" for thorough analysis.`,
576
- },
577
- },
578
- ],
579
- }));
580
- server.registerPrompt('create_function_schema', {
581
- title: 'Create Function Schema',
582
- description: 'Generate JSON Schema for function calling from natural language description',
583
- argsSchema: {
584
- description: z
585
- .string()
586
- .describe('Natural language description of the function'),
587
- examples: z.string().optional().describe('Example inputs/outputs'),
588
- },
589
- }, ({ description, examples }, _extra) => ({
590
- messages: [
591
- {
592
- role: 'user',
593
- content: {
594
- type: 'text',
595
- text: `You are an expert at creating JSON Schemas for function calling. Create a tool definition from this description.
596
-
597
- Function Description: ${description}
598
- ${examples ? `\nExamples:\n${examples}` : ''}
599
-
600
- Generate:
601
- 1. **Tool Definition**: Complete JSON tool definition with type, function name, description, and parameters schema
602
- 2. **Parameters**: Well-typed JSON Schema with descriptions for each parameter
603
- 3. **Required Fields**: Which parameters are required
604
- 4. **Example Call**: Show an example of how the model would call this function
605
- 5. **Usage**: How to use this with the deepseek_chat tool's \`tools\` parameter
606
-
607
- Output the tool definition as a JSON code block ready to use.
608
-
609
- Use the deepseek_chat tool with model: "deepseek-reasoner" for precise schema generation.`,
610
- },
611
- },
612
- ],
613
- }));
614
- // Start server with stdio transport
615
- async function main() {
616
- console.error('[DeepSeek MCP] Starting server v1.1.0...');
617
- // Test connection
618
- console.error('[DeepSeek MCP] Testing API connection...');
619
- const isConnected = await deepseek.testConnection();
620
- if (!isConnected) {
621
- console.error('[DeepSeek MCP] Warning: Failed to connect to DeepSeek API');
622
- console.error('[DeepSeek MCP] Please check your API key and internet connection');
19
+ if (error instanceof ConfigError) {
20
+ console.error('Error: ' + error.message);
21
+ for (const issue of error.issues) {
22
+ console.error(` - ${issue.path}: ${issue.message}`);
23
+ }
24
+ }
25
+ process.exit(1);
623
26
  }
624
- else {
625
- console.error('[DeepSeek MCP] API connection successful');
27
+ const config = loadConfig();
28
+ const deepseek = new DeepSeekClient();
29
+ const server = createServer();
30
+ // Register tools and prompts
31
+ registerAllTools(server, deepseek);
32
+ registerAllPrompts(server);
33
+ console.error(`[DeepSeek MCP] Starting server v${version}...`);
34
+ // Optional connection test (controlled by SKIP_CONNECTION_TEST env)
35
+ if (!config.skipConnectionTest) {
36
+ console.error('[DeepSeek MCP] Testing API connection...');
37
+ const isConnected = await deepseek.testConnection();
38
+ if (!isConnected) {
39
+ console.error('[DeepSeek MCP] Warning: Failed to connect to DeepSeek API');
40
+ console.error('[DeepSeek MCP] Please check your API key and internet connection');
41
+ }
42
+ else {
43
+ console.error('[DeepSeek MCP] API connection successful');
44
+ }
626
45
  }
627
46
  // Connect to stdio transport
628
47
  const transport = new StdioServerTransport();