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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| ctx | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/tools/file_tools.py:20-45 (handler)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) - src/tools/__init__.py:5-14 (registration)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", ] - src/mcp_config_manager.py:30-39 (helper)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", ] - src/airg_hook.py:394-397 (helper)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."