@mozilla-ai/mcpd 0.0.4 → 0.1.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.
- package/README.md +35 -20
- package/dist/client.d.ts.map +1 -1
- package/dist/errors.d.ts +68 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LRUCache } from "lru-cache";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
const PIPELINE_FLOW_REQUEST = "request";
|
|
4
|
+
const PIPELINE_FLOW_RESPONSE = "response";
|
|
3
5
|
class McpdError extends Error {
|
|
4
6
|
constructor(message, cause) {
|
|
5
7
|
super(message);
|
|
@@ -86,6 +88,19 @@ class TimeoutError extends McpdError {
|
|
|
86
88
|
Error.captureStackTrace(this, this.constructor);
|
|
87
89
|
}
|
|
88
90
|
}
|
|
91
|
+
class PipelineError extends McpdError {
|
|
92
|
+
serverName;
|
|
93
|
+
operation;
|
|
94
|
+
pipelineFlow;
|
|
95
|
+
constructor(message, serverName, operation, pipelineFlow, cause) {
|
|
96
|
+
super(message, cause);
|
|
97
|
+
this.name = "PipelineError";
|
|
98
|
+
this.serverName = serverName;
|
|
99
|
+
this.operation = operation;
|
|
100
|
+
this.pipelineFlow = pipelineFlow;
|
|
101
|
+
Error.captureStackTrace(this, this.constructor);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
89
104
|
var HealthStatus = /* @__PURE__ */ ((HealthStatus2) => {
|
|
90
105
|
HealthStatus2["OK"] = "ok";
|
|
91
106
|
HealthStatus2["TIMEOUT"] = "timeout";
|
|
@@ -1042,6 +1057,11 @@ const REQUEST_TIMEOUT_SECONDS = 30;
|
|
|
1042
1057
|
const SERVER_HEALTH_CACHE_TTL_SECONDS = 10;
|
|
1043
1058
|
const SERVER_HEALTH_CACHE_MAXSIZE = 100;
|
|
1044
1059
|
const TOOL_SEPARATOR = "__";
|
|
1060
|
+
const MCPD_ERROR_TYPE_HEADER = "Mcpd-Error-Type";
|
|
1061
|
+
const PIPELINE_ERROR_FLOWS = {
|
|
1062
|
+
"request-pipeline-failure": PIPELINE_FLOW_REQUEST,
|
|
1063
|
+
"response-pipeline-failure": PIPELINE_FLOW_RESPONSE
|
|
1064
|
+
};
|
|
1045
1065
|
class McpdClient {
|
|
1046
1066
|
#endpoint;
|
|
1047
1067
|
#apiKey;
|
|
@@ -1128,6 +1148,21 @@ class McpdClient {
|
|
|
1128
1148
|
} catch {
|
|
1129
1149
|
errorModel = null;
|
|
1130
1150
|
}
|
|
1151
|
+
if (response.status === 500) {
|
|
1152
|
+
const errorType = response.headers.get(MCPD_ERROR_TYPE_HEADER)?.toLowerCase();
|
|
1153
|
+
const flow = errorType ? PIPELINE_ERROR_FLOWS[errorType] : void 0;
|
|
1154
|
+
if (flow) {
|
|
1155
|
+
const message = errorModel?.detail || body || "Pipeline failure";
|
|
1156
|
+
throw new PipelineError(
|
|
1157
|
+
message,
|
|
1158
|
+
void 0,
|
|
1159
|
+
// serverName - enriched by caller if available.
|
|
1160
|
+
void 0,
|
|
1161
|
+
// operation - enriched by caller if available.
|
|
1162
|
+
flow
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1131
1166
|
if (errorModel && errorModel.detail) {
|
|
1132
1167
|
const errorDetails = errorModel.errors?.map((e) => `${e.location}: ${e.message}`).join("; ");
|
|
1133
1168
|
const fullMessage = errorDetails ? `${errorModel.detail} - ${errorDetails}` : errorModel.detail;
|
|
@@ -1560,6 +1595,15 @@ class McpdClient {
|
|
|
1560
1595
|
}
|
|
1561
1596
|
return response;
|
|
1562
1597
|
} catch (error) {
|
|
1598
|
+
if (error instanceof PipelineError) {
|
|
1599
|
+
throw new PipelineError(
|
|
1600
|
+
error.message,
|
|
1601
|
+
serverName,
|
|
1602
|
+
`${serverName}.${toolName}`,
|
|
1603
|
+
error.pipelineFlow,
|
|
1604
|
+
error.cause
|
|
1605
|
+
);
|
|
1606
|
+
}
|
|
1563
1607
|
if (error instanceof McpdError) {
|
|
1564
1608
|
throw error;
|
|
1565
1609
|
}
|
|
@@ -1678,6 +1722,9 @@ export {
|
|
|
1678
1722
|
HealthStatusHelpers,
|
|
1679
1723
|
McpdClient,
|
|
1680
1724
|
McpdError,
|
|
1725
|
+
PIPELINE_FLOW_REQUEST,
|
|
1726
|
+
PIPELINE_FLOW_RESPONSE,
|
|
1727
|
+
PipelineError,
|
|
1681
1728
|
ServerNotFoundError,
|
|
1682
1729
|
ServerUnhealthyError,
|
|
1683
1730
|
TimeoutError,
|