Browse documentation

get_file_contents

[solution]

Gets text content for a file under the loaded root, with optional line-window limits. If you seek a C# type in the loaded workspace, use find_code with its name. Supports files outside the loaded C# project model when they are still inside the loaded root.

Try it locally in the Glider playground

Parameters

NameTypeRequiredDescription
contentModestringNolegacy preserves content plus optional rawContent. raw returns only exact rawContent for an impending guarded edit. Null rawContent requires a smaller window. Default: "legacy"
includeRawContentbooleanNoInclude rawContent with exact line endings and the final line terminator. Null means the character limit prevents an exact window. Default: false
filePathstringYesFile path to read. Can be absolute or relative to the loaded root. A repository-relative path also resolves, given its complete prefix, such as src/App/Foo.cs. A partial prefix is not resolved, because guessing one could name a different file.
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. Default: 400
maxCharsnumberNoMaximum characters to return. Use 0 for unlimited. Default is 100000. Default: 100000
pathStylestringNoPath style: 'absolute' (default) or 'relative' (to solution root). Default: "absolute"
responseDetailstringNocompact returns results and actionable state. full adds diagnostic metadata under responseDiagnostics. Default: "compact"

Examples

Replace sample paths and symbol keys with values from your workspace.

Read an entire file

Arguments
{
  "filePath": "/Users/dev/MyProject/Program.cs"
}
Full MCP request
Full MCP request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_file_contents",
    "arguments": {
      "filePath": "/Users/dev/MyProject/Program.cs"
    }
  }
}
Illustrative response
{
  "success": true,
  "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..."
}

Read a bounded line range

Arguments
{
  "filePath": "/Users/dev/MyProject/Program.cs",
  "startLine": 40,
  "endLine": 90
}
Full MCP request
Full MCP 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
    }
  }
}

Read using relative paths with limits

Arguments
{
  "filePath": "src/Program.cs",
  "maxLines": 80,
  "maxChars": 12000,
  "pathStyle": "relative"
}
Full MCP request
Full MCP 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 Notes

Returns bounded text content plus file metadata and workspace inclusion state. Glider 13.0.0 accepts contentMode=raw and omits content while preserving exact rawContent, including original whitespace and terminators. Legacy includeRawContent=true retains both source representations. A character-cut window has no exact rawContent; reduce the window before a guarded edit. Ordinary navigation needs no raw copy. For a missing relative path, candidatePaths can list up to five nearby files; choose one and retry its loaded-root-relative path unchanged. If you seek a C# type in the loaded workspace, use find_code. Set query to its name and kinds to Type. Read the selected type match filePath, or pass its symbolKey to get_source. An absolute path or an outside-root error has no candidates. Referenced project membership does not expand the authorized loaded root. For an outside-root referenced file, load the containing .sln or .slnx whose directory contains the file, then retry. The watched directory does not change that boundary. Results use top-level fields with success. Compact is the default; full adds responseDiagnostics. Both modes retain errors, coverage, partial state, and recovery advice.