{"record":{"id":"1f2a3865569d31f7","repo":"CherryHQ/cherry-studio","slug":"difyknowledgeserver-requires-at-least-one-argument","errorCode":null,"errorMessage":"DifyKnowledgeServer requires at least one argument","messagePattern":"DifyKnowledgeServer requires at least one argument","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/main/ai/mcp/servers/difyKnowledge.ts","lineNumber":59,"sourceCode":"\nconst SearchKnowledgeArgsSchema = z.object({\n  id: z.string().describe('Knowledge ID'),\n  query: z.string().describe('Query string'),\n  topK: z.number().optional().describe('Number of top results to return')\n})\n\ntype McpResponse = {\n  content: Array<{ type: 'text'; text: string }>\n  isError?: boolean\n}\n\nclass DifyKnowledgeServer {\n  public server: Server\n  private config: DifyKnowledgeServerConfig\n\n  constructor(difyKey: string, args: string[]) {\n    if (args.length === 0) {\n      throw new Error('DifyKnowledgeServer requires at least one argument')\n    }\n    this.config = {\n      difyKey: difyKey,\n      apiHost: args[0]\n    }\n    this.server = new Server(\n      {\n        name: '@cherry/dify-knowledge-server',\n        version: '0.1.0'\n      },\n      {\n        capabilities: {\n          tools: {}\n        }\n      }\n    )\n    this.initialize()\n  }","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/difyKnowledge.ts#L41-L77","documentation":"Generic Error thrown by the DifyKnowledgeServer constructor when the args array is empty. The constructor uses args[0] as the apiHost for all Dify API requests, so without it the server cannot form any URL. This is a startup/configuration failure, not a runtime tool-call error.","triggerScenarios":"Instantiating DifyKnowledgeServer via the factory (createInMemoryMcpServer) with an empty args array. In the factory, args defaults to [] when the MCP server configuration does not provide any command-line arguments.","commonSituations":"The MCP server entry for difyKnowledge in the user's config omits the 'args' field or sets it to an empty array; the apiHost was expected in args[0] but the configuration placed it elsewhere (e.g., in envs); copy-paste error when configuring the server.","solutions":["Add the Dify API host URL as the first element of the args array in the MCP server configuration.","Verify the server config entry has 'args': ['https://your-dify-host/v1'].","Ensure the configuration is loaded and parsed correctly before the factory is called."],"exampleFix":"// before — config omits args\n{ \"name\": \"dify-knowledge\", \"args\": [] }\n\n// after — provide apiHost as first arg\n{ \"name\": \"dify-knowledge\", \"args\": [\"https://api.dify.ai/v1\"] }","handlingStrategy":"validation","validationCode":"if (!args || args.length === 0) {\n  throw new Error('DifyKnowledgeServer requires the API host URL as the first argument (args[0])')\n}\nconst apiHost = args[0]\nif (!/^https?:\\/\\//.test(apiHost)) {\n  throw new Error(`Invalid apiHost: '${apiHost}'. Must be a full URL.`)\n}\nnew DifyKnowledgeServer(difyKey, args)","typeGuard":"function hasApiHostArg(args: unknown): args is [string, ...unknown[]] {\n  return Array.isArray(args) && args.length > 0 && typeof args[0] === 'string'\n}","tryCatchPattern":"try {\n  new DifyKnowledgeServer(difyKey, args)\n} catch (e) {\n  if (e instanceof Error && e.message.includes('at least one argument')) {\n    // fix the config to include the apiHost in args, then retry\n  }\n  throw e\n}","preventionTips":["Always provide the Dify API host URL as args[0] in the server configuration.","Validate the config has a non-empty args array before instantiating.","Use the full URL including the API base path (e.g., https://api.dify.ai/v1)."],"tags":["dify","configuration","missing-argument","startup"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}