Skip to content
reaatechREAATECH

@reaatech/mcp-server-core

npm v1.0.0

Provides shared TypeScript types, Zod schemas, and environment configuration utilities for building Model Context Protocol (MCP) servers. It exports factory functions for content blocks and tool responses alongside a cached, validated environment configuration object.

@reaatech/mcp-server-core

npm version License: MIT CI

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

Core MCP types, Zod schemas, configuration, and version utilities. This package is the single source of truth for all domain types used throughout the @reaatech/mcp-server-* ecosystem.

Installation

terminal
npm install @reaatech/mcp-server-core
# or
pnpm add @reaatech/mcp-server-core

Feature Overview

  • Runtime schema validation — Zod schemas for all external-facing data shapes
  • Environment configuration — Validated, cached environment variables with fail-fast semantics
  • Shared domain typesToolResponse, ContentBlock, RequestContext, ToolContext, and more
  • Content block helperstextContent() and errorResponse() factories
  • Version management — Centralized APP_VERSION, SERVICE_NAME, and SERVER_INFO
  • Dual ESM/CJS output — works with import and require

Quick Start

typescript
import {
  textContent,
  errorResponse,
  envConfig,
  isProduction,
  APP_VERSION,
  SERVER_INFO,
} from '@reaatech/mcp-server-core';
 
// Create a text content block
const content = textContent('Hello, world!');
 
// Create an error response
const response = errorResponse('Something went wrong');
 
// Access validated environment config (cached, validated at startup)
const port = envConfig.PORT;
const logLevel = envConfig.LOG_LEVEL;
 
// Check the environment
if (isProduction()) {
  // ...
}

API Reference

Content Blocks

ExportDescription
TextContentSchema{ type: "text", text: string }
ImageContentSchema{ type: "image", data: string, mimeType: string }
ResourceContentSchema{ type: "resource", uri: string, mimeType?, text?, blob? }
ContentBlockSchema / ContentBlockUnion of all content block types
textContent(text)Factory: { type: "text", text }
errorResponse(message)Factory: { content: [...], isError: true }

Tool Response

ExportDescription
ToolResponseSchema / ToolResponse{ content: ContentBlock[], isError?: boolean }

Request & Session Types

ExportDescription
RequestContextrequestId, sessionId?, idempotencyKey?, apiKey?, ipAddress?
ToolContext{ request: RequestContext, session?: SessionData }
SessionData{ id, createdAt, lastAccessedAt, metadata? }
RateLimitState{ tokens: number, lastRefill: number }
IdempotencyEntry{ key, response, statusCode, createdAt, ttl }

Health Status

ExportDescription
HealthStatusSchema / HealthStatus{ status: "healthy" | "unhealthy", version, environment, uptime, timestamp }

Environment Configuration

typescript
import { getEnvConfig, resetEnvConfigCache, envConfig, isProduction, isDevelopment, isTest } from '@reaatech/mcp-server-core';
ExportDescription
getEnvConfig()Parse and validate process.env, returns cached EnvConfig
envConfigProxy accessor — lazy-loads on access, caches result
resetEnvConfigCache()Clear cache (for tests that mutate process.env)
isProduction()envConfig.NODE_ENV === 'production'
isDevelopment()envConfig.NODE_ENV === 'development'
isTest()envConfig.NODE_ENV === 'test'

EnvConfig Fields

FieldTypeDefaultDescription
PORTnumber8080Server port
NODE_ENVdevelopment' | 'production' | 'testdevelopmentEnvironment
CORS_ORIGINstring*CORS allowed origins
API_KEYstring | undefinedShared secret for auth
AUTH_MODEapi-key' | 'bearerapi-keyAuthentication mode
AUTH_BYPASS_IN_DEVbooleantrueBypass auth in dev when no key
OTEL_EXPORTER_OTLP_ENDPOINTstring | undefinedOTLP collector URL
OTEL_SERVICE_NAMEstringmcp-serverService name for OTel
OTEL_RESOURCE_ATTRIBUTESstring | undefinedAdditional OTel attributes
IDEMPOTENCY_TTL_MSnumber300000Idempotency cache TTL
RATE_LIMIT_RPMnumber60Rate limit per minute
LOG_LEVELdebug' | 'info' | 'warn' | 'errorinfoLog level
SESSION_TIMEOUT_MSnumber1800000Session expiry ms
SANITIZATION_DENY_PATTERNSstring | undefinedExtra deny patterns

Version Constants

typescript
import { APP_VERSION, SERVICE_NAME, SERVICE_VERSION, SERVER_INFO } from '@reaatech/mcp-server-core';
ExportDescription
APP_VERSIONCurrent application version
SERVICE_NAMEmcp-server-starter-ts
SERVICE_VERSIONSame as APP_VERSION
SERVER_INFO{ name: SERVICE_NAME, version: APP_VERSION }

Usage Pattern

Every schema export has a matching type export. Use the Zod schema for runtime validation and the inferred type for compile-time checking:

typescript
import { ToolResponseSchema, type ToolResponse } from '@reaatech/mcp-server-core';
 
function handleResponse(raw: unknown): ToolResponse {
  return ToolResponseSchema.parse(raw);
}

License

MIT