When to use app() vs define()?
| Pattern | When to use it |
|---|---|
define() | A single operation with one HTTP endpoint |
app() | Multiple related tools you want to deploy together |
define(). If you need to group multiple operations — for example, sending and reading emails from the same service — use app().
Basic example
index.ts
Local testing
Start the server withjelou functions dev and test each tool at its route:
400 with details:
API
AppConfig
| Field | Type | Default | Description |
|---|---|---|---|
cors | object | { origin: "*" } | Global CORS configuration |
timeout | number | 30000 | Timeout in ms for all tools |
methods | string[] | ["GET","POST","PUT","PATCH","DELETE"] | Allowed HTTP methods |
mcp | boolean | true | Register tools in the MCP server |
Auto-generated routes
Yourtools object keys are automatically converted to kebab-case to generate HTTP routes:
| Key | Route |
|---|---|
sendEmail | /send-email |
readInbox | /read-inbox |
MyTool | /my-tool |
config.path in the individual define():
Config combination
The global config ofapp() applies to all tools. Each define() can override specific values:
| Field | Behavior |
|---|---|
timeout | Tool overrides the global |
methods | Tool overrides the global |
cors | Tool overrides the global |
mcp | Tool overrides the global |
path | Always per tool |
cron | Always per tool |
fast has a 5-second timeout and slow inherits the global 30 seconds. Both share the CORS configuration.
Health endpoint
In app mode,/__health returns information about all tools:
Type guards
UseisEdgeApp() and isEdgeFunction() to identify the export type at runtime:
Multi-tool cron
Each tool insideapp() can have its own independent cron schedules. Cron requests are sent to the specific route of each tool.
Multi-tool MCP
A single MCP server at/mcp automatically registers all tools from the app(). To exclude a tool from the MCP registry, use mcp: false in its config:
publicTool via MCP. internalTool is only accessible via direct HTTP at its /internal-tool route.
Exposed routes (app mode)
| Route | Description |
|---|---|
/__health | Health check with tool list |
/mcp | Unified MCP server (unless config.mcp: false globally) |
/<tool-key> | Each tool’s route (kebab-case or custom config.path) |
Common issues
- 404 on tool route
- Validation fails with 400
- Tool does not appear in MCP
tools keys are converted to kebab-case. If your key is sendEmail, the route is /send-email, not /sendEmail.Verify the actual routes with the health check:Next steps
Testing
Learn to test multi-tool functions with
createMockApp().MCP
Configure the unified MCP server for your AI agents.
Cron
Independent schedules per tool inside
app().