> Source: https://wexa.ai/docs/context/fetch-code

# fetch-code

Fetch one code span from the ingested codebase. Needs the `fabric:query.read` grant.

**Fetch a span**

**Wexa MCP server**

```bash
curl -sS -X POST https://fabric.wexa.ai/mcp/$FABRIC_PROJECT_ID \
  -H "authorization: Bearer $FABRIC_API_KEY" \
  -H "Mcp-Session-Id: $MCP_SESSION_ID" \
  -H "content-type: application/json" -H "accept: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"fetch-code","arguments":{"path":"src/main.go","start_line":1,"end_line":10}}}'
```

```json
{
  "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
}
```

**REST API**

```bash
curl -sS https://fabric.wexa.ai/v1/fetch-code \
  -H "authorization: Bearer $FABRIC_API_KEY" \
  -H "content-type: application/json" \
  -d '{"path":"src/main.go","start_line":1,"end_line":10}'
```

```json
{
  "lifecycle_id": "qlc_000166",
  "result": {
    "content": "",
    "note": "no CodeChunk matched; re-sync the repo after CodeChunk ingest shipped",
    "truncated": false
  }
}
```

**TypeScript SDK**

```ts
import { Fabric } from '@wexa-fabric/sdk'

const fabric = new Fabric()
const result = await fabric.fetchCode({
  path: 'src/main.go',
  start_line: 1,
  end_line: 10
})
```

```ts
// result is the payload itself, with no `.result` to read
{
  content: '',
  note: 'no CodeChunk matched; re-sync the repo after CodeChunk ingest shipped',
  truncated: false
}
```

**Python SDK**

```python
from wexa import Fabric

fabric = Fabric()
out = fabric.fetch_code(
    path="src/main.go",
    start_line=1,
    end_line=10,
)
```

```python
# out is the result, already unwrapped
{
    "content": "",
    "note": "no CodeChunk matched; re-sync the repo after CodeChunk ingest shipped",
    "truncated": False
}
```

## Parameters

| Parameter | Type | Required | Notes |
| --- | --- | --- | --- |
| `path` | string | Optional | Repo-relative file path, from a `search-code` hit. Give `path` with `start_line` and `end_line`, or `row_pk` instead. |
| `start_line` | integer | Optional | 1-based start line (inclusive). Needed with `path`; positive. |
| `end_line` | integer | Optional | 1-based end line (inclusive). Needed with `path`; positive and not below `start_line`. |
| `row_pk` | string | Optional | A CodeChunk `row_pk` from `search-code`. Replaces `path` and the line range. |

**Errors**

A path or `row_pk` that matches nothing is not an error: the call succeeds with empty `content` and a `note`.

**Show full response**

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

**Result of fetch-code**

**REST API**

```json
{
  "lifecycle_id": "qlc_000166",
  "result": {
    "content": "",
    "note": "no CodeChunk matched; re-sync the repo after CodeChunk ingest shipped",
    "truncated": false
  }
}
```

**Wexa MCP server**

```json
{
  "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
}
```

**TypeScript SDK**

```ts
// the object you get back IS the result — there is no `.result` to read
{
  content: '',
  note: 'no CodeChunk matched; re-sync the repo after CodeChunk ingest shipped',
  truncated: false
}

// The TS SDK names these camelCase — lifecycleId, traceId — where Python uses
// lifecycle_id and trace_id. Both are non-enumerable: readable, but omitted by
// Object.keys() and JSON.stringify(). `result.lifecycleId` here is undefined.
result.lifecycleId // 'qlc_000166'
```

**Python SDK**

```python
# a dict subclass; `result` is already unwrapped
{
 "content": "",
 "note": "no CodeChunk matched; re-sync the repo after CodeChunk ingest shipped",
 "truncated": False
}

out.lifecycle_id  # 'qlc_000166' — an attribute, not a key
```

**More details**

Full description from the tool, as the gateway advertises it:

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.

The captured call matched no chunk, so `content` is empty and `note` says to re-sync the repository. There is no 404 for a missing file.

Not marked consequential: it is audited lightly and the project's write gate never holds it.

Every tool call works the same way: [How every tool call works](/docs/sdks-and-apis/how-every-tool-call-works).
