# edit_flight_source
> Edit a Flight's source code with one or more find-and-replace operations, producing a new version.
Edit a [Flight](/concepts/flights)'s `source_code` by applying one or more text replacements, then save as a new `FlightVersion`. The tool reads the current source, applies the edits in sequence, validates the result, and persists.

Use this when you want to change a small part of a Flight without resending the entire file through [`update_flight`](../update-flight).

## Description

Each edit is a `{old_string, new_string, replace_all?}` object. `old_string` must occur exactly once in the source unless `replace_all` is true. Edits apply sequentially: edit N sees the source after edits 1 through N-1.

No prior `get_flight` call is required — the tool reads the current source itself.

This tool is MCP-only; there is no direct SQL equivalent. To achieve the same outcome in SQL, read the source through [`MD_GET_FLIGHT`](/sql-reference/motherduck-sql-reference/flights/md-get-flight), modify it client-side, and call [`MD_UPDATE_FLIGHT`](/sql-reference/motherduck-sql-reference/flights/md-update-flight) with the full updated source.

## Input parameters

| Parameter | Type | Required | Description |
|---|---|---|---|
| `id` | string (UUID) | Yes | The Flight UUID. |
| `edits` | array | Yes | List of edit objects (see below). Must contain at least one. |

Each entry in `edits`:

| Field | Type | Required | Description |
|---|---|---|---|
| `old_string` | string | Yes | Exact text to find and replace. Must be unique in the source unless `replace_all` is true. |
| `new_string` | string | Yes | The replacement text. Must differ from `old_string`. |
| `replace_all` | boolean | No | If true, replace every occurrence. Default `false`. |

## Output schema

```json
{
  "success": boolean,
  "flight": {
    "id": string,
    "name": string,
    "current_version": number
  },
  "error": string
}
```

## Example usage

Change one line:

```json
{
  "id": "80000000-...",
  "edits": [
    {
      "old_string": "duckdb==1.5.1",
      "new_string": "duckdb==1.5.2"
    }
  ]
}
```

Rename every occurrence of a variable:

```json
{
  "id": "80000000-...",
  "edits": [
    {
      "old_string": "raw_table",
      "new_string": "raw_events",
      "replace_all": true
    }
  ]
}
```

## Related

- [`update_flight`](../update-flight) — Send a full replacement source.
- [`get_flight`](../get-flight) — Inspect the source before editing.
- [`list_flight_versions`](../list-flight-versions) — See the versions created by edits.


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `POST https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

Payload:

```json
{
  "page_path": "/sql-reference/mcp/edit-flight-source/",
  "page_title": "edit_flight_source",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed payloads, and `429` when rate-limited.
