Skip to content
reaatechREAATECH

@reaatech/multi-tenant-mcp-config-isolation

npm v0.1.0

Manages multi-tenant application configurations by providing Zod-based schema validation, base-config inheritance, and versioned migration support. It exposes a `TenantConfigManager` class to handle merged configuration access and a `ConfigMigrationRunner` to orchestrate schema updates across tenant stores.

@reaatech/multi-tenant-mcp-config-isolation

npm version License: MIT CI

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

Per-tenant configuration with Zod schema validation, base-config merging, and versioned migration support.

Installation

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

Feature Overview

  • Schema validation — Zod-powered: missing or malformed configs are rejected with human-readable errors.
  • Base-config inheritance — Set shared defaults in a base config; tenant configs override individual fields.
  • Pluggable storage — In-memory store ships out of the box; implement TenantConfigStore for any backend.
  • Versioned migrationsConfigMigrationRunner runs ordered migrations when your config schema evolves.

Quick Start

typescript
import { z } from 'zod';
import {
  InMemoryConfigStore,
  ZodConfigValidator,
  TenantConfigManager,
} from '@reaatech/multi-tenant-mcp-config-isolation';
 
const schema = z.object({
  theme: z.string().default('light'),
  model: z.string().optional(),
  maxTools: z.number().min(1).default(5),
});
 
const validator = new ZodConfigValidator({ schema });
const store = new InMemoryConfigStore({ defaults: { theme: 'light', maxTools: 5 } });
const manager = new TenantConfigManager({ store, validator });
 
// Set tenant-specific overrides
await manager.set('tenant-a', { theme: 'dark', maxTools: 20 });
 
// Get merged config (tenant overrides + base defaults)
const config = await manager.get('tenant-a');
// { theme: 'dark', maxTools: 20 }
 
// Invalid configs are rejected
await manager.set('tenant-b', { maxTools: -1 }); // throws ValidationError

Config Migrations

typescript
import { ConfigMigrationRunner } from '@reaatech/multi-tenant-mcp-config-isolation';
 
const runner = new ConfigMigrationRunner();
runner.register({
  version: 1,
  migrate: async (store) => {
    // Add "model" field to all existing tenant configs
    for (const tenantId of await store.listTenants()) {
      const config = await store.get(tenantId);
      if (config && !config.model) {
        await store.set(tenantId, { ...config, model: 'gpt-4-turbo' });
      }
    }
  },
});
 
await runner.run(store);

Exports

ExportKindDescription
TenantConfigTypeRecord<string, unknown>
ConfigValidatorInterfacevalidate(config) → TenantConfig
TenantConfigStoreInterfaceget, set, delete per tenant
InMemoryConfigStoreClassIn-memory store with base defaults
ZodConfigValidatorClassValidate tenant configs against a Zod schema
TenantConfigManagerClassHigh-level facade: get/set with validation and base merge
ConfigMigrationRunnerClassRun ordered versioned migrations
ConfigMigrationInterface{ version, migrate: (store) => Promise<void> }

License

MIT