Skip to main content
Glama

file-token-size-mcp

An MCP server that calculates estimated token size for files before reading them.

Purpose

Estimate token budgets before reading or delegating file content:

  • Plan task scope — know file sizes and line counts before deciding how to decompose work

  • Intelligent reading — decide whether to read entire files or use targeted approaches

  • Context budgeting — verify content fits within context limits before delegation

  • Batch planning — estimate total token cost when processing multiple files

Related MCP server: AITree MCP Server

Installation

No installation required. MCP clients run the server directly from the GitHub repository using npx.

Configuration

VS Code (GitHub Copilot)

Add to your VS Code settings.json, or create a .vscode/mcp.json in your workspace root:

macOS / Linux — settings.json:

{
  "mcp": {
    "servers": {
      "file-token-size-mcp": {
        "command": "npx",
        "args": ["-y", "github:ming86/file-token-size-mcp"]
      }
    }
  }
}

Windows — settings.json:

{
  "mcp": {
    "servers": {
      "file-token-size-mcp": {
        "command": "cmd",
        "args": ["/c", "npx", "-y", "github:ming86/file-token-size-mcp"]
      }
    }
  }
}

.vscode/mcp.json (per-project, macOS/Linux):

{
  "servers": {
    "file-token-size-mcp": {
      "command": "npx",
      "args": ["-y", "github:ming86/file-token-size-mcp"]
    }
  }
}

.vscode/mcp.json (per-project, Windows):

{
  "servers": {
    "file-token-size-mcp": {
      "command": "cmd",
      "args": ["/c", "npx", "-y", "github:ming86/file-token-size-mcp"]
    }
  }
}

GitHub Copilot CLI

The MCP config file is ~/.copilot/mcp-config.json (macOS/Linux) or %USERPROFILE%\.copilot\mcp-config.json (Windows). You can also add servers interactively with /mcp add inside the CLI.

macOS / Linux:

{
  "mcpServers": {
    "file-token-size-mcp": {
      "type": "local",
      "command": "npx",
      "args": ["-y", "github:ming86/file-token-size-mcp"],
      "tools": ["*"]
    }
  }
}

Windows:

{
  "mcpServers": {
    "file-token-size-mcp": {
      "type": "local",
      "command": "cmd",
      "args": ["/c", "npx", "-y", "github:ming86/file-token-size-mcp"],
      "tools": ["*"]
    }
  }
}

Environment Variables

Variable

Default

Description

TOKEN_COUNTER_MODEL

GPT-5

Model for token counting. Valid: GPT-5, Claude Sonnet 4.5, Gemini 2.5 Pro

To override the default model (macOS/Linux example; on Windows use "command": "cmd" with "args": ["/c", "npx", ...]):

{
  "mcpServers": {
    "file-token-size-mcp": {
      "command": "npx",
      "args": ["-y", "github:ming86/file-token-size-mcp"],
      "env": {
        "TOKEN_COUNTER_MODEL": "Claude Sonnet 4.5"
      }
    }
  }
}

Tool: calculateFilesTokenSize

Input

Parameter

Type

Required

Description

filePaths

string[]

Yes

Array of absolute file paths to analyze

Output

Returns an array of result objects per file:

Field

Type

Description

filePath

string

Absolute path of the analyzed file

tokens

number

Estimated token count for the configured model

characters

number

Character count

words

number

Word count

fileSizeBytes

number

File size in bytes

totalLines

number

Total line count

error

string?

Error description if file processing failed

Example

{
  "filePaths": ["/path/to/file.ts", "/path/to/another.ts"]
}

Response:

[
  {
    "filePath": "/path/to/file.ts",
    "tokens": 298,
    "characters": 928,
    "words": 81,
    "fileSizeBytes": 928,
    "totalLines": 38
  },
  {
    "filePath": "/path/to/another.ts",
    "tokens": 1024,
    "characters": 3200,
    "words": 420,
    "fileSizeBytes": 3200,
    "totalLines": 102
  }
]

Token Counting

Uses ai-tokenizer with model-specific encodings:

Model

Encoding

Multiplier

GPT-5

o200k_base

Per model config

Claude Sonnet 4.5

claude

Per model config

Gemini 2.5 Pro

o200k_base

Per model config

Binary files are detected automatically and return an error result rather than incorrect token counts.

License

See LICENSE.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to generate annotated file trees, retrieve file statistics, list git-changed files, and read file contents from local directories or GitHub repositories.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides coding agents with pre-flight cost estimation by analyzing local logs to forecast token usage and quota impact before expensive work, exposing tools for remaining quota, per-task cost estimates, and attempt affordability.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Lets AI agents know things about files without reading them, supporting outline, search, slicing, SQL, log clustering, diffs, validation, and extraction for formats like PDF, DOCX, PPTX, XLSX, CSV, logs, and code.
      MIT