Labsco
khromov logo

Safe File MCP

โ˜… 17

from khromov

A test server demonstrating all features of the MCP protocol, including prompts, tools, resources, and sampling.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

๐Ÿฅฅ Context Coder MCP

Context Coder (aka. Coco) provides AI models with an MCP tools to load your entire codebase into the LLM context. This gives AI assistants everything they need to write code that fits your existing patterns and architecture.

๐Ÿ“ฆ Available on npm

Demo

One-shot complex redesign with a vague prompt not mentioning any specific files.

https://github.com/user-attachments/assets/7eb4c39b-f069-47b5-b81a-d3d40c506f61

Limiting which files are including when fetching the codebase

Context Coder works best in small and medium-sized repositories, as it's limited to the maximum context of your LLM (in the case of Claude Sonnet/Opus 4, that's 200,000 tokens). Your whole codebase might not fit, and for this case you have two options.

Excluding Files (.cocoignore)

Create a .cocoignore file in the root of your project. This file works similarly to .gitignore, allowing you to specify files and directories that should be excluded from the command to aggregate your code - this could be test fixtures, snapshots, large test files or other secondary information that isn't useful to the LLM.

Minifying Files (.cocominify)

Create a .cocominify file in the root of your project to include files with placeholder content instead of excluding them entirely. This saves tokens while still informing the AI that the files exist and allows the AI to read them with the read_file tool if necessary. This is useful for large generated files, compiled assets, or files that don't need their full content in the AI context.

Many common build artifacts and folders are already automatically excluded (such as node_modules). The LLM can also help you with this - ask it to run the get_codebase_top_largest_files tool and suggest files that are large and/or suitable for inclusion in a .cocoignore or .cocominify file.

Combining

You can have both a .cocoignore and a .cocominify file in the same repo.

Available Tools

ToolPurpose
get_codebase_sizeCheck codebase size and token counts - LLMs should call this first to ensure codebase isn't too large
get_codebaseGenerate AI-digestible summary of entire codebase (paginated) - Call after checking size
get_codebase_top_largest_filesGet top X largest files in codebase - helpful for identifying files to add to .cocoignore/.cocominify
read_fileRead file contents (only use when specifically asked to re-read or for debugging)
write_fileCreate or overwrite files
edit_fileMake line-based partial edits to files (available when --edit-file-mode is enabled)
create_directoryCreate directories
list_directoryList directory contents (only use when specifically asked or for debugging)
directory_treeGet directory structure as JSON (only use when specifically asked or for debugging)
move_fileMove or rename files
search_filesSearch by pattern
execute_commandRun shell commands

Available Prompts

Context Coder provides MCP prompts that help configure Claude properly for your development workflow:

PromptPurpose
context-coder-claude-desktopDefault starting prompt for Claude Desktop - configures proper MCP tool usage
context-coder-claude-codeDefault starting prompt for Claude Code - explains how to use both tool sets together

To use these prompts in Claude Code:

  1. Type / to open the prompt menu
  2. Find "context-coder" in the list, then "Context Coder: Claude Code Setup"
  3. The prompt will be inserted automatically
  4. You may directly add a task after the prompt, eg /context-coder:Context Coder: Claude Code Setup (MCP) Add a new endpoint that returns a random number

To use these prompts in Claude Desktop:

Use the "plus" button just below the chat text box, the Add from <name of server>.

CLI Commands

Context Coder also provides a convenient CLI command to inspect your codebase:

List Files Command

npx context-coder ls [options]

Lists all files that will be included in the codebase analysis, showing file sizes and respecting .cocoignore and .cocominify patterns.

Options:

  • --sort-by <type> - Sort by "size" or "path" (default: "size")
  • -r, --reverse - Reverse sort order (ascending instead of descending)
  • -d, --directory <dir> - Directory to analyze (default: current directory)
  • --help - Show usage information

Examples:

npx context-coder ls                           # Default: sort by size descending
npx context-coder ls --sort-by path            # Sort alphabetically by path
npx context-coder ls -r                        # Sort by size ascending
npx context-coder ls --sort-by path --reverse  # Sort by path Z-A
npx context-coder ls -d ./src                  # Analyze specific directory

The command shows:

  • Total file count and token estimates for Claude and ChatGPT
  • Whether .cocoignore and .cocominify files are being used
  • Formatted list of all files with sizes

Runtime Options

Context Coder supports several runtime options to modify its behavior:

npx context-coder [options]

Options:

  • -m, --mini - Run in mini mode (only core tools)
  • -f, --full - Run in full mode (all tools) - this is the default
  • -s, --stdio - Use stdio transport instead of HTTP
  • -e, --edit - Enable the edit_file tool for line-based partial edits instead of requiring complete file rewrites with write_file
  • --edit-file-mode - Same as -e, --edit (legacy flag)
  • -p, --port <number> - Port to listen on (default: 3001)
  • -c, --claude-token-limit <number> - Set Claude token limit - useful for models with larger context windows (default: 150000)
  • -g, --gpt-token-limit <number> - Set GPT token limit - useful for models with larger context windows (default: 128000)

Examples:

npx context-coder                           # Default: full mode with HTTP transport
npx context-coder -m                        # Mini mode with core tools only
npx context-coder -s                        # Use stdio transport (for Claude Code)
npx context-coder -e                        # Enable partial file editing
npx context-coder -p 8080                   # Use port 8080 instead of 3001
npx context-coder -m -s                     # Combine options for mini mode with stdio
npx context-coder -s -e -p 8080             # stdio transport with edit mode enabled and custom port

Token Limit Examples:

Context Coder helps detect when your codebase might exceed your model's context window. You can adjust these limits based on the model you're using:

# For Claude Enterprise with 500k context window
npx context-coder -c 500000

# For GPT-4 Turbo with 128k context
npx context-coder -g 128000

# For models with very large context windows
npx context-coder -c 1000000 -g 1000000

# Combine with other options
npx context-coder --edit-file-mode -c 300000 -p 8080

Model Context Window Reference:

  • Claude Sonnet 3.5: ~200k tokens
  • Claude Enterprise: ~500k tokens
  • GPT-4: ~128k tokens
  • GPT-4 Turbo: ~128k tokens
  • Custom/Local Models: Varies widely

Setting appropriate token limits helps Context Coder provide better warnings when your codebase might not fit in your model's context window.

Development

Development setup and commands

Clone and install dependencies:

npm install

Build and run:

npm run build
npm start  # HTTP mode
npm start -- --stdio  # stdio mode

Development mode with auto-reload:

npm run dev

In development mode, file operations are sandboxed to the ./mount directory.

Docker Variants

Context Coder provides three Docker variants:

VariantImageDescription
Fullghcr.io/khromov/context-coder:fullFull mode with all tools using write_file (complete file rewrites)
Minighcr.io/khromov/context-coder:miniCore analysis tools only (get_codebase_size, get_codebase, get_codebase_top_largest_files)
Editghcr.io/khromov/context-coder:editFull mode with edit_file tool for line-based partial edits in addition to write_file

Docker Build

Docker build instructions

Build all versions:

./build-all.sh

Or build individually:

# Full version
docker build -t context-coder:latest .

# Mini version
docker build --build-arg COCO_BUILD_TYPE=mini -t context-coder:mini .

# Edit version
docker build --build-arg COCO_BUILD_TYPE=edit -t context-coder:edit .

Build a custom image:

FROM ghcr.io/khromov/context-coder:full
# Add customizations

Or build from source:

docker build -t my-coco .