@ubuligan/shared

v0.1.1

Published

Shared, dependency-free types and utilities for the MCP Toolkit (logger, retry, transport types)

Readme

@ubuligan/shared

Shared, dependency-free types and utilities for the MCP Toolkit. Browser-safe — no MCP SDK import — so it can be used from both Node and the browser.

It is the base layer that @ubuligan/client, @ubuligan/server and @ubuligan/react build on. You rarely install it directly — it comes in as a transitive dependency — but its types and helpers are useful on their own.

Install

npm install @ubuligan/shared

What's inside

| Export | Kind | Purpose | | --- | --- | --- | | createConsoleLogger(level) | fn | A leveled console logger (debug / info / warn / error). | | noopLogger | const | A logger that discards everything (default when none is given). | | Logger, LogLevel | type | The logger interface and the level union. | | withRetry(fn, opts, logger, label) | fn | Run an async fn with exponential-backoff + jitter retries. | | RetryOptions | type | { retries, minDelayMs, maxDelayMs, shouldRetry }. | | resolveAuthHeaders(auth) | fn | Turn an AuthConfig into HTTP headers (async). | | AuthConfig | type | { type: "bearer" } or { type: "headers" } (values may be async getters). | | TransportConfig | type | Union of StdioTransportConfig and HttpTransportConfig. |

Usage

Logging

import { createConsoleLogger } from "@ubuligan/shared";

const log = createConsoleLogger("info"); // logs info+ to the console
log.debug("hidden"); // below level → dropped
log.info("connecting", { url });
log.error("failed", err);

Retry

import { withRetry, createConsoleLogger } from "@ubuligan/shared";

const data = await withRetry(
  () => fetch(url).then((r) => r.json()),
  { retries: 3, minDelayMs: 200, maxDelayMs: 5000 },
  createConsoleLogger("warn"),
  "fetch-data", // label shown in retry logs
);

Auth headers

import { resolveAuthHeaders } from "@ubuligan/shared";

const headers = resolveAuthHeaders({ type: "bearer", token: process.env.TOKEN! });
// → { Authorization: "Bearer ..." }

License

MIT