[solution]
Gets text content for a file under the loaded root, with optional line-window limits. Supports files outside the Roslyn workspace when they are still inside the loaded root.
Try this tool in Playground.
| Name | Type | Required | Description |
|---|---|---|---|
| filePath | string | Yes | File path to read. Can be absolute or relative to the loaded root. |
| startLine | number | No | Optional 1-based start line. Defaults to 1. |
| endLine | number | No | Optional 1-based inclusive end line. Defaults to the end of the file. |
| maxLines | number | No | Maximum number of lines to return. Use 0 for unlimited. Default is 400. |
| maxChars | number | No | Maximum characters to return. Use 0 for unlimited. Default is 100000. |
| pathStyle | string | No | Path style: 'absolute' (default) or 'relative' (to solution root). |
Read an entire file
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_file_contents",
"arguments": {
"filePath": "/Users/dev/MyProject/Program.cs"
}
}
}{
"success": true,
"data": {
"filePath": "/Users/dev/MyProject/Program.cs",
"totalLines": 180,
"startLine": 40,
"endLine": 90,
"lineCount": 51,
"truncated": false,
"inWorkspace": true,
"fileExtension": ".cs",
"content": "using System;\n\nnamespace MyProject;\n..."
},
"meta": {
"durationMs": 89,
"cancelled": false,
"timedOut": false,
"timeoutMs": 1200000
},
"error": null
}Read a bounded line range
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_file_contents",
"arguments": {
"filePath": "/Users/dev/MyProject/Program.cs",
"startLine": 40,
"endLine": 90
}
}
}{
"success": true,
"data": {
"filePath": "/Users/dev/MyProject/Program.cs",
"totalLines": 180,
"startLine": 40,
"endLine": 90,
"lineCount": 51,
"truncated": false,
"inWorkspace": true,
"fileExtension": ".cs",
"content": "using System;\n\nnamespace MyProject;\n..."
},
"meta": {
"durationMs": 89,
"cancelled": false,
"timedOut": false,
"timeoutMs": 1200000
},
"error": null
}Read using relative paths with limits
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_file_contents",
"arguments": {
"filePath": "src/Program.cs",
"maxLines": 80,
"maxChars": 12000,
"pathStyle": "relative"
}
}
}{
"success": true,
"data": {
"filePath": "/Users/dev/MyProject/Program.cs",
"totalLines": 180,
"startLine": 40,
"endLine": 90,
"lineCount": 51,
"truncated": false,
"inWorkspace": true,
"fileExtension": ".cs",
"content": "using System;\n\nnamespace MyProject;\n..."
},
"meta": {
"durationMs": 89,
"cancelled": false,
"timedOut": false,
"timeoutMs": 1200000
},
"error": null
}Returns bounded text content plus file metadata and workspace inclusion state