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

@mokronos/a2a-chat-api

v0.4.0

Published

Production-safe server-side A2A proxy endpoints built with Effect and `@effect/platform`'s `HttpApi`.

Readme

@mokronos/a2a-chat-api

Production-safe server-side A2A proxy endpoints built with Effect and @effect/platform's HttpApi.

The proxy exposes target IDs, never caller-selected production URLs:

| Method | Path | Purpose | | --- | --- | --- | | GET | /api/a2a/agent-card?targetId=<id> | Fetch the configured target's agent card | | POST | /api/a2a/jsonrpc?targetId=<id> | Proxy JSON-RPC and SSE traffic to the configured target |

GET / remains the health check.

Security Model

A2AProxyModule.layer({ targets }) is the production default. The server owns every URL and the browser only selects an allowlisted ID.

For every initial request and redirect, the module:

  • accepts only absolute http: and https: URLs without credentials or fragments;
  • resolves DNS and rejects any private, loopback, link-local, standard IPv4-translated, multicast, or non-routable IPv4 or IPv6 answer;
  • uses redirect: "manual", checks every redirect against the target policy, and DNS-validates every hop;
  • forwards only explicitly allowlisted client headers (Accept and Content-Type by default);
  • never accepts client Authorization, Cookie, proxy authorization, host, or hop-by-hop headers;
  • injects server-owned target headers only on the original origin, preventing credential leakage through redirects;
  • forwards only explicitly allowlisted response headers and always strips Set-Cookie, credentials, and hop-by-hop headers;
  • bounds request, agent-card, buffered response, and streaming response bytes;
  • propagates Effect interruption and client aborts to the upstream AbortSignal;
  • streams SSE with backpressure instead of buffering it.

The default Node/Bun HTTP(S) adapter pins each connection to a DNS-validated address while preserving the URL hostname for HTTP Host and TLS SNI. Custom fetch adapters receive all validated addresses and are responsible for equivalent pinning.

Install

bun add @mokronos/a2a-chat-api effect @effect/platform

Add the platform runtime used by your server, such as @effect/platform-bun.

Production Usage

import {
  A2AProxyModule,
  CoreHandlers,
  InspectorApi,
} from "@mokronos/a2a-chat-api"
import { HttpApiBuilder, HttpServer } from "@effect/platform"
import { Layer } from "effect"

const ProxyLive = A2AProxyModule.layer({
  targets: {
    support: {
      baseUrl: "https://agent.example.com/a2a",
      // Optional overrides; these default to baseUrl and its agent-card path.
      jsonRpcUrl: "https://agent.example.com/a2a/jsonrpc",
      agentCardUrl: "https://agent.example.com/a2a/.well-known/agent-card.json",
      // These values are server-owned and are never accepted from the browser.
      headers: {
        authorization: `Bearer ${process.env.AGENT_TOKEN}`,
      },
      // Cross-origin redirects are denied unless their exact origin is listed.
      allowedRedirectOrigins: ["https://agent-cdn.example.com"],
    },
  },
})

const HandlersLive = CoreHandlers.pipe(Layer.provide(ProxyLive))
const ApiLive = HttpApiBuilder.api(InspectorApi).pipe(Layer.provide(HandlersLive))
const ApiLayer = Layer.mergeAll(ApiLive, HttpServer.layerContext)
const { handler } = HttpApiBuilder.toWebHandler(ApiLayer)

Bun.serve({
  port: 8000,
  fetch: (request) => handler(request),
})

Clients use only the configured ID:

await fetch("/api/a2a/jsonrpc?targetId=support", {
  method: "POST",
  headers: {
    accept: "text/event-stream",
    "content-type": "application/json",
  },
  body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "message/send" }),
})

Configuration

The secure defaults are:

| Option | Default | | --- | ---: | | maxRedirects | 3 | | requestTimeoutMs | 10,000 | | maxRequestBytes | 1 MiB | | maxAgentCardBytes | 256 KiB | | maxResponseBytes | 8 MiB | | maxStreamingResponseBytes | 64 MiB | | streamIdleTimeoutMs | 60,000 |

Override limits and safe header allowlists at module construction:

const ProxyLive = A2AProxyModule.layer({
  targets,
  limits: {
    requestTimeoutMs: 5_000,
    maxRequestBytes: 256 * 1024,
  },
  headers: {
    request: ["accept", "content-type", "x-request-id"],
    response: ["content-type", "cache-control", "x-request-id"],
  },
})

Sensitive and hop-by-hop headers cannot be added to client allowlists. Target-specific headers are the only way to inject upstream authorization or cookies.

For deeper integration, supply the policy, dnsResolver, or fetchAdapter interfaces instead of targets. The fetch adapter receives the operation, target ID, redirect count, validated URL, validated DNS addresses, and an interruption-aware request init.

Development URLs

Caller-provided URLs require an explicit development-only policy. They remain HTTP(S)-only, same-origin across redirects, and subject to DNS checks.

import { A2AProxyModule, A2AProxyPolicy } from "@mokronos/a2a-chat-api"

const DevelopmentProxyLive = A2AProxyModule.layer({
  policy: A2AProxyPolicy.developmentUrls(),
  // Required only when intentionally testing agents on localhost/private networks.
  allowPrivateAddresses: true,
})

Do not use this policy in production. With it enabled, targetId is interpreted as the complete development URL.

Errors

Policy and proxy failures use typed JSON responses:

| Status | Type | Examples | | --- | --- | --- | | 400 | ProxyBadRequest | Missing target ID, malformed development URL | | 403 | ProxyForbidden | Unknown target ID, blocked address, disallowed redirect | | 413 | ProxyPayloadTooLarge | Request body exceeds its configured limit | | 502 | ProxyBadGateway | DNS/fetch failure, invalid redirect, oversized upstream body | | 504 | ProxyGatewayTimeout | Upstream did not respond within the configured timeout |

Each response includes a stable code and a safe human-readable message.