Skip to main content

Context

Context is an optional first argument of a handler function. It provides request metadata and response control.

Reading metadata

export function myMethod(ctx: Context, input: string): string {
const rid = ctx.requestId;
const tid = ctx.traceId;
const sid = ctx.sessionId;
const me = ctx.skillId;
const who = ctx.callerId;
const mtd = ctx.method;
// ...
}

LLM context

When a skill is invoked as an MCP tool, the host returns the result to the LLM. LLM context lets you prepend additional instructions or hints that the LLM sees before the tool output. The final response the LLM receives looks like:

<llm context lines>
---
<tool result>

This is useful for guiding the LLM's interpretation of the result — for example, warning about binary content, suggesting next steps, or adding formatting hints.

  • setLLMContext(text) — sets the LLM context (replaces any previous value).
  • appendLLMContext(text) — appends a line to the existing LLM context. Call multiple times to build up multi-line context.
ctx.setLLMContext("Warning: file contains binary data");
ctx.appendLLMContext("Tip: use --format json");