MCPcopy Create free account
hub / github.com/modelcontextprotocol/mcpb / read_file

Function read_file

examples/file-manager-python/server/main.py:51–72  ·  view source on GitHub ↗

Read file contents

(path: str)

Source from the content-addressed store, hash-verified

49
50@mcp.tool()
51def read_file(path: str) -> str:
52 """Read file contents"""
53 path_obj = Path(path)
54
55 if not path_obj.exists():
56 return f"File not found: {path}"
57
58 if not path_obj.is_file():
59 return f"Path is not a file: {path}"
60
61 try:
62 with path_obj.open("r", encoding="utf-8") as f:
63 content = f.read()
64
65 return f"Contents of {path}:\n{content}"
66
67 except UnicodeDecodeError:
68 return f"File is not text or uses unsupported encoding: {path}"
69 except PermissionError:
70 return f"Permission denied reading: {path}"
71 except Exception as e:
72 return f"Error reading file: {str(e)}"
73
74
75@mcp.tool()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…