Skip to main content
Glama
Ronnietag
by Ronnietag

file_read

Read file contents to access text, code, or data stored in Linux systems. Specify the absolute file path to retrieve information for analysis or processing.

Instructions

Read contents of a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to file

Implementation Reference

  • The core implementation of the file_read tool logic, including security checks for path traversal.
    def execute_file_read(path: str) -> str:
        """Read a file and return its contents."""
        tool = get_tool_by_name("file_read")
        tool_id = next(tid for tid, t in {}.items() if t.name == "file_read")  # placeholder
    
        # Security: path traversal check
        resolved = Path(path).resolve()
        if not str(resolved).startswith(os.path.expanduser("~")):
            log_action(tool_id or "unknown", {"path": path}, "BLOCKED: outside home", False)
            return "Error: Can only read files within home directory"
    
        try:
            content = resolved.read_text()
            log_action(tool_id or "unknown", {"path": path}, "OK", True)
            return content
  • The MCP handler function that processes tool calls and invokes the execute_file_read helper.
    async def handle_file_read(arguments: dict[str, Any]) -> list[TextContent]:
        """Handle file_read tool calls."""
        if not arguments or "path" not in arguments:
            return [TextContent(type="text", text="Error: missing 'path' parameter")]
    
        result = execute_file_read(arguments["path"])
        return [TextContent(type="text", text=result)]
  • Tool registration including schema definitions for file_read.
    register_tool(
        name="file_read",
        scope=PermissionLevel.SAFE,
        description="Read contents of a file",
        params_schema={
            "type": "object",
            "properties": {
                "path": {"type": "string", "description": "Absolute path to file"},
            },
            "required": ["path"],
        },
    )

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/Ronnietag/linux-mcp'

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