read_file
Access and retrieve the contents of any UTF-8 text file located within the configured file operations root.
Instructions
Read a UTF-8 text file inside MCP_FILE_OPS_ROOT.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:192-198 (handler)The read_file tool handler: decorated with @mcp.tool(), reads a UTF-8 text file from within MCP_FILE_OPS_ROOT after path validation.
@mcp.tool() def read_file(path: str) -> str: """Read a UTF-8 text file inside MCP_FILE_OPS_ROOT.""" target = _resolve_file_ops_path(path) if not target.is_file(): raise ValueError(f"File does not exist: {target}") return target.read_text(encoding="utf-8") - server.py:66-75 (helper)_resolve_file_ops_path helper function used by read_file to resolve and validate the file path against MCP_FILE_OPS_ROOT, preventing path traversal.
def _resolve_file_ops_path(path: str | None = None) -> Path: if not FILE_OPS_ROOT: raise ValueError("MCP_FILE_OPS_ROOT is not configured in .env.") root = Path(FILE_OPS_ROOT).expanduser().resolve() root.mkdir(parents=True, exist_ok=True) target = root if path is None else (root / path).resolve() if target != root and root not in target.parents: raise ValueError("Path escapes the configured MCP_FILE_OPS_ROOT.") - server.py:192-192 (registration)The @mcp.tool() decorator registers the read_file function as an MCP tool.
@mcp.tool()