Skip to main content
Glama
runtimeguard

ai-runtime-guard

by runtimeguard

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()

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.5.0

TDQS

B3.4/5.0
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.