CherryHQ/cherry-studio · critical · McpError

InternalError

InternalError

Error message

Agent not found: ${this.agentId}

What it means

The only non-InvalidParams error in this set: a config `status` call could not find the session's own agent in AgentService. This is MCP InternalError, meaning the server state is inconsistent rather than the caller's parameters being wrong. It implies the agent record was deleted while the MCP session was still bound to it, or the session's `agentId` is corrupt.

Source

Thrown at src/main/ai/mcp/servers/cherryAutonomyTools.ts:508

    // A requested payload that reached nobody because every attempt failed is a failed
    // tool call — otherwise the agent sees success while the user received nothing
    // (unsupported adapter, platform size reject, etc.). Zero recipients with no failed
    // attempts (no chats configured) stays a normal result.
    const messageFailed = sanitizedMessage !== undefined && messagesSent === 0
    const fileFailed = file !== undefined && filesSent === 0
    const deliveryFailed = errors.length > 0 && (messageFailed || fileFailed)

    return {
      content: [{ type: 'text' as const, text: parts.join(' ') }],
      ...(deliveryFailed ? { isError: true } : {})
    }
  }

  // ── Config tool handlers ──────────────────────────────────────────

  private configStatus() {
    const agent = agentService.getAgent(this.agentId)
    if (!agent) throw new McpError(ErrorCode.InternalError, `Agent not found: ${this.agentId}`)

    const config = agent.configuration
    const channels = channelService.listChannels({ agentId: this.agentId })

    const adapterStatuses = application.get('ChannelManager').getAdapterStatuses(this.agentId)
    const statusMap = new Map(adapterStatuses.map((s) => [s.channelId, s.connected]))

    const channelSummary = channels.map((ch) => ({
      id: ch.id,
      type: ch.type,
      name: ch.name,
      enabled: ch.isActive,
      connected: statusMap.get(ch.id) ?? false
    }))

    const result = {
      agentId: agent.id,
      name: agent.name,

View on GitHub (pinned to 726446b54c)

Solutions

  1. Recreate the agent or reselect it in the UI, then start a fresh MCP session.
  2. Verify the session context's `agentId` still resolves via `agentService.getAgent(id)` before issuing config calls.
  3. If this recurs, inspect logs for agent deletion events timestamped near the failure.
Defensive patterns

Strategy: try-catch

Validate before calling

// Not fully preventable client-side, but you can pre-check the agent still exists if you have
// access to the same AgentService in-process:
if (!agentService.getAgent(sessionAgentId)) {
  throw new Error('Session agent no longer exists; recreate the agent and restart the session.');
}

Try / catch

const result = await autonomy.call('config', { action: 'status' });
if (result.isError && result.content[0].text.startsWith('Error: Agent not found')) {
  // unrecoverable for this session — surface to the user, do not retry with the same agentId
}

Prevention

When it happens

Trigger: Agent deleted via UI/DB while its MCP session is live; a database reset/restore between session creation and a config call; session constructed with a stale or wrong agentId.

Common situations: User removes the agent from settings mid-conversation; test fixtures wiped the agents table while a long-lived session lingered; race between session teardown and an in-flight tool call.

Related errors


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