/jwynia:mastra-honofrom jwynia
Develop AI agents, tools, and workflows using Mastra v1 Beta and Hono servers. Covers agent definition, Zod-schema tools, multi-step workflows, and API server setup.
Ships in jwynia. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Build production-ready AI agents, tools, and workflows using Mastra v1 Beta with Hono API servers. This skill covers the complete stack from agent definition to deployment.
Target version: Mastra v1 Beta (stable release expected January 2026)
Use when:
Do NOT use when:
# Install v1 Beta packages
npm install @mastra/core@beta @mastra/hono@beta
npm install @ai-sdk/openai # or other provider
npm install zod hono @hono/node-server
// src/mastra/tools/weather-tool.ts
import { createTool } from "@mastra/core/tools";
import { z } from "zod";
export const weatherTool = createTool({
id: "get-weather",
description: "Fetches current weather for a location",
inputSchema: z.object({
location: z.string().describe("City name, e.g., 'Seattle'"),
}),
outputSchema: z.object({
temperature: z.number(),
conditions: z.string(),
}),
// v1 Beta signature: (inputData, context)
execute: async (inputData, context) => {
const { location } = inputData;
const { abortSignal } = context;
if (abortSignal?.aborted) throw new Error("Aborted");
// Fetch weather data...
return { temperature: 72, conditions: "sunny" };
},
});
// src/mastra/agents/weather-agent.ts
import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";
import { weatherTool } from "../tools/weather-tool.js";
export const weatherAgent = new Agent({
name: "weather-agent",
instructions: "You are a helpful weather assistant.",
model: openai("gpt-4o-mini"),
tools: { weatherTool }, // Object, not array
});
// src/mastra/index.ts
import { Mastra } from "@mastra/core/mastra";
import { weatherAgent } from "./agents/weather-agent.js";
export const mastra = new Mastra({
agents: { weatherAgent },
});
// src/index.ts
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { MastraServer } from "@mastra/hono";
import { mastra } from "./mastra/index.js";
const app = new Hono();
const server = new MastraServer({ app, mastra });
await server.init();
app.get("/", (c) => c.text("Mastra + Hono Server"));
serve({ fetch: app.fetch, port: 3000 });
console.log("Server running at http://localhost:3000");
// Agent endpoint: POST /api/agents/weather-agent/generate
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
name: "my-agent", // Required: unique identifier
instructions: "You are a helpful assistant.", // Required: system prompt
model: openai("gpt-4o-mini"), // Required: LLM model
tools: { weatherTool, searchTool }, // Optional: object with named tools
});
// Model routing (1113+ models from 53 providers)
model: "openai/gpt-4o-mini"
model: "anthropic/claude-3-5-sonnet"
model: "google/gemini-2.5-flash"
// Model fallbacks for resilience
model: [
{ model: "anthropic/claude-3-opus", maxRetries: 3 },
{ model: "openai/gpt-4o", maxRetries: 2 },
{ model: "google/gemini-pro", maxRetries: 1 },
]
// Agent execution with memory
const response = await agent.generate("Remember my name is Alex", {
memory: {
thread: "conversation-123", // Isolates conversation
resource: "user-456", // Associates with user
},
});
// v1 Beta: execute(inputData, context)
execute: async (inputData, context) => {
const { location } = inputData; // First parameter: parsed input
const { mastra, runtimeContext, abortSignal } = context; // Second: context
// Access nested agents via mastra
const helper = mastra?.getAgent("helperAgent");
// Always check abort signal for long operations
if (abortSignal?.aborted) throw new Error("Aborted");
return { temperature: 72, conditions: "sunny" };
}
// WRONG for v1 Beta:
execute: async ({ context }) => { ... } // This is stable 0.24.x signature
This is where most errors occur. See references/workflow-data-flow.md for complete patterns.
import { createWorkflow, createStep } from "@mastra/core/workflows";
const step1 = createStep({
id: "step-1",
inputSchema: z.object({ message: z.string() }),
outputSchema: z.object({ formatted: z.string() }),
execute: async ({ inputData }) => {
// inputData = workflow input (for first step)
return { formatted: inputData.message.toUpperCase() };
},
});
const step2 = createStep({
id: "step-2",
inputSchema: z.object({ formatted: z.string() }), // MUST match step1 output
outputSchema: z.object({ emphasized: z.string() }),
execute: async ({ inputData }) => {
// inputData = step1's return value directly
return { emphasized: `${inputData.formatted}!!!` };
},
});
const workflow = createWorkflow({
id: "my-workflow",
inputSchema: z.object({ message: z.string() }), // MUST match step1 input
outputSchema: z.object({ emphasized: z.string() }), // MUST match final output
})
.then(step1)
.then(step2)
.commit();
Schema matching rules:
| Rule | Description |
|---|---|
| Workflow input → Step 1 input | Must match exactly |
| Step N output → Step N+1 input | Must match exactly |
| Final step output → Workflow output | Must match exactly |
Data access in steps:
execute: async ({
inputData, // Previous step's output (or workflow input for step 1)
getStepResult, // Access ANY step's output by ID
getInitData, // Get original workflow input
mastra, // Access agents, tools, storage
}) => {
const step1Result = getStepResult("step-1");
const originalInput = getInitData();
return { result: inputData.formatted };
}
import { MastraServer } from "@mastra/hono";
const app = new Hono();
const server = new MastraServer({ app, mastra });
await server.init();
// Endpoints auto-registered:
// POST /api/agents/{agent-name}/generate
// POST /api/agents/{agent-name}/stream
// POST /api/workflows/{workflow-id}/start
Custom route prefix:
const server = new MastraServer({
app,
mastra,
prefix: "/v1/ai" // Routes at /v1/ai/agents/...
});
Custom API routes:
import { registerApiRoute } from "@mastra/core/server";
registerApiRoute("/my-custom-route", {
method: "POST",
handler: async (c) => {
const mastra = c.get("mastra");
const agent = mastra.getAgent("my-agent");
const result = await agent.generate("Hello");
return c.json({ response: result.text });
},
});
| Topic | Wrong | Correct |
|---|---|---|
| Imports | import { Agent } from "@mastra/core" | import { Agent } from "@mastra/core/agent" |
| Tools array | tools: [tool1, tool2] | tools: { tool1, tool2 } |
| Memory context | { threadId: "123" } | { memory: { thread: "123", resource: "user" } } |
| Workflow data | context.steps.step1.output | inputData or getStepResult("step-1") |
| After parallel | inputData.result | inputData["step-id"].result |
| After branch | inputData.result | inputData["step-id"]?.result (optional) |
| Nested agents | import agent; agent.generate() | mastra.getAgent("name").generate() |
| State mutation | state.counter++ | setState({ ...state, counter: state.counter + 1 }) |
| v1 tool exec | execute: async ({ context }) | execute: async (inputData, context) |
| Script | Purpose | Usage |
|---|---|---|
scaffold-project.ts | Create new Mastra+Hono project | deno run --allow-all scripts/scaffold-project.ts --name my-project |
scaffold-agent.ts | Create agent with tools | deno run --allow-all scripts/scaffold-agent.ts --name weather |
scaffold-workflow.ts | Create workflow with steps | deno run --allow-all scripts/scaffold-workflow.ts --name process-data |
scaffold-tool.ts | Create tool with schemas | deno run --allow-all scripts/scaffold-tool.ts --name fetch-weather |
validate-workflow-schemas.ts | Validate step schema matching | deno run --allow-read scripts/validate-workflow-schemas.ts ./src/mastra/workflows/ |
check-version-patterns.ts | Detect v1/stable pattern mixing | deno run --allow-read scripts/check-version-patterns.ts ./src/mastra/ |
references/workflow-data-flow.md - Complete data flow patterns (CRITICAL)references/common-mistakes.md - Extended anti-patterns and fixesreferences/agent-patterns.md - Agent definition deep-divereferences/tool-patterns.md - Tool signatures, wrappersreferences/hono-server-patterns.md - Server setup, routes, middlewarereferences/testing-patterns.md - Vitest setup, mocking LLMsreferences/mcp-server-patterns.md - Model Context Protocol authoringreferences/agent-networks.md - Multi-agent collaboration, A2Areferences/rag-memory-patterns.md - Vector stores, embeddings, memoryreferences/context-network-memory.md - Context networks for agent memoryassets/agent-template.ts - Agent boilerplateassets/tool-template.ts - Tool boilerplate (v1 signature)assets/workflow-template.ts - Workflow boilerplateassets/hono-server-template.ts - Hono+Mastra server setupassets/vitest-setup-template.ts - Test configurationassets/agent-template.ts (opens in a new tab)assets/hono-server-template.ts (opens in a new tab)assets/tool-template.ts (opens in a new tab)assets/vitest-setup-template.ts (opens in a new tab)assets/workflow-template.ts (opens in a new tab)references/agent-networks.md (opens in a new tab)references/agent-patterns.md (opens in a new tab)references/common-mistakes.md (opens in a new tab)references/context-network-memory.md (opens in a new tab)references/hono-server-patterns.md (opens in a new tab)references/mcp-server-patterns.md (opens in a new tab)references/rag-memory-patterns.md (opens in a new tab)references/testing-patterns.md (opens in a new tab)references/tool-patterns.md (opens in a new tab)references/workflow-data-flow.md (opens in a new tab)scripts/check-version-patterns.ts (opens in a new tab)scripts/scaffold-agent.ts (opens in a new tab)scripts/scaffold-project.ts (opens in a new tab)scripts/scaffold-tool.ts (opens in a new tab)scripts/scaffold-workflow.ts (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
35 skills in this plugin
/adaptation-synthesisspeech-adaptationTransform comprehensive written content into purposeful spoken guidance. Use when adapting for speech, converting to spoken format, optimizing for listening, or creating audio content from written material. Keywords: speech, audio, spoken, listening, adaptation, podcast./brainstormingYou MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation./character-namingnamingDiagnose why names don't work and guide creation of names that do. Use for brand names, product names, character names, place names, and titles when something feels off or when systematic naming is needed./code-reviewConduct thorough, constructive code reviews for quality and security. Use when reviewing pull requests, checking code quality, identifying bugs, or auditing security. Handles best practices, SOLID principles, security vulnerabilities, performance analysis, and testing coverage./competency-builderGuide competency framework development and operation. Use when building training that produces capability, when existing training doesn't produce competence, when structuring knowledge for multiple audiences, or when setting up feedback loops to surface gaps./context-networkBootstrap, maintain, and evolve context networks across their full lifecycle. Use when starting a new project, when existing documentation feels scattered, or when agent effectiveness degrades due to missing context.npx claudepluginhub ulpi-io/plugin-marketplace --plugin jwyniaOther plugins' skills for the same job