multica-ai/multica · error

remove agent mcp server: %w

Error message

remove agent mcp server: %w

What it means

Thrown by `multica agent mcp remove <agentID> <serverID>` when DELETE /api/agents/{id}/mcp-servers/{serverID} fails. The wrapped error typically indicates the attachment does not exist (already removed), the agent ID is unknown, or an auth/connectivity problem.

Source

Thrown at server/cmd/multica/cmd_agent_mcp.go:163

	body := map[string]any{"enabled": enabled}
	if err := client.PutJSON(ctx, agentMcpPath(agentID, serverID, "enabled"), body, &servers); err != nil {
		return fmt.Errorf("update agent mcp server: %w", err)
	}
	return printWorkspaceMcpServers(cmd, servers)
}

func runAgentMcpRemove(cmd *cobra.Command, args []string) error {
	agentID, serverID := strings.TrimSpace(args[0]), strings.TrimSpace(args[1])
	client, err := newAPIClient(cmd)
	if err != nil {
		return err
	}
	ctx, cancel := cli.APIContext(context.Background())
	defer cancel()

	var servers []workspaceMcpServer
	if err := client.DeleteJSONResponse(ctx, agentMcpPath(agentID, serverID), &servers); err != nil {
		return fmt.Errorf("remove agent mcp server: %w", err)
	}
	return printWorkspaceMcpServers(cmd, servers)
}

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. List attachments first and only remove IDs present: multica agent mcp list <agent-id>
  2. If the wrapped error is 404 for an already-removed server, treat it as success in cleanup scripts
  3. Fix auth/connectivity for 401/403/network errors and retry

Example fix

# before (script)
multica agent mcp remove "$AGENT" "$SERVER" || exit 1
# after (script)
multica agent mcp list "$AGENT" --output json | jq -e --arg s "$SERVER" 'map(.id) | index($s)' >/dev/null \
  && multica agent mcp remove "$AGENT" "$SERVER" || true
Defensive patterns

Strategy: try-catch

Validate before calling

multica agent mcp list "$AGENT_ID" --output json | jq -e --arg s "$SERVER_ID" 'map(.id) | index($s)' >/dev/null \
  && multica agent mcp remove "$AGENT_ID" "$SERVER_ID" \
  || echo "already removed: $SERVER_ID"

Try / catch

In Go: if err := client.DeleteJSONResponse(ctx, agentMcpPath(agentID, serverID), &servers); err != nil { if isNotFound(err) { return nil } ; return fmt.Errorf("remove agent mcp server: %w", err) } — treat 404 as already-removed (idempotent success), surface everything else.

Prevention

When it happens

Trigger: Removing a server that was already detached; removing from a deleted agent; concurrent scripts racing to remove the same attachment; expired credentials.

Common situations: Re-running an idempotency-intended cleanup script that assumes remove of a missing attachment succeeds but the API returns 404; state drift between local records and the server.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/0f90935f6e38f66a. Report an issue: GitHub.