createFunction
Create a new MicroFn workspace/function with TypeScript code. The code must export either: 1) A 'main' function as the entry point, OR 2) Any named function (which will be auto-wrapped with a main function). Examples: 'export async function main() { return "hello" }', 'export async function sayHello(name) { return "hello " + name }' (auto-wrapped), 'export async function main() { const btc = await fetch("..."); return btc.json() }'. IMPORTANT: Import @microfn/* modules as defaults: 'import kv from "@microfn/kv"' NOT 'import { kv } from "@microfn/kv"'. Common patterns: use @microfn/secret for env vars, @microfn/kv for persistent storage (e.g., counters, cache), and fetch() for HTTP requests. Input: 'name' (string) - the function name, 'code' (string) - the TypeScript code. Output: the created workspace object with its name and metadata.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"name": "<name>",
"code": "<code>"
},
"name": "createFunction"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | TypeScript code with exported function(s). Can be: 1) 'export async function main() {...}' for direct entry point, 2) 'export async function anyName() {...}' which auto-wraps with main(), 3) Multiple functions where main() calls others. Examples: Simple API call: 'export async function main() { const res = await fetch("https://api.example.com"); return res.json(); }'. With KV storage: 'import kv from "@microfn/kv"; export async function main() { const count = (await kv.get("count")) || 0; await kv.set("count", count + 1); return count + 1; }'. ALWAYS use default imports for @microfn/* modules. | |
| name | Yes | The name for the new function/workspace |