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

journal-gateway-client

v0.8.1

Published

TypeScript service-side client for accepting Journal Gateway connections

Readme

journal-gateway-client

TypeScript service-side library for the Journal Gateway protocol. Use this package in the service that accepts gateway WebSocket connections, validates gateway tokens, receives tool and skill catalogs, and calls tools on connected gateways.

If you want to run the customer-side gateway process, install journal-gateway instead.

Install

Requires Node.js 22 or newer.

npm install journal-gateway-client

Quick Start

import { GatewayServer } from "journal-gateway-client";

const server = new GatewayServer({
  port: 8080,
  validateToken: async (token) => {
    if (token === process.env.JOURNAL_GATEWAY_TOKEN) {
      return { organizationId: "org_123" };
    }
    return null;
  },
});

server.onGatewayConnected = (gateway) => {
  console.info("gateway connected", {
    gatewayId: gateway.id,
    organizationId: gateway.organizationId,
    integrations: gateway.integrations.length,
  });
};

server.onGatewayUpdated = (gateway) => {
  console.info("gateway catalog updated", { gatewayId: gateway.id });
};

server.onGatewayDisconnected = (gateway, closeCode, closeReason) => {
  console.info("gateway disconnected", {
    gatewayId: gateway.id,
    closeCode,
    closeReason,
  });
};

await server.start();

// After a gateway for org_123 connects and publishes the postgresql integration:
const result = await server.callToolForOrg(
  "org_123",
  "postgresql",
  "execute_sql",
  { sql: "SELECT 1" },
);

The library never writes logs or metrics by itself. Route callbacks into your own logger, metrics, and tracing stack.

Key APIs

  • start() / stop(): start or stop the built-in WebSocket server.
  • startHeartbeat() / handleConnection(ws): use your own HTTP/WebSocket server and pass accepted sockets to the client library.
  • callTool(integrationId, toolName, args, timeoutMs?): call a tool on any connected gateway that exposes the integration.
  • callToolForOrg(orgId, integrationId, toolName, args, timeoutMs?): call a tool for one organization, with candidate gateway selection and retry on connection-level failure.
  • getToolsForOrg(orgId): list deduplicated tools for an organization.
  • getVersions(gatewayId), getTools(gatewayId), getSkills(gatewayId): explicitly pull catalog data from a specific gateway.
  • connectedGateways: inspect currently connected gateways.

Callbacks

  • onGatewayConnected(gateway): fired after authentication and initial catalog pull.
  • onGatewayUpdated(gateway): fired when MCP tools or skills change.
  • onGatewayDisconnected(gateway, closeCode?, closeReason?): fired after a connected gateway disconnects.
  • onSocketError(error, gateway | null): optional constructor callback for socket-level errors and unexpected connection-handler failures.

Trace Propagation

Pass getTraceContext when you want Journal Gateway tool execution to attach to your active distributed trace:

import { context, propagation } from "@opentelemetry/api";

const server = new GatewayServer({
  validateToken,
  getTraceContext: () => {
    const carrier: Record<string, string> = {};
    propagation.inject(context.active(), carrier);
    return carrier.traceparent
      ? { traceparent: carrier.traceparent, tracestate: carrier.tracestate }
      : null;
  },
  onSocketError: (error, gateway) => {
    logger.error({ error, gatewayId: gateway?.id }, "gateway connection error");
  },
});

getTraceContext is called for each tool call. The returned W3C trace context is sent to the gateway and used as the parent for remote tool execution spans.

More Documentation

License

MIT