Skip to main content
Glama

read_file

Enforce path-policy rules to read a text file from the workspace, ensuring only allowed files are accessed.

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 core read_file function that enforces path policy, logs the action, and reads the file contents.
    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)
    Registers read_file as an MCP tool by passing it to mcp.tool().
    for tool in [
        server_info,
        restore_backup,
        execute_command,
        read_file,
        write_file,
        edit_file,
        delete_file,
        list_directory,
    ]:
        mcp.tool()(tool)
  • Exports read_file in the public tools package __all__.
    from .command_tools import execute_command, server_info
    from .file_tools import delete_file, edit_file, list_directory, read_file, write_file
    from .restore_tools import restore_backup
    
    __all__ = [
        "server_info",
        "execute_command",
        "read_file",
        "write_file",
        "edit_file",
        "delete_file",
        "list_directory",
        "restore_backup",
    ]
  • Lists read_file as one of the AIRG MCP tools in the config manager.
    AIRG_MCP_TOOLS = [
        "server_info",
        "restore_backup",
        "execute_command",
        "read_file",
        "write_file",
        "edit_file",
        "delete_file",
        "list_directory",
    ]
  • AIRG hook handling 'beforereadfile' event for native Read tool interception, redirecting users to use mcp__ai-runtime-guard__read_file.
    if hook_event == "beforereadfile":
        file_path = str(payload.get("file_path", "")).strip()
        lowered = file_path.lower()
        violated = _blocked_by_policy(file_path) if file_path else None
        if not violated and lowered:
            if any(lowered.endswith(suffix) for suffix in SENSITIVE_READ_SUFFIXES) or "/secrets/" in lowered:
                violated = "sensitive read target"
        if violated:
            reason = f"AIRG policy: read blocked ({violated}). Use AIRG MCP tools within allowed path policy."
            _append_log(
                _build_activity_entry(
                    payload=payload,
                    tool_name="Read",
                    allowed=False,
                    event="hook_before_read_blocked",
                    hook_reason=reason,
                    hook_detail=file_path,
                )
            )
            return _emit_deny(reason, hook_event_name="beforeReadFile")
        _append_log(
            _build_activity_entry(
                payload=payload,
                tool_name="Read",
                allowed=True,
                event="hook_before_read_allowed",
                hook_reason="read_allowed",
                hook_detail=file_path,
            )
        )
        return _allow()
Behavior2/5

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

No annotations are present, so the description fully bears the burden of behavioral disclosure. It mentions reading a text file but omits details on file type, size limits, encoding, behavior on missing files, or error handling, leaving significant gaps.

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

Conciseness2/5

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

The description is extremely short (one sentence) but suffers from under-specification rather than efficiency. It fails to include essential details that could be added without significant length, such as parameter hints or behavior notes.

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

Completeness2/5

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

Given the tool has two parameters (one required), no schema descriptions, and no annotations, the description is insufficient for an agent to correctly select and invoke the tool. It lacks parameter semantics and behavioral context.

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

Parameters1/5

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

The input schema has 0% description coverage, and the description does not explain either parameter. 'path' is only loosely implied, and 'ctx' is completely ignored. The description adds no value beyond the schema.

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), resource (text file from workspace), and a condition (after path-policy enforcement). It distinguishes from sibling tools like write_file, delete_file, and list_directory, making the purpose unambiguous.

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

Usage Guidelines2/5

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

The description implies a prerequisite (path-policy enforcement) but does not explicitly state when to use this tool over alternatives like list_directory or write_file. No when-not-to-use guidance is provided.

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

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