@mcpmesh/sdk 0.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/__tests__/claude-handler.test.d.ts +7 -0
  2. package/dist/__tests__/claude-handler.test.d.ts.map +1 -0
  3. package/dist/__tests__/claude-handler.test.js +455 -0
  4. package/dist/__tests__/claude-handler.test.js.map +1 -0
  5. package/dist/__tests__/config.test.d.ts +7 -0
  6. package/dist/__tests__/config.test.d.ts.map +1 -0
  7. package/dist/__tests__/config.test.js +156 -0
  8. package/dist/__tests__/config.test.js.map +1 -0
  9. package/dist/__tests__/errors.test.d.ts +7 -0
  10. package/dist/__tests__/errors.test.d.ts.map +1 -0
  11. package/dist/__tests__/errors.test.js +170 -0
  12. package/dist/__tests__/errors.test.js.map +1 -0
  13. package/dist/__tests__/generic-handler.test.d.ts +7 -0
  14. package/dist/__tests__/generic-handler.test.d.ts.map +1 -0
  15. package/dist/__tests__/generic-handler.test.js +243 -0
  16. package/dist/__tests__/generic-handler.test.js.map +1 -0
  17. package/dist/__tests__/llm-provider.test.d.ts +7 -0
  18. package/dist/__tests__/llm-provider.test.d.ts.map +1 -0
  19. package/dist/__tests__/llm-provider.test.js +217 -0
  20. package/dist/__tests__/llm-provider.test.js.map +1 -0
  21. package/dist/__tests__/openai-handler.test.d.ts +7 -0
  22. package/dist/__tests__/openai-handler.test.d.ts.map +1 -0
  23. package/dist/__tests__/openai-handler.test.js +359 -0
  24. package/dist/__tests__/openai-handler.test.js.map +1 -0
  25. package/dist/__tests__/provider-handler-registry.test.d.ts +9 -0
  26. package/dist/__tests__/provider-handler-registry.test.d.ts.map +1 -0
  27. package/dist/__tests__/provider-handler-registry.test.js +187 -0
  28. package/dist/__tests__/provider-handler-registry.test.js.map +1 -0
  29. package/dist/__tests__/response-parser.test.d.ts +7 -0
  30. package/dist/__tests__/response-parser.test.d.ts.map +1 -0
  31. package/dist/__tests__/response-parser.test.js +360 -0
  32. package/dist/__tests__/response-parser.test.js.map +1 -0
  33. package/dist/__tests__/route.test.d.ts +7 -0
  34. package/dist/__tests__/route.test.d.ts.map +1 -0
  35. package/dist/__tests__/route.test.js +281 -0
  36. package/dist/__tests__/route.test.js.map +1 -0
  37. package/dist/__tests__/sse.test.d.ts +7 -0
  38. package/dist/__tests__/sse.test.d.ts.map +1 -0
  39. package/dist/__tests__/sse.test.js +172 -0
  40. package/dist/__tests__/sse.test.js.map +1 -0
  41. package/dist/__tests__/template.test.d.ts +7 -0
  42. package/dist/__tests__/template.test.d.ts.map +1 -0
  43. package/dist/__tests__/template.test.js +176 -0
  44. package/dist/__tests__/template.test.js.map +1 -0
  45. package/dist/__tests__/tracing.test.d.ts +7 -0
  46. package/dist/__tests__/tracing.test.d.ts.map +1 -0
  47. package/dist/__tests__/tracing.test.js +264 -0
  48. package/dist/__tests__/tracing.test.js.map +1 -0
  49. package/dist/agent.d.ts +165 -0
  50. package/dist/agent.d.ts.map +1 -0
  51. package/dist/agent.js +626 -0
  52. package/dist/agent.js.map +1 -0
  53. package/dist/api-runtime.d.ts +166 -0
  54. package/dist/api-runtime.d.ts.map +1 -0
  55. package/dist/api-runtime.js +459 -0
  56. package/dist/api-runtime.js.map +1 -0
  57. package/dist/config.d.ts +31 -0
  58. package/dist/config.d.ts.map +1 -0
  59. package/dist/config.js +60 -0
  60. package/dist/config.js.map +1 -0
  61. package/dist/debug.d.ts +47 -0
  62. package/dist/debug.d.ts.map +1 -0
  63. package/dist/debug.js +86 -0
  64. package/dist/debug.js.map +1 -0
  65. package/dist/errors.d.ts +99 -0
  66. package/dist/errors.d.ts.map +1 -0
  67. package/dist/errors.js +110 -0
  68. package/dist/errors.js.map +1 -0
  69. package/dist/express.d.ts +146 -0
  70. package/dist/express.d.ts.map +1 -0
  71. package/dist/express.js +371 -0
  72. package/dist/express.js.map +1 -0
  73. package/dist/index.d.ts +96 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +107 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/llm-agent.d.ts +193 -0
  78. package/dist/llm-agent.d.ts.map +1 -0
  79. package/dist/llm-agent.js +634 -0
  80. package/dist/llm-agent.js.map +1 -0
  81. package/dist/llm-provider.d.ts +323 -0
  82. package/dist/llm-provider.d.ts.map +1 -0
  83. package/dist/llm-provider.js +446 -0
  84. package/dist/llm-provider.js.map +1 -0
  85. package/dist/llm.d.ts +194 -0
  86. package/dist/llm.d.ts.map +1 -0
  87. package/dist/llm.js +304 -0
  88. package/dist/llm.js.map +1 -0
  89. package/dist/provider-handlers/claude-handler.d.ts +98 -0
  90. package/dist/provider-handlers/claude-handler.d.ts.map +1 -0
  91. package/dist/provider-handlers/claude-handler.js +268 -0
  92. package/dist/provider-handlers/claude-handler.js.map +1 -0
  93. package/dist/provider-handlers/gemini-handler.d.ts +82 -0
  94. package/dist/provider-handlers/gemini-handler.d.ts.map +1 -0
  95. package/dist/provider-handlers/gemini-handler.js +152 -0
  96. package/dist/provider-handlers/gemini-handler.js.map +1 -0
  97. package/dist/provider-handlers/generic-handler.d.ts +78 -0
  98. package/dist/provider-handlers/generic-handler.d.ts.map +1 -0
  99. package/dist/provider-handlers/generic-handler.js +152 -0
  100. package/dist/provider-handlers/generic-handler.js.map +1 -0
  101. package/dist/provider-handlers/index.d.ts +29 -0
  102. package/dist/provider-handlers/index.d.ts.map +1 -0
  103. package/dist/provider-handlers/index.js +32 -0
  104. package/dist/provider-handlers/index.js.map +1 -0
  105. package/dist/provider-handlers/openai-handler.d.ts +86 -0
  106. package/dist/provider-handlers/openai-handler.d.ts.map +1 -0
  107. package/dist/provider-handlers/openai-handler.js +160 -0
  108. package/dist/provider-handlers/openai-handler.js.map +1 -0
  109. package/dist/provider-handlers/provider-handler-registry.d.ts +124 -0
  110. package/dist/provider-handlers/provider-handler-registry.d.ts.map +1 -0
  111. package/dist/provider-handlers/provider-handler-registry.js +180 -0
  112. package/dist/provider-handlers/provider-handler-registry.js.map +1 -0
  113. package/dist/provider-handlers/provider-handler.d.ts +245 -0
  114. package/dist/provider-handlers/provider-handler.d.ts.map +1 -0
  115. package/dist/provider-handlers/provider-handler.js +238 -0
  116. package/dist/provider-handlers/provider-handler.js.map +1 -0
  117. package/dist/proxy.d.ts +44 -0
  118. package/dist/proxy.d.ts.map +1 -0
  119. package/dist/proxy.js +324 -0
  120. package/dist/proxy.js.map +1 -0
  121. package/dist/response-parser.d.ts +103 -0
  122. package/dist/response-parser.d.ts.map +1 -0
  123. package/dist/response-parser.js +232 -0
  124. package/dist/response-parser.js.map +1 -0
  125. package/dist/route.d.ts +185 -0
  126. package/dist/route.d.ts.map +1 -0
  127. package/dist/route.js +310 -0
  128. package/dist/route.js.map +1 -0
  129. package/dist/sse.d.ts +45 -0
  130. package/dist/sse.d.ts.map +1 -0
  131. package/dist/sse.js +77 -0
  132. package/dist/sse.js.map +1 -0
  133. package/dist/template.d.ts +86 -0
  134. package/dist/template.d.ts.map +1 -0
  135. package/dist/template.js +206 -0
  136. package/dist/template.js.map +1 -0
  137. package/dist/tracing.d.ts +88 -0
  138. package/dist/tracing.d.ts.map +1 -0
  139. package/dist/tracing.js +193 -0
  140. package/dist/tracing.js.map +1 -0
  141. package/dist/types.d.ts +618 -0
  142. package/dist/types.d.ts.map +1 -0
  143. package/dist/types.js +5 -0
  144. package/dist/types.js.map +1 -0
  145. package/package.json +68 -0
package/dist/config.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Configuration utilities for MCP Mesh agents.
3
+ *
4
+ * All configuration resolution is delegated to Rust core for consistency
5
+ * across all language SDKs. Priority: ENV > config > defaults
6
+ *
7
+ * Defaults are also sourced from Rust core to ensure single source of truth.
8
+ */
9
+ import { randomBytes } from "crypto";
10
+ import { resolveConfig as rustResolveConfig, resolveConfigInt, getDefault, } from "@mcpmesh/core";
11
+ // TypeScript-specific defaults (not in Rust core)
12
+ const TS_DEFAULTS = {
13
+ version: "1.0.0",
14
+ description: "",
15
+ };
16
+ /**
17
+ * Generate a short UUID suffix (8 hex chars) for agent IDs.
18
+ */
19
+ export function generateAgentIdSuffix() {
20
+ return randomBytes(4).toString("hex");
21
+ }
22
+ /**
23
+ * Resolve configuration with environment variable precedence via Rust core.
24
+ *
25
+ * All resolution is delegated to Rust core to ensure consistent behavior
26
+ * across Python and TypeScript SDKs.
27
+ *
28
+ * Priority (handled by Rust): ENV > config > defaults
29
+ *
30
+ * Environment variables:
31
+ * - MCP_MESH_AGENT_NAME: Override agent name
32
+ * - MCP_MESH_HTTP_HOST: Override host (auto-detected if not set)
33
+ * - MCP_MESH_HTTP_PORT: Override port
34
+ * - MCP_MESH_NAMESPACE: Override namespace
35
+ * - MCP_MESH_REGISTRY_URL: Override registry URL
36
+ * - MCP_MESH_HEALTH_INTERVAL: Override heartbeat interval
37
+ */
38
+ export function resolveConfig(config) {
39
+ // All config resolution via Rust core - ensures consistent ENV > param > default
40
+ const resolvedName = rustResolveConfig("agent_name", config.name);
41
+ const resolvedPort = resolveConfigInt("http_port", config.port) ?? config.port;
42
+ const resolvedHost = rustResolveConfig("http_host", config.host ?? null);
43
+ const resolvedNamespace = rustResolveConfig("namespace", config.namespace ?? null);
44
+ const resolvedRegistryUrl = rustResolveConfig("registry_url", config.registryUrl ?? null);
45
+ // Get heartbeat interval with fallback to Rust core default
46
+ const healthIntervalDefault = parseInt(getDefault("health_interval") ?? "5", 10);
47
+ const resolvedHeartbeatInterval = resolveConfigInt("health_interval", config.heartbeatInterval ?? null) ??
48
+ healthIntervalDefault;
49
+ return {
50
+ name: resolvedName,
51
+ version: config.version ?? TS_DEFAULTS.version,
52
+ description: config.description ?? TS_DEFAULTS.description,
53
+ port: resolvedPort,
54
+ host: resolvedHost,
55
+ namespace: resolvedNamespace,
56
+ registryUrl: resolvedRegistryUrl,
57
+ heartbeatInterval: resolvedHeartbeatInterval,
58
+ };
59
+ }
60
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["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AE,MAAM,CAAC,OAAO,IAAI,WAAW,CAAC,OAAO;QAC9C,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,WAAW,CAAC,WAAW;QAC1D,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,YAAY;QAClB,SAAS,EAAE,iBAAiB;QAC5B,WAAW,EAAE,mBAAmB;QAChC,iBAAiB,EAAE,yBAAyB;KAC7C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Debug logging utilities for MCP Mesh SDK.
3
+ *
4
+ * Debug output is controlled by standard MCP Mesh environment variables:
5
+ * - MCP_MESH_LOG_LEVEL=DEBUG - Enable debug output (DEBUG, INFO, WARNING, ERROR, CRITICAL)
6
+ * - MCP_MESH_DEBUG_MODE=true - Force DEBUG level
7
+ *
8
+ * @example
9
+ * ```bash
10
+ * # Enable debug output
11
+ * MCP_MESH_LOG_LEVEL=DEBUG node my-agent.js
12
+ *
13
+ * # Or use debug mode
14
+ * MCP_MESH_DEBUG_MODE=true node my-agent.js
15
+ * ```
16
+ */
17
+ type DebugCategory = "llm" | "llm-provider" | "sse" | "template" | "agent" | "registry" | "provider-handler-registry" | "provider-handler" | "claude-handler" | "openai-handler" | "gemini-handler";
18
+ /**
19
+ * Create a debug logger for a specific category.
20
+ *
21
+ * @param category - Debug category (e.g., "llm", "sse", "template")
22
+ * @returns Debug function that only logs when category is enabled
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const debug = createDebug("llm");
27
+ * debug("Executing tool", { name: "add" });
28
+ * // Only logs if MCP_MESH_LOG_LEVEL=DEBUG or MCP_MESH_DEBUG_MODE=true
29
+ * ```
30
+ */
31
+ export declare function createDebug(category: DebugCategory): (...args: unknown[]) => void;
32
+ /**
33
+ * Pre-configured debug loggers for common categories.
34
+ */
35
+ export declare const debug: {
36
+ llm: (...args: unknown[]) => void;
37
+ sse: (...args: unknown[]) => void;
38
+ template: (...args: unknown[]) => void;
39
+ agent: (...args: unknown[]) => void;
40
+ registry: (...args: unknown[]) => void;
41
+ };
42
+ /**
43
+ * Check if any debug logging is enabled.
44
+ */
45
+ export declare function isAnyDebugEnabled(): boolean;
46
+ export {};
47
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,KAAK,aAAa,GAAG,KAAK,GAAG,cAAc,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,2BAA2B,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AAyCpM;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAQjF;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;mBAb8C,OAAO,EAAE,KAAK,IAAI;mBAAlB,OAAO,EAAE,KAAK,IAAI;wBAAlB,OAAO,EAAE,KAAK,IAAI;qBAAlB,OAAO,EAAE,KAAK,IAAI;wBAAlB,OAAO,EAAE,KAAK,IAAI;CAmBjF,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C"}
package/dist/debug.js ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Debug logging utilities for MCP Mesh SDK.
3
+ *
4
+ * Debug output is controlled by standard MCP Mesh environment variables:
5
+ * - MCP_MESH_LOG_LEVEL=DEBUG - Enable debug output (DEBUG, INFO, WARNING, ERROR, CRITICAL)
6
+ * - MCP_MESH_DEBUG_MODE=true - Force DEBUG level
7
+ *
8
+ * @example
9
+ * ```bash
10
+ * # Enable debug output
11
+ * MCP_MESH_LOG_LEVEL=DEBUG node my-agent.js
12
+ *
13
+ * # Or use debug mode
14
+ * MCP_MESH_DEBUG_MODE=true node my-agent.js
15
+ * ```
16
+ */
17
+ /** Log levels in order of severity */
18
+ const LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"];
19
+ /**
20
+ * Get the current log level from environment.
21
+ */
22
+ function getLogLevel() {
23
+ // MCP_MESH_DEBUG_MODE forces DEBUG level
24
+ const debugMode = process.env.MCP_MESH_DEBUG_MODE;
25
+ if (debugMode === "true" || debugMode === "1") {
26
+ return "DEBUG";
27
+ }
28
+ // MCP_MESH_LOG_LEVEL sets the level
29
+ const level = process.env.MCP_MESH_LOG_LEVEL?.toUpperCase();
30
+ if (level && LOG_LEVELS.includes(level)) {
31
+ return level;
32
+ }
33
+ // Default to INFO
34
+ return "INFO";
35
+ }
36
+ /**
37
+ * Check if a log level is enabled.
38
+ */
39
+ function isLevelEnabled(level) {
40
+ const currentLevel = getLogLevel();
41
+ return LOG_LEVELS.indexOf(level) >= LOG_LEVELS.indexOf(currentLevel);
42
+ }
43
+ /**
44
+ * Check if debug logging is enabled.
45
+ */
46
+ function isDebugEnabled(_category) {
47
+ return isLevelEnabled("DEBUG");
48
+ }
49
+ /**
50
+ * Create a debug logger for a specific category.
51
+ *
52
+ * @param category - Debug category (e.g., "llm", "sse", "template")
53
+ * @returns Debug function that only logs when category is enabled
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const debug = createDebug("llm");
58
+ * debug("Executing tool", { name: "add" });
59
+ * // Only logs if MCP_MESH_LOG_LEVEL=DEBUG or MCP_MESH_DEBUG_MODE=true
60
+ * ```
61
+ */
62
+ export function createDebug(category) {
63
+ const prefix = `[mesh.${category}]`;
64
+ return (...args) => {
65
+ if (isDebugEnabled(category)) {
66
+ console.log(prefix, ...args);
67
+ }
68
+ };
69
+ }
70
+ /**
71
+ * Pre-configured debug loggers for common categories.
72
+ */
73
+ export const debug = {
74
+ llm: createDebug("llm"),
75
+ sse: createDebug("sse"),
76
+ template: createDebug("template"),
77
+ agent: createDebug("agent"),
78
+ registry: createDebug("registry"),
79
+ };
80
+ /**
81
+ * Check if any debug logging is enabled.
82
+ */
83
+ export function isAnyDebugEnabled() {
84
+ return isLevelEnabled("DEBUG");
85
+ }
86
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,sCAAsC;AACtC,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,CAAU,CAAC;AAG9E;;GAEG;AACH,SAAS,WAAW;IAClB,yCAAyC;IACzC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;IAClD,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;QAC9C,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,oCAAoC;IACpC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,WAAW,EAA0B,CAAC;IACpF,IAAI,KAAK,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,kBAAkB;IAClB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,KAAe;IACrC,MAAM,YAAY,GAAG,WAAW,EAAE,CAAC;IACnC,OAAO,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AACvE,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,SAAwB;IAC9C,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,QAAuB;IACjD,MAAM,MAAM,GAAG,SAAS,QAAQ,GAAG,CAAC;IAEpC,OAAO,CAAC,GAAG,IAAe,EAAE,EAAE;QAC5B,IAAI,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;IACvB,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC;IACvB,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC;IACjC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC;IAC3B,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Typed error classes for mesh.llm() operations.
3
+ *
4
+ * These errors provide specific context about different failure modes,
5
+ * matching Python's error class hierarchy.
6
+ */
7
+ /**
8
+ * Error thrown when the agentic loop reaches max iterations without completing.
9
+ */
10
+ export declare class MaxIterationsError extends Error {
11
+ /** Number of iterations that were executed */
12
+ readonly iterations: number;
13
+ /** The last response from the LLM before reaching the limit */
14
+ readonly lastResponse: unknown;
15
+ /** The message history at the time of the error */
16
+ readonly messages?: unknown[] | undefined;
17
+ readonly name = "MaxIterationsError";
18
+ constructor(
19
+ /** Number of iterations that were executed */
20
+ iterations: number,
21
+ /** The last response from the LLM before reaching the limit */
22
+ lastResponse: unknown,
23
+ /** The message history at the time of the error */
24
+ messages?: unknown[] | undefined);
25
+ }
26
+ /**
27
+ * Error thrown when a tool execution fails during the agentic loop.
28
+ */
29
+ export declare class ToolExecutionError extends Error {
30
+ /** Name of the tool that failed */
31
+ readonly toolName: string;
32
+ /** The underlying error that caused the failure */
33
+ readonly cause: Error;
34
+ /** Arguments that were passed to the tool */
35
+ readonly args?: Record<string, unknown> | undefined;
36
+ readonly name = "ToolExecutionError";
37
+ constructor(
38
+ /** Name of the tool that failed */
39
+ toolName: string,
40
+ /** The underlying error that caused the failure */
41
+ cause: Error,
42
+ /** Arguments that were passed to the tool */
43
+ args?: Record<string, unknown> | undefined);
44
+ }
45
+ /**
46
+ * Error thrown when the LLM API returns an error response.
47
+ */
48
+ export declare class LLMAPIError extends Error {
49
+ /** HTTP status code from the API */
50
+ readonly statusCode: number;
51
+ /** Response body from the API */
52
+ readonly body: string;
53
+ /** The provider that returned the error */
54
+ readonly provider?: string | undefined;
55
+ readonly name = "LLMAPIError";
56
+ constructor(
57
+ /** HTTP status code from the API */
58
+ statusCode: number,
59
+ /** Response body from the API */
60
+ body: string,
61
+ /** The provider that returned the error */
62
+ provider?: string | undefined);
63
+ }
64
+ /**
65
+ * Error thrown when response parsing/validation fails.
66
+ * Unified class used by both LLM agent and response parser.
67
+ */
68
+ export declare class ResponseParseError extends Error {
69
+ /** The raw content that failed to parse */
70
+ readonly rawContent: string;
71
+ /** Zod validation error (if schema validation failed) */
72
+ readonly zodError?: unknown | undefined;
73
+ /** The expected schema (if using structured output) */
74
+ readonly expectedSchema?: unknown | undefined;
75
+ readonly name = "ResponseParseError";
76
+ constructor(message: string,
77
+ /** The raw content that failed to parse */
78
+ rawContent: string,
79
+ /** Zod validation error (if schema validation failed) */
80
+ zodError?: unknown | undefined,
81
+ /** The expected schema (if using structured output) */
82
+ expectedSchema?: unknown | undefined);
83
+ }
84
+ /**
85
+ * Error thrown when the LLM provider is not available.
86
+ */
87
+ export declare class ProviderUnavailableError extends Error {
88
+ /** The provider specification that could not be resolved */
89
+ readonly providerSpec: unknown;
90
+ /** Additional details about why resolution failed */
91
+ readonly reason?: string | undefined;
92
+ readonly name = "ProviderUnavailableError";
93
+ constructor(
94
+ /** The provider specification that could not be resolved */
95
+ providerSpec: unknown,
96
+ /** Additional details about why resolution failed */
97
+ reason?: string | undefined);
98
+ }
99
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"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K;IAKzC,2CAA2C;aAC3B,UAAU,EAAE,MAAM;IAClC,yDAAyD;aACzC,QAAQ,CAAC,EAAE,OAAO;IAClC,uDAAuD;aACvC,cAAc,CAAC,EAAE,OAAO;IAT1C,QAAQ,CAAC,IAAI,wBAAwB;gBAGnC,OAAO,EAAE,MAAM;IACf,2CAA2C;IAC3B,UAAU,EAAE,MAAM;IAClC,yDAAyD;IACzC,QAAQ,CAAC,EAAE,OAAO,YAAA;IAClC,uDAAuD;IACvC,cAAc,CAAC,EAAE,OAAO,YAAA;CAI3C;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAI/C,4DAA4D;aAC5C,YAAY,EAAE,OAAO;IACrC,qDAAqD;aACrC,MAAM,CAAC,EAAE,MAAM;IANjC,QAAQ,CAAC,IAAI,8BAA8B;;IAGzC,4DAA4D;IAC5C,YAAY,EAAE,OAAO;IACrC,qDAAqD;IACrC,MAAM,CAAC,EAAE,MAAM,YAAA;CAOlC"}
package/dist/errors.js ADDED
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Typed error classes for mesh.llm() operations.
3
+ *
4
+ * These errors provide specific context about different failure modes,
5
+ * matching Python's error class hierarchy.
6
+ */
7
+ /**
8
+ * Error thrown when the agentic loop reaches max iterations without completing.
9
+ */
10
+ export class MaxIterationsError extends Error {
11
+ iterations;
12
+ lastResponse;
13
+ messages;
14
+ name = "MaxIterationsError";
15
+ constructor(
16
+ /** Number of iterations that were executed */
17
+ iterations,
18
+ /** The last response from the LLM before reaching the limit */
19
+ lastResponse,
20
+ /** The message history at the time of the error */
21
+ messages) {
22
+ super(`Max iterations (${iterations}) reached without completing the task`);
23
+ this.iterations = iterations;
24
+ this.lastResponse = lastResponse;
25
+ this.messages = messages;
26
+ }
27
+ }
28
+ /**
29
+ * Error thrown when a tool execution fails during the agentic loop.
30
+ */
31
+ export class ToolExecutionError extends Error {
32
+ toolName;
33
+ cause;
34
+ args;
35
+ name = "ToolExecutionError";
36
+ constructor(
37
+ /** Name of the tool that failed */
38
+ toolName,
39
+ /** The underlying error that caused the failure */
40
+ cause,
41
+ /** Arguments that were passed to the tool */
42
+ args) {
43
+ super(`Tool '${toolName}' failed: ${cause.message}`);
44
+ this.toolName = toolName;
45
+ this.cause = cause;
46
+ this.args = args;
47
+ }
48
+ }
49
+ /**
50
+ * Error thrown when the LLM API returns an error response.
51
+ */
52
+ export class LLMAPIError extends Error {
53
+ statusCode;
54
+ body;
55
+ provider;
56
+ name = "LLMAPIError";
57
+ constructor(
58
+ /** HTTP status code from the API */
59
+ statusCode,
60
+ /** Response body from the API */
61
+ body,
62
+ /** The provider that returned the error */
63
+ provider) {
64
+ super(`LLM API error (${statusCode}): ${body}`);
65
+ this.statusCode = statusCode;
66
+ this.body = body;
67
+ this.provider = provider;
68
+ }
69
+ }
70
+ /**
71
+ * Error thrown when response parsing/validation fails.
72
+ * Unified class used by both LLM agent and response parser.
73
+ */
74
+ export class ResponseParseError extends Error {
75
+ rawContent;
76
+ zodError;
77
+ expectedSchema;
78
+ name = "ResponseParseError";
79
+ constructor(message,
80
+ /** The raw content that failed to parse */
81
+ rawContent,
82
+ /** Zod validation error (if schema validation failed) */
83
+ zodError,
84
+ /** The expected schema (if using structured output) */
85
+ expectedSchema) {
86
+ super(message);
87
+ this.rawContent = rawContent;
88
+ this.zodError = zodError;
89
+ this.expectedSchema = expectedSchema;
90
+ }
91
+ }
92
+ /**
93
+ * Error thrown when the LLM provider is not available.
94
+ */
95
+ export class ProviderUnavailableError extends Error {
96
+ providerSpec;
97
+ reason;
98
+ name = "ProviderUnavailableError";
99
+ constructor(
100
+ /** The provider specification that could not be resolved */
101
+ providerSpec,
102
+ /** Additional details about why resolution failed */
103
+ reason) {
104
+ super(`LLM provider unavailable${reason ? `: ${reason}` : ""}. ` +
105
+ `Provider spec: ${JSON.stringify(providerSpec)}`);
106
+ this.providerSpec = providerSpec;
107
+ this.reason = reason;
108
+ }
109
+ }
110
+ //# sourceMappingURL=errors.js.map
@@ -0,0 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SAAQ,KAAK;IAMzB;IAEA;IAEA;IATT,IAAI,GAAG,oBAAoB,CAAC;IAErC,YACE,OAAe;IACf,2CAA2C;IAC3B,UAAkB;IAClC,yDAAyD;IACzC,QAAkB;IAClC,uDAAuD;IACvC,cAAwB;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QANC,eAAU,GAAV,UAAU,CAAQ;QAElB,aAAQ,GAAR,QAAQ,CAAU;QAElB,mBAAc,GAAd,cAAc,CAAU;IAG1C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAK/B;IAEA;IANT,IAAI,GAAG,0BAA0B,CAAC;IAE3C;IACE,4DAA4D;IAC5C,YAAqB;IACrC,qDAAqD;IACrC,MAAe;QAE/B,KAAK,CACH,2BAA2B,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI;YACxD,kBAAkB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CACnD,CAAC;QAPc,iBAAY,GAAZ,YAAY,CAAS;QAErB,WAAM,GAAN,MAAM,CAAS;IAMjC,CAAC;CACF"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * MeshExpress: Express app integration with MCP Mesh.
3
+ *
4
+ * Provides automatic registration with mesh registry and dependency injection
5
+ * for Express route handlers. Uses agent_type: "api" since API services only
6
+ * consume capabilities, they don't provide them.
7
+ *
8
+ * **Note:** For simpler usage, just use `mesh.route()` without `meshExpress()`.
9
+ * The API runtime auto-initializes when the first `mesh.route()` is called.
10
+ *
11
+ * @example Simple usage (recommended)
12
+ * ```typescript
13
+ * import express from "express";
14
+ * import { mesh } from "@mcpmesh/sdk";
15
+ *
16
+ * const app = express();
17
+ * app.use(express.json());
18
+ *
19
+ * // mesh.route() auto-initializes the mesh connection
20
+ * app.post("/compute", mesh.route(
21
+ * [{ capability: "calculator" }],
22
+ * async (req, res, { calculator }) => {
23
+ * res.json({ result: await calculator({ a: req.body.a, b: req.body.b }) });
24
+ * }
25
+ * ));
26
+ *
27
+ * app.listen(3000);
28
+ * ```
29
+ *
30
+ * @example Explicit control (advanced)
31
+ * ```typescript
32
+ * import express from "express";
33
+ * import { meshExpress, mesh } from "@mcpmesh/sdk";
34
+ *
35
+ * const app = express();
36
+ * const meshApp = meshExpress(app, { name: "my-api", port: 3000 });
37
+ *
38
+ * app.post("/compute", mesh.route(...));
39
+ *
40
+ * meshApp.start();
41
+ * ```
42
+ */
43
+ import type { Application } from "express";
44
+ import type { Server } from "http";
45
+ import { type JsAgentHandle } from "@mcpmesh/core";
46
+ import type { AgentConfig, ResolvedAgentConfig } from "./types.js";
47
+ /**
48
+ * Configuration for MeshExpress.
49
+ * Extends AgentConfig with Express-specific options.
50
+ */
51
+ export interface MeshExpressConfig extends AgentConfig {
52
+ /**
53
+ * If true, automatically start when the module loads.
54
+ * Defaults to false for Express (explicit start preferred).
55
+ */
56
+ autoStart?: boolean;
57
+ }
58
+ /**
59
+ * MeshExpress wraps an Express app with MCP Mesh capabilities.
60
+ *
61
+ * Provides:
62
+ * - Registration with mesh registry via Rust core
63
+ * - Heartbeat management
64
+ * - Dependency resolution for route handlers
65
+ * - Distributed tracing
66
+ */
67
+ export declare class MeshExpress {
68
+ private app;
69
+ private config;
70
+ private serviceId;
71
+ private handle;
72
+ private server;
73
+ private started;
74
+ constructor(app: Application, config: MeshExpressConfig);
75
+ /**
76
+ * Setup health check endpoints for the registry.
77
+ */
78
+ private setupHealthEndpoints;
79
+ /**
80
+ * Start the Express server and register with mesh.
81
+ */
82
+ start(): Promise<void>;
83
+ /**
84
+ * Start the Express HTTP server.
85
+ */
86
+ private startServer;
87
+ /**
88
+ * Start the Rust core heartbeat loop.
89
+ */
90
+ private startHeartbeat;
91
+ /**
92
+ * Run the event loop to handle mesh events.
93
+ */
94
+ private runEventLoop;
95
+ /**
96
+ * Handle dependency_available event.
97
+ */
98
+ private handleDependencyAvailable;
99
+ /**
100
+ * Handle dependency_unavailable event.
101
+ */
102
+ private handleDependencyUnavailable;
103
+ /**
104
+ * Install signal handlers for graceful shutdown.
105
+ */
106
+ private installSignalHandlers;
107
+ /**
108
+ * Get the service ID.
109
+ */
110
+ getServiceId(): string;
111
+ /**
112
+ * Get the resolved configuration.
113
+ */
114
+ getConfig(): ResolvedAgentConfig;
115
+ /**
116
+ * Get the underlying Express app.
117
+ */
118
+ getApp(): Application;
119
+ /**
120
+ * Get the HTTP server instance.
121
+ */
122
+ getServer(): Server | null;
123
+ /**
124
+ * Get the agent handle for advanced operations.
125
+ */
126
+ getHandle(): JsAgentHandle | null;
127
+ /**
128
+ * Shutdown the service gracefully.
129
+ */
130
+ shutdown(): Promise<void>;
131
+ }
132
+ /**
133
+ * Create a MeshExpress instance wrapping an Express app.
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const app = express();
138
+ * const meshApp = meshExpress(app, { name: "my-api", port: 3000 });
139
+ *
140
+ * // Define routes with mesh.route()...
141
+ *
142
+ * meshApp.start();
143
+ * ```
144
+ */
145
+ export declare function meshExpress(app: Application, config: MeshExpressConfig): MeshExpress;
146
+ //# sourceMappingURL=express.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,SAAS,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AA8BnE;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,qBAAa,WAAW;I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