@ogment-ai/cli 0.5.0 → 0.7.0

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 (111) hide show
  1. package/dist/cli.js +21382 -4
  2. package/dist/cli.js.map +1 -0
  3. package/package.json +46 -55
  4. package/README.md +0 -143
  5. package/dist/cli/commands.d.ts +0 -38
  6. package/dist/cli/commands.d.ts.map +0 -1
  7. package/dist/cli/commands.js +0 -57
  8. package/dist/cli/execute.d.ts +0 -11
  9. package/dist/cli/execute.d.ts.map +0 -1
  10. package/dist/cli/execute.js +0 -487
  11. package/dist/cli/invocations.d.ts +0 -32
  12. package/dist/cli/invocations.d.ts.map +0 -1
  13. package/dist/cli/invocations.js +0 -1
  14. package/dist/cli/parse-errors.d.ts +0 -17
  15. package/dist/cli/parse-errors.d.ts.map +0 -1
  16. package/dist/cli/parse-errors.js +0 -184
  17. package/dist/cli/program.d.ts +0 -10
  18. package/dist/cli/program.d.ts.map +0 -1
  19. package/dist/cli/program.js +0 -183
  20. package/dist/cli/run.d.ts +0 -6
  21. package/dist/cli/run.d.ts.map +0 -1
  22. package/dist/cli/run.js +0 -83
  23. package/dist/cli/runtime.d.ts +0 -22
  24. package/dist/cli/runtime.d.ts.map +0 -1
  25. package/dist/cli/runtime.js +0 -86
  26. package/dist/cli.d.ts +0 -4
  27. package/dist/cli.d.ts.map +0 -1
  28. package/dist/commands/auth.d.ts +0 -22
  29. package/dist/commands/auth.d.ts.map +0 -1
  30. package/dist/commands/auth.js +0 -29
  31. package/dist/commands/catalog.d.ts +0 -31
  32. package/dist/commands/catalog.d.ts.map +0 -1
  33. package/dist/commands/catalog.js +0 -167
  34. package/dist/commands/context.d.ts +0 -15
  35. package/dist/commands/context.d.ts.map +0 -1
  36. package/dist/commands/context.js +0 -1
  37. package/dist/commands/invoke.d.ts +0 -17
  38. package/dist/commands/invoke.d.ts.map +0 -1
  39. package/dist/commands/invoke.js +0 -173
  40. package/dist/commands/server-context.d.ts +0 -14
  41. package/dist/commands/server-context.d.ts.map +0 -1
  42. package/dist/commands/server-context.js +0 -26
  43. package/dist/commands/status.d.ts +0 -12
  44. package/dist/commands/status.d.ts.map +0 -1
  45. package/dist/commands/status.js +0 -5
  46. package/dist/index.d.ts +0 -4
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js +0 -3
  49. package/dist/infra/browser.d.ts +0 -12
  50. package/dist/infra/browser.d.ts.map +0 -1
  51. package/dist/infra/browser.js +0 -20
  52. package/dist/infra/credentials.d.ts +0 -22
  53. package/dist/infra/credentials.d.ts.map +0 -1
  54. package/dist/infra/credentials.js +0 -81
  55. package/dist/infra/env.d.ts +0 -15
  56. package/dist/infra/env.d.ts.map +0 -1
  57. package/dist/infra/env.js +0 -100
  58. package/dist/infra/http.d.ts +0 -16
  59. package/dist/infra/http.d.ts.map +0 -1
  60. package/dist/infra/http.js +0 -84
  61. package/dist/output/envelope.d.ts +0 -22
  62. package/dist/output/envelope.d.ts.map +0 -1
  63. package/dist/output/envelope.js +0 -67
  64. package/dist/output/manager.d.ts +0 -49
  65. package/dist/output/manager.d.ts.map +0 -1
  66. package/dist/output/manager.js +0 -128
  67. package/dist/services/account.d.ts +0 -16
  68. package/dist/services/account.d.ts.map +0 -1
  69. package/dist/services/account.js +0 -75
  70. package/dist/services/auth.d.ts +0 -49
  71. package/dist/services/auth.d.ts.map +0 -1
  72. package/dist/services/auth.js +0 -739
  73. package/dist/services/info.d.ts +0 -24
  74. package/dist/services/info.d.ts.map +0 -1
  75. package/dist/services/info.js +0 -316
  76. package/dist/services/mcp-error-mapping.d.ts +0 -9
  77. package/dist/services/mcp-error-mapping.d.ts.map +0 -1
  78. package/dist/services/mcp-error-mapping.js +0 -129
  79. package/dist/services/mcp.d.ts +0 -39
  80. package/dist/services/mcp.d.ts.map +0 -1
  81. package/dist/services/mcp.js +0 -169
  82. package/dist/shared/constants.d.ts +0 -7
  83. package/dist/shared/constants.d.ts.map +0 -1
  84. package/dist/shared/constants.js +0 -8
  85. package/dist/shared/error-codes.d.ts +0 -31
  86. package/dist/shared/error-codes.d.ts.map +0 -1
  87. package/dist/shared/error-codes.js +0 -25
  88. package/dist/shared/error-presentation.d.ts +0 -17
  89. package/dist/shared/error-presentation.d.ts.map +0 -1
  90. package/dist/shared/error-presentation.js +0 -151
  91. package/dist/shared/errors.d.ts +0 -146
  92. package/dist/shared/errors.d.ts.map +0 -1
  93. package/dist/shared/errors.js +0 -233
  94. package/dist/shared/exit-codes.d.ts +0 -15
  95. package/dist/shared/exit-codes.d.ts.map +0 -1
  96. package/dist/shared/exit-codes.js +0 -44
  97. package/dist/shared/guards.d.ts +0 -11
  98. package/dist/shared/guards.d.ts.map +0 -1
  99. package/dist/shared/guards.js +0 -29
  100. package/dist/shared/recovery.d.ts +0 -5
  101. package/dist/shared/recovery.d.ts.map +0 -1
  102. package/dist/shared/recovery.js +0 -123
  103. package/dist/shared/schema-example.d.ts +0 -3
  104. package/dist/shared/schema-example.d.ts.map +0 -1
  105. package/dist/shared/schema-example.js +0 -105
  106. package/dist/shared/schemas.d.ts +0 -15
  107. package/dist/shared/schemas.d.ts.map +0 -1
  108. package/dist/shared/schemas.js +0 -15
  109. package/dist/shared/types.d.ts +0 -225
  110. package/dist/shared/types.d.ts.map +0 -1
  111. package/dist/shared/types.js +0 -1
@@ -1,24 +0,0 @@
1
- import type { CredentialsStore } from "../infra/credentials.js";
2
- import type { HttpClient } from "../infra/http.js";
3
- import type { AccountService } from "./account.js";
4
- import type { BaseUrlSource, InfoPayload } from "../shared/types.js";
5
- export interface InfoService {
6
- collect(apiKeyOverride?: string): Promise<InfoPayload>;
7
- }
8
- interface InfoServiceDeps {
9
- accountService: AccountService;
10
- baseUrl: string;
11
- baseUrlSource: BaseUrlSource;
12
- configDir: string;
13
- credentialsPath: string;
14
- credentialsStore: CredentialsStore;
15
- detectExecutionEnvironmentFn?: () => string;
16
- envApiKey: string | undefined;
17
- existsSyncFn?: (path: string) => boolean;
18
- httpClient: HttpClient;
19
- now?: () => number;
20
- version: string;
21
- }
22
- export declare const createInfoService: (deps: InfoServiceDeps) => InfoService;
23
- export {};
24
- //# sourceMappingURL=info.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../src/services/info.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EACV,aAAa,EAGb,WAAW,EAEZ,MAAM,oBAAoB,CAAC;AAsB5B,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACxD;AAED,UAAU,eAAe;IACvB,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,4BAA4B,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5C,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACzC,UAAU,EAAE,UAAU,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAmGD,eAAO,MAAM,iBAAiB,GAAI,MAAM,eAAe,KAAG,WAwQzD,CAAC"}
@@ -1,316 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { existsSync } from "node:fs";
3
- import { Result } from "better-result";
4
- import { detectExecutionEnvironment } from "../infra/env.js";
5
- const maskApiKey = (apiKey) => {
6
- if (apiKey.length <= 8) {
7
- return `*** (sha256:${createHash("sha256").update(apiKey).digest("hex").slice(0, 12)})`;
8
- }
9
- const start = apiKey.slice(0, 4);
10
- const end = apiKey.slice(-4);
11
- const fingerprint = createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
12
- return `${start}...${end} (sha256:${fingerprint})`;
13
- };
14
- const resolveApiKey = (apiKeyOverride, envApiKey, credentialsStore) => {
15
- if (typeof apiKeyOverride === "string" && apiKeyOverride.length > 0) {
16
- return {
17
- loadError: null,
18
- source: "apiKeyOption",
19
- value: apiKeyOverride,
20
- };
21
- }
22
- if (typeof envApiKey === "string" && envApiKey.length > 0) {
23
- return {
24
- loadError: null,
25
- source: "env",
26
- value: envApiKey,
27
- };
28
- }
29
- const storedCredentials = credentialsStore.load();
30
- if (Result.isError(storedCredentials)) {
31
- return {
32
- loadError: storedCredentials.error.message,
33
- source: "credentialsError",
34
- value: null,
35
- };
36
- }
37
- if (storedCredentials.value !== null) {
38
- return {
39
- loadError: null,
40
- source: "credentialsFile",
41
- value: storedCredentials.value.apiKey,
42
- };
43
- }
44
- return {
45
- loadError: null,
46
- source: "none",
47
- value: null,
48
- };
49
- };
50
- const nextActionByIssueCode = {
51
- auth_failed: "Run `ogment auth login` to refresh credentials.",
52
- credentials_load_failed: "Check file permissions and contents of `~/.config/ogment/credentials.json`.",
53
- no_api_key: "Run `ogment auth login` or set `OGMENT_API_KEY`.",
54
- unreachable: "Verify `OGMENT_BASE_URL` and network connectivity.",
55
- };
56
- const toSummary = (issues) => {
57
- const nextActions = new Set();
58
- for (const issue of issues) {
59
- const nextAction = nextActionByIssueCode[issue.code];
60
- if (nextAction !== undefined) {
61
- nextActions.add(nextAction);
62
- }
63
- }
64
- nextActions.add("Run `ogment catalog` to inspect available servers.");
65
- return {
66
- issues: issues.map((issue) => issue.message),
67
- nextActions: [...nextActions],
68
- status: issues.length > 0 ? "warning" : "ok",
69
- };
70
- };
71
- const emptyAccountErrorDetails = () => {
72
- return {
73
- errorCode: null,
74
- errorHttpStatus: null,
75
- errorMcpCode: null,
76
- errorRaw: null,
77
- errorRetryable: null,
78
- errorSource: null,
79
- };
80
- };
81
- export const createInfoService = (deps) => {
82
- const detectEnvironment = deps.detectExecutionEnvironmentFn ?? detectExecutionEnvironment;
83
- const existsSyncFn = deps.existsSyncFn ?? existsSync;
84
- const now = deps.now ?? Date.now;
85
- return {
86
- collect: async (apiKeyOverride) => {
87
- const apiKeyResolution = resolveApiKey(apiKeyOverride, deps.envApiKey, deps.credentialsStore);
88
- const selectedApiKey = apiKeyResolution.value;
89
- const credentialsFileExists = existsSyncFn(deps.credentialsPath);
90
- const endpoint = `${deps.baseUrl}/api/v1/mcp-auth/me`;
91
- const pingHeaders = typeof selectedApiKey === "string"
92
- ? {
93
- Authorization: `Bearer ${selectedApiKey}`,
94
- }
95
- : undefined;
96
- const pingStartedAt = now();
97
- const pingResult = await deps.httpClient.request(endpoint, pingHeaders === undefined ? undefined : { headers: pingHeaders });
98
- const pingElapsedMs = now() - pingStartedAt;
99
- const ping = pingResult.status === "ok"
100
- ? {
101
- endpoint,
102
- error: null,
103
- latencyMs: pingElapsedMs,
104
- reachable: true,
105
- status: pingResult.value.status,
106
- statusText: pingResult.value.statusText,
107
- }
108
- : {
109
- endpoint,
110
- error: pingResult.error.message,
111
- latencyMs: null,
112
- reachable: false,
113
- status: null,
114
- statusText: null,
115
- };
116
- const collectAccount = async () => {
117
- if (selectedApiKey === null) {
118
- return {
119
- ...emptyAccountErrorDetails(),
120
- errorType: null,
121
- latencyMs: null,
122
- message: "No API key available",
123
- orgCount: null,
124
- serverCount: null,
125
- serverPaths: [],
126
- status: "skipped",
127
- };
128
- }
129
- const accountStartedAt = now();
130
- const accountResult = await deps.accountService.fetchAccount(selectedApiKey);
131
- const accountElapsedMs = now() - accountStartedAt;
132
- if (accountResult.status === "ok") {
133
- const servers = accountResult.value.orgs.flatMap((organization) => {
134
- return organization.servers.map((server) => server.path);
135
- });
136
- return {
137
- ...emptyAccountErrorDetails(),
138
- errorType: null,
139
- latencyMs: accountElapsedMs,
140
- message: null,
141
- orgCount: accountResult.value.orgs.length,
142
- serverCount: servers.length,
143
- serverPaths: servers.slice(0, 5),
144
- status: "success",
145
- };
146
- }
147
- let normalizedStatus = "unexpected_error";
148
- switch (accountResult.error._tag) {
149
- case "AuthError": {
150
- normalizedStatus = "auth_error";
151
- break;
152
- }
153
- case "RemoteRequestError": {
154
- normalizedStatus = "remote_error";
155
- break;
156
- }
157
- case "ValidationError": {
158
- normalizedStatus = "validation_error";
159
- break;
160
- }
161
- default: {
162
- normalizedStatus = "unexpected_error";
163
- break;
164
- }
165
- }
166
- return {
167
- ...("code" in accountResult.error
168
- ? {
169
- errorCode: String(accountResult.error.code),
170
- }
171
- : {
172
- errorCode: null,
173
- }),
174
- ...("httpStatus" in accountResult.error
175
- ? {
176
- errorHttpStatus: typeof accountResult.error.httpStatus === "number"
177
- ? accountResult.error.httpStatus
178
- : null,
179
- }
180
- : {
181
- errorHttpStatus: null,
182
- }),
183
- ...("mcpCode" in accountResult.error
184
- ? {
185
- errorMcpCode: typeof accountResult.error.mcpCode === "number"
186
- ? accountResult.error.mcpCode
187
- : null,
188
- }
189
- : {
190
- errorMcpCode: null,
191
- }),
192
- ...("raw" in accountResult.error
193
- ? {
194
- errorRaw: accountResult.error.raw ?? null,
195
- }
196
- : {
197
- errorRaw: null,
198
- }),
199
- ...("retryable" in accountResult.error
200
- ? {
201
- errorRetryable: typeof accountResult.error.retryable === "boolean"
202
- ? accountResult.error.retryable
203
- : null,
204
- }
205
- : {
206
- errorRetryable: null,
207
- }),
208
- ...("source" in accountResult.error
209
- ? {
210
- errorSource: typeof accountResult.error.source === "string"
211
- ? accountResult.error.source
212
- : null,
213
- }
214
- : {
215
- errorSource: null,
216
- }),
217
- errorType: accountResult.error._tag,
218
- latencyMs: accountElapsedMs,
219
- message: accountResult.error.message,
220
- orgCount: null,
221
- serverCount: null,
222
- serverPaths: [],
223
- status: normalizedStatus,
224
- };
225
- };
226
- const account = await collectAccount();
227
- const issues = [];
228
- if (!ping.reachable) {
229
- issues.push({
230
- code: "unreachable",
231
- message: `Could not reach ${deps.baseUrl}: ${ping.error ?? "unknown error"}`,
232
- });
233
- }
234
- if (apiKeyResolution.source === "none") {
235
- issues.push({
236
- code: "no_api_key",
237
- message: "No API key found in --api-key, OGMENT_API_KEY, or credentials file.",
238
- });
239
- }
240
- if (apiKeyResolution.source === "credentialsError" && apiKeyResolution.loadError !== null) {
241
- issues.push({
242
- code: "credentials_load_failed",
243
- message: `Failed to load credentials file: ${apiKeyResolution.loadError}`,
244
- });
245
- }
246
- if (account.status === "auth_error") {
247
- issues.push({
248
- code: "auth_failed",
249
- message: `Authentication failed: ${account.message ?? "unknown auth error"}`,
250
- });
251
- }
252
- if (account.status === "remote_error") {
253
- issues.push({
254
- code: "remote_request_failed",
255
- message: `Remote request failed: ${account.message ?? "unknown remote error"}`,
256
- });
257
- }
258
- if (account.status === "validation_error") {
259
- issues.push({
260
- code: "response_validation_failed",
261
- message: `Response validation failed: ${account.message ?? "unknown validation error"}`,
262
- });
263
- }
264
- if (account.status === "unexpected_error") {
265
- issues.push({
266
- code: "unexpected_diagnostic_error",
267
- message: `Unexpected diagnostic error: ${account.message ?? "unknown error"}`,
268
- });
269
- }
270
- return {
271
- auth: {
272
- apiKeyPresent: selectedApiKey !== null,
273
- apiKeyPreview: selectedApiKey === null ? null : maskApiKey(selectedApiKey),
274
- apiKeySource: apiKeyResolution.source,
275
- credentialsFileExists,
276
- credentialsFileLoadError: apiKeyResolution.loadError,
277
- },
278
- config: {
279
- baseUrl: deps.baseUrl,
280
- baseUrlSource: deps.baseUrlSource,
281
- configDir: deps.configDir,
282
- credentialsPath: deps.credentialsPath,
283
- },
284
- documentation: {
285
- configPrecedence: [
286
- "--api-key option",
287
- "OGMENT_API_KEY environment variable",
288
- "~/.config/ogment/credentials.json",
289
- "default base URL when OGMENT_BASE_URL is unset",
290
- ],
291
- quickCommands: [
292
- "ogment status",
293
- "ogment auth login",
294
- "ogment catalog",
295
- "ogment catalog <server-id>",
296
- "ogment catalog <server-id> <tool-name>",
297
- "ogment invoke <server-id>/<tool-name> --input '{}'",
298
- ],
299
- },
300
- generatedAt: new Date(now()).toISOString(),
301
- remote: {
302
- account,
303
- ping,
304
- },
305
- runtime: {
306
- cliVersion: deps.version,
307
- executionEnvironment: detectEnvironment(),
308
- nodeVersion: process.version,
309
- platform: process.platform,
310
- processArch: process.arch,
311
- },
312
- summary: toSummary(issues),
313
- };
314
- },
315
- };
316
- };
@@ -1,9 +0,0 @@
1
- import { RemoteRequestError } from "../shared/errors.js";
2
- interface CreateRemoteRequestErrorOptions {
3
- cause: unknown;
4
- message: string;
5
- operation: string;
6
- }
7
- export declare const createRemoteRequestErrorFromMcpCause: (options: CreateRemoteRequestErrorOptions) => RemoteRequestError;
8
- export {};
9
- //# sourceMappingURL=mcp-error-mapping.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-error-mapping.d.ts","sourceRoot":"","sources":["../../src/services/mcp-error-mapping.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAazD,UAAU,+BAA+B;IACvC,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AA0ID,eAAO,MAAM,oCAAoC,GAC/C,SAAS,+BAA+B,KACvC,kBAaF,CAAC"}
@@ -1,129 +0,0 @@
1
- import { StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
2
- import { McpError, isJSONRPCErrorResponse } from "@modelcontextprotocol/sdk/types.js";
3
- import { RemoteRequestError } from "../shared/errors.js";
4
- const toSerializable = (value) => {
5
- if (value instanceof Error) {
6
- return {
7
- message: value.message,
8
- name: value.name,
9
- stack: value.stack,
10
- };
11
- }
12
- try {
13
- return structuredClone(value);
14
- }
15
- catch {
16
- return String(value);
17
- }
18
- };
19
- const toJsonRpcErrorPayload = (payload) => {
20
- if (isJSONRPCErrorResponse(payload)) {
21
- return {
22
- code: payload.error.code,
23
- data: payload.error.data,
24
- raw: toSerializable(payload),
25
- };
26
- }
27
- if (typeof payload !== "object" || payload === null || !Object.hasOwn(payload, "error")) {
28
- return null;
29
- }
30
- const errorRecord = payload.error;
31
- if (typeof errorRecord !== "object" || errorRecord === null) {
32
- return null;
33
- }
34
- const asRecord = errorRecord;
35
- const code = asRecord["code"];
36
- if (typeof code !== "number") {
37
- return null;
38
- }
39
- return {
40
- code,
41
- data: asRecord["data"],
42
- raw: toSerializable(payload),
43
- };
44
- };
45
- const extractStreamableBody = (message) => {
46
- const marker = "Error POSTing to endpoint:";
47
- const markerIndex = message.indexOf(marker);
48
- if (markerIndex === -1) {
49
- return undefined;
50
- }
51
- const body = message.slice(markerIndex + marker.length).trim();
52
- return body.length > 0 ? body : undefined;
53
- };
54
- const mapStreamableHttpError = (error) => {
55
- const body = extractStreamableBody(error.message);
56
- const parsedBody = body === undefined
57
- ? null
58
- : (() => {
59
- try {
60
- return JSON.parse(body);
61
- }
62
- catch {
63
- return null;
64
- }
65
- })();
66
- const jsonRpcPayload = parsedBody === null ? null : toJsonRpcErrorPayload(parsedBody);
67
- const httpStatus = typeof error.code === "number" && error.code >= 100 ? error.code : undefined;
68
- const retryable = httpStatus === undefined
69
- ? undefined
70
- : httpStatus === 429 || httpStatus >= 500 || httpStatus === 408;
71
- return {
72
- ...(body === undefined ? {} : { body }),
73
- ...(httpStatus === undefined ? {} : { httpStatus }),
74
- ...(jsonRpcPayload === null ? {} : { mcpCode: jsonRpcPayload.code }),
75
- ...(jsonRpcPayload === null ? {} : { mcpData: jsonRpcPayload.data }),
76
- raw: jsonRpcPayload?.raw ?? toSerializable(parsedBody ?? error),
77
- ...(retryable === undefined ? {} : { retryable }),
78
- source: "mcp_transport_http",
79
- };
80
- };
81
- const mapMcpError = (error) => {
82
- return {
83
- mcpCode: error.code,
84
- mcpData: toSerializable(error.data),
85
- raw: toSerializable({
86
- code: error.code,
87
- data: error.data,
88
- message: error.message,
89
- name: error.name,
90
- }),
91
- retryable: error.code === -32_001,
92
- source: "mcp_jsonrpc",
93
- };
94
- };
95
- const mapUnknownError = (cause) => {
96
- if (cause instanceof Error) {
97
- return {
98
- raw: toSerializable(cause),
99
- source: "network",
100
- };
101
- }
102
- return {
103
- raw: toSerializable(cause),
104
- source: "unknown",
105
- };
106
- };
107
- const mapCause = (cause) => {
108
- if (cause instanceof StreamableHTTPError) {
109
- return mapStreamableHttpError(cause);
110
- }
111
- if (cause instanceof McpError) {
112
- return mapMcpError(cause);
113
- }
114
- return mapUnknownError(cause);
115
- };
116
- export const createRemoteRequestErrorFromMcpCause = (options) => {
117
- const mapped = mapCause(options.cause);
118
- return new RemoteRequestError({
119
- ...(mapped.body === undefined ? {} : { body: mapped.body }),
120
- ...(mapped.httpStatus === undefined ? {} : { httpStatus: mapped.httpStatus }),
121
- ...(mapped.mcpCode === undefined ? {} : { mcpCode: mapped.mcpCode }),
122
- ...(mapped.mcpData === undefined ? {} : { mcpData: mapped.mcpData }),
123
- message: options.message,
124
- operation: options.operation,
125
- raw: mapped.raw,
126
- ...(mapped.retryable === undefined ? {} : { retryable: mapped.retryable }),
127
- source: mapped.source,
128
- });
129
- };
@@ -1,39 +0,0 @@
1
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
2
- import type { Result as ResultType } from "better-result";
3
- import { RemoteRequestError, type ValidationError } from "../shared/errors.js";
4
- import type { McpToolSummary, ToolCallResult } from "../shared/types.js";
5
- interface McpTarget {
6
- orgSlug: string;
7
- serverPath: string;
8
- }
9
- interface McpClientLike {
10
- callTool(params: {
11
- arguments: Record<string, unknown>;
12
- name: string;
13
- }, resultSchema?: unknown, options?: {
14
- timeout?: number;
15
- }): Promise<unknown>;
16
- close(): Promise<void>;
17
- connect(transport: unknown, options?: {
18
- timeout?: number;
19
- }): Promise<void>;
20
- listTools(params?: unknown, options?: {
21
- timeout?: number;
22
- }): Promise<{
23
- tools: Array<Record<string, unknown>>;
24
- }>;
25
- }
26
- interface McpServiceDeps {
27
- baseUrl: string;
28
- createClient?: () => McpClientLike;
29
- createTransport?: (url: URL, apiKey: string) => StreamableHTTPClientTransport;
30
- version: string;
31
- }
32
- export type McpServiceError = RemoteRequestError | ValidationError;
33
- export interface McpService {
34
- callTool(target: McpTarget, apiKey: string, toolName: string, args: Record<string, unknown>): Promise<ResultType<ToolCallResult, McpServiceError>>;
35
- listTools(target: McpTarget, apiKey: string): Promise<ResultType<McpToolSummary[], McpServiceError>>;
36
- }
37
- export declare const createMcpService: (deps: McpServiceDeps) => McpService;
38
- export {};
39
- //# sourceMappingURL=mcp.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/services/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAI1D,OAAO,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG/E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAMzE,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,aAAa;IACrB,QAAQ,CACN,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAC5D,YAAY,CAAC,EAAE,OAAO,EACtB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC7B,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,SAAS,CACP,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC7B,OAAO,CAAC;QACT,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACvC,CAAC,CAAC;CACJ;AAED,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,aAAa,CAAC;IACnC,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,KAAK,6BAA6B,CAAC;IAC9E,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,eAAe,GAAG,kBAAkB,GAAG,eAAe,CAAC;AAEnE,MAAM,WAAW,UAAU;IACzB,QAAQ,CACN,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,UAAU,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;IACxD,SAAS,CACP,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,cAAc,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC;CAC3D;AAkFD,eAAO,MAAM,gBAAgB,GAAI,MAAM,cAAc,KAAG,UAkIvD,CAAC"}