Read file contents
(path: str)
| 49 | |
| 50 | @mcp.tool() |
| 51 | def 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() |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…