On this page

fetch-code

Fetch a single code span from the ingested codebase (CodeChunk store). Pass path + start_line/end_line from a search-code hit, or row_pk of a chunk. Response is size-capped. Do not use query-context to dump source text.

What it is called on each surface

The wire name is fetch-code everywhere: it is what the Wexa MCP server advertises, the REST path is POST /v1/fetch-code, and each SDK exposes it under its own language's naming convention.

SurfaceName
Wexa MCP serverfetch-code
REST APIPOST /v1/fetch-code
TypeScript SDKfabric.fetchCode()
Python SDKfabric.fetch_code()

Arguments

Every argument is optional: fetch-code answers a bare call.

ArgumentTypeRequiredNotes
end_lineintegerOptional1-based end line (inclusive)
pathstringOptionalRepo-relative file path
row_pkstringOptionalOptional CodeChunk row_pk from search-code
start_lineintegerOptional1-based start line (inclusive)

project_id, projectID, organization_id and executed_by are not arguments you pass: the platform binds all four from the credential you authenticated with, and both SDKs refuse them before the request leaves your process — see server-bound arguments.

What it returns

The three surfaces wrap this differently, and code written against one will not read another correctly — see return shape.

A real response, captured from a live call to fetch-code:

{
  "content": [
    {
      "type": "text",
      "text": "{\"lifecycle_id\":\"qlc_000166\",\"result\":{\"content\":\"\",\"note\":\"no CodeChunk matched; re-sync the repo after CodeChunk ingest shipped\",\"truncated\":false}}"
    }
  ],
  "isError": false
}

Keeping the lifecycle_id is what lets you ask later why a call was allowed, refused or held.

Calling it

The same call on all four surfaces. Pick a tab once and every code block in the documentation follows it.

The ids in this example are real: they resolve against the project the documentation is written against, so the call runs as written once you point it at your own deployment. Swap them for the ids of your own objects.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "fetch-code",
    "arguments": {
      "end_line": 10
    }
  }
}

Errors

Both SDKs raise the same typed errors, chosen from the gateway's own error string first and its HTTP status second. fetch-code checks the fabric:query.read grant, and reaches the seven classes every tool reaches — listed under the common set. These are the ones specific to it:

ErrorStatusRaised when
NotFound404path, or row_pk, matches no ingested file in this project.

Governance

Every call to fetch-code runs through the same ten-stage lifecycle as every other Wexa tool: the credential is resolved to a scope, the fabric:query.read grant is checked, quota is drawn down, the arguments are validated, policy rules are evaluated, the call is executed, the result is shaped and redacted, and an audit record is written. The lifecycle_id in the response is the handle to that record.

fetch-code only reads, so it is not marked consequential: it is audited lightly and is never held for approval. It still consumes quota and is still refused by policy like anything else.

See also

The tool index and errors.