Skip to content

Get Code Context

get-code-context · Query · CorePlugin · Code discovery and navigation

Returns a bounded code window with the enclosing semantic context for a selected location.

Availability: Built in and published by default.

Generated from Roslyn Workbench MCP 0.1.0-beta.294 (0.1.0-beta.294).

Behaviour annotations

Annotation Value
destructiveHint false
idempotentHint true
openWorldHint false
readOnlyHint true
title "Get Code Context"

Request

Property Type Required Description
location object Yes The location selector.
beforeLines integer | null No The optional number of lines to include before the selected location.
afterLines integer | null No The optional number of lines to include after the selected location.
includeEnclosingSymbols boolean No Whether the enclosing symbol chain should be included.
includeDiagnostics boolean No Whether diagnostics should be included for the selected span.
enclosingSymbolsLimit integer | null No Maximum number of enclosing symbols to return.
diagnosticsLimit integer | null No Maximum number of diagnostics to return.
expectedSnapshot object | null No Echo the snapshot returned with the data or transaction state used to construct this request.
workspace object | null No Provide workspaceId, alias, path, or any combination.

Response

Success response

Property Type Required Description
ok boolean constant (true) Yes Whether the tool invocation succeeded.
data object | null Yes Tool-specific result payload.
snapshot object Yes Exact immutable workspace snapshot associated with the result, when available.

Error response

Property Type Required Description
ok boolean constant (false) Yes Whether the tool invocation succeeded.
error object Yes Structured error details when the invocation failed.
continuation oneOf No Action the agent should take before retrying or continuing.

Bounded collections and continuation

These response locations publish returned items with explicit bounds and continuation state:

  • $/oneOf/0/properties/data/properties/enclosingSymbols
  • $/oneOf/0/properties/data/properties/diagnostics

Continuations and required actions

A non-success response may include a structured continuation at the following schema location. Follow its tool call or user-action instruction instead of guessing how to retry:

  • $/oneOf/1/properties/continuation
Complete input schema
{
  "type": "object",
  "properties": {
    "location": {
      "description": "The location selector.",
      "type": "object",
      "properties": {
        "span": {
          "type": "object",
          "properties": {
            "document": {
              "description": "Provide exactly one of path or documentId.",
              "type": "object",
              "properties": {
                "project": {
                  "description": "Disambiguates documents with matching paths or IDs.",
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "projectId": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "path": {
                      "description": "Workspace-relative path.",
                      "type": "string"
                    },
                    "targetFramework": {
                      "type": "string"
                    }
                  }
                },
                "path": {
                  "description": "Workspace-relative path.",
                  "type": "string"
                },
                "documentId": {
                  "description": "Workspace-local document ID.",
                  "type": "string"
                }
              }
            },
            "range": {
              "description": "Zero-based UTF-16 range.",
              "type": "object",
              "properties": {
                "start": {
                  "description": "Zero-based UTF-16 offset.",
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 2147483647
                },
                "length": {
                  "description": "UTF-16 code-unit length.",
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 2147483647
                }
              }
            }
          },
          "required": [
            "document",
            "range"
          ]
        },
        "selection": {
          "type": "object",
          "properties": {
            "document": {
              "description": "Provide exactly one of path or documentId.",
              "type": "object",
              "properties": {
                "project": {
                  "description": "Disambiguates documents with matching paths or IDs.",
                  "$ref": "#/properties/location/properties/span/properties/document/properties/project"
                },
                "path": {
                  "description": "Workspace-relative path.",
                  "type": "string"
                },
                "documentId": {
                  "description": "Workspace-local document ID.",
                  "type": "string"
                }
              }
            },
            "selectedText": {
              "type": "string",
              "minLength": 1
            },
            "contextBefore": {
              "type": [
                "string",
                "null"
              ]
            },
            "contextAfter": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "document",
            "selectedText"
          ]
        }
      }
    },
    "beforeLines": {
      "description": "The optional number of lines to include before the selected location.",
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "maximum": 100,
      "default": 10
    },
    "afterLines": {
      "description": "The optional number of lines to include after the selected location.",
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "maximum": 100,
      "default": 10
    },
    "includeEnclosingSymbols": {
      "description": "Whether the enclosing symbol chain should be included.",
      "type": "boolean"
    },
    "includeDiagnostics": {
      "description": "Whether diagnostics should be included for the selected span.",
      "type": "boolean"
    },
    "enclosingSymbolsLimit": {
      "description": "Maximum number of enclosing symbols to return.",
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "maximum": 2147483647,
      "default": 16
    },
    "diagnosticsLimit": {
      "description": "Maximum number of diagnostics to return.",
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "maximum": 2147483647,
      "default": 50
    },
    "expectedSnapshot": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "workspaceId": {
          "type": "string",
          "format": "uuid"
        },
        "workspaceEpoch": {
          "type": "integer"
        },
        "snapshotId": {
          "type": "string",
          "format": "uuid"
        },
        "transactionRevision": {
          "type": [
            "integer",
            "null"
          ]
        }
      },
      "required": [
        "workspaceId",
        "workspaceEpoch",
        "snapshotId",
        "transactionRevision"
      ],
      "description": "Echo the snapshot returned with the data or transaction state used to construct this request."
    },
    "workspace": {
      "description": "Provide workspaceId, alias, path, or any combination.",
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "workspaceId": {
          "type": "string",
          "format": "uuid"
        },
        "alias": {
          "type": "string"
        },
        "path": {
          "description": "Absolute workspace path.",
          "type": "string"
        }
      }
    }
  },
  "required": [
    "location"
  ]
}
Complete output schema
{
  "type": "object",
  "oneOf": [
    {
      "type": "object",
      "required": [
        "ok",
        "data",
        "snapshot"
      ],
      "properties": {
        "ok": {
          "const": true,
          "description": "Whether the tool invocation succeeded."
        },
        "data": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "location": {
              "description": "The resolved source location.",
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "document": {
                  "description": "The resolved document.",
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "documentId": {
                      "description": "The document identifier.",
                      "type": "string"
                    },
                    "path": {
                      "description": "The normalized document path.",
                      "type": "string"
                    },
                    "projectId": {
                      "description": "The owning project identifier.",
                      "type": "string"
                    }
                  },
                  "required": [
                    "documentId",
                    "path",
                    "projectId"
                  ]
                },
                "span": {
                  "description": "The resolved text span.",
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "start": {
                      "description": "Zero-based UTF-16 offset.",
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 2147483647
                    },
                    "length": {
                      "description": "UTF-16 code-unit length.",
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 2147483647
                    }
                  }
                },
                "line": {
                  "description": "The one-based line number.",
                  "type": "integer"
                },
                "column": {
                  "description": "The one-based column number.",
                  "type": "integer"
                },
                "snapshot": {
                  "description": "The exact immutable workspace snapshot associated with this location.",
                  "type": "object",
                  "properties": {
                    "workspaceId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "workspaceEpoch": {
                      "type": "integer"
                    },
                    "snapshotId": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "transactionRevision": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "workspaceId",
                    "workspaceEpoch",
                    "snapshotId",
                    "transactionRevision"
                  ]
                },
                "selector": {
                  "description": "The canonical selector that can resolve this source location again.",
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "span": {
                      "type": "object",
                      "properties": {
                        "document": {
                          "description": "Provide exactly one of path or documentId.",
                          "type": "object",
                          "properties": {
                            "project": {
                              "description": "Disambiguates documents with matching paths or IDs.",
                              "type": [
                                "object",
                                "null"
                              ],
                              "properties": {
                                "projectId": {
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                },
                                "name": {
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                },
                                "path": {
                                  "description": "Workspace-relative path.",
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                },
                                "targetFramework": {
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                }
                              }
                            },
                            "path": {
                              "description": "Workspace-relative path.",
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "documentId": {
                              "description": "Workspace-local document ID.",
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          }
                        },
                        "range": {
                          "description": "Zero-based UTF-16 range.",
                          "type": "object",
                          "properties": {
                            "start": {
                              "description": "Zero-based UTF-16 offset.",
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 2147483647
                            },
                            "length": {
                              "description": "UTF-16 code-unit length.",
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 2147483647
                            }
                          }
                        }
                      },
                      "required": [
                        "document",
                        "range"
                      ]
                    }
                  },
                  "required": [
                    "span"
                  ]
                }
              },
              "required": [
                "snapshot"
              ]
            },
            "text": {
              "description": "The bounded source text.",
              "type": "string"
            },
            "enclosingSymbols": {
              "description": "The enclosing symbol chain from the innermost symbol outward.",
              "type": "object",
              "properties": {
                "items": {
                  "description": "Items returned in this page.",
                  "type": [
                    "array",
                    "null"
                  ],
                  "items": {
                    "type": "object",
                    "properties": {
                      "displayName": {
                        "description": "The display name of the symbol.",
                        "type": "string"
                      },
                      "kind": {
                        "description": "The symbol kind.",
                        "type": "string"
                      },
                      "documentationCommentId": {
                        "description": "The documentation comment identifier, when available.",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "location": {
                        "description": "The optional source location of the symbol.",
                        "type": [
                          "object",
                          "null"
                        ],
                        "properties": {
                          "document": {
                            "description": "The resolved document.",
                            "$ref": "#/properties/request/properties/value/properties/location/properties/document"
                          },
                          "span": {
                            "description": "The resolved text span.",
                            "$ref": "#/properties/request/properties/value/properties/location/properties/span"
                          },
                          "line": {
                            "description": "The one-based line number.",
                            "type": "integer"
                          },
                          "column": {
                            "description": "The one-based column number.",
                            "type": "integer"
                          },
                          "snapshot": {
                            "description": "The exact immutable workspace snapshot associated with this location.",
                            "$ref": "#/properties/request/properties/value/properties/location/properties/snapshot"
                          },
                          "selector": {
                            "description": "The canonical selector that can resolve this source location again.",
                            "$ref": "#/properties/request/properties/value/properties/location/properties/selector"
                          }
                        },
                        "required": [
                          "snapshot"
                        ]
                      }
                    },
                    "required": [
                      "displayName",
                      "kind"
                    ]
                  }
                },
                "hasMore": {
                  "description": "Whether additional items were available beyond this page.",
                  "type": "boolean"
                },
                "totalCount": {
                  "description": "Complete result count, when available without additional expensive work.",
                  "type": [
                    "integer",
                    "null"
                  ]
                }
              }
            },
            "diagnostics": {
              "description": "The diagnostics projected for the selected location.",
              "type": "object",
              "properties": {
                "items": {
                  "description": "Items returned in this page.",
                  "type": [
                    "array",
                    "null"
                  ],
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "description": "The diagnostic identifier.",
                        "type": "string"
                      },
                      "severity": {
                        "description": "The diagnostic severity.",
                        "type": "string",
                        "enum": [
                          "Hidden",
                          "Info",
                          "Warning",
                          "Error"
                        ]
                      },
                      "message": {
                        "description": "The diagnostic message.",
                        "type": "string"
                      },
                      "location": {
                        "description": "The optional source location of the diagnostic.",
                        "type": [
                          "object",
                          "null"
                        ],
                        "properties": {
                          "document": {
                            "description": "The resolved document.",
                            "$ref": "#/properties/request/properties/value/properties/location/properties/document"
                          },
                          "span": {
                            "description": "The resolved text span.",
                            "$ref": "#/properties/request/properties/value/properties/location/properties/span"
                          },
                          "line": {
                            "description": "The one-based line number.",
                            "type": "integer"
                          },
                          "column": {
                            "description": "The one-based column number.",
                            "type": "integer"
                          },
                          "snapshot": {
                            "description": "The exact immutable workspace snapshot associated with this location.",
                            "$ref": "#/properties/request/properties/value/properties/location/properties/snapshot"
                          },
                          "selector": {
                            "description": "The canonical selector that can resolve this source location again.",
                            "$ref": "#/properties/request/properties/value/properties/location/properties/selector"
                          }
                        },
                        "required": [
                          "snapshot"
                        ]
                      }
                    },
                    "required": [
                      "id",
                      "message"
                    ]
                  }
                },
                "hasMore": {
                  "description": "Whether additional items were available beyond this page.",
                  "type": "boolean"
                },
                "totalCount": {
                  "description": "Complete result count, when available without additional expensive work.",
                  "type": [
                    "integer",
                    "null"
                  ]
                }
              }
            }
          },
          "description": "Tool-specific result payload."
        },
        "snapshot": {
          "type": "object",
          "properties": {
            "workspaceId": {
              "type": "string",
              "format": "uuid"
            },
            "workspaceEpoch": {
              "type": "integer"
            },
            "snapshotId": {
              "type": "string",
              "format": "uuid"
            },
            "transactionRevision": {
              "type": [
                "integer",
                "null"
              ]
            }
          },
          "required": [
            "workspaceId",
            "workspaceEpoch",
            "snapshotId",
            "transactionRevision"
          ],
          "description": "Exact immutable workspace snapshot associated with the result, when available."
        }
      }
    },
    {
      "type": "object",
      "required": [
        "ok",
        "error"
      ],
      "properties": {
        "ok": {
          "const": false,
          "description": "Whether the tool invocation succeeded."
        },
        "error": {
          "type": "object",
          "properties": {
            "code": {
              "description": "Stable machine-readable error code.",
              "type": "string"
            },
            "message": {
              "description": "Human-readable explanation of the failure.",
              "type": "string"
            },
            "correlationId": {
              "description": "Correlation identifier for matching the failure to server-side diagnostics, when available.",
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "code",
            "message"
          ],
          "description": "Structured error details when the invocation failed."
        },
        "continuation": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "tool",
                "instruction"
              ],
              "properties": {
                "kind": {
                  "const": "CallTool",
                  "description": "Action required before the original request can continue."
                },
                "instruction": {
                  "type": "string",
                  "description": "Agent-facing instruction explaining how to continue.",
                  "minLength": 1
                },
                "tool": {
                  "type": "string",
                  "description": "Tool to call before continuing the original request.",
                  "minLength": 1
                }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "tools",
                "instruction"
              ],
              "properties": {
                "kind": {
                  "const": "ChooseTool",
                  "description": "Action required before the original request can continue."
                },
                "instruction": {
                  "type": "string",
                  "description": "Agent-facing instruction explaining how to continue.",
                  "minLength": 1
                },
                "tools": {
                  "type": "array",
                  "description": "Allowed tool choices from which the agent must select one.",
                  "minItems": 1,
                  "uniqueItems": true,
                  "items": {
                    "type": "string",
                    "description": "Name of a tool the agent may choose.",
                    "minLength": 1
                  }
                }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "instruction"
              ],
              "properties": {
                "kind": {
                  "const": "RetryRequest",
                  "description": "Action required before the original request can continue."
                },
                "instruction": {
                  "type": "string",
                  "description": "Agent-facing instruction explaining how to continue.",
                  "minLength": 1
                }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "instruction"
              ],
              "properties": {
                "kind": {
                  "const": "ReviseRequest",
                  "description": "Action required before the original request can continue."
                },
                "instruction": {
                  "type": "string",
                  "description": "Agent-facing instruction explaining how to continue.",
                  "minLength": 1
                }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "instruction"
              ],
              "properties": {
                "kind": {
                  "const": "ResolveExternally",
                  "description": "Action required before the original request can continue."
                },
                "instruction": {
                  "type": "string",
                  "description": "Agent-facing instruction explaining how to continue.",
                  "minLength": 1
                }
              }
            }
          ],
          "description": "Action the agent should take before retrying or continuing."
        }
      }
    }
  ]
}

Machine reference