YAML Syntax & Structure
flAPI extends standard YAML with section includes, environment-variable substitution, and a fixed set of top-level keys per endpoint. This guide covers the extended syntax, the supported endpoint shapes (REST + 3 MCP variants), and path resolution rules.
Extended YAML Features
flAPI's YAML parser supports standard YAML plus these extensions:
1. Section Includes
flAPI's include directive copies one named section out of another YAML file. The syntax is:
{{include:section_name from path/to/file.yaml}}
No quotes around the path. The path is resolved relative to the including file.
Includable sections (anything else is rejected):
requestauthrate-limitconnectiontemplate-sourcecacheheartbeat
Example — a shared customer-common.yaml:
# common/customer-common.yaml
request:
- field-name: id
field-in: query
validators:
- type: int
min: 1
auth:
enabled: true
type: basic
users:
- username: admin
password: '{{env.ADMIN_PASSWORD}}'
roles: [admin, read]
rate-limit:
enabled: true
max: 100
interval: 60
connection:
- customers-parquet
template-source: customers.sql
cache:
enabled: true
table: customers_cache
schema: analytics
schedule: 5m
Endpoint that pulls them in:
# customers-rest.yaml
url-path: /customers/
method: GET
{{include:request from common/customer-common.yaml}}
{{include:auth from common/customer-common.yaml}}
{{include:rate-limit from common/customer-common.yaml}}
{{include:connection from common/customer-common.yaml}}
{{include:template-source from common/customer-common.yaml}}
{{include:cache from common/customer-common.yaml}}
with-pagination: true
You can also keep multiple variants of a section under different top-level keys in the source file (auth, auth-dev, auth-prod, ...) and choose which to include:
{{include:auth-prod from common/customer-common.yaml}}
This works because the include directive grabs the value of whatever top-level key you name.
2. Environment Variables
Reference environment variables anywhere a value is expected, with {{env.VAR}}:
auth:
jwt-secret: '{{env.JWT_SECRET}}'
jwt-issuer: '{{env.JWT_ISSUER}}'
{{env.VAR}}is the only supported form. Spaces inside the braces are fine ({{ env.VAR }}); the same form works inside SQL templates.${VAR}is not a supported syntax and is not substituted. Write{{env.VAR}}.
Every variable must match a pattern in template.environment-whitelist in the main flapi.yaml. An empty or missing whitelist allows none, and an unlisted variable in a YAML file stops startup with an error naming it.
3. Template Variables
These context variables are available inside SQL templates (not in endpoint YAML):
params.*— validated request parametersconn.*— properties of the first connection listed underconnection:auth.*— authenticated user (auth.username,auth.roles,auth.email,auth.type,auth.authenticated)cache.*— cache metadata (in cache-refresh templates)env.*— whitelisted environment variables
See SQL Templating for the full reference.
Endpoint YAML Structure
Each YAML file defines one endpoint of one of four kinds. flAPI decides which kind by inspecting the top-level keys:
| Top-level key present | Endpoint kind |
|---|---|
url-path | REST |
mcp-tool | MCP tool |
mcp-resource | MCP resource |
mcp-prompt | MCP prompt |
url-path can also coexist with mcp-tool / mcp-resource when the same query should be exposed both ways.
Basic REST Endpoint
# sqls/customers.yaml
url-path: /customers/
method: GET
request:
- field-name: segment
field-in: query
description: Market segment to filter by
required: false
validators:
- type: enum
allowedValues: [AUTOMOBILE, BUILDING, FURNITURE, HOUSEHOLD, MACHINERY]
- field-name: min_balance
field-in: query
description: Minimum account balance
required: false
validators:
- type: int
min: 0
max: 1000000
template-source: customers.sql
connection:
- customers-parquet
with-pagination: true
cache:
enabled: true
table: customers_cache
schema: analytics
schedule: 5m
primary-key: [id]
Full-Featured REST Endpoint
# sqls/orders.yaml
url-path: /orders/:order_id
method: GET
request:
- field-name: order_id
field-in: path
description: Order ID
required: true
validators:
- type: int
min: 1
- field-name: status
field-in: query
description: Order status filter
required: false
default: "completed"
validators:
- type: enum
allowedValues: [pending, completed, cancelled, refunded]
- field-name: start_date
field-in: query
description: Start of the date range (YYYY-MM-DD)
required: false
validators:
- type: date
min: "2020-01-01"
- field-name: end_date
field-in: query
description: End of the date range (YYYY-MM-DD)
required: false
validators:
- type: date
template-source: orders/detail.sql
connection:
- bigquery-warehouse
- customers-parquet
with-pagination: true
request-fields-validation: true
auth:
enabled: true
type: bearer
jwt-secret: '{{env.JWT_SECRET}}'
jwt-issuer: 'my-auth-server'
rate-limit:
enabled: true
max: 1000
interval: 60
cache:
enabled: true
table: orders_cache
schema: analytics
schedule: 15m
primary-key: [order_id]
cursor:
column: updated_at
type: timestamp
retention:
keep-last-snapshots: 5
max-snapshot-age: 14d
Top-Level Keys Reference
| Key | Type | Default | Notes |
|---|---|---|---|
url-path | string | – | Required for REST endpoints. Path parameters use :name. |
method | string | GET | Single HTTP method: GET, POST, PUT, PATCH, DELETE. Use one string, not a list. |
template-source | string | – | Required for REST + MCP-tool + MCP-resource. Path to .sql file. |
connection | list[string] | – | Required when a template is used. First entry exposes conn.* in templates. |
request | list | [] | Request parameter definitions. |
with-pagination | bool | true | Wraps responses in {data, next, total_count} and accepts limit/offset. |
request-fields-validation | bool | false | Reject requests containing parameters not declared in request:. |
auth | mapping | inherits global | Per-endpoint auth override — see Authentication. |
rate-limit | mapping | inherits global | Per-endpoint rate-limit override. |
cache | mapping | – | DuckLake cache configuration. |
operation | mapping | auto | type: Read / type: Write, plus returns-data, transaction, validate-before-write. |
heartbeat | mapping | – | Endpoint heartbeat config. |
mcp-tool | mapping | – | Declares an MCP tool. |
mcp-resource | mapping | – | Declares an MCP resource. |
mcp-prompt | mapping | – | Declares an MCP prompt. |
Note:
methodis a single string. There is nomethods: [GET]list form.
MCP Endpoint Variants
flAPI exposes the same YAML configuration as three MCP shapes for AI agents.
MCP Tool
A callable tool that runs an SQL query. Only these three keys are recognised:
| Key | Type | Default | Description |
|---|---|---|---|
mcp-tool.name | string | required | Unique tool name (alphanumeric / underscore) |
mcp-tool.description | string | required | Tool description for the LLM |
mcp-tool.result-mime-type | string | application/json | MIME type sent back to the model |
# sqls/customers-mcp.yaml
mcp-tool:
name: search_customers
description: |
Search and retrieve customer information with flexible filtering
by segment, balance, name, or registration date.
result-mime-type: application/json
request:
- field-name: segment
field-in: query
required: false
validators:
- type: enum
allowedValues: [AUTOMOBILE, BUILDING, FURNITURE, MACHINERY, HOUSEHOLD]
- field-name: min_balance
field-in: query
required: false
validators:
- type: int
min: 0
max: 1000000
- field-name: name
field-in: query
required: false
validators:
- type: string
min: 2
max: 50
regex: '^[A-Za-z ]+$'
template-source: customers/search.sql
connection:
- customers-parquet
MCP Resource
A readable resource — e.g. an introspection query exposed as data.
| Key | Type | Default | Description |
|---|---|---|---|
mcp-resource.name | string | required | Unique resource name |
mcp-resource.description | string | required | Description shown to the model |
mcp-resource.mime-type | string | application/json | Content MIME type |
mcp-resource:
name: customer_schema
description: Customer table schema and field definitions
mime-type: application/json
template-source: customers/schema.sql
connection:
- customers-parquet
MCP Prompt
A reusable, parameterised Mustache prompt. Prompts have an inline template (no template-source) and do not need a connection.
| Key | Type | Default | Description |
|---|---|---|---|
mcp-prompt.name | string | required | Unique prompt name |
mcp-prompt.description | string | required | Description shown to the model |
mcp-prompt.template | string | required | Inline Mustache template body |
mcp-prompt.arguments | list[string] | [] | Template argument names |
mcp-prompt:
name: customer_analysis
description: Generate a customer analysis prompt
template: |
You are a data analyst. Analyse this customer:
{{#customer_id}}Customer ID: {{customer_id}}{{/customer_id}}
{{#segment}}Segment: {{segment}}{{/segment}}
Provide insights on purchasing patterns and recommendations.
arguments:
- customer_id
- segment
File Structure Best Practices
Recommended Directory Layout
project/
├── flapi.yaml # Main configuration