Skip to content

Gemini sessions in MCP: get_tool_usage_stats and get_session_cost return zeroes #3

@mishanefedov

Description

@mishanefedov

When an MCP client calls `get_tool_usage_stats({sessionId: ""})` or `get_session_cost({sessionId: ""})` against agentwatch's MCP server (`agentwatch mcp`), both return an honest empty result.

Why

`src/mcp/server.ts::parseSession()` currently has this branch:

```ts
if (s.agent === "gemini") {
// Gemini sessions are single-JSON not JSONL, and we don't yet
// translate them to AgentEvents for stats purposes. Return empty
// so get_tool_usage_stats / get_session_cost produce honest zeroes
// rather than fake data. Raw content still reachable via
// get_session_events.
return [];
}
```

The live Gemini adapter (`src/adapters/gemini.ts`) DOES translate Gemini messages into AgentEvents (including `toolCalls[]` and token usage). The gap is that the MCP server uses its own one-shot read-and-translate path, not the live adapter.

What to fix

Either:

  • Easier: port the Gemini translation logic from `gemini.ts` into the MCP's `parseSession()` branch.
  • Better: have the MCP server reuse the live event buffer when agentwatch is running, fall back to its own scan only when running standalone. This eliminates duplication entirely.

Acceptance

  • `get_tool_usage_stats` returns real per-tool counts for Gemini sessions.
  • `get_session_cost` returns real token breakdown + USD using the gemini-2.5-pro / flash rate table.
  • Claude and Codex paths remain unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions