Skip to main content
Glama

Execute File Processing

ctx_execute_file

Run code against a file's content in a sandbox, returning only the printed output. Analyzes large or structured files without loading raw bytes into conversation memory.

Instructions

Read a file into a sandboxed FILE_CONTENT variable and run code over it. Only what you console.log() enters your conversation — the file bytes stay in the sandbox.

Think-in-Code applied to file-level analysis: Reading the whole file means every byte enters your conversation memory and costs reasoning capacity for the rest of the session. Running code over it here lets you keep the raw bytes out and only the derived answer in. Same principle as ctx_execute, scoped to one named file via the FILE_CONTENT variable.

WHEN:

  • You want to KNOW SOMETHING ABOUT a file (line count, matches of a pattern, parsed structure, statistical aggregate) without needing to SEE all of it

  • The file is structured (CSV, JSON, log, code) and a code-level derivation is cheaper than reading verbatim

  • The file is large enough that reading the full content would burn meaningful conversation memory you need for the actual work

  • The derivation may itself produce a large output you want recall-by-topic on later — pass an intent string; outputs over ~5KB are auto-indexed and only matching sections come back, retrievable via ctx_search

WHEN NOT:

  • You intend to EDIT the file — use Read so the subsequent Edit can match the exact text

  • You only need one specific line and you know its offset — Read with offset/limit is the simplest path

  • The file is small AND you will consume all of it for understanding/editing — Read directly

RETURNS: Only what your code prints. The FILE_CONTENT variable holds the raw bytes inside the sandbox; nothing else leaves. When intent is set and output exceeds the auto-index threshold, the response carries searchable section titles + previews instead of the raw stdout.

EXAMPLE: ctx_execute_file(path: "huge.log", language: "javascript", code: "const errs = FILE_CONTENT.split('\n').filter(l => /ERROR|FATAL/.test(l)); console.log(${errs.length} error lines); console.log(errs.slice(-5).join('\n'))") EXAMPLE: ctx_execute_file(path: "data.csv", language: "javascript", code: "const rows = FILE_CONTENT.split('\n'); console.log(rows: ${rows.length - 1}, header: ${rows[0]})")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute file path or relative to project root
languageYesRuntime language
codeYesCode to process FILE_CONTENT (file_content in Elixir). Print summary via console.log/print/echo/IO.puts/Console.WriteLine.
timeoutNoMax execution time in ms. When omitted, no server-side timer fires — the MCP host's RPC timeout governs.
intentNoWhat you're looking for in the output. When provided and output is large (>5KB), returns only matching sections via BM25 search instead of truncated output.
Behavior5/5

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

With no annotations, the description explains that only console.log output enters conversation, file bytes stay sandboxed, and large outputs with intent are auto-indexed. Discloses the FILE_CONTENT variable and that nothing else leaves the sandbox. No contradictions.

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?

Well-structured with clear sections (WHEN, WHEN NOT, RETURNS, EXAMPLE). Front-loaded with core purpose. Some redundancy (e.g., 'Only what your code prints' is stated twice), but overall efficient for the richness of information.

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?

Given 5 params, no output schema, and no annotations, the description covers purpose, usage, behavior, parameter semantics, and return values comprehensively. Addresses large output handling and two examples cover common cases.

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

Parameters5/5

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

Schema coverage is 100%, but description adds significant value: explains the FILE_CONTENT variable for code, the effect of intent on output indexing, and provides two concrete examples showing how parameters are used together.

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?

Clearly states the tool reads a file into a sandboxed variable and runs code over it. Distinguishes from sibling ctx_execute by scoping to a named file, and provides examples that reinforce its 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?

Provides explicit WHEN and WHEN NOT sections with specific scenarios (file analysis, structure, size, edits). Suggests alternatives like Read when editing or needing a single line, giving clear decision guidance.

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/mksglu/context-mode'

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