this.respond
this.respond() ends a tool call on the spot. Pass the tool's output and FrontMCP builds content and structuredContent and checks outputSchema, as for a returned value. You can also pass a complete result with content to send it as written. In a hook, the flow's ctx.respond() answers a call without running the tool at all, which is how a cache works. In resources, prompts, jobs and agents, respond(value) ends execute() as return value would.
this.respond(result)
Reference
this.respond(result)
Call this.respond() inside a tool's execute(). Nothing after it runs.
import { Tool, ToolContext, z } from "@frontmcp/sdk";
@Tool({ name: "list_tickets", description: "List a customer's open tickets", inputSchema: { customer: z.string() } })
export class ListTickets extends ToolContext {
async execute({ customer }: { customer: string }) {
const tickets = await openTicketsOf(customer);
if (tickets.length === 0) {
this.respond({ content: [{ type: "text", text: `${customer} has no open tickets.` }] });
}
return { customer, tickets };
}
}Parameters
| Parameter | Type | Description |
|---|---|---|
result | The tool's output or CallToolResult | An output value, validated and finalized like a return, or a complete result with content, sent as written. |
Returns
never. It throws to end execute(), like this.fail().
What the client receives
An output value is finalized like a returned value. A complete result with content is sent as written. Under MCP 2026-07-28 FrontMCP adds resultType: "complete" and its serverInfo in _meta, as it does to every result; nothing else changes. Compare that with returning the same object:
In execute() | The client gets |
|---|---|
return { id: "T-1" } | content: [{ type: "text", text: '{"id":"T-1"}' }] and structuredContent: { id: "T-1" }, checked against outputSchema |
this.respond({ id: "T-1" }) | The same text and structured content as return, checked against outputSchema |
this.respond({ content: [...], structuredContent: {...} }) | That result, as it is. structuredContent isn't checked against outputSchema either. |
Did("execute") hooks still run after this.respond(), and see result as the tool's output.
Where it works
| In | What respond(value) does | Use instead |
|---|---|---|
A tool's execute() | Ends the call. An output value is finalized like a return; a complete result is sent as written. | return, for everything except hand-built results |
A hook, as the flow's ctx.respond(value) | Ends the call. The tool doesn't run, and Did("execute") hooks are skipped. value is the whole result; one without content gets content: []. | |
A hook, as ctx.state.toolContext.respond(value) | Ends the call with the tool's output, validated and finalized like a return. | Either |
A resource's execute() | Ends the read, and value is sent as a returned value would be: { contents } as it is, anything else as a text block, an object as JSON. (Changed in 1.9.3: before, the read failed with Resource output not found.) | Either |
A prompt's execute() | Ends the request, and value is sent as a returned value would be. (Changed in 1.9.3: before, the request failed with Prompt output not found.) | Either |
A job's execute() | Ends the run, and value becomes its result, checked against outputSchema as a returned value is. (Changed in 1.9.2: before, value replaced the whole execute_job response.) | Either |
An agent's execute() | Ends the call, and value is sent as a returned value would be, with content and structuredContent. (Changed in 1.8.5: before, value was the whole result, with no content.) | Either |
Caveats
this.respond()works by throwing, likethis.fail(). Atry/catcharound it catches it, as aFlowControlwithtype: "respond", andexecute()carries on. See the call carries on.- Changed in 1.11.3: before, a plain value passed to a tool's
respond()was spread into the whole result, withoutcontent. It is now validated and finalized like a return. A complete result with acontentarray still bypasses output validation. - Use
returnwhen the method can finish normally, orrespond(value)to stop it early.
Usage
Sending a result you built yourself
A returned object becomes one JSON text block and structuredContent. To send several text blocks, one per ticket here, build the result yourself:
import { Tool, ToolContext, z } from "@frontmcp/sdk";
const tickets = [
{ id: "T-1", customer: "acme", title: "Cannot log in" },
{ id: "T-3", customer: "acme", title: "Login link expired" },
{ id: "T-2", customer: "globex", title: "Invoice total is wrong" },
];
@Tool({ name: "list_tickets", description: "List a customer's open tickets", inputSchema: { customer: z.string() } })
export class ListTickets extends ToolContext {
async execute({ customer }: { customer: string }) {
const open = tickets.filter((t) => t.customer === customer);
this.respond({
content: open.map((t) => ({ type: "text" as const, text: `${t.id}: ${t.title}` })),
structuredContent: { customer, tickets: open },
});
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
execute() doesn't need a return after this.respond(): nothing after it runs.
Answering a call from a hook
A Will("execute") hook can answer a call itself, with the flow's ctx.respond(), and the tool never runs. Here a plugin answers repeated calls to read-only tools from memory. Hooking into Calls builds the same cache step by step, in "Answering without running the tool". For a real cache, with expiry, Redis and per-caller keys, use the Cache plugin.
import { DynamicPlugin, FlowCtxOf, Plugin, ToolHook } from "@frontmcp/sdk";
type CallCtx = FlowCtxOf<"tools:call-tool">;
const readOnly = (ctx: CallCtx) => ctx.state.tool?.metadata.annotations?.readOnlyHint === true;
@Plugin({ name: "cache", description: "Answers repeated read-only calls from memory" })
export class CachePlugin extends DynamicPlugin<object> {
private results = new Map<string, Record<string, unknown>>();
private key(ctx: CallCtx) {
return `${ctx.state.tool?.metadata.name}:${JSON.stringify(ctx.state.toolContext?.input)}`;
}
@ToolHook.Will("execute", { filter: readOnly })
async answerFromCache(ctx: CallCtx) {
const cached = this.results.get(this.key(ctx));
if (cached) ctx.respond({ content: [{ type: "text", text: JSON.stringify(cached) }], structuredContent: cached });
}
@ToolHook.Did("execute", { filter: readOnly })
async store(ctx: CallCtx) {
this.results.set(this.key(ctx), ctx.state.toolContext?.output as Record<string, unknown>);
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
ctx.respond() ends the whole call: the tool, the Did("execute") hooks and the result formatting are skipped, so pass a finished result, with content. Neither ctx.respond() nor ctx.state.toolContext.respond() builds one from a plain value: see a hook's answer is empty. The hook decorators page lists the stages you can answer from.
Ending early everywhere else
Outside tools, respond(value) ends execute() as return value would: FrontMCP builds and checks the result from value as it does from a returned value. Each tab shows it next to return.
respond() outside tools
Example 1 of 4
Resource
import { ResourceContext, ResourceTemplate } from "@frontmcp/sdk";
@ResourceTemplate({ name: "ticket", uriTemplate: "tickets://{id}", mimeType: "application/json" })
export class Ticket extends ResourceContext<{ id: string }> {
async execute(uri: string, { id }: { id: string }) {
if (id === "T-0") {
this.respond({ contents: [{ uri, mimeType: "application/json", text: "{}" }] }); // ✅ since 1.9.3
}
return { contents: [{ uri, mimeType: "application/json", text: JSON.stringify({ id, title: "Cannot log in" }) }] }; // ✅
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Example 2 of 4
Prompt
import { Prompt, PromptContext, type GetPromptResult } from "@frontmcp/sdk";
@Prompt({
name: "summarize_ticket",
description: "Summarize a ticket for a handover",
arguments: [{ name: "id", description: "Ticket id, like T-1", required: true }],
})
export class SummarizeTicket extends PromptContext {
async execute({ id }: Record<string, string>): Promise<GetPromptResult> {
const message = (text: string): GetPromptResult => ({ messages: [{ role: "user", content: { type: "text", text } }] });
if (id === "T-0") this.respond(message("There's no ticket T-0.")); // ✅ since 1.9.3
return message(`Summarize ticket ${id} for the next agent on shift.`); // ✅
}
}import { test, expect } from "@frontmcp/testing";
test("respond() ends the request with its value", async ({ mcp }) => {
const result = await mcp.prompts.get("summarize_ticket", { id: "T-0" });
expect(result.messages[0].content.text).toBe("There's no ticket T-0.");
});
test("return works", async ({ mcp }) => {
const result = await mcp.prompts.get("summarize_ticket", { id: "T-1" });
expect(result.messages[0].content.text).toBe("Summarize ticket T-1 for the next agent on shift.");
});Example 3 of 4
Job
import { Job, JobContext, z } from "@frontmcp/sdk";
const open: Record<string, number> = { acme: 2, globex: 1 };
@Job({
name: "count-open-tickets",
description: "Count a customer's open tickets",
inputSchema: { customer: z.string() },
outputSchema: { customer: z.string(), open: z.number() },
})
export class CountOpenTickets extends JobContext {
async execute({ customer }: { customer: string }) {
if (!(customer in open)) this.respond({ customer, open: 0, note: "not a customer yet" }); // ✅ since 1.9.2
return { customer, open: open[customer] }; // ✅
}
}import { App } from "@frontmcp/sdk";
import { CountOpenTickets } from "./count-open.job";
@App({ id: "help-desk", name: "Help Desk", jobs: [CountOpenTickets] })
export class HelpDeskApp {}import { test, expect } from "@frontmcp/testing";
test("respond() ends the run, and its value is the run's result", async ({ mcp }) => {
const result = await mcp.tools.call("execute_job", { name: "count-open-tickets", input: { customer: "initech" } });
expect(result.json()).toMatchObject({ runId: expect.any(String), state: "completed" });
expect(result.json().result).toEqual({ customer: "initech", open: 0 }); // checked against outputSchema: `note` is dropped
});
test("✅ return gives a run record", async ({ mcp }) => {
const result = await mcp.tools.call("execute_job", { name: "count-open-tickets", input: { customer: "acme" } });
expect(result.json()).toMatchObject({ state: "completed", result: { customer: "acme", open: 2 } });
});Example 4 of 4
Agent
import { Agent, AgentContext, z } from "@frontmcp/sdk";
import { model } from "./model.example";
@Agent({
name: "triage",
description: "Suggest a priority for a new support ticket. Pass what the customer wrote.",
systemInstructions: "You triage tickets for a help desk. Answer high, normal or low, and say why in one sentence.",
inputSchema: { query: z.string().describe("What the customer wrote") },
llm: { adapter: model },
})
export class Triage extends AgentContext {
async execute(input: { query: string }) {
if (input.query.trim() === "") this.respond({ response: "Nothing to triage." }); // ✅ since 1.8.5
return super.execute(input); // ✅
}
}import { App } from "@frontmcp/sdk";
import { Triage } from "./triage.agent";
@App({ id: "help-desk", name: "Help Desk", agents: [Triage] })
export class HelpDeskApp {}// Stands in for a real model, which the Playground can't reach.
import type { AgentLlmAdapter } from "@frontmcp/sdk";
export const model: AgentLlmAdapter = {
async completion() {
return { content: "Normal: nothing is blocked.", finishReason: "stop" };
},
};import { test, expect } from "@frontmcp/testing";
test("respond() ends the call with a formatted result", async ({ mcp }) => {
const result = await mcp.tools.call("invoke_triage", { query: "" });
expect(result.json()).toEqual({ response: "Nothing to triage." });
expect(result.raw.structuredContent).toEqual({ response: "Nothing to triage." });
});
test("✅ a returned value is formatted", async ({ mcp }) => {
const result = await mcp.tools.call("invoke_triage", { query: "The invoice total is wrong." });
expect(result.json()).toEqual({ response: "Normal: nothing is blocked." });
});In an agent, this.respond() before super.execute() ends the call without asking the model, and the client gets a normal result, as it would from return { response: "Nothing to triage." }.
Troubleshooting
The result has no content
Changed in 1.11.3: before, plain output values passed to a tool’s respond() had no content. They now get text and structured content, just as returned values do:
import { Tool, ToolContext, z } from "@frontmcp/sdk";
@Tool({ name: "close_ticket", description: "Close a support ticket", inputSchema: { id: z.string() } })
export class CloseTicket extends ToolContext {
async execute({ id }: { id: string }) {
this.respond({ id, status: "closed" }); // finalized as the tool's output
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Use this.respond(value) or return value for an output value. Use a complete result when you need several content blocks.
A hook's answer reaches the client empty
The hook passed the tool's output to ctx.respond(), as a cache that stored toolContext.output would. The flow's ctx.respond() only adds an empty content to it, while ctx.state.toolContext.respond(value) validates and finalizes the tool's output:
import { DynamicPlugin, FlowCtxOf, Plugin, ToolHook } from "@frontmcp/sdk";
type CallCtx = FlowCtxOf<"tools:call-tool">;
@Plugin({ name: "pinned", description: "Answers get_ticket for pinned tickets from memory" })
export class PinnedPlugin extends DynamicPlugin<object> {
private pinned = new Map<string, any>([["T-1", { id: "T-1", title: "Cannot log in", status: "open" }]]);
@ToolHook.Will("execute")
async answer(ctx: CallCtx) {
const input = ctx.state.toolContext?.input as { id: string; mode?: string };
const ticket = this.pinned.get(input.id);
if (!ticket) return;
if (input.mode === "toolContext") ctx.state.toolContext?.respond(ticket); // validated and finalized
else ctx.respond(ticket); // 🚩 gets an empty content
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
TypeScript refuses a plain object in ctx.respond(), which wants a result with content, but not a value typed any, like this Map<string, any> or anything from JSON.parse(). Build the result from the value: ctx.respond({ content: [{ type: "text", text: JSON.stringify(value) }], structuredContent: value }), as the cache in Answering a call from a hook does.
A text result arrives as {"0":"C","1":"l",…}
Changed in 1.11.3: before, a string passed to this.respond() was spread into a key per character. It is now finalized as output: without an output schema it becomes { value: "Closed T-1." }, just as a returned string does:
import { Tool, ToolContext, z } from "@frontmcp/sdk";
@Tool({ name: "close_ticket", description: "Close a support ticket", inputSchema: { id: z.string() } })
export class CloseTicket extends ToolContext {
async execute({ id }: { id: string }) {
this.respond(`Closed ${id}.`); // finalized like a returned string
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Respond with a complete result, { content: [{ type: "text", text: "Closed T-1." }] }, or return an object and let FrontMCP build the result.
Prompt execution failed: Prompt output not found
A prompt's execute() finished without returning anything: a code path has no return. Return the messages on every path, or end early with this.respond(), as in the Prompt tab above. (Before 1.9.3, calling this.respond() in a prompt failed this way too.)
Resource "…" read failed: Resource output not found
The same for a resource: execute() finished without a return. Return { contents: [...] }, or end early with this.respond(). (Before 1.9.3, calling this.respond() in a resource failed this way too.)
The call carries on after this.respond()
this.respond() throws to end execute(), and a try/catch around it catches that. The call then continues after the catch, and whatever execute() returns is the result:
import { Tool, ToolContext, z } from "@frontmcp/sdk";
@Tool({ name: "reopen_ticket", description: "Reopen a closed ticket", inputSchema: { id: z.string() } })
export class ReopenTicket extends ToolContext {
async execute({ id }: { id: string }) {
try {
if (id === "T-1") this.respond({ content: [{ type: "text", text: `${id} is already open.` }] });
return { id, reopened: true };
} catch {
// 🚩 this also catches respond()
return { id, reopened: false };
}
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Call this.respond() outside the try, or rethrow what you didn't expect in the catch. this.fail() has the same catch.
The client got a result that doesn't match outputSchema
A complete result with content, passed to this.respond() or to ctx.respond() in a hook, is sent as it is, and a Did("execute") hook sees it as the tool's output:
import { Tool, ToolContext, z } from "@frontmcp/sdk";
@Tool({
name: "close_ticket",
description: "Close a support ticket",
inputSchema: { id: z.string(), how: z.enum(["respond", "return"]) },
outputSchema: { id: z.string(), status: z.enum(["open", "closed"]) },
})
export class CloseTicket extends ToolContext {
async execute({ id, how }: { id: string; how: "respond" | "return" }) {
const result = { id, status: "done" as "closed" }; // 🚩 not a status the schema allows
if (how === "respond") {
this.respond({ content: [{ type: "text", text: JSON.stringify(result) }], structuredContent: result });
}
return result;
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Return the value to have it checked. A hook that reads toolContext.output gets the whole result after this.respond(), and the output value after a return: check for content if it has to handle both.