Supports .gitignore files when scanning directories to automatically filter out files that are excluded from version control.
TokenScope
Token-Aware Directory Explorer for Large Language Models (LLMs).
A Model Context Protocol (MCP) server that helps LLMs efficiently explore and understand codebases and directory structures.
Overview
TokenScope provides intelligent directory structure analysis and token-aware file content exploration designed for LLMs like Claude. It helps LLMs understand codebases by:
- Exploring directory structures with token-aware summarization
- Viewing file contents with token limitations in mind
- Generating comprehensive reports about directories
Key Features
Token-Aware Directory Exploration
- Automatic summarization for large directories while showing small directories in full
- Respect for token limits to maximize useful information within constraints
- Built-in security with base path validation
- Smart filtering with default patterns and .gitignore support
- Accurate directory statistics for even the largest directories
Simple, Intuitive Tools
TokenScope provides just three core tools:
explore_directory
- Scan and understand directory structuresview_content
- Access file contents with token awarenessgenerate_report
- Create comprehensive reports (with option to save to file)
Installation
Prerequisites
- Python 3.10 or higher
- uv (recommended for dependency management)
Installation (PyPI)
This is the recommended method for most users who just want to use TokenScope:
Running TokenScope
The --base-path
argument is mandatory for security reasons. It restricts all file operations to the specified directory.
Configuring in Claude Desktop
- Locate Claude Desktop's configuration file (typically
~/.config/claude/config.json
) - Add TokenScope to the
mcpServers
section:
- Replace
/your/secure/base/path
with the directory you want to restrict operations to - Save the configuration file and restart Claude Desktop
Usage
Running TokenScope Server
The --base-path
argument is required for security (it restricts file operations to the specified directory):
Testing Tools Directly
TokenScope includes a test mode for trying out tools directly:
Example Prompts
Here are some examples of how to use TokenScope with Claude:
Accurate Directory Statistics
TokenScope now provides two levels of directory information:
- Quick Scan Statistics: Information about files and directories visible in the tree view
- Full Directory Statistics: Complete counts of ALL files and directories, even in very large repositories
This dual approach ensures that even for massive directories (with thousands or millions of files), you'll get accurate information about the total number of files, directories, and disk usage. This is especially valuable when working with large codebases where a complete directory listing would exceed token limits.
Example Output
Smart Filtering with Ignore Patterns
TokenScope automatically filters out common directories and files that typically don't contribute to understanding a codebase:
- Default ignored patterns:
.git/
,.venv/
,venv/
,__pycache__/
,node_modules/
,build/
,dist/
, etc. - Custom ignore patterns: You can specify additional patterns to ignore via the
ignore_patterns
parameter - .gitignore support: TokenScope can automatically respect .gitignore files in the directories it scans
This functionality helps prevent token waste on irrelevant files and directories like:
- Dependency directories (e.g.,
node_modules
, virtual environments) - Build artifacts and cache directories
- Version control metadata
- IDE configuration files
Using Ignore Patterns in CLI Test Mode
Security Features
TokenScope includes important security features:
- All file operations are validated to ensure they're within the specified base directory
- Attempts to access files outside the base path are rejected
- The base path is set once when starting the server and cannot be changed without restart
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
A Model Context Protocol server that enables token-aware directory exploration and file analysis for LLMs, helping them understand codebases through intelligent scanning and reporting.
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol server that enables LLMs to read, search, and analyze code files with advanced caching and real-time file watching capabilities.Last updated 17 days ago62020JavaScriptMIT License
- AsecurityFlicenseAqualityA Model Context Protocol server that connects LLMs to the Compiler Explorer API, enabling them to compile code, explore compiler features, and analyze optimizations across different compilers and languages.Last updated 4 months ago513Python
- -securityAlicense-qualityA Model Context Protocol server that provides tools to find regex pattern positions in files and list allowed directories, enabling text analysis with LSP-like functionality.Last updated 5 months agoTypeScriptMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that helps large language models process code repositories by providing file tree generation, code merging, and code analysis capabilities.Last updated 3 months ago320JavaScriptMIT License