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

# search-code

Grep-like search over the project's ingested codebase. Needs the `fabric:query.read` grant.

**Search code**

**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":"search-code","arguments":{"query":"handler"}}}'
```

```json
{
  "content": [
    {
      "type": "text",
      "text": "{\"lifecycle_id\":\"qlc_000165\",\"result\":{\"backend\":\"fulltext_unavailable\",\"count\":0,\"filtered_out\":0,\"hits\":[],\"note\":\"Use fetch-code with path + start_line/end_line (or row_pk) to load one span. Prefer search-code over query-context for code text.\"}}"
    }
  ],
  "isError": false
}
```

**REST API**

```bash
curl -sS https://fabric.wexa.ai/v1/search-code \
  -H "authorization: Bearer $FABRIC_API_KEY" \
  -H "content-type: application/json" \
  -d '{"query":"handler"}'
```

```json
{
  "lifecycle_id": "qlc_000165",
  "result": {
    "backend": "fulltext_unavailable",
    "count": 0,
    "filtered_out": 0,
    "hits": [],
    "note": "Use fetch-code with path + start_line/end_line (or row_pk) to load one span. Prefer search-code over query-context for code text."
  }
}
```

**TypeScript SDK**

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

const fabric = new Fabric()
const result = await fabric.searchCode({
  query: 'handler'
})
```

```ts
// result is the payload itself, with no `.result` to read
{
  backend: 'fulltext_unavailable',
  count: 0,
  filtered_out: 0,
  hits: [],
  note: 'Use fetch-code with path + start_line/end_line (or row_pk) to load one span. Prefer search-code over query-context for code text.'
}
```

**Python SDK**

```python
from wexa import Fabric

fabric = Fabric()
out = fabric.search_code(
    query="handler",
)
```

```python
# out is the result, already unwrapped
{
    "backend": "fulltext_unavailable",
    "count": 0,
    "filtered_out": 0,
    "hits": [],
    "note": "Use fetch-code with path + start_line/end_line (or row_pk) to load one span. Prefer search-code over query-context for code text."
}
```

## Parameters

| Parameter | Type | Required | Notes |
| --- | --- | --- | --- |
| `query` | string | Required | Search terms: a symbol, string or keywords. Must not be blank. |
| `lang` | string | Optional | Language filter, for example `python` or `rust`. |
| `path_prefix` | string | Optional | Path prefix filter, for example `src/`. |
| `limit` | integer | Optional | Max hits (default 25, max 50). A positive integer: zero, negative or non-numeric is refused. |

**Show full response**

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

**Result of search-code**

**REST API**

```json
{
  "lifecycle_id": "qlc_000165",
  "result": {
    "backend": "fulltext_unavailable",
    "count": 0,
    "filtered_out": 0,
    "hits": [],
    "note": "Use fetch-code with path + start_line/end_line (or row_pk) to load one span. Prefer search-code over query-context for code text."
  }
}
```

**Wexa MCP server**

```json
{
  "content": [
    {
      "type": "text",
      "text": "{\"lifecycle_id\":\"qlc_000165\",\"result\":{\"backend\":\"fulltext_unavailable\",\"count\":0,\"filtered_out\":0,\"hits\":[],\"note\":\"Use fetch-code with path + start_line/end_line (or row_pk) to load one span. Prefer search-code over query-context for code text.\"}}"
    }
  ],
  "isError": false
}
```

**TypeScript SDK**

```ts
// the object you get back IS the result — there is no `.result` to read
{
  backend: 'fulltext_unavailable',
  count: 0,
  filtered_out: 0,
  hits: [],
  note: 'Use fetch-code with path + start_line/end_line (or row_pk) to load one span. Prefer search-code over query-context for code text.'
}

// 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_000165'
```

**Python SDK**

```python
# a dict subclass; `result` is already unwrapped
{
 "backend": "fulltext_unavailable",
 "count": 0,
 "filtered_out": 0,
 "hits": [],
 "note": "Use fetch-code with path + start_line/end_line (or row_pk) to load one span. Prefer search-code over query-context for code text."
}

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

**More details**

`backend: "fulltext_unavailable"` means the project's code text indexes do not exist yet, which is the state of a project with no ingested codebase. The call degrades to an empty result (`count: 0`, no hits) instead of an error. Run code sync, then search again.

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

Grep-like search over the project's ingested codebase (CodeChunk fulltext on the server). Use this for finding symbols, strings, and file text when you have no local repo access. Returns slim hits \{path, start_line, end_line, preview, score\}. Then call fetch-code for one span. Do NOT write Cypher / query-context for code text search.

It is not consequential, so it is never held for approval, and it is registered on every deployment, so it cannot be missing.

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