# create_flight
> Create a new Flight from Python source code, requirements, 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. Optionally provide `md_token_name` to run the Flight as a specific access token; omit it to use the default `MotherDuck Flights` access token. Optionally provide a 5-field cron expression to run on a schedule.

You are responsible for the code you run and the packages it installs. Flights does not scan customer code or dependencies. Avoid untrusted packages, pin dependency versions, and treat dependency installs as a supply-chain risk.

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, executed as a plain script; end it with `if __name__ == "__main__": main()` to invoke your entrypoint. |
| `md_token_name` | string | No | Label of a MotherDuck access token to run the Flight as. Injected as `MOTHERDUCK_TOKEN` at runtime. Omit it to use the default `MotherDuck Flights` access token. 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 | Names of [Flight secrets](/sql-reference/motherduck-sql-reference/create-secret#flight-secrets) whose key-value pairs are surfaced as environment variables. |

## 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\nif __name__ == \"__main__\":\n    main()\n",
  "requirements_txt": "duckdb==1.5.3"
}
```

Scheduled Flight with config, running as a specific access token:

```json
{
  "name": "hourly_metrics",
  "source_code": "...",
  "md_token_name": "analytics_token",
  "requirements_txt": "duckdb==1.5.3\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.
