# create_flight
> Create a new Flight from Python source code, requirements, token, and an optional schedule.
Create a new [Flight](/concepts/flights). A Flight is a Python entrypoint plus an optional `requirements.txt` that runs on MotherDuck compute. Provide `md_token_name` so the Flight can connect to MotherDuck at runtime. Optionally provide a 5-field cron expression to run on a schedule.

Call [`get_flight_guide`](../get-flight-guide) first if you need the authoring reference.

## Description

`create_flight` is the marquee entry point for the MCP Flights surface. The SQL equivalent is [`MD_CREATE_FLIGHT`](/sql-reference/motherduck-sql-reference/flights/md-create-flight).

The parameter names on the MCP tool keep the `md_*` prefix (for example, `md_token_name`, `md_secret_names`); the equivalent SQL function uses unprefixed names (`access_token_name`, `flight_secret_names`).

## Input parameters

| Parameter | Type | Required | Description |
|---|---|---|---|
| `name` | string | Yes | Flight name (used in logs and listings). |
| `source_code` | string | Yes | Python source for the Flight. A single-file program with a top-level `def main(): ...`. |
| `md_token_name` | string | Yes | Label of a MotherDuck access token. Injected as `MOTHERDUCK_TOKEN` at runtime. List labels with `SELECT * FROM md_access_tokens();`. |
| `schedule_cron` | string | No | 5-field cron expression in UTC. Omit for on-demand only. |
| `requirements_txt` | string | No | `requirements.txt` contents, one pinned package per line. |
| `config` | object | No | Non-secret key/value pairs surfaced as environment variables. |
| `md_secret_names` | string[] | No | MotherDuck secret names surfaced as environment variables. End-to-end secret delivery is in development. |

## Output schema

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

## Example usage

Minimal Flight:

```json
{
  "name": "heartbeat",
  "source_code": "import duckdb\n\ndef main():\n    duckdb.connect('md:').execute('SELECT 1').fetchall()\n    print('ok')\n",
  "md_token_name": "analytics_token",
  "requirements_txt": "duckdb==1.5.2"
}
```

Scheduled Flight with config:

```json
{
  "name": "hourly_metrics",
  "source_code": "...",
  "md_token_name": "analytics_token",
  "requirements_txt": "duckdb==1.5.2\nrequests==2.32.4",
  "schedule_cron": "0 * * * *",
  "config": { "REGION": "eu-central-1" }
}
```

## Related

- [`update_flight`](../update-flight) — Modify an existing Flight.
- [`edit_flight_source`](../edit-flight-source) — Surgical source edit.
- [`run_flight`](../run-flight) — Trigger a manual run after creation.
- [`MD_CREATE_FLIGHT`](/sql-reference/motherduck-sql-reference/flights/md-create-flight) — SQL equivalent.


---

## 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/create-flight/",
  "page_title": "create_flight",
  "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.
