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

@swarmclawai/mcp-core

v0.1.0

Published

Transport-agnostic MCP gateway primitives: downstream multiplexing, tool namespacing, lazy connect, token estimation. Shared by @swarmclawai/mcp-gateway and embedders like SwarmClaw.

Downloads

92

Readme

@swarmclawai/mcp-core

Transport-agnostic MCP gateway primitives: downstream multiplexing, tool namespacing, lazy connect, token estimation. The library half of @swarmclawai/mcp-gateway, made embeddable.

npm version License: MIT

What this is

@swarmclawai/mcp-gateway is a CLI that runs as a separate process and exposes itself as an MCP server to Claude Code / Cursor / etc. @swarmclawai/mcp-core is the library inside it — no CLI, no stdio server binding, just the pieces you need to embed gateway behavior in-process in your own agent runtime.

SwarmClaw uses it for exactly this reason.

Install

pnpm add @swarmclawai/mcp-core
# or
npm i @swarmclawai/mcp-core

Quick start

import { McpMultiClient } from "@swarmclawai/mcp-core";

const mc = new McpMultiClient({
  config: {
    version: 1,
    namespaceSeparator: "__",
    servers: [
      {
        name: "fs",
        command: "npx",
        args: ["-y", "@modelcontextprotocol/server-filesystem", "."],
        alwaysExpose: true,
      },
      {
        name: "github",
        command: "docker",
        args: ["run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/github/github-mcp-server"],
        alwaysExpose: false,
      },
      {
        name: "remote",
        url: "https://mcp.example.com/mcp",
        headers: { Authorization: "Bearer …" },
        alwaysExpose: false,
      },
    ],
  },
});

await mc.connectEager();

// list_tools — includes fs__* eagerly, github__* + remote__* only after
// mcp_tool_search has promoted them.
const tools = await mc.listExposedTools();

// call a tool by its namespaced name
const result = await mc.callTool("fs__read_file", { path: "/tmp/x" });

await mc.shutdown();

Public API

McpMultiClient

One-stop convenience class. Wraps DownstreamManager + McpRequestRouter + SessionToolPromoter.

new McpMultiClient({
  config,               // GatewayConfig or raw object (parseConfig is run either way)
  transportFactory?,    // Inject stdio/http/in-memory; defaults to auto-select by spec shape
  toolSearch?,          // true (default) to enable mcp_tool_search; false to disable; or pass your own SessionToolPromoter
  isToolExposureAllowed?, // (prefixedName) => boolean, additional host policy
  onLog?, clientName?, clientVersion?,
})

Methods: connectEager(), connect(name), ensureConnected(name), listExposedTools(), callTool(name, args), tokenReport(), shutdown(), register(spec), exposedTools(), allKnownTools().

McpRequestRouter

Pure request routing — the transport-agnostic piece of the Gateway. Build your own server wrapper around it.

const router = new McpRequestRouter({ config, downstreams, promoter, isToolExposureAllowed });
await router.lazyConnectAll();
const tools = await router.listExposedTools();
const result = await router.callTool(name, args);
const report = router.tokenReport();

DownstreamManager

Maintains one MCP Client per downstream spec, routes tool calls, tracks tool schemas. Accepts any ClientTransportFactory — ships with stdio, streamable-http, and an auto-selecting default.

SessionToolPromoter

Session-scoped state for the mcp_tool_search meta-tool. promote(name) marks a tool as eager for subsequent list_tools calls; allow(name) reports whether a name is promoted.

Config

  • configSchema / serverSpecSchema — Zod schemas for mcp-gateway.config.json.
  • parseConfig(raw) — validate + apply defaults.
  • loadConfigFile(path) — read + parse.
  • resolvedServerAlwaysExposed(spec, toolName) — helper for the alwaysExpose: true | false | string[] tri-state.

Transports

  • stdioClientTransportFactory — spawn a subprocess per spec.
  • streamableHttpClientTransportFactory — hit a spec's url with optional headers.
  • defaultClientTransportFactory — picks stdio if command is set, HTTP if url is set, throws otherwise.

Tokens

  • estimateTokens(text) — tokenizer-free heuristic (chars / 3.5).
  • estimateToolTokens({ name, description?, inputSchema? }) — per-tool cost.
  • TokenReport type with totals + per-server / per-tool breakdowns via McpMultiClient#tokenReport().

Architecture

┌─────────────────────────────────────────────────┐
│ Your agent host (SwarmClaw, a custom runtime, …)│
│                                                 │
│  ┌──────────────┐   ┌───────────────────┐       │
│  │ McpMulti     │──▶│ McpRequestRouter  │       │
│  │ Client       │   │  (pure routing)   │       │
│  └──────┬───────┘   └──────────┬────────┘       │
│         │                      │                │
│         ▼                      ▼                │
│  ┌──────────────┐   ┌───────────────────┐       │
│  │ Downstream   │   │ SessionTool       │       │
│  │ Manager      │   │ Promoter          │       │
│  └──────┬───────┘   └───────────────────┘       │
└─────────┼───────────────────────────────────────┘
          │ transportFactory (stdio | http | custom)
          ▼
   ┌──────────────────────────────┐
   │ Downstream MCP servers       │
   │ (fs, github, sentry, remote) │
   └──────────────────────────────┘

License

MIT. See LICENSE at the monorepo root.