Using PDK from an agent¶
PDK is designed to be driven by an AI agent. Every command is also an MCP tool, the outputs are short and structured so they fit in a model’s context, and every diagnostic says where the problem is and how to fix it. This chapter describes the Claude Code integration that ships with the repository, and how to connect any other MCP client.
Claude Code¶
Open the PDK folder with Claude Code (run claude in it). The repository configures four things:
- MCP server (
.mcp.json) Starts
pdk-mcpand offers its tools (see MCP tools). Claude Code asks you to approve the server the first time.- Validation hook (
.claude/settings.json) After every file the agent writes or edits,
pdk hookvalidates it if it is aview.json(or checks it if it is astylesheet.css) and sends the problems back to the agent, which fixes them before moving on.- Skill
perspective-views(.claude/skills/) Instructions the agent loads when asked for a Perspective screen: the cycle to follow, the golden rules of
view.json, idioms and traps observed in real projects, and ten validated example views (snippets).- Subagents (
.claude/agents/) Smaller models for closed tasks that would otherwise fill the main conversation:
pdk-reviewerchecks a deployed view against acceptance criteria using only inspections and screenshots;pdk-brief-runnerbuilds a benchmark brief end to end;pdk-log-readersummarizes gateway logs; andpdk-mechanic,pdk-auditor,pdk-bundle-readerandpdk-sdk-readerhelp when developing PDK itself.
With that in place you can simply ask, for example: “Build a pump status panel in PDK/Pump with the pump name as a parameter, the setpoint from Sandbox/Setpoint and a running indicator; the header must span the full width.” The agent looks up the components, writes the view, fixes what the hook reports, deploys it, inspects it with expectations derived from your request and iterates until the report is clean. It then hands over the validation and inspection summaries and the preview URL.
Rules the agent follows¶
The skill and the tool descriptions set a few rules that keep the agent within safe limits:
Write only in the sandbox, under
PDK/; tags only under[default]PDK/.Never overwrite a Designer edit: on a
G008conflict, merge and redeploy withresolved.Run destructive tools (
pdk_promote,pdk_delete) and promotions to the target project only when a person asks for them.Fix every error; fix or justify every warning.
Check the request with expectations, not by looking at a screenshot.
Other MCP clients¶
Any client that supports MCP over standard input/output can use PDK. With PDK installed, the server is the
pdk-mcp command. It keeps pulled views in work/ of the folder it starts in: name the work/ of the folder
you set up with pdk init in PDK_WORK_DIR (or start the server in that folder, where the client has a cwd
setting):
{
"mcpServers": {
"pdk": {
"command": "pdk-mcp",
"env": {"PDK_WORK_DIR": "/path/to/screens/work"}
}
}
}
The same entry in other clients’ formats:
Codex (
~/.codex/config.toml, or.codex/config.tomlin a trusted project):[mcp_servers.pdk]withcommand = "pdk-mcp"andenv(orcwd), plusstartup_timeout_sec = 30andtool_timeout_sec = 180: the eyes take longer than Codex’s defaults.Gemini CLI (
.gemini/settings.json):"mcpServers": {"pdk": {"command": "pdk-mcp", "env": {...}, "timeout": 180000}}.VS Code (
.vscode/mcp.json):"servers": {"pdk": {"type": "stdio", "command": "pdk-mcp"}}(the key isservers); Cursor (.cursor/mcp.json) usesmcpServerslike the block above.
From a clone, run it through uv instead: "command": "uv", "args": ["--directory", "/path/to/pdk", "run",
"--quiet", "pdk-mcp"]; then work/ is the clone’s unless PDK_WORK_DIR says otherwise.
The server describes its workflow in its instructions, so the model learns the cycle from the server itself. The
validation hook and the subagents are Claude Code’s; elsewhere, have the agent call pdk_validate after writing a
view.json (pdk_deploy validates anyway). The skill’s content (.claude/skills/perspective-views/SKILL.md
and reference.md) is plain text and can be given to other agents as instructions, for example in AGENTS.md.
Agent sessions¶
A host that starts an agent runtime for the user, such as the PDK Agent panel, starts PDK’s server with a session
folder: pdk-mcp --agent-session <folder>. PDK’s rules then apply to every tool call, in the server itself, so the
runtime’s own settings (allow rules, hooks) cannot loosen them:
Normal reads, looks at sandbox views with the eyes (no
act) and changes props of the view open in the Designer. Anything that writes, adds code that runs on the gateway to the open view, or looks at a view of the target is refused (T002).Ultra first presents a plan with
pdk_plan(T003until then). Once the user approves it, everything runs, and the target receives only what the plan names (T004).Writes of files go through
pdk_work, confined to the work folder and to PDK’s resource files (T006).
The host writes the session’s state (the mode, the work folder, the approval) to state.json in that folder,
signed with a key it passes in the server’s environment (PDK_AGENT_KEY). An approval is a lease that the host
renews while the request runs. A state that is missing, unreadable or signed with another key allows reading and
looking only (T005). Without --agent-session none of this applies: Claude Code and other clients use the
server as before.
Without an agent¶
Everything works from the command line as well (see the Tutorial: your first verified view), which is also the easiest way to understand what an agent sees: the CLI and the MCP tools print the same reports.