Skip to main content

create_flight

Preview
This feature is in preview and is subject to change.

Create a new Flight. 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 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.

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

ParameterTypeRequiredDescription
namestringYesFlight name (used in logs and listings).
source_codestringYesPython 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_namestringNoLabel 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_cronstringNo5-field cron expression in UTC. Omit for on-demand only.
requirements_txtstringNorequirements.txt contents, one pinned package per line.
configobjectNoNon-secret key/value pairs surfaced as environment variables.
md_secret_namesstring[]NoNames of Flight secrets whose key-value pairs are surfaced as environment variables.

Output schema

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

Example usage

Minimal Flight:

{
"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:

{
"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" }
}