Context
Context is an optional first argument of a handler function. It provides request metadata and response control.
Reading metadata
- AssemblyScript
- Go
- Rust
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;
// ...
}
func MyMethod(ctx *sdk.Context, input string) (string, error) {
rid := ctx.RequestID()
tid := ctx.TraceID()
sid := ctx.SessionID()
lid := ctx.LLMSessionID()
me := ctx.SkillID()
who := ctx.CallerID()
mtd := ctx.Method()
// ...
}
pub fn my_method(ctx: &Context, input: String) -> Result<String, SkillError> {
let rid = ctx.request_id();
let tid = ctx.trace_id();
let sid = ctx.session_id();
let lid = ctx.llm_session_id();
let me = ctx.skill_id();
let who = ctx.caller_id();
let 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.
- AssemblyScript
- Go
- Rust
ctx.setLLMContext("Warning: file contains binary data");
ctx.appendLLMContext("Tip: use --format json");
ctx.SetLLMContext("Warning: file contains binary data")
ctx.AppendLLMContext("Tip: use --format json")
ctx.set_llm_context("Warning: file contains binary data");
ctx.append_llm_context("Tip: use --format json");