Claude Agent SDK (preview)
In-process MCP servers, one per skill, enabled as skills load, with a PreToolUse guard. A preview adapter in v0.1.
Preview. This adapter is a preview in v0.1. The Claude Agent SDK does not tell the adapter where one model message ends, so a second tool call in the same model message as a skill load may run before the step opens; grants still hold, so only tools of allowed skills can run. The core session and the other adapters enforce the next-step rule fully.
skills = context.load_skills("../quickstart/skills", tools=[lookup_order, issue_refund, search_docs])
ctx = with_skills(skills) # one per conversation
# With a key: async with ClaudeSDKClient(ClaudeAgentOptions(**ctx.options)) as client: ctx.attach(client)
toggles: list[str] = []
class Client:
async def toggle_mcp_server(self, name: str, enabled: bool) -> None:
toggles.append(f"{name}={enabled}")
ctx.attach(Client())const skills = await loadSkills("../quickstart/skills", { tools: [lookupOrder, issueRefund, searchDocs] });
const ctx = withSkills(skills); // one per conversation
// With a key: const q = ctx.attach(query({ prompt, options: { ...ctx.options } }));
const toggles: string[] = [];
ctx.attach({ toggleMcpServer: async (name: string, on: boolean) => void toggles.push(`${name}=${on}`) });Create one per conversation. load_skill lives on an always-loaded skills server; each skill's tools live on their
own server, skill-<name>. Attaching the running query disables every skill server the session has not loaded, and
load_skill enables the ones it loads, so Claude Code only offers loaded tools.
Binding holds without trusting visibility: a PreToolUse hook denies calls to skill tools that are not bound, and
every handler runs through the session's guard. The hook only judges tools served by the in-process servers this host
registered; Claude Code's own tools and your other MCP servers are never touched. Merge your own options around
ctx.options; your hooks run before Context's, and your system prompt comes before Context's.
After loading or unloading skills from code, call refresh(). Save ctx.session.state to resume a conversation.
Two limits of this SDK path. Context's system prompt is fixed when you call withSkills (Claude Code owns the prompt
after that). A model load's instructions arrive in the load_skill result, and a tool_called trigger's skill
arrives in the result of the call that fired it (its server is enabled at the same time). A skill you load from code
mid-run gets its server enabled after refresh(), but its instructions do not reach the model until the next query;
prefer model loads here. And when no
system prompt is given, the adapter appends Context's prompt to the claude_code preset, which is Claude Code's
default behavior and cost profile; pass your own systemPrompt to change that.
The example drives the servers through an in-memory MCP client because a real run needs Claude Code and a key.