Skip to main content

Module 15: Agent Requests

Agents can request file operations and permissions from the client.

What You’ll Learn

  • Reading files from the client with context.readFile()
  • Writing files with context.writeFile()
  • Requesting permissions with context.client().requestPermission()
  • The client-side handler pattern for responding to agent requests

The Agent

The prompt handler uses SyncPromptContext convenience methods:

The Client

The client registers handlers to respond to agent requests:
Throw exceptions from handlers for errors. The SDK converts exceptions to JSON-RPC error responses. Do not return error strings as content — agents will misinterpret them as file content.

Client Capabilities

As of 0.80.0, the client advertises file system support automatically: registering readTextFileHandler and writeTextFileHandler, shown above, is enough for initialize() to send fs.readTextFile and fs.writeTextFile, with no separate clientCapabilities(...) call needed.
initialize(InitializeRequest) is removed as of 0.80.0: capabilities come from the client builder, either derived from registered handlers (as here) or set explicitly with clientCapabilities(..) when a handler alone can’t express what to advertise. See the 0.80.0 migration guide.
Agents can check capabilities before using them:

Source Code

View on GitHub

Running the Example

Next Module

Module 16: In-Memory Testing — test agents without subprocess launching.