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.
| Subpath | Exports |
|---|---|
@erpbridge/sdk | Everything below |
@erpbridge/sdk/client | createClient, ErpbridgeClient |
@erpbridge/sdk/rest | The REST surface factories and parsePrometheusText plus their types |
@erpbridge/sdk/types | ErpbridgeConfig, 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.
| Factory | Returns | Surface |
|---|---|---|
createLogsApi(config) | LogsApi | recent(), stream(options) |
createMetricsApi(config) | MetricsApi | text(), parsed() |
createRegistryApi(config) | RegistryApi | list({ name?, version? }), apply(), delete(), invoke() |
createSystemApi(config) | SystemApi | health(), 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.
| Method | Signature | Behavior |
|---|---|---|
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:
| Member | Type | Purpose |
|---|---|---|
mcp | McpClient | Protocol surface: connect, list, call, close |
tools | Record<string, ToolFunction> | Exact-name tool proxy (outside .registry so tool names like list never collide with registry methods) |
registry | RegistryApi | REST registry CRUD over stored tool resources |
invoke | (name, args, { role? }) => Promise<ToolResult> | Direct REST invocation; role is sent as X-ERPBridge-Role |
logs | LogsApi | recent() and stream() (SSE) |
metrics | MetricsApi | Raw and parsed Prometheus metrics |
health | SystemApi['health'] | Server health check |
cache | SystemApi['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:
| Field | Type | Default | Notes |
|---|---|---|---|
baseUrl | string | http://localhost:8080 | Server base URL |
mcpUrl | string | derived from baseUrl | MCP streamable HTTP endpoint |
timeoutMs | number | SDK default | Per-request timeout |
fetch | typeof fetch | globalThis.fetch | Injectable fetch for testing |
token | string | โ | Global bearer token. Surface credentials can override it. |
tokenEnv | string | ERPBRIDGE_TOKEN | Environment-variable name for the global bearer token; legacy ERPBridge_TOKEN is a fallback |
declaredScopes | readonly ('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:
| Type | Description |
|---|---|
LogRecord | A single log entry as returned by logs.recent() |
LogStreamOptions | Options for logs.stream() (follow, tail, and more) |
ToolDefinition | Server tool metadata: name, description, input schema |
McpToolResult | Official MCP CallToolResult envelope (content, optional structuredContent, isError) |
ToolResult | REST direct-invoke envelope (result, optional error, isError) |
ToolCallArguments | Record<string, unknown> tool arguments |
ToolFunction | The callable tool signature used by the proxy |
CacheStats | Cache statistics from cache.stats() |
CacheFlushOptions / CacheFlushResult | cache.flush() options (all?: true) and result |
HealthStatus | Health check payload from health() |
MetricSample / MetricFamily | Parsed Prometheus samples and families |
ParsedMetrics / SkippedFamily | parsePrometheusText output, including skipped families |
RegistryTool* | Registry tool resources: RegistryTool, RegistryToolMetadata, RegistryToolDescription, RegistryToolProperty, RegistryToolInputSchema, RegistryToolExecution, RegistryToolSecurity, RegistryToolRouting, RegistryToolLifecycle, RegistryToolSpec |
ToolApplyResult | Result of registry.apply() |
RegistryDeleteOptions | Options for registry.delete() (hard?: true) |
The tool registry types mirror the server's tool schema โ see the server API for the wire format.