Skip to main content
Glama

read_file

Read a text file from the workspace with path-policy enforcement to prevent unauthorized access.

Instructions

Read a text file from the workspace after path-policy enforcement.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
ctxNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler for the read_file tool. Reads a text file from the workspace after path-policy enforcement, logging, and runtime context management.
    def read_file(path: str, ctx: Context | None = None) -> str:
        """Read a text file from the workspace after path-policy enforcement."""
        context_tokens = activate_runtime_context(ctx)
        path = str(pathlib.Path(WORKSPACE_ROOT) / path) if not os.path.isabs(path) else path
    
        try:
            refresh_policy_if_changed()
            path_check = check_path_policy(path, tool="read_file")
            if path_check:
                result = PolicyResult(allowed=False, reason=path_check[0], decision_tier="blocked", matched_rule=path_check[1])
            else:
                result = PolicyResult(allowed=True, reason="allowed", decision_tier="allowed", matched_rule=None)
    
            append_log_entry(build_log_entry("read_file", result, path=path))
            if not result.allowed:
                return f"[POLICY BLOCK] {result.reason}"
    
            try:
                with open(path, "r", errors="replace") as f:
                    return f.read()
            except FileNotFoundError:
                return f"Error: file not found: {path}"
            except OSError as e:
                return f"Error reading file: {e}"
        finally:
            reset_runtime_context(context_tokens)
  • src/server.py:21-31 (registration)
    Registration of read_file as an MCP tool via mcp.tool()(read_file) in the server entrypoint.
    for tool in [
        server_info,
        restore_backup,
        execute_command,
        read_file,
        write_file,
        edit_file,
        delete_file,
        list_directory,
    ]:
        mcp.tool()(tool)
  • Re-export of read_file from tools package, listed in __all__.
    __all__ = [
        "server_info",
        "execute_command",
        "read_file",
        "write_file",
        "edit_file",
        "delete_file",
        "list_directory",
        "restore_backup",
    ]
  • read_file listed in AIRG_MCP_TOOLS for MCP config generation (used for tool allowlisting).
    AIRG_MCP_TOOLS = [
        "server_info",
        "restore_backup",
        "execute_command",
        "read_file",
        "write_file",
        "edit_file",
        "delete_file",
        "list_directory",
    ]
  • AIRG hook references read_file when blocking native 'Read' tool and suggesting the AIRG MCP tool instead.
    # Allow general read-only tools except sensitive read targets.
    if tool_name in ALWAYS_ALLOW:
        if tool_name == "Read" and _is_sensitive_read(tool_input):
            reason = "AIRG policy: sensitive native Read target restricted. Use mcp__ai-runtime-guard__read_file instead."
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'path-policy enforcement' but omits behaviors such as error handling, size limits, or encoding. For a simple read tool, more detail would be beneficial.

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

Conciseness5/5

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

The description is a single sentence of 9 words, front-loading the core information. Every word is purposeful with no waste.

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

Completeness3/5

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

The description is adequate for a simple read tool with an output schema, but it lacks details on file type, encoding, or error scenarios. It does not fully contextualize when to use this vs list_directory.

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

Parameters2/5

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

With 0% schema description coverage, the description must compensate. It adds meaning for 'path' (the file to read) but completely ignores 'ctx'. The parameter semantics are insufficient.

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 clearly states the action ('Read') and the resource ('text file from the workspace') with an additional qualifier ('after path-policy enforcement'). This distinguishes it from siblings like write_file, delete_file, and edit_file.

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

Usage Guidelines3/5

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

The description does not provide explicit when-to-use or when-not-to-use guidance. It implies use for reading file content but does not contrast with list_directory or other tools.

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/jimmyracheta/ai-runtime-guard'

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