How to Build and Publish Your First Toolpal Workflow
Go from an empty folder to a published workflow on toolpal.dev — covering scaffolding, TypeBox schemas, auto-derived permissions, live sandbox examples, local testing, and public or private publishing.
On this page
Prerequisites & sign-in
Publishing a workflow takes about five minutes. Every workflow lives under your personal @username scope, gets bundled into a single inspectable ESM file, and has its permissions derived automatically from static analysis before it ever hits the registry.
- Node.js 22.15 or newer (Node 25+ / 26 LTS recommended).
- A free Toolpal account — sign up on toolpal.dev or straight from your terminal with
toolpal login.
Sign in once from your terminal to link the CLI to your account:
npx toolpal login
npx toolpal whoamitoolpal login opens a browser verification code, pins the registry's Ed25519 signing key, and stores a revocable CLI token in ~/.toolpal/config.json.
1. Scaffold a new workflow project
Use npx toolpal init to create a ready-to-build TypeScript project under your scope. Because you're signed in, a bare name like word-count automatically becomes @your-login/word-count:
npx toolpal init word-count
cd word-count
npm install(If you haven't logged in yet, pass the scoped name explicitly: npx toolpal init word-count --name @your-login/word-count.)
Here is what init generates:
| File | Purpose |
|---|---|
package.json | Workflow name, license, keywords, repository, optional limits, and @toolpal/tool dependency. |
src/index.ts | Your workflow source file exporting defineTool({ ... }). |
tsconfig.json | Strict ESM TypeScript configuration for NodeNext. |
README.md | Displayed on your workflow page on toolpal.dev below the verified Examples card. |
2. Write your workflow with defineTool()
Open src/index.ts. In TypeScript, every workflow default-exports defineTool() from @toolpal/tool (which maps directly to an MCP tool and an SDK callable). Define your input and output schemas with TypeBox's Type builder, which compiles to plain JSON Schema with full static TypeScript inference:
// src/index.ts
import { defineTool, Type } from "@toolpal/tool";
export default defineTool({
description: "Counts words, characters, and estimated reading time for a block of text.",
input: Type.Object({
text: Type.String({ maxLength: 100_000, description: "Text to analyze" }),
wordsPerMinute: Type.Optional(
Type.Integer({ minimum: 50, maximum: 1000, description: "Reading speed (default 200)" }),
),
}),
output: Type.Object({
words: Type.Integer(),
characters: Type.Integer(),
uniqueWords: Type.Integer(),
readingMinutes: Type.Number(),
}),
examples: [
{
title: "Analyze a short paragraph",
prompt: "Count the words and reading time of this paragraph",
input: {
text: "Toolpal bundles workflows into inspectable local sandboxes with automatic permission checks.",
},
},
],
handler: async ({ text, wordsPerMinute = 200 }, ctx) => {
ctx.log("info", "Analyzing text", { length: text.length });
const tokens = text.trim() ? text.trim().split(/\s+/) : [];
const uniqueWords = new Set(tokens.map((w) => w.toLowerCase())).size;
return {
words: tokens.length,
characters: text.length,
uniqueWords,
readingMinutes: Number((tokens.length / wordsPerMinute).toFixed(2)),
};
},
});Notice that examples only takes input (plus optional title and prompt) — never hand-written outputs. During toolpal build, Toolpal runs each example in the sandbox and captures the real output automatically for your toolpal.dev overview page (see Docs → Examples for env flags and limits).
You can import any pure JS/TS npm package — esbuild bundles it into dist/tool.mjs automatically. Native C++ addons and dangerous Node modules (child_process, worker_threads, inspector) are blocked by the sandbox.
3. Work with files (FilePath)
If your workflow reads input files or generates output files (PDFs, CSVs, images, docs), declare top-level FilePath() fields from @toolpal/tool. Toolpal automatically grants permissions.tmp: true, copies input files into a private call directory, and lets you write output files inside ctx.outputDir:
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { defineTool, FilePath, Type } from "@toolpal/tool";
export default defineTool({
description: "Converts a UTF-8 text file to uppercase and writes a new file.",
input: Type.Object({
file: FilePath({ description: "Input UTF-8 text file" }),
}),
output: Type.Object({
result: FilePath({ description: "Uppercased output file" }),
bytes: Type.Integer(),
}),
examples: [
{
title: "Uppercase a sample text file",
prompt: "Convert notes.txt to uppercase",
input: { file: "examples/notes.txt" }, // fixture inside your project folder
},
],
handler: async ({ file }, ctx) => {
const upper = (await readFile(file, "utf8")).toUpperCase();
const result = join(ctx.outputDir, "upper.txt");
await writeFile(result, upper, "utf8");
return { result, bytes: Buffer.byteLength(upper) };
},
});FilePath() must be a top-level property of input / output (or the items of a top-level Type.Array(FilePath())). Always write outputs inside ctx.outputDir — paths outside it fail with OUTPUT_INVALID.
4. Build and review derived permissions
Before building, polish your package.json metadata (license, keywords, and repository) so users can discover your workflow cleanly. Notice there is no version field to maintain — Toolpal assigns versions automatically on publish:
{
"name": "@your-login/word-count",
"type": "module",
"license": "MIT",
"repository": "https://github.com/your-login/word-count",
"keywords": ["text", "words", "reading-time", "offline"],
"toolpal": {
"entry": "src/index.ts",
"limits": {
"timeoutMs": 10000,
"memoryMb": 128
}
},
"dependencies": {
"@toolpal/tool": "^0.1.5"
},
"devDependencies": {
"toolpal": "^0.1.5",
"typescript": "^5.9.0"
}
}Now build the bundle and inspect the generated manifest and static analysis report:
npx toolpal build
npx toolpal info ./
npx toolpal analyzeToolpal inspects your bundle's AST and automatically derives three capabilities — and re-runs the exact same analyzer on the server when you publish:
net— enabled automatically if your code callsfetch,WebSocket, or Node HTTP/TLS modules (literal hostnames are recorded for transparency).env— lists everyprocess.env.MY_KEYread in your code.tmp— enabled automatically if you importnode:fsor declare aFilePath()field.
For pure offline workflows like word-count, all three permissions stay completely off — giving users maximum confidence when installing it.
5. Test locally via CLI, SDK, or MCP
You can test your built workflow locally in the real Toolpal sandbox before publishing a single version:
# Run directly from the terminal
npx toolpal run ./ -i '{"text":"Hello from my local Toolpal workflow"}'
# Or serve ONLY this local folder over MCP to test with Claude / Cursor / Antigravity
npx -y toolpal mcp ./You can even call a local build directory straight from @toolpal/sdk without pinning it first:
import { toolpal } from "@toolpal/sdk";
const out = await toolpal.execute({
tool: "./word-count",
input: { text: "Testing locally before publishing" },
});
console.log(out);6. Publish (public, private, or from CI)
Run a --dry-run first to execute every registry validation check (manifest, schemas, permissions, scope) without creating a version, then publish for real:
# Validate everything against api.toolpal.dev without publishing
npx toolpal publish --dry-run
# Publish publicly to toolpal.dev (assigned version 1.0)
npx toolpal publishPublishing a private workflow
Building an internal workflow for your own scripts or MCP assistant? Pass --private on the first publish. Only your account can see, search, install, or serve it via toolpal mcp:
npx toolpal publish --privateVisibility sticks to the workflow, so subsequent publishes don't need the flag. You can switch later with npx toolpal visibility @your-login/word-count public (or from the ⋯ menu on the workflow page).
Publishing automatically from GitHub Actions / CI
Generate a CI token in Settings → API tokens (or npx toolpal token create --name ci), store it as a secret, and publish non-interactively:
# Standard CI publish
TOOLPAL_TOKEN=${{ secrets.TOOLPAL_TOKEN }} npx toolpal publish
# Or skip sandbox examples in CI if they require local secrets
npx toolpal build --no-examples
TOOLPAL_TOKEN=${{ secrets.TOOLPAL_TOKEN }} npx toolpal publish --no-build7. Versioning, issues, and maintenance
Every publish automatically receives the next sequential version number (1.0, 2.0, 3.0, …). Published versions are immutable and never reused — and because Toolpal packs your src/ and lockfile alongside dist/tool.mjs, anyone can run npx toolpal verify-build @your-login/word-count to confirm the bundle is byte-for-byte reproducible.
| Task | How to do it |
|---|---|
| Track broken versions & user reports | Every public workflow page has a built-in Issues tab. When someone reports a broken version (or clicks "Me too"), you receive an email alert automatically. |
| Yank a faulty release | npx toolpal yank @your-login/[email protected] --reason "fix edge case" |
| Deprecate an old workflow | npx toolpal deprecate @your-login/word-count "Use @your-login/text-stats" |
Want to call your newly published workflow from a Node.js app? Follow our @toolpal/sdk guide, or check the full Documentation for complete CLI flags, schema limits, and security details.