> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.basement.chat/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.basement.chat/_mcp/server.

# Find a phrase in a document or a text file

POST https://mcp.basement.chat/v1/tools/find_text
Content-Type: application/json

Find a phrase in a document, a skill or a text file, without reading all of it. Give docId or fileId. Returns each matching line with its line number and the lines around it. The match ignores case. Use the returned text as oldText in edit_doc, edit_skill or edit_file. To read more lines, use read_lines.

Reference: https://docs.basement.chat/api-reference/gateway-api/text/find

## Authentication

- `Authorization` header (bearer token, required) — A Basement key (bsmt_...), from Agents, Connect in the app.

## Request

### Body (application/json)

This endpoint expects an object.

- `query` (string, required) — The phrase to find, on one line
- `docId` (string, optional) — The document ID from list_docs
- `fileId` (string, optional) — The file ID from list_files, list_skills or search
- `contextLines` (double, optional) — Lines to return before and after each match (default 2, maximum 10)
- `limit` (double, optional) — Max matches (default 20, maximum 50)

## Response

### 200

The tool's answer.

- `totalLines` (integer, required)
- `totalMatches` (integer, required)
- `matches` (list of TextMatch, required)

## Errors

### 400 Bad Request Error

The arguments are not valid, or the tool refused them.

- `error` (ErrorResponseError, required)

### 401 Unauthorized Error

The API key is missing, wrong, revoked or expired.

- `error` (ErrorResponseError, required)

### 403 Forbidden Error

The key's access level does not allow this call.

- `error` (ErrorResponseError, required)

### 429 Too Many Requests Error

Too many calls in a minute. Wait and try again.

- `error` (ErrorResponseError, required)

### 500 Internal Server Error

Basement failed to complete the call.

- `error` (ErrorResponseError, required)

## Types

### TextMatch

- `line` (integer, required) — The line's number, starting at 1
- `text` (string, required) — The line that matches
- `before` (list of string, required)
- `after` (list of string, required)

### ErrorResponseError

- `code` (string, required) — unauthorized, forbidden, invalid_request, not_found, rate_limited, service_error or internal_error
- `message` (string, required) — What went wrong, in English

## Examples

**Request**

```json
{
  "query": "string"
}
```

**Response**

```json
{
  "totalLines": 1,
  "totalMatches": 1,
  "matches": [
    {
      "line": 1,
      "text": "string",
      "before": [
        "string"
      ],
      "after": [
        "string"
      ]
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "https://mcp.basement.chat/v1/tools/find_text"

payload = { "query": "string" }
headers = {
    "Authorization": "Bearer <apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://mcp.basement.chat/v1/tools/find_text';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <apiKey>', 'Content-Type': 'application/json'},
  body: '{"query":"string"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://mcp.basement.chat/v1/tools/find_text"

	payload := strings.NewReader("{\n  \"query\": \"string\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://mcp.basement.chat/v1/tools/find_text")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"query\": \"string\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://mcp.basement.chat/v1/tools/find_text")
  .header("Authorization", "Bearer <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"query\": \"string\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://mcp.basement.chat/v1/tools/find_text', [
  'body' => '{
  "query": "string"
}',
  'headers' => [
    'Authorization' => 'Bearer <apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://mcp.basement.chat/v1/tools/find_text");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"query\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["query": "string"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://mcp.basement.chat/v1/tools/find_text")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```