Skip to main content
Version: SDK ยท v1.1.0

API reference

This page documents the complete public surface of @erpbridge/sdk. It covers the package root, the ./client, ./rest, and ./types subpaths, and the typed error hierarchy.

Entry pointsโ€‹

The package exposes four entry points. All names are named exports โ€” there is no default export.

SubpathExports
@erpbridge/sdkEverything below
@erpbridge/sdk/clientcreateClient, ErpbridgeClient
@erpbridge/sdk/restThe REST surface factories and parsePrometheusText plus their types
@erpbridge/sdk/typesErpbridgeConfig, the error classes, and all shared types

Functionsโ€‹

createClient(input?)โ€‹

Create an ERPBridge SDK client facade. input is a partial ErpbridgeConfigInput; it defaults to { baseUrl: "http://localhost:8080" }.

createClient(input?: ErpbridgeConfigInput): ErpbridgeClient
import { createClient } from '@erpbridge/sdk'

const client = createClient({ baseUrl: 'http://localhost:8080' })
await client.mcp.connect()
const result = await client.tools.list_employees({})

resolveConfig(input?)โ€‹

Resolve a partial configuration into a fully populated ErpbridgeConfig. Useful when you build REST surfaces manually.

resolveConfig(input?: ErpbridgeConfigInput): ErpbridgeConfig

REST surface factoriesโ€‹

Each factory takes a fully resolved ErpbridgeConfig and returns one REST surface. Use createClient to connect all surfaces.

FactoryReturnsSurface
createLogsApi(config)LogsApirecent(), stream(options)
createMetricsApi(config)MetricsApitext(), parsed()
createRegistryApi(config)RegistryApilist({ name?, version? }), apply(), delete(), invoke()
createSystemApi(config)SystemApihealth(), cache.stats(), cache.flush()

createToolsProxy(mcp)โ€‹

Build the exact-name tool proxy over an existing McpClient. The proxy discovers tools on first access, so each registered tool name becomes a callable property.

createToolsProxy(mcp: McpClient): Record<string, ToolFunction>

parsePrometheusText(text)โ€‹

Parse Prometheus exposition text into structured families. The parser handles counter, gauge, and histogram families. It reports summary and untyped families in skipped instead of dropping them.

parsePrometheusText(text: string): ParsedMetrics

McpClientโ€‹

The MCP protocol wrapper for v2 streamable HTTP. Construct it with a resolved configuration, or use client.mcp on the ERPBridge SDK client facade.

MethodSignatureBehavior
connect()() => Promise<void>Opens the session; negotiates protocol versions; reconnects transparently once, then throws ProtocolError
listTools()() => Promise<ToolDefinition[]>Lists server tools
callTool(name, args)(name: string, args: ToolCallArguments) => Promise<McpToolResult>Calls a tool and preserves the complete MCP result envelope
close()() => Promise<void>Closes the session and transport

INVALID_PARAMS_CODE is the numeric -32602 used for JSON-RPC invalid-parameter responses.

The client facadeโ€‹

ErpbridgeClient, returned by createClient, exposes nine surfaces:

MemberTypePurpose
mcpMcpClientProtocol surface: connect, list, call, close
toolsRecord<string, ToolFunction>Exact-name tool proxy (outside .registry so tool names like list never collide with registry methods)
registryRegistryApiREST registry CRUD over stored tool resources
invoke(name, args, { role? }) => Promise<ToolResult>Direct REST invocation; role is sent as X-ERPBridge-Role
logsLogsApirecent() and stream() (SSE)
metricsMetricsApiRaw and parsed Prometheus metrics
healthSystemApi['health']Server health check
cacheSystemApi['cache']Cache stats and flush
close() => Promise<void>Close the MCP session

Error hierarchyโ€‹

All errors extend ErpbridgeError and carry status and code when available. Match errors by class, not by raw error string.

ErpbridgeError
โ”œโ”€โ”€ AuthenticationError HTTP 401
โ”œโ”€โ”€ AuthorizationError HTTP 403
โ”œโ”€โ”€ NotFoundError HTTP 404
โ”œโ”€โ”€ RateLimitError HTTP 429
โ”œโ”€โ”€ ClientError HTTP 4xx (other than 401/404/429)
โ”œโ”€โ”€ ServerError HTTP 5xx
โ””โ”€โ”€ ProtocolError MCP/SSE transport failures

AuthenticationError represents an unauthenticated request. AuthorizationError represents a forbidden request. It can carry a server-declared requiredScope.

Configurationโ€‹

ErpbridgeConfigInput has optional fields. The resolved configuration uses ErpbridgeConfig:

FieldTypeDefaultNotes
baseUrlstringhttp://localhost:8080Server base URL
mcpUrlstringderived from baseUrlMCP streamable HTTP endpoint
timeoutMsnumberSDK defaultPer-request timeout
fetchtypeof fetchglobalThis.fetchInjectable fetch for testing
tokenstringโ€”Global bearer token. Surface credentials can override it.
tokenEnvstringERPBRIDGE_TOKENEnvironment-variable name for the global bearer token; legacy ERPBridge_TOKEN is a fallback
declaredScopesreadonly ('mcp' | 'metrics' | 'logs')[]โ€”Optional local assertion used for fail-fast scope checks
auth{ mcp?, metrics?, logs? }โ€”Per-surface token/tokenEnv/declaredScopes overrides

Shared typesโ€‹

Types used across the public surface:

TypeDescription
LogRecordA single log entry as returned by logs.recent()
LogStreamOptionsOptions for logs.stream() (follow, tail, and more)
ToolDefinitionServer tool metadata: name, description, input schema
McpToolResultOfficial MCP CallToolResult envelope (content, optional structuredContent, isError)
ToolResultREST direct-invoke envelope (result, optional error, isError)
ToolCallArgumentsRecord<string, unknown> tool arguments
ToolFunctionThe callable tool signature used by the proxy
CacheStatsCache statistics from cache.stats()
CacheFlushOptions / CacheFlushResultcache.flush() options (all?: true) and result
HealthStatusHealth check payload from health()
MetricSample / MetricFamilyParsed Prometheus samples and families
ParsedMetrics / SkippedFamilyparsePrometheusText output, including skipped families
RegistryTool*Registry tool resources: RegistryTool, RegistryToolMetadata, RegistryToolDescription, RegistryToolProperty, RegistryToolInputSchema, RegistryToolExecution, RegistryToolSecurity, RegistryToolRouting, RegistryToolLifecycle, RegistryToolSpec
ToolApplyResultResult of registry.apply()
RegistryDeleteOptionsOptions for registry.delete() (hard?: true)

The tool registry types mirror the server's tool schema โ€” see the server API for the wire format.