CherryHQ/cherry-studio · critical · Error

DifyKnowledgeServer requires at least one argument

Error message

DifyKnowledgeServer requires at least one argument

What it means

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.

Source

Thrown at src/main/ai/mcp/servers/difyKnowledge.ts:59

const SearchKnowledgeArgsSchema = z.object({
  id: z.string().describe('Knowledge ID'),
  query: z.string().describe('Query string'),
  topK: z.number().optional().describe('Number of top results to return')
})

type McpResponse = {
  content: Array<{ type: 'text'; text: string }>
  isError?: boolean
}

class DifyKnowledgeServer {
  public server: Server
  private config: DifyKnowledgeServerConfig

  constructor(difyKey: string, args: string[]) {
    if (args.length === 0) {
      throw new Error('DifyKnowledgeServer requires at least one argument')
    }
    this.config = {
      difyKey: difyKey,
      apiHost: args[0]
    }
    this.server = new Server(
      {
        name: '@cherry/dify-knowledge-server',
        version: '0.1.0'
      },
      {
        capabilities: {
          tools: {}
        }
      }
    )
    this.initialize()
  }

View on GitHub (pinned to 726446b54c)

Solutions

  1. Add the Dify API host URL as the first element of the args array in the MCP server configuration.
  2. Verify the server config entry has 'args': ['https://your-dify-host/v1'].
  3. Ensure the configuration is loaded and parsed correctly before the factory is called.

Example fix

// before — config omits args
{ "name": "dify-knowledge", "args": [] }

// after — provide apiHost as first arg
{ "name": "dify-knowledge", "args": ["https://api.dify.ai/v1"] }
Defensive patterns

Strategy: validation

Validate before calling

if (!args || args.length === 0) {
  throw new Error('DifyKnowledgeServer requires the API host URL as the first argument (args[0])')
}
const apiHost = args[0]
if (!/^https?:\/\//.test(apiHost)) {
  throw new Error(`Invalid apiHost: '${apiHost}'. Must be a full URL.`)
}
new DifyKnowledgeServer(difyKey, args)

Type guard

function hasApiHostArg(args: unknown): args is [string, ...unknown[]] {
  return Array.isArray(args) && args.length > 0 && typeof args[0] === 'string'
}

Try / catch

try {
  new DifyKnowledgeServer(difyKey, args)
} catch (e) {
  if (e instanceof Error && e.message.includes('at least one argument')) {
    // fix the config to include the apiHost in args, then retry
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/1f2a3865569d31f7. Report an issue: GitHub.