get_file_contents

[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.

Parameters

NameTypeRequiredDescription
filePathstringYesFile path to read. Can be absolute or relative to the loaded root.
startLinenumberNoOptional 1-based start line. Defaults to 1.
endLinenumberNoOptional 1-based inclusive end line. Defaults to the end of the file.
maxLinesnumberNoMaximum number of lines to return. Use 0 for unlimited. Default is 400.
maxCharsnumberNoMaximum characters to return. Use 0 for unlimited. Default is 100000.
pathStylestringNoPath style: 'absolute' (default) or 'relative' (to solution root).

Examples

Read an entire file

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_file_contents",
    "arguments": {
      "filePath": "/Users/dev/MyProject/Program.cs"
    }
  }
}
Response
{
  "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

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_file_contents",
    "arguments": {
      "filePath": "/Users/dev/MyProject/Program.cs",
      "startLine": 40,
      "endLine": 90
    }
  }
}
Response
{
  "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

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_file_contents",
    "arguments": {
      "filePath": "src/Program.cs",
      "maxLines": 80,
      "maxChars": 12000,
      "pathStyle": "relative"
    }
  }
}
Response
{
  "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
}

Response Notes

Returns bounded text content plus file metadata and workspace inclusion state