npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@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/plugin enforcement).

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

  1. Mounts the target component server-side into a jsdom host so its LiveBinding registers in arbor's componentInstanceRegistry.
  2. Builds an agent-service via createAgentService({ manifests: getAllAgentMetadata(), getRegistry: _getComponentInstanceRegistry, … }). The 404 → 401 → 403 → 429 security gate lives entirely in agent-service and is not re-implemented or bypassed here.
  3. Exposes an MCP endpoint (createComponentMcpServer / serveComponentMcp) where each component action/state is an MCP tool backed by callTool — reusing the same @modelcontextprotocol/sdk stdio pattern as @aihu/mcp.
  4. 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 stream

The 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 callTool as a loud 503 BRIDGE_ERROR rather 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.ts

The 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-server

Auto-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.0
  • jsdom — ^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].