Capturing agent intent
Intent explains why an agent called a tool. Use it to understand the goals behind tool usage.
The SDK captures intent as a single property – $mcp_intent – that can come from one of two sources:
- A
contextargument the agent passes on every tool call. Captured with$mcp_intent_source = "context_parameter". - A fallback callback you supply on
instrument(). Captured with$mcp_intent_source = "inferred".
Explicit context always wins, except in Rust, where userIntent in the request's io.modelcontextprotocol/aiInvocation metadata overrides it and is captured with $mcp_intent_source = "client_metadata". If the agent passes a non-empty context, the fallback is not invoked.
The context argument
Intent capture is on by default. The SDK adds a context string to compatible tool schemas and removes it before your handler runs when it can confirm it injected the field. An application-owned context argument is preserved.
Calls can omit it without failing validation.
What the agent sees in the schema:
Your handler receives only your own arguments. The SDK removes context before the handler runs.
The full default prompt also tells the agent never to include personal data and to generalize people into roles such as "a user" or "the customer".
PostHog captures this value as $mcp_intent:
If the agent includes personal data anyway, the SDK replaces emails, phone numbers, IP addresses, card numbers, and US Social Security numbers with [redacted] before sending. See Privacy and redaction.
Customize the prompt
If you want to nudge the agent toward a specific style of context (use case, user goal, ticket id, etc.), pass an object:
Disabling the injected argument
Set the context option to false to turn off the injected argument. See your language's installation page for the option name. Use an intent fallback if you still want intent. Model capture and conversation IDs have their own options, which you can disable separately.
The intent fallback callback
A client can omit the SDK-injected context argument. Without a fallback, the event has no $mcp_intent.
The SDK calls the fallback when the agent provides no context. It captures a non-empty result as $mcp_intent with $mcp_intent_source = "inferred".
The SDK does no inference of its own. Your callback supplies the intent.
Deterministic, per-tool
Use a synchronous callback when you can derive intent from the tool name and arguments:
Using transport metadata
extra carries MCP transport details – useful when the agent's user-agent or auth context hints at intent:
LLM-derived intent
An LLM call in intentFallback adds latency to each tool call that lacks context. Cache results where possible. Handle failures in the callback:
Filtering on intent source
$mcp_intent_source is set to "context_parameter" or "inferred" only when an intent was captured. If neither a context argument nor a fallback result was available, both $mcp_intent and $mcp_intent_source are absent on the event.
If you want to know what fraction of your traffic is contextualized:
A high share of inferred means most clients do not supply context. Review context.description or improve intentFallback.
Gotchas
get_more_tools always reports $mcp_intent_source = "context_parameter". Filter it out of source-attribution queries.





