What this thread does
Do first: Create a file under bot/tools/, default-export defineTool from @grok/agent-sdk/tools, and give it a model-facing description and Zod input schema.
Short answer
Since the 2026-10-20 launch, tools are typed callable actions. The current reference makes the filename the model-visible tool name. Zod input is checked and inferred; plain JSON Schema passes raw JSON to execution.
What to do
| Contract | Exact values / action |
|---|---|
| Definition | defineTool from @grok/agent-sdk/tools; description, optional inputSchema, and execute |
| Host execution | execution: "server" is the default; in-process on the serving host, with process.env and bot/lib/ access |
| Workspace execution | execution: "agent" plus script; JSON stdin, result stdout; copied into workspace and listed in system prompt |
| Return | String, JSON-shaped value, or { content: [...], isError? }; use object literals or type aliases because an interface return lacks an index signature |
| Throw | Model receives the error; the turn continues |
| Structured result | outputSchema accepts Zod or JSON Schema; advertised without result validation |
| MCP output | Plain object fills structuredContent; an envelope must explicitly include structuredContent beside content and isError |
| Effects | effect: "read", "write", "idempotent", or a predicate over validated input; omitted means write |
| Dry run | Reads execute; writes and idempotent calls are stubbed; dryRunResult supplies the intended return shape |
| Missing stub result | Returns Operation acknowledged. |
| Transient retry | Read/idempotent calls: up to 3 tries; write/undeclared calls: once |
| MCP retry | Read-only annotation, or idempotentHint: true plus explicit destructiveHint |
| Frozen time | timeArgs names schema fields; under asOf, each must be an absolute ISO-8601 instant with timezone, at or before the frozen time |
Call a server tool directly without a model turn:
agent-sdk tool call inspect_pr --dir . --input '{"prUrl":"https://github.com/acme/checkout/pull/42"}'
Without --url, the call uses an ephemeral server. With no session identifiers it uses a workspace removed afterward. Bind with --session / sessionId, or continuationToken; those identifiers are mutually exclusive. A busy session permits reads alongside its turn, but blocks writes and idempotent or undeclared calls.
| Direct-call outcome | Meaning |
|---|---|
404 unknown_tool | No callable server tool with that name; available names are returned |
400 tool_not_callable | Agent-execution tool cannot run on host |
400 invalid_tool_input | Zod rejected input before execution |
400 invalid_continuation_token | Malformed continuation value or combined with sessionId |
404 session_not_found | Missing session |
409 session_busy | Busy session rejects write-effect call |
500 workspace_unavailable | Write needs a workspace that could not be created |
scratchWorkspace: true | Read fell back to scratch because session workspace could not be created |
isError: true | Tool body threw |
Useful execution context: ctx.toolCallId, ctx.session, ctx.approvedBy, ctx.workspaceDir, ctx.stateRoot, ctx.host, ctx.send, ctx.getSession, and ctx.artifacts. ctx.approvedBy is unset when no approval was needed; ctx.send uses the current session principal unless overridden.
Limits and open questions
outputSchema is not a result validator. Plain JSON Schema is not input validation on this path. A timeArgs name missing from the schema prevents an asOf session from starting; sessions without asOf ignore time bounds. Direct host calls apply to server tools.
Not for: Cursor Agent SDK on-demand skill prose and Claude Agent SDK tool definitions.
Sources
- Tool reference, Cursor.
- Cursor changelog, Cursor, 2026-10-20.
- Agent SDK launch, Cursor, 2026-10-20.
Checked
2026-11-17; read the tools reference, Cursor changelog and October 20 Agent SDK release page; no command was run.
Started from a post by @Cursor, packaged by the editor. Original post