Skip to main content
Glama

Estimate context budget

get_context_budget
Read-onlyIdempotent

Estimate token cost of a file's declarations for an LLM context window. Use per-category estimates to pick between targeted symbol calls and a full read, or choose a budget.

Instructions

Estimate the token cost of loading a file's declarations into an LLM context window, per category: types, effects, actors, supervisors, tools, and function signatures. Use it before pulling a module in wholesale, to choose between get_context_for_symbol calls and a full read, or to pick a budget; it names no individual symbols. Returns approx_tokens with types, effects, actors, supervisors, tools, functions, and total, estimated at ~4 characters per token from one-line signatures, and a note restating that. Fails only when the file is unreadable or has parse or type errors. Read-only: compiles the file's directory in memory (cached until a sibling changes) and writes or executes nothing. Failures are isError results with a stable error.code: file_not_found, read_error, invalid_params, and, for every tool but check_file, parse_error or check_error carrying coded diagnostics in error.data.diagnostics (the shape check_file returns).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesPath to a .hird source file, absolute or relative to the server's working directory. Every .hird file in its directory is compiled with it as one program, so imported names resolve; answers may name a sibling file.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYes
noteYes
moduleYes
approx_tokensYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changed
    • changedInput schema / properties / file / description
      Previous value: -"Path to a .hird source file. Its directory's .hird files are compiled together as one program, so imported names resolve."New value: +"Path to a .hird source file, absolute or relative to the server's working directory. Every .hird file in its directory is compiled with it as one program, so imported names resolve; answers may name a sibling file."
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "properties": {
      +    "approx_tokens": {
      +      "properties": {
      +        "actors": {
      +          "type": "integer"
      +        },
      +        "effects": {
      +          "type": "integer"
      +        },
      +        "functions": {
      +          "type": "integer"
      +        },
      +        "supervisors": {
      +          "type": "integer"
      +        },
      +        "tools": {
      +          "type": "integer"
      +        },
      +        "total": {
      +          "type": "integer"
      +        },
      +        "types": {
      +          "type": "integer"
      +        }
      +      },
      +      "required": [
      +        "types",
      +        "effects",
      +        "actors",
      +        "supervisors",
      +        "tools",
      +        "functions",
      +        "total"
      +      ],
      +      "type": "object"
      +    },
      +    "file": {
      +      "type": "string"
      +    },
      +    "module": {
      +      "type": "string"
      +    },
      +    "note": {
      +      "type": "string"
      +    }
      +  },
      +  "required": [
      +    "approx_tokens",
      +    "file",
      +    "module",
      +    "note"
      +  ],
      +  "type": "object"
      +}
  2. Changed1 schema field changedv0.1.1
    • changedInput schema / properties / file / description
      Previous value: -"Path to a .hird source file."New value: +"Path to a .hird source file. Its directory's .hird files are compiled together as one program, so imported names resolve."
  3. First observedv0.1.0

TDQS

A4.8/5.0
Behavior5/5

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

The description goes well beyond the annotations. It discloses that the tool is read-only (compiles in memory, cached until a sibling changes, writes/executes nothing), which reinforces the readOnlyHint. It also discloses failure modes with stable error codes (file_not_found, read_error, invalid_params, parse_error, check_error) and the shape of diagnostics. It even explains the estimation heuristic (~4 characters per token from one-line signatures). This is rich behavioral context that annotations alone do not provide.

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

Conciseness4/5

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

The description is dense but well-organized: purpose first, then usage, then return shape, then failure modes. Every sentence carries information. It is longer than the typical description, but the length is justified by the behavioral and error details. It loses one point because the failure-mode enumeration is somewhat verbose and could be tightened without losing meaning.

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

Completeness5/5

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

The description is complete for a read-only estimation tool. It covers what the tool returns (approx_tokens with per-category breakdown and total), the estimation method, the failure modes with error codes, and the read-only safety profile. The output schema exists, so return values are further documented. An agent has everything needed to decide when to call it and how to interpret results.

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

Parameters4/5

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

The schema already provides 100% coverage of the single parameter, including path resolution semantics and the fact that sibling files are compiled together. The description adds value by explaining why that matters ('so imported names resolve; answers may name a sibling file') and by clarifying the tool's scope ('it names no individual symbols'). Since the schema covers the parameter well, the description's additional context earns a 4 rather than a 3.

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

Purpose5/5

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

The description states a specific verb ('Estimate'), a specific resource ('token cost of loading a file's declarations'), and enumerates the exact categories counted (types, effects, actors, supervisors, tools, function signatures). It also explicitly distinguishes itself from siblings by noting it 'names no individual symbols' and by referencing get_context_for_symbol as the alternative for symbol-level queries. This is a clear, differentiated purpose.

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

Usage Guidelines5/5

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

The description gives explicit when-to-use guidance: 'Use it before pulling a module in wholesale, to choose between get_context_for_symbol calls and a full read, or to pick a budget.' It also names the alternative tool (get_context_for_symbol) and the decision it informs. This is exactly the kind of routing guidance an agent needs.

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