Skip to main content
Glama

mavis_usage

Inspect token usage by session, agent, model, or day within a specified time range.

Instructions

Inspect token usage by session, agent, or globally.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdNoSession ID to query usage for
agentNameNoAgent name to query usage for
fromNoStart of time range (unix-ms)
toNoEnd of time range (unix-ms)
groupNoGroup by dimension

Implementation Reference

  • The runTool function is the generic handler for all tools, including mavis_usage. It executes the tool by calling execMavisJSON with the buildArgs result.
    function runTool(spec, parsedArgs) {
      const { execFn, outputMode, stdin, buildArgs } = spec;
      const args = buildArgs(parsedArgs);
      const input = typeof stdin === 'function' ? stdin(parsedArgs) : stdin;
    
      const execPromise = execFn
        ? execMavis(args, input || '')
        : execMavisJSON(args);
    
      return execPromise.then(result => {
        const text = outputMode === OUTPUT_RAW
          ? (result || '')
          : JSON.stringify(result, null, 2);
        return [{ type: 'text', text }];
      });
    }
  • Input schema for mavis_usage: accepts optional sessionId, agentName, from (unix-ms), to (unix-ms), and group (enum: agent/session/model/day).
    inputSchema: z.object({
      sessionId: z.string().optional().describe('Session ID to query usage for'),
      agentName: z.string().optional().describe('Agent name to query usage for'),
      from: z.number().optional().describe('Start of time range (unix-ms)'),
      to: z.number().optional().describe('End of time range (unix-ms)'),
      group: z.enum(['agent', 'session', 'model', 'day']).optional().describe('Group by dimension')
    }).strict(),
  • src/index.js:446-466 (registration)
    The mavis_usage tool definition in the tools array, with name, description, inputSchema, and buildArgs. Registered as part of the tool list.
    {
      name: 'mavis_usage',
      description: 'Inspect token usage by session, agent, or globally.',
      inputSchema: z.object({
        sessionId: z.string().optional().describe('Session ID to query usage for'),
        agentName: z.string().optional().describe('Agent name to query usage for'),
        from: z.number().optional().describe('Start of time range (unix-ms)'),
        to: z.number().optional().describe('End of time range (unix-ms)'),
        group: z.enum(['agent', 'session', 'model', 'day']).optional().describe('Group by dimension')
      }).strict(),
      buildArgs: ({ sessionId, agentName, from, to, group }) => {
        const args = sessionId ? ['usage', 'session', sessionId]
          : agentName ? ['usage', 'agent', agentName]
          : ['usage', 'list'];
        if (from !== undefined) args.push('--from', String(from));
        if (to !== undefined) args.push('--to', String(to));
        if (group) args.push('--group', group);
        args.push('--json');
        return args;
      }
    }
  • execMavisJSON helper wraps execMavis to parse JSON output - used by mavis_usage since it has no execFn, so it goes through execMavisJSON.
    function execMavisJSON(args) {
      return execMavis(args).then(raw => {
        try {
          return JSON.parse(raw);
        } catch {
          const jsonStart = raw.indexOf('{');
          return JSON.parse(jsonStart >= 0 ? raw.slice(jsonStart) : raw);
        }
      });
    }
  • src/index.js:484-509 (registration)
    MavisServer registers all tools (including mavis_usage) by building a toolMap and handling CallToolRequestSchema by looking up the tool, parsing args, and running it.
    this.toolMap = new Map(tools.map(t => [t.name, t]));
    
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: tools.map(t => ({
        name: t.name,
        description: t.description,
        inputSchema: normalizeObjectSchema(t.inputSchema),
      })),
    }));
    
    this.server.setRequestHandler(CallToolRequestSchema, async request => {
      const { name, arguments: args } = request.params;
      const tool = this.toolMap.get(name);
    
      if (!tool) {
        return { content: [{ type: 'text', text: `Error: unknown tool "${name}"` }], isError: true };
      }
    
      try {
        const parsedArgs = tool.inputSchema.parse(args || {});
        const results = await runTool(tool, parsedArgs);
        return { content: results };
      } catch (err) {
        return { content: [{ type: 'text', text: `Mavis error: ${err.message}` }], isError: true };
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, and the description does not disclose whether the tool is read-only or if it has any side effects. For a query-like operation, explicitly stating it is a read operation would improve transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, front-loaded with the action and resource, containing no extraneous information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema and optional parameters, the description lacks context on how to perform a global query (no 'global' enum value) and what the output format is, making it incomplete for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the description adds little beyond the schema. It mentions scoping dimensions but does not clarify parameter interactions or provide examples of valid parameter combinations.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool inspects token usage with scoping by session, agent, or globally, which is specific and distinct from sibling tools that focus on agents, sessions, or skills.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives is provided. Sibling tools like mavis_session_info or mavis_agent_info serve different purposes but could overlap in querying agent or session data.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Cunning-Kang/mavis-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server