ahp-client
Interact with an Agent Host Protocol (AHP) server via WebSocket. Use when asked to connect to, message, or control an AHP server.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 453
- Forks
- 163
01 前言 Front Matter
- description
- Interact with an Agent Host Protocol (AHP) server via WebSocket. Use when asked to connect to, message, or control an AHP server.
03 SKILL.md 正文
Agent Host Protocol – Copilot Skill
You have access to an MCP server (ahp-websocket) that lets you connect to an
Agent Host Protocol server over WebSocket and exchange JSON-RPC 2.0 messages.
Available MCP tools
| Tool | Purpose |
|---|---|
connect |
Open (or re-open) a WebSocket to an AHP server URL |
send |
Send a JSON-RPC message and get the response + any pending notifications |
get_notifications |
Drain the notification inbox (optionally wait N seconds first) |
status |
Check connection state, pending request count, inbox depth |
next_id |
Get a unique incrementing integer for JSON-RPC request id fields |
Quick-start workflow
1. connect(url: "ws://localhost:3000")
2. send initialize notification
3. wait for serverHello via get_notifications
4. subscribe to root state
5. create a session, subscribe, send turns
Protocol overview
AHP is a Redux-inspired state synchronisation protocol built on JSON-RPC 2.0 over WebSocket. The server maintains an authoritative state tree; clients apply actions optimistically and reconcile with the server's echoed actions.
Key concepts:
- Root state (
ahp-root://) – lists available agents/models. - Session state (
ahp-session:/<uuid>) – per-conversation state with turns, deltas, tool calls, and permissions. - Actions – the sole mutation mechanism, wrapped in
ActionEnvelopes with aserverSeq. - Subscriptions – clients subscribe to URI-identified state resources to receive action streams.
- Notifications – ephemeral broadcasts (session added/removed) that are NOT part of the state tree and NOT replayed on reconnect.
Connection lifecycle
1. Initialize
Send an initialize notification (no id field):
{
"jsonrpc": "2.0",
"method": "initialize",
"params": {
"protocolVersions": ["0.3.0"],
"clientId": "<unique-client-id>",
"initialSubscriptions": ["ahp-root://"]
}
}
Then call get_notifications(wait: 2) to collect the serverHello response,
which includes snapshots for any initial subscriptions.
2. Subscribe to state
{
"jsonrpc": "2.0",
"id": 1,
"method": "subscribe",
"params": { "channel": "ahp-root://" }
}
The response contains the current state snapshot.
After subscribing, subsequent mutations arrive as action notifications.
3. Create a session
{
"jsonrpc": "2.0",
"id": 2,
"method": "createSession",
"params": {
"session": "<provider>:/<uuid>",
"provider": "<provider>",
"model": "<model-id>"
}
}
Then subscribe to the session URI. Wait for a session/ready action.
4. Send a message (start a turn)
Dispatch a session/turnStarted action as a notification (fire-and-forget):
{
"jsonrpc": "2.0",
"method": "dispatchAction",
"params": {
"channel": "<provider>:/<uuid>",
"clientSeq": 1,
"action": {
"type": "session/turnStarted",
"turnId": "<unique-turn-id>",
"userMessage": { "text": "Hello, world!" }
}
}
}
Then poll get_notifications(wait: 2) to collect streaming session/delta
actions until you see session/turnComplete.
5. Handle tool calls and permissions
If the agent calls a tool, the server sends:
session/toolStart– tool invocation startedsession/permissionRequest– user approval needed
Resolve permissions with:
{
"jsonrpc": "2.0",
"method": "dispatchAction",
"params": {
"channel": "<provider>:/<uuid>",
"clientSeq": 2,
"action": {
"type": "session/permissionResolved",
"turnId": "<turn-id>",
"requestId": "<perm-request-id>",
"approved": true
}
}
}
6. Other commands
| Command | Purpose |
|---|---|
listSessions |
List all session summaries |
disposeSession |
Tear down a session |
resourceRead |
Read content by URI reference |
resourceList |
List directory entries |
resourceCopy |
Copy a resource |
resourceDelete |
Delete a resource |
resourceMove |
Move/rename a resource |
resourceWrite |
Write content to a file |
fetchTurns |
Fetch historical turns for a session |
7. Reconnection
If the connection drops, call connect again and send a reconnect message
instead of initialize:
{
"jsonrpc": "2.0",
"method": "reconnect",
"params": {
"clientId": "<same-client-id>",
"lastSeenServerSeq": 42,
"subscriptions": ["ahp-root://", "<provider>:/<uuid>"]
}
}
Action types reference
Client-dispatchable actions
| Action | Effect |
|---|---|
session/turnStarted |
Begin a new turn with a user message |
session/permissionResolved |
Approve or deny a pending tool permission |
session/turnCancelled |
Abort an in-progress turn |
session/modelChanged |
Switch the model for future turns |
Server-originated actions
| Action | Meaning |
|---|---|
root/agentsChanged |
Available agents or models changed |
session/ready |
Session backend initialized |
session/creationFailed |
Session failed to initialize |
session/delta |
Streaming text content for a turn |
session/toolStart |
Agent is calling a tool |
session/toolDelta |
Streaming tool output |
session/toolComplete |
Tool execution finished |
session/permissionRequest |
User approval needed for a tool |
session/turnComplete |
Turn finished |
session/error |
Error during turn |
Full documentation
For complete protocol details, refer to the docs in this repository:
- Guide:
docs/guide/– conceptual overviews and walkthroughsgetting-started.md– end-to-end examplestate-model.md– full state tree shapeactions.md– how actions workreconciliation.md– write-ahead reconciliation algorithm
- Specification:
docs/specification/– normative protocol spectransport.md– transport requirementslifecycle.md– connection, session, and reconnection lifecyclesubscriptions.md– subscription mechanicsversioning.md– version negotiation
- Reference:
docs/reference/– complete type referencesmessages.md– all state typesactions.md– all action types with fieldscommands.md– all JSON-RPC commandsnotifications.md– all notification typeserror-codes.md– error code reference
Read these files when you need exact field names, type shapes, or edge-case behaviour.
04 同仓库更多 Skills
release-ahp
Cut a coordinated AHP release (spec + all 6 clients) — bumps manifests, dates CHANGELOGs, promotes website docs alongside the development bump in one PR, and pushes seven release tags before merging. Use when the user says "release AHP X.Y.Z", "publish AHP", "cut a release", "tag the release", or similar. Includes recovery for missing publish triggers.
groom-backlog
Audits recently closed PRs in agent-host-protocol (AHP) to make sure any future work they promised has a tracking issue (filing new ones or linking PRs to existing ones), then triages every open issue into implementable-now / no-longer-relevant / blocked-on-a-dependency, closing or annotating each accordingly, and finally prioritizes and implements the ready issues. Validates every follow-up and issue against the current state of this repo — the canonical `types/`, the generated client mirrors, the conformance fixtures, and the published versioned artifacts — before acting. Use when asked to triage or groom the issue backlog, file follow-up issues from merged PRs, audit closed PRs for un-tracked work, or work through the open issues.
session-metadata-migration
Migrate code that talks to or implements the Agent Host Protocol to the flattened SessionState model. Use when asked to upgrade an AHP client/server/binding and you see a `summary` sub-object on `SessionState` (e.g. `state.summary.title`, `session.summary.modifiedAt`), `model` / `agent` on `SessionState` / `SessionSummary` / `ChatState` / `ChatSummary`, the `session/modelChanged` or `session/agentChanged` actions, numeric `createdAt` / `modifiedAt`, or `model` / `agent` arguments to `createSession` / `createChat`.
channels-migration
Migrate code that talks to or implements the Agent Host Protocol from the pre-channels model to the current channel-based model. Use when asked to upgrade an AHP client/server, when seeing references to `agenthost:/root`, `<provider>:/<uuid>` session URIs, a `notification` wrapper method, an `envelope` field inside `action` params, a `resource` field on subscribe/unsubscribe/snapshot results, or `session` / `terminal` / `changeset` fields on command params or action payloads.