Skip to content
reaatech

@reaatech/multi-tenant-mcp-types

npm v0.1.0

Shared TypeScript types, error classes, and data structures for the multi-tenant MCP ecosystem, including `TenantContext`, `MiddlewareError`, `MiddlewareErrorCode`, and `BoundedMap`.

@reaatech/multi-tenant-mcp-types

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Foundation of the multi-tenant-mcp ecosystem: shared TypeScript types, error classes, and data structures consumed by every other package in the monorepo.

Installation

terminal
npm install @reaatech/multi-tenant-mcp-types
# or
pnpm add @reaatech/multi-tenant-mcp-types

Feature Overview

  • TenantContext — Immutable tenant identity, metadata, and resolution timestamp propagated through AsyncLocalStorage.
  • MiddlewareError — Typed error class carrying a JSON-RPC 2.0 error code and optional diagnostic data.
  • MiddlewareErrorCode — Exhaustive enum of error codes (-32001-32603) used by every middleware layer.
  • BoundedMap<K,V> — LRU-evicting map with a hard size cap — used internally by in-memory stores (rate limiter, cost tracker, metrics) to prevent unbounded growth from caller-controlled keys.

Quick Start

typescript
import {
  TenantContext,
  MiddlewareError,
  MiddlewareErrorCode,
  BoundedMap,
} from '@reaatech/multi-tenant-mcp-types';
 
const ctx: TenantContext = {
  tenantId: 'acme-corp',
  metadata: { tier: 'enterprise' },
  resolvedAt: new Date(),
};
 
throw new MiddlewareError(MiddlewareErrorCode.RateLimitExceeded, 'Too many requests', {
  retryAfter: 30,
});

Exports

ExportKindDescription
TenantContextInterfaceResolved tenant identity within the MCP request lifecycle
MiddlewareErrorCodeEnumJSON-RPC 2.0 error codes (Unauthorized, RateLimitExceeded, ToolForbidden, ResourceForbidden, PromptForbidden, InternalError)
MiddlewareErrorClassTyped error with code, message, and optional diagnostic data
BoundedMap<K, V>ClassLRU-evicting map; oldest entry dropped when capacity is exceeded

License

MIT