@aihu/agent-server
v0.5.0
Published
Server-side glue: mount an aihu component server-side and let an MCP client drive it through the agent-service live-dispatch gate, forwarding approved invocations to a browser bridge.
Downloads
187
Readme
@aihu/agent-server
Aihu — agentic discovery and interaction, for human purpose.
Server-side glue: mount an aihu component server-side and let an MCP client drive it through the agent-service live-dispatch gate, forwarding approved invocations to a browser bridge.
Held-private workspace package. Not yet published to npm.
Status: Held private — not yet published to npm. See v1.1 roadmap for ratification gating (e.g. RFC #56 live-binding for
@aihu/pluginenforcement).
Server-side glue that lets an external MCP client drive a server-mounted
aihu component through the already-tested live-dispatch runtime
(@aihu/agent-service), and forwards only approved invocations to a
connected browser "capability bridge" (the visible, authoritative instance).
This is a server-side package: it depends on jsdom (host DOM) and the MCP
SDK, targets Node/Bun, and carries no .size-limit.json row (see
.size-limit.README.md).
What createAgentServer() does
- Mounts the target component server-side into a jsdom host so its
LiveBindingregisters in arbor'scomponentInstanceRegistry. - Builds an agent-service via
createAgentService({ manifests: getAllAgentMetadata(), getRegistry: _getComponentInstanceRegistry, … }). The404 → 401 → 403 → 429security gate lives entirely in agent-service and is not re-implemented or bypassed here. - Exposes an MCP endpoint (
createComponentMcpServer/serveComponentMcp) where each component action/state is an MCP tool backed bycallTool— reusing the same@modelcontextprotocol/sdkstdio pattern as@aihu/mcp. - Exposes a WS/SSE capability bridge: on an approved tool call only, the
server forwards
{ opaqueActionId, args }(no policy info) to a connected browser client and surfaces the visible instance's result +serialize()snapshots back.
import { JSDOM } from 'jsdom'
import { createAgentServer, serveComponentMcp } from '@aihu/agent-server'
import { __agentBinding, render } from './my-counter.server.js' // compiler output
const server = createAgentServer({
target: { node: render(), agentBinding: __agentBinding },
createHost: () => new JSDOM('<!doctype html><body>').window.document.body,
})
// Drive it from an MCP client over stdio:
await serveComponentMcp(server)WS capability-bridge contract (server side — for the browser-bridge client, T3)
The browser-bridge client (a separate task) implements against the message
shapes in src/types.ts. BRIDGE_PROTOCOL_VERSION = 1.
Server → client
// Sent ONLY after the gate authorizes the call. Carries NO scope/rate-limit info.
{ type: 'invoke', callId: string, opaqueActionId: string, args: unknown[] }opaqueActionId is "<tag>/<action>" for v1 (the compiler's stable opaque-id
emit, T1, will replace the plain name; the client allowlist keys on the same
string).
Client → server
{ type: 'hello', protocol: number } // handshake on connect
{ type: 'result', callId: string, result: unknown } // visible instance's return
{ type: 'error', callId: string, message: string } // exec failed → surfaced to agent
{ type: 'snapshot', callId?: string, snapshot: Snapshot } // serialize() state streamThe transport is abstracted behind BridgeChannel (send / onMessage /
onClose / connected) so a real deployment passes a ws WebSocket and tests
pass an in-memory channel. The server never imports ws.
Guarantees
- A rejected call (404/401/403/429) is never forwarded to the bridge.
- A bridge disconnect mid-drive rejects the pending
callToolas a loud503 BRIDGE_ERRORrather than silently dropping it. - The forwarded frame contains only the opaque id + args — no scope, no rate-limit, no auth context.
Upgrade origin check
createAgentServer is transport-agnostic and never sees the raw HTTP upgrade
request for /bridge, so nothing stops an arbitrary page from opening a
WebSocket to a running bridge port unless the consuming server checks it — a
WS upgrade isn't subject to the same-origin policy the way fetch/XHR are.
Run verifyBridgeUpgrade(req, { allowedOrigins }) before calling your
runtime's upgrade(), and never forward a rejected upgrade to attachBridge:
import { verifyBridgeUpgrade } from '@aihu/agent-server'
const verdict = verifyBridgeUpgrade(req, { allowedOrigins: ['http://localhost:5108'] })
if (!verdict.ok) return new Response(verdict.reason, { status: verdict.status })It fails closed: a missing Origin header and an Origin outside
allowedOrigins are both rejected. This is not authentication — it only
constrains which pages may attach as the bridge's browser peer; session-bound
auth (confirming which user opened the page) is a separate check layered on
top and remains open (see docs/TODOS.md).
Testing
bunx vitest run packages/agent-server/tests/agent-server.test.tsThe suite drives a real @aihu/signals + @aihu/arbor component mounted into a
jsdom host: a scripted in-process MCP client calls increment, a real signal
changes, and serialize() reflects it — plus 404 / 401 / 403 gate paths and the
full bridge contract.
Install
npm install @aihu/agent-server
# or
bun add @aihu/agent-serverAuto-generated against @aihu/[email protected].
Package facts
| | |
|---|---|
| Version | 0.5.0 |
| Tier | C — Agent surface — server-mount + MCP live-dispatch bridge to a browser |
| Published files | 3 entries |
| License | MIT |
Auto-generated against @aihu/[email protected].
Exports
| Subpath | ESM | CJS |
|---|---|---|
| . | ./dist/index.js | — |
Auto-generated against @aihu/[email protected].
Dependencies
Dependencies:
@aihu/agent—workspace:*@aihu/agent-service—workspace:*@modelcontextprotocol/sdk—^1.0.0jsdom—^25.0.0
Peer dependencies:
@aihu/arbor—^4.1.2
Auto-generated against @aihu/[email protected].
See also
Auto-generated against @aihu/[email protected].
License
MIT — see LICENSE.
Auto-generated against @aihu/[email protected].
