@frontmcp/sdk 0.3.0 → 0.4.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.
- package/LICENSE +201 -0
- package/README.md +192 -164
- package/package.json +7 -4
- package/src/__test-utils__/fixtures/hook.fixtures.d.ts +46 -0
- package/src/__test-utils__/fixtures/hook.fixtures.js +114 -0
- package/src/__test-utils__/fixtures/hook.fixtures.js.map +1 -0
- package/src/__test-utils__/fixtures/index.d.ts +7 -0
- package/src/__test-utils__/fixtures/index.js +11 -0
- package/src/__test-utils__/fixtures/index.js.map +1 -0
- package/src/__test-utils__/fixtures/plugin.fixtures.d.ts +46 -0
- package/src/__test-utils__/fixtures/plugin.fixtures.js +127 -0
- package/src/__test-utils__/fixtures/plugin.fixtures.js.map +1 -0
- package/src/__test-utils__/fixtures/provider.fixtures.d.ts +69 -0
- package/src/__test-utils__/fixtures/provider.fixtures.js +131 -0
- package/src/__test-utils__/fixtures/provider.fixtures.js.map +1 -0
- package/src/__test-utils__/fixtures/scope.fixtures.d.ts +14 -0
- package/src/__test-utils__/fixtures/scope.fixtures.js +59 -0
- package/src/__test-utils__/fixtures/scope.fixtures.js.map +1 -0
- package/src/__test-utils__/fixtures/tool.fixtures.d.ts +36 -0
- package/src/__test-utils__/fixtures/tool.fixtures.js +91 -0
- package/src/__test-utils__/fixtures/tool.fixtures.js.map +1 -0
- package/src/__test-utils__/helpers/assertion.helpers.d.ts +45 -0
- package/src/__test-utils__/helpers/assertion.helpers.js +153 -0
- package/src/__test-utils__/helpers/assertion.helpers.js.map +1 -0
- package/src/__test-utils__/helpers/async.helpers.d.ts +48 -0
- package/src/__test-utils__/helpers/async.helpers.js +112 -0
- package/src/__test-utils__/helpers/async.helpers.js.map +1 -0
- package/src/__test-utils__/helpers/index.d.ts +6 -0
- package/src/__test-utils__/helpers/index.js +10 -0
- package/src/__test-utils__/helpers/index.js.map +1 -0
- package/src/__test-utils__/helpers/setup.helpers.d.ts +54 -0
- package/src/__test-utils__/helpers/setup.helpers.js +106 -0
- package/src/__test-utils__/helpers/setup.helpers.js.map +1 -0
- package/src/__test-utils__/index.d.ts +9 -0
- package/src/__test-utils__/index.js +14 -0
- package/src/__test-utils__/index.js.map +1 -0
- package/src/__test-utils__/mocks/flow-instance.mock.d.ts +50 -0
- package/src/__test-utils__/mocks/flow-instance.mock.js +72 -0
- package/src/__test-utils__/mocks/flow-instance.mock.js.map +1 -0
- package/src/__test-utils__/mocks/hook-registry.mock.d.ts +25 -0
- package/src/__test-utils__/mocks/hook-registry.mock.js +65 -0
- package/src/__test-utils__/mocks/hook-registry.mock.js.map +1 -0
- package/src/__test-utils__/mocks/index.d.ts +8 -0
- package/src/__test-utils__/mocks/index.js +12 -0
- package/src/__test-utils__/mocks/index.js.map +1 -0
- package/src/__test-utils__/mocks/plugin-registry.mock.d.ts +43 -0
- package/src/__test-utils__/mocks/plugin-registry.mock.js +70 -0
- package/src/__test-utils__/mocks/plugin-registry.mock.js.map +1 -0
- package/src/__test-utils__/mocks/provider-registry.mock.d.ts +39 -0
- package/src/__test-utils__/mocks/provider-registry.mock.js +72 -0
- package/src/__test-utils__/mocks/provider-registry.mock.js.map +1 -0
- package/src/__test-utils__/mocks/tool-registry.mock.d.ts +43 -0
- package/src/__test-utils__/mocks/tool-registry.mock.js +79 -0
- package/src/__test-utils__/mocks/tool-registry.mock.js.map +1 -0
- package/src/app/app.utils.js.map +1 -1
- package/src/app/instances/app.local.instance.js +8 -11
- package/src/app/instances/app.local.instance.js.map +1 -1
- package/src/auth/auth.registry.d.ts +2 -2
- package/src/auth/auth.registry.js +3 -3
- package/src/auth/auth.registry.js.map +1 -1
- package/src/auth/flows/oauth.authorize.flow.d.ts +8 -8
- package/src/auth/flows/oauth.register.flow.d.ts +4 -4
- package/src/auth/flows/oauth.token.flow.d.ts +4 -4
- package/src/auth/flows/well-known.jwks.flow.d.ts +12 -12
- package/src/auth/flows/well-known.oauth-authorization-server.flow.d.ts +8 -8
- package/src/auth/flows/well-known.prm.flow.d.ts +4 -4
- package/src/auth/instances/instance.local-primary-auth.d.ts +3 -2
- package/src/auth/instances/instance.local-primary-auth.js +4 -2
- package/src/auth/instances/instance.local-primary-auth.js.map +1 -1
- package/src/auth/instances/instance.remote-primary-auth.d.ts +3 -2
- package/src/auth/instances/instance.remote-primary-auth.js +3 -1
- package/src/auth/instances/instance.remote-primary-auth.js.map +1 -1
- package/src/auth/jwks/jwks.service.js +0 -1
- package/src/auth/jwks/jwks.service.js.map +1 -1
- package/src/common/decorators/tool.decorator.d.ts +97 -36
- package/src/common/decorators/tool.decorator.js +0 -1
- package/src/common/decorators/tool.decorator.js.map +1 -1
- package/src/common/entries/scope.entry.d.ts +1 -0
- package/src/common/entries/scope.entry.js +6 -0
- package/src/common/entries/scope.entry.js.map +1 -1
- package/src/common/entries/tool.entry.d.ts +54 -11
- package/src/common/entries/tool.entry.js +19 -0
- package/src/common/entries/tool.entry.js.map +1 -1
- package/src/common/interfaces/internal/registry.interface.d.ts +10 -2
- package/src/common/interfaces/internal/registry.interface.js.map +1 -1
- package/src/common/interfaces/plugin.interface.d.ts +1 -1
- package/src/common/interfaces/plugin.interface.js.map +1 -1
- package/src/common/interfaces/tool.interface.d.ts +12 -7
- package/src/common/interfaces/tool.interface.js +1 -1
- package/src/common/interfaces/tool.interface.js.map +1 -1
- package/src/common/metadata/front-mcp.metadata.d.ts +145 -145
- package/src/common/metadata/hook.metadata.d.ts +4 -2
- package/src/common/metadata/hook.metadata.js.map +1 -1
- package/src/common/metadata/prompt.metadata.d.ts +28 -28
- package/src/common/metadata/prompt.metadata.js.map +1 -1
- package/src/common/metadata/resource.metadata.d.ts +54 -54
- package/src/common/metadata/tool.metadata.d.ts +190 -7
- package/src/common/metadata/tool.metadata.js +41 -6
- package/src/common/metadata/tool.metadata.js.map +1 -1
- package/src/common/records/scope.record.d.ts +2 -2
- package/src/common/records/scope.record.js.map +1 -1
- package/src/common/schemas/http-output.schema.d.ts +106 -106
- package/src/common/tokens/tool.tokens.js.map +1 -1
- package/src/common/types/options/logging.options.d.ts +1 -2
- package/src/common/types/options/logging.options.js +1 -9
- package/src/common/types/options/logging.options.js.map +1 -1
- package/src/common/types/options/server-info.options.d.ts +19 -19
- package/src/errors/error-handler.d.ts +65 -0
- package/src/errors/error-handler.js +107 -0
- package/src/errors/error-handler.js.map +1 -0
- package/src/errors/index.d.ts +2 -0
- package/src/errors/index.js +26 -0
- package/src/errors/index.js.map +1 -0
- package/src/errors/mcp.error.d.ts +156 -0
- package/src/errors/mcp.error.js +243 -0
- package/src/errors/mcp.error.js.map +1 -0
- package/src/flows/flow.instance.js +7 -6
- package/src/flows/flow.instance.js.map +1 -1
- package/src/flows/flow.registry.js +1 -1
- package/src/flows/flow.registry.js.map +1 -1
- package/src/front-mcp/front-mcp.providers.d.ts +20 -20
- package/src/hooks/hook.registry.d.ts +5 -3
- package/src/hooks/hook.registry.js +13 -1
- package/src/hooks/hook.registry.js.map +1 -1
- package/src/plugin/plugin.registry.d.ts +7 -2
- package/src/plugin/plugin.registry.js +23 -11
- package/src/plugin/plugin.registry.js.map +1 -1
- package/src/prompt/prompt.registry.js +1 -0
- package/src/prompt/prompt.registry.js.map +1 -1
- package/src/resource/resource.registry.js +1 -0
- package/src/resource/resource.registry.js.map +1 -1
- package/src/scope/scope.instance.js +8 -2
- package/src/scope/scope.instance.js.map +1 -1
- package/src/scope/scope.registry.js +3 -2
- package/src/scope/scope.registry.js.map +1 -1
- package/src/scope/scope.utils.js +6 -4
- package/src/scope/scope.utils.js.map +1 -1
- package/src/store/adapters/store.memory.adapter.js +3 -1
- package/src/store/adapters/store.memory.adapter.js.map +1 -1
- package/src/tool/flows/call-tool.flow.d.ts +1012 -676
- package/src/tool/flows/call-tool.flow.js +94 -61
- package/src/tool/flows/call-tool.flow.js.map +1 -1
- package/src/tool/flows/tools-list.flow.d.ts +347 -590
- package/src/tool/flows/tools-list.flow.js +76 -49
- package/src/tool/flows/tools-list.flow.js.map +1 -1
- package/src/tool/tool.instance.d.ts +27 -8
- package/src/tool/tool.instance.js +40 -5
- package/src/tool/tool.instance.js.map +1 -1
- package/src/tool/tool.registry.js +19 -21
- package/src/tool/tool.registry.js.map +1 -1
- package/src/tool/tool.utils.d.ts +3 -2
- package/src/tool/tool.utils.js +377 -14
- package/src/tool/tool.utils.js.map +1 -1
- package/src/transport/adapters/transport.sse.adapter.js +2 -1
- package/src/transport/adapters/transport.sse.adapter.js.map +1 -1
- package/src/transport/adapters/transport.streamable-http.adapter.js.map +1 -1
- package/src/transport/flows/handle.sse.flow.js +6 -13
- package/src/transport/flows/handle.sse.flow.js.map +1 -1
- package/src/transport/flows/handle.streamable-http.flow.js +1 -0
- package/src/transport/flows/handle.streamable-http.flow.js.map +1 -1
- package/src/transport/mcp-handlers/call-tool-request.handler.d.ts +1 -1
- package/src/transport/mcp-handlers/call-tool-request.handler.js +10 -5
- package/src/transport/mcp-handlers/call-tool-request.handler.js.map +1 -1
- package/src/transport/mcp-handlers/index.d.ts +151 -268
- package/src/transport/mcp-handlers/list-tools-request.handler.d.ts +124 -216
- package/src/transport/transport.local.js +1 -0
- package/src/transport/transport.local.js.map +1 -1
- package/src/utils/string.utils.js +1 -1
- package/src/utils/string.utils.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.tokens.js","sourceRoot":"","sources":["../../../../src/common/tokens/tool.tokens.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAIhC,QAAA,kBAAkB,GAAG;IAChC,IAAI,EAAE,0BAAY,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/B,EAAE,EAAE,0BAAY,CAAC,IAAI,CAAC,IAAI,CAAC;IAC3B,IAAI,EAAE,0BAAY,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/B,WAAW,EAAE,0BAAY,CAAC,IAAI,CAAC,aAAa,CAAC;IAC7C,WAAW,EAAE,0BAAY,CAAC,IAAI,CAAC,aAAa,CAAC;IAC7C,cAAc,EAAE,0BAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC;IACnD,YAAY,EAAE,0BAAY,CAAC,IAAI,CAAC,cAAc,CAAC;IAC/C,IAAI,EAAE,0BAAY,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/B,WAAW,EAAE,0BAAY,CAAC,IAAI,CAAC,aAAa,CAAC;IAC7C,iBAAiB,EAAE,0BAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC;IACzD,QAAQ,EAAE,0BAAY,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,gCAAgC;CACI,CAAC;AAEnE,QAAA,oBAAoB,GAAG,0BAAY,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC","sourcesContent":["import { tokenFactory } from './base.tokens';\nimport { RawMetadataShape } from '../types';\nimport { ToolMetadata } from '../metadata';\n\nexport const FrontMcpToolTokens = {\n type: tokenFactory.type('tool'),\n id: tokenFactory.meta('id'),\n name: tokenFactory.meta('name'),\n description: tokenFactory.meta('description'),\n inputSchema: tokenFactory.meta('inputSchema'),\n rawInputSchema: tokenFactory.meta('rawInputSchema'),\n outputSchema: tokenFactory.meta('outputSchema'),\n tags: tokenFactory.meta('tags'),\n annotations: tokenFactory.meta('annotations'),\n hideFromDiscovery: tokenFactory.meta('hideFromDiscovery'),\n metadata: tokenFactory.meta('metadata'), // used in tool({}) construction\n} as const satisfies RawMetadataShape<ToolMetadata, ExtendFrontMcpToolMetadata>;\n\nexport const extendedToolMetadata = tokenFactory.meta('extendedToolMetadata')
|
|
1
|
+
{"version":3,"file":"tool.tokens.js","sourceRoot":"","sources":["../../../../src/common/tokens/tool.tokens.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAIhC,QAAA,kBAAkB,GAAG;IAChC,IAAI,EAAE,0BAAY,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/B,EAAE,EAAE,0BAAY,CAAC,IAAI,CAAC,IAAI,CAAC;IAC3B,IAAI,EAAE,0BAAY,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/B,WAAW,EAAE,0BAAY,CAAC,IAAI,CAAC,aAAa,CAAC;IAC7C,WAAW,EAAE,0BAAY,CAAC,IAAI,CAAC,aAAa,CAAC;IAC7C,cAAc,EAAE,0BAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC;IACnD,YAAY,EAAE,0BAAY,CAAC,IAAI,CAAC,cAAc,CAAC;IAC/C,IAAI,EAAE,0BAAY,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/B,WAAW,EAAE,0BAAY,CAAC,IAAI,CAAC,aAAa,CAAC;IAC7C,iBAAiB,EAAE,0BAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC;IACzD,QAAQ,EAAE,0BAAY,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,gCAAgC;CACI,CAAC;AAEnE,QAAA,oBAAoB,GAAG,0BAAY,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC","sourcesContent":["import { tokenFactory } from './base.tokens';\nimport { RawMetadataShape } from '../types';\nimport { ToolMetadata } from '../metadata';\n\nexport const FrontMcpToolTokens = {\n type: tokenFactory.type('tool'),\n id: tokenFactory.meta('id'),\n name: tokenFactory.meta('name'),\n description: tokenFactory.meta('description'),\n inputSchema: tokenFactory.meta('inputSchema'),\n rawInputSchema: tokenFactory.meta('rawInputSchema'),\n outputSchema: tokenFactory.meta('outputSchema'),\n tags: tokenFactory.meta('tags'),\n annotations: tokenFactory.meta('annotations'),\n hideFromDiscovery: tokenFactory.meta('hideFromDiscovery'),\n metadata: tokenFactory.meta('metadata'), // used in tool({}) construction\n} as const satisfies RawMetadataShape<ToolMetadata, ExtendFrontMcpToolMetadata>;\n\nexport const extendedToolMetadata = tokenFactory.meta('extendedToolMetadata');\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { LogTransportType } from
|
|
2
|
+
import { LogTransportType } from '../../interfaces';
|
|
3
3
|
export declare enum LogLevel {
|
|
4
4
|
Debug = 0,
|
|
5
5
|
VERBOSE = 1,
|
|
@@ -9,7 +9,6 @@ export declare enum LogLevel {
|
|
|
9
9
|
Off = 100
|
|
10
10
|
}
|
|
11
11
|
export declare const LogLevelName: Record<LogLevel, string>;
|
|
12
|
-
export declare const LogLevelValue: Record<string, LogLevel>;
|
|
13
12
|
export type LoggingOptions = {
|
|
14
13
|
level?: LogLevel;
|
|
15
14
|
enableConsole?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loggingOptionsSchema = exports.
|
|
3
|
+
exports.loggingOptionsSchema = exports.LogLevelName = exports.LogLevel = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const schemas_1 = require("../../schemas");
|
|
6
6
|
var LogLevel;
|
|
@@ -20,14 +20,6 @@ exports.LogLevelName = {
|
|
|
20
20
|
[LogLevel.Error]: 'error',
|
|
21
21
|
[LogLevel.Off]: 'off',
|
|
22
22
|
};
|
|
23
|
-
exports.LogLevelValue = {
|
|
24
|
-
'debug': LogLevel.Debug,
|
|
25
|
-
'verbose': LogLevel.VERBOSE,
|
|
26
|
-
'info': LogLevel.Info,
|
|
27
|
-
'warn': LogLevel.Warn,
|
|
28
|
-
'error': LogLevel.Error,
|
|
29
|
-
'off': LogLevel.Off,
|
|
30
|
-
};
|
|
31
23
|
exports.loggingOptionsSchema = zod_1.z.object({
|
|
32
24
|
level: zod_1.z.nativeEnum(LogLevel).optional().default(LogLevel.Info),
|
|
33
25
|
prefix: zod_1.z.string().optional(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.options.js","sourceRoot":"","sources":["../../../../../src/common/types/options/logging.options.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"logging.options.js","sourceRoot":"","sources":["../../../../../src/common/types/options/logging.options.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,2CAA8D;AAI9D,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,yCAAS,CAAA;IACT,6CAAW,CAAA;IACX,uCAAQ,CAAA;IACR,uCAAQ,CAAA;IACR,yCAAS,CAAA;IACT,uCAAS,CAAA;AACX,CAAC,EAPW,QAAQ,wBAAR,QAAQ,QAOnB;AAEY,QAAA,YAAY,GAA6B;IACpD,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS;IAC7B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK;CACtB,CAAC;AAaW,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,OAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC/D,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,aAAa,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACnD,UAAU,EAAE,OAAC,CAAC,KAAK,CAAC,uCAA6B,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;CACpC,CAAC,CAAC","sourcesContent":["import { z } from 'zod';\nimport { annotatedFrontMcpLoggerSchema } from '../../schemas';\nimport { LogTransportType } from '../../interfaces';\nimport { RawZodShape } from '../common.types';\n\nexport enum LogLevel {\n Debug = 0,\n VERBOSE = 1,\n Info = 2,\n Warn = 3,\n Error = 4,\n Off = 100, // never log\n}\n\nexport const LogLevelName: Record<LogLevel, string> = {\n [LogLevel.Debug]: 'debug',\n [LogLevel.VERBOSE]: 'verbose',\n [LogLevel.Info]: 'info',\n [LogLevel.Warn]: 'warn',\n [LogLevel.Error]: 'error',\n [LogLevel.Off]: 'off',\n};\n\nexport type LoggingOptions = {\n level?: LogLevel; // default to 'info'\n enableConsole?: boolean;\n prefix?: string;\n /**\n * Additional custom LogTransport types to register.\n * @default []\n */\n transports?: LogTransportType[];\n};\n\nexport const loggingOptionsSchema = z.object({\n level: z.nativeEnum(LogLevel).optional().default(LogLevel.Info),\n prefix: z.string().optional(),\n enableConsole: z.boolean().optional().default(true),\n transports: z.array(annotatedFrontMcpLoggerSchema).optional().default([]),\n} satisfies RawZodShape<LoggingOptions>);\n\nexport type LoggingConfigType = Omit<z.infer<typeof loggingOptionsSchema>, 'transports'>;\n"]}
|
|
@@ -16,33 +16,33 @@ export declare const serverInfoOptionsSchema: z.ZodObject<{
|
|
|
16
16
|
src: z.ZodString;
|
|
17
17
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
18
18
|
sizes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
19
|
-
}, "
|
|
20
|
-
src:
|
|
21
|
-
mimeType
|
|
22
|
-
sizes
|
|
23
|
-
},
|
|
24
|
-
src:
|
|
25
|
-
mimeType
|
|
26
|
-
sizes
|
|
27
|
-
}
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
src: string;
|
|
21
|
+
mimeType?: string | undefined;
|
|
22
|
+
sizes?: string[] | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
src: string;
|
|
25
|
+
mimeType?: string | undefined;
|
|
26
|
+
sizes?: string[] | undefined;
|
|
27
|
+
}>, "many">>;
|
|
28
28
|
}, "strip", z.ZodTypeAny, {
|
|
29
29
|
name: string;
|
|
30
30
|
version: string;
|
|
31
31
|
title?: string | undefined;
|
|
32
|
-
icons?:
|
|
33
|
-
src:
|
|
34
|
-
mimeType
|
|
35
|
-
sizes
|
|
36
|
-
}
|
|
32
|
+
icons?: {
|
|
33
|
+
src: string;
|
|
34
|
+
mimeType?: string | undefined;
|
|
35
|
+
sizes?: string[] | undefined;
|
|
36
|
+
}[] | undefined;
|
|
37
37
|
websiteUrl?: string | undefined;
|
|
38
38
|
}, {
|
|
39
39
|
name: string;
|
|
40
40
|
version: string;
|
|
41
41
|
title?: string | undefined;
|
|
42
|
-
icons?:
|
|
43
|
-
src:
|
|
44
|
-
mimeType
|
|
45
|
-
sizes
|
|
46
|
-
}
|
|
42
|
+
icons?: {
|
|
43
|
+
src: string;
|
|
44
|
+
mimeType?: string | undefined;
|
|
45
|
+
sizes?: string[] | undefined;
|
|
46
|
+
}[] | undefined;
|
|
47
47
|
websiteUrl?: string | undefined;
|
|
48
48
|
}>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface ErrorHandlerOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Whether to include stack traces in error responses
|
|
4
|
+
*/
|
|
5
|
+
isDevelopment?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Logger function for error logging
|
|
8
|
+
*/
|
|
9
|
+
logger?: {
|
|
10
|
+
error: (message: string, meta?: any) => void;
|
|
11
|
+
warn: (message: string, meta?: any) => void;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Custom error transformer
|
|
15
|
+
*/
|
|
16
|
+
errorTransformer?: (error: any) => any;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handle errors in MCP flows and format them appropriately
|
|
20
|
+
*/
|
|
21
|
+
export declare class ErrorHandler {
|
|
22
|
+
private isDevelopment;
|
|
23
|
+
private logger?;
|
|
24
|
+
private errorTransformer?;
|
|
25
|
+
constructor(options?: ErrorHandlerOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Handle an error and return a formatted MCP response
|
|
28
|
+
*/
|
|
29
|
+
handle(error: any, context?: {
|
|
30
|
+
flowName?: string;
|
|
31
|
+
toolName?: string;
|
|
32
|
+
}): {
|
|
33
|
+
content: Array<{
|
|
34
|
+
type: "text";
|
|
35
|
+
text: string;
|
|
36
|
+
}>;
|
|
37
|
+
isError: true;
|
|
38
|
+
_meta?: {
|
|
39
|
+
errorId: string;
|
|
40
|
+
code: string;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
stack?: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Log error with appropriate level
|
|
47
|
+
*/
|
|
48
|
+
private logError;
|
|
49
|
+
/**
|
|
50
|
+
* Wrap a function with error handling
|
|
51
|
+
*/
|
|
52
|
+
wrap<T extends (...args: any[]) => any>(fn: T): T;
|
|
53
|
+
/**
|
|
54
|
+
* Transform any error to MCP error
|
|
55
|
+
*/
|
|
56
|
+
private transformToMcpError;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a global error handler instance
|
|
60
|
+
*/
|
|
61
|
+
export declare function createErrorHandler(options?: ErrorHandlerOptions): ErrorHandler;
|
|
62
|
+
/**
|
|
63
|
+
* Helper to check if an error should stop execution
|
|
64
|
+
*/
|
|
65
|
+
export declare function shouldStopExecution(error: any): boolean;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorHandler = void 0;
|
|
4
|
+
exports.createErrorHandler = createErrorHandler;
|
|
5
|
+
exports.shouldStopExecution = shouldStopExecution;
|
|
6
|
+
// errors/error-handler.ts
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
const mcp_error_1 = require("./mcp.error");
|
|
9
|
+
/**
|
|
10
|
+
* Handle errors in MCP flows and format them appropriately
|
|
11
|
+
*/
|
|
12
|
+
class ErrorHandler {
|
|
13
|
+
isDevelopment;
|
|
14
|
+
logger;
|
|
15
|
+
errorTransformer;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.isDevelopment = options.isDevelopment ?? process.env['NODE_ENV'] !== 'production';
|
|
18
|
+
this['logger'] = options.logger;
|
|
19
|
+
this.errorTransformer = options.errorTransformer;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Handle an error and return a formatted MCP response
|
|
23
|
+
*/
|
|
24
|
+
handle(error, context) {
|
|
25
|
+
// Transform error if transformer is provided
|
|
26
|
+
const transformedError = this.errorTransformer ? this.errorTransformer(error) : error;
|
|
27
|
+
// Log the error
|
|
28
|
+
this.logError(transformedError, context);
|
|
29
|
+
// Format for MCP response
|
|
30
|
+
return (0, mcp_error_1.formatMcpErrorResponse)(transformedError, this.isDevelopment);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Log error with appropriate level
|
|
34
|
+
*/
|
|
35
|
+
logError(error, context) {
|
|
36
|
+
if (!this.logger)
|
|
37
|
+
return;
|
|
38
|
+
const meta = {
|
|
39
|
+
...context,
|
|
40
|
+
errorId: error instanceof mcp_error_1.McpError ? error.errorId : undefined,
|
|
41
|
+
code: error instanceof mcp_error_1.McpError ? error.code : undefined,
|
|
42
|
+
stack: this.isDevelopment ? error.stack : undefined,
|
|
43
|
+
};
|
|
44
|
+
if (error instanceof mcp_error_1.McpError) {
|
|
45
|
+
if (error.isPublic) {
|
|
46
|
+
this.logger.warn(`Public error: ${error.getInternalMessage()}`, meta);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.logger.error(`Internal error: ${error.getInternalMessage()}`, meta);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.logger.error(`Unexpected error: ${error.message || String(error)}`, meta);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Wrap a function with error handling
|
|
58
|
+
*/
|
|
59
|
+
wrap(fn) {
|
|
60
|
+
return ((...args) => {
|
|
61
|
+
try {
|
|
62
|
+
const result = fn(...args);
|
|
63
|
+
if (result instanceof Promise) {
|
|
64
|
+
return result.catch((error) => {
|
|
65
|
+
throw this.transformToMcpError(error);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw this.transformToMcpError(error);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Transform any error to MCP error
|
|
77
|
+
*/
|
|
78
|
+
transformToMcpError(error) {
|
|
79
|
+
if (error instanceof mcp_error_1.McpError) {
|
|
80
|
+
return error;
|
|
81
|
+
}
|
|
82
|
+
if (this.errorTransformer) {
|
|
83
|
+
const transformed = this.errorTransformer(error);
|
|
84
|
+
if (transformed instanceof mcp_error_1.McpError) {
|
|
85
|
+
return transformed;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return (0, mcp_error_1.toMcpError)(error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.ErrorHandler = ErrorHandler;
|
|
92
|
+
/**
|
|
93
|
+
* Create a global error handler instance
|
|
94
|
+
*/
|
|
95
|
+
function createErrorHandler(options = {}) {
|
|
96
|
+
return new ErrorHandler(options);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Helper to check if an error should stop execution
|
|
100
|
+
*/
|
|
101
|
+
function shouldStopExecution(error) {
|
|
102
|
+
if (error instanceof common_1.FlowControl) {
|
|
103
|
+
return ['fail', 'abort'].includes(error.type);
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/errors/error-handler.ts"],"names":[],"mappings":"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","sourcesContent":["// errors/error-handler.ts\nimport { FlowControl } from '../common';\nimport { McpError, formatMcpErrorResponse, toMcpError} from './mcp.error';\n\nexport interface ErrorHandlerOptions {\n /**\n * Whether to include stack traces in error responses\n */\n isDevelopment?: boolean;\n\n /**\n * Logger function for error logging\n */\n logger?: {\n error: (message: string, meta?: any) => void;\n warn: (message: string, meta?: any) => void;\n };\n\n /**\n * Custom error transformer\n */\n errorTransformer?: (error: any) => any;\n}\n\n/**\n * Handle errors in MCP flows and format them appropriately\n */\nexport class ErrorHandler {\n private isDevelopment: boolean;\n private logger?: ErrorHandlerOptions['logger'];\n private errorTransformer?: ErrorHandlerOptions['errorTransformer'];\n\n constructor(options: ErrorHandlerOptions = {}) {\n this.isDevelopment = options.isDevelopment ?? process.env['NODE_ENV'] !== 'production';\n this['logger'] = options.logger;\n this.errorTransformer = options.errorTransformer;\n }\n\n /**\n * Handle an error and return a formatted MCP response\n */\n handle(error: any, context?: { flowName?: string; toolName?: string }) {\n // Transform error if transformer is provided\n const transformedError = this.errorTransformer ? this.errorTransformer(error) : error;\n\n // Log the error\n this.logError(transformedError, context);\n\n // Format for MCP response\n return formatMcpErrorResponse(transformedError, this.isDevelopment);\n }\n\n /**\n * Log error with appropriate level\n */\n private logError(error: any, context?: { flowName?: string; toolName?: string }) {\n if (!this.logger) return;\n\n const meta = {\n ...context,\n errorId: error instanceof McpError ? error.errorId : undefined,\n code: error instanceof McpError ? error.code : undefined,\n stack: this.isDevelopment ? error.stack : undefined,\n };\n\n if (error instanceof McpError) {\n if (error.isPublic) {\n this.logger.warn(`Public error: ${error.getInternalMessage()}`, meta);\n } else {\n this.logger.error(`Internal error: ${error.getInternalMessage()}`, meta);\n }\n } else {\n this.logger.error(`Unexpected error: ${error.message || String(error)}`, meta);\n }\n }\n\n /**\n * Wrap a function with error handling\n */\n wrap<T extends (...args: any[]) => any>(fn: T): T {\n return ((...args: any[]) => {\n try {\n const result = fn(...args);\n if (result instanceof Promise) {\n return result.catch((error) => {\n throw this.transformToMcpError(error);\n });\n }\n return result;\n } catch (error) {\n throw this.transformToMcpError(error);\n }\n }) as T;\n }\n\n /**\n * Transform any error to MCP error\n */\n private transformToMcpError(error: any): McpError {\n if (error instanceof McpError) {\n return error;\n }\n\n if (this.errorTransformer) {\n const transformed = this.errorTransformer(error);\n if (transformed instanceof McpError) {\n return transformed;\n }\n }\n\n return toMcpError(error);\n }\n}\n\n/**\n * Create a global error handler instance\n */\nexport function createErrorHandler(options: ErrorHandlerOptions = {}): ErrorHandler {\n return new ErrorHandler(options);\n}\n\n/**\n * Helper to check if an error should stop execution\n */\nexport function shouldStopExecution(error: any): boolean {\n if (error instanceof FlowControl) {\n return ['fail', 'abort'].includes(error.type);\n }\n return true;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { McpError, PublicMcpError, InternalMcpError, ToolNotFoundError, InvalidInputError, InvalidOutputError, InvalidMethodError, ToolExecutionError, RateLimitError, QuotaExceededError, UnauthorizedError, GenericServerError, isPublicError, toMcpError, formatMcpErrorResponse, } from './mcp.error';
|
|
2
|
+
export { ErrorHandler, ErrorHandlerOptions, createErrorHandler, shouldStopExecution } from './error-handler';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldStopExecution = exports.createErrorHandler = exports.ErrorHandler = exports.formatMcpErrorResponse = exports.toMcpError = exports.isPublicError = exports.GenericServerError = exports.UnauthorizedError = exports.QuotaExceededError = exports.RateLimitError = exports.ToolExecutionError = exports.InvalidMethodError = exports.InvalidOutputError = exports.InvalidInputError = exports.ToolNotFoundError = exports.InternalMcpError = exports.PublicMcpError = exports.McpError = void 0;
|
|
4
|
+
// Export all error classes
|
|
5
|
+
var mcp_error_1 = require("./mcp.error");
|
|
6
|
+
Object.defineProperty(exports, "McpError", { enumerable: true, get: function () { return mcp_error_1.McpError; } });
|
|
7
|
+
Object.defineProperty(exports, "PublicMcpError", { enumerable: true, get: function () { return mcp_error_1.PublicMcpError; } });
|
|
8
|
+
Object.defineProperty(exports, "InternalMcpError", { enumerable: true, get: function () { return mcp_error_1.InternalMcpError; } });
|
|
9
|
+
Object.defineProperty(exports, "ToolNotFoundError", { enumerable: true, get: function () { return mcp_error_1.ToolNotFoundError; } });
|
|
10
|
+
Object.defineProperty(exports, "InvalidInputError", { enumerable: true, get: function () { return mcp_error_1.InvalidInputError; } });
|
|
11
|
+
Object.defineProperty(exports, "InvalidOutputError", { enumerable: true, get: function () { return mcp_error_1.InvalidOutputError; } });
|
|
12
|
+
Object.defineProperty(exports, "InvalidMethodError", { enumerable: true, get: function () { return mcp_error_1.InvalidMethodError; } });
|
|
13
|
+
Object.defineProperty(exports, "ToolExecutionError", { enumerable: true, get: function () { return mcp_error_1.ToolExecutionError; } });
|
|
14
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return mcp_error_1.RateLimitError; } });
|
|
15
|
+
Object.defineProperty(exports, "QuotaExceededError", { enumerable: true, get: function () { return mcp_error_1.QuotaExceededError; } });
|
|
16
|
+
Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return mcp_error_1.UnauthorizedError; } });
|
|
17
|
+
Object.defineProperty(exports, "GenericServerError", { enumerable: true, get: function () { return mcp_error_1.GenericServerError; } });
|
|
18
|
+
Object.defineProperty(exports, "isPublicError", { enumerable: true, get: function () { return mcp_error_1.isPublicError; } });
|
|
19
|
+
Object.defineProperty(exports, "toMcpError", { enumerable: true, get: function () { return mcp_error_1.toMcpError; } });
|
|
20
|
+
Object.defineProperty(exports, "formatMcpErrorResponse", { enumerable: true, get: function () { return mcp_error_1.formatMcpErrorResponse; } });
|
|
21
|
+
// Export error handler utilities
|
|
22
|
+
var error_handler_1 = require("./error-handler");
|
|
23
|
+
Object.defineProperty(exports, "ErrorHandler", { enumerable: true, get: function () { return error_handler_1.ErrorHandler; } });
|
|
24
|
+
Object.defineProperty(exports, "createErrorHandler", { enumerable: true, get: function () { return error_handler_1.createErrorHandler; } });
|
|
25
|
+
Object.defineProperty(exports, "shouldStopExecution", { enumerable: true, get: function () { return error_handler_1.shouldStopExecution; } });
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AAC3B,yCAgBqB;AAfnB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,8GAAA,iBAAiB,OAAA;AACjB,8GAAA,iBAAiB,OAAA;AACjB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,2GAAA,cAAc,OAAA;AACd,+GAAA,kBAAkB,OAAA;AAClB,8GAAA,iBAAiB,OAAA;AACjB,+GAAA,kBAAkB,OAAA;AAClB,0GAAA,aAAa,OAAA;AACb,uGAAA,UAAU,OAAA;AACV,mHAAA,sBAAsB,OAAA;AAGxB,iCAAiC;AACjC,iDAA6G;AAApG,6GAAA,YAAY,OAAA;AAAuB,mHAAA,kBAAkB,OAAA;AAAE,oHAAA,mBAAmB,OAAA","sourcesContent":["// Export all error classes\nexport {\n McpError,\n PublicMcpError,\n InternalMcpError,\n ToolNotFoundError,\n InvalidInputError,\n InvalidOutputError,\n InvalidMethodError,\n ToolExecutionError,\n RateLimitError,\n QuotaExceededError,\n UnauthorizedError,\n GenericServerError,\n isPublicError,\n toMcpError,\n formatMcpErrorResponse,\n} from './mcp.error';\n\n// Export error handler utilities\nexport { ErrorHandler, ErrorHandlerOptions, createErrorHandler, shouldStopExecution } from './error-handler';\n"]}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all MCP-related errors
|
|
3
|
+
*/
|
|
4
|
+
export declare abstract class McpError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Unique error ID for tracking in logs
|
|
7
|
+
*/
|
|
8
|
+
errorId: string;
|
|
9
|
+
/**
|
|
10
|
+
* Whether this error should expose details to the client
|
|
11
|
+
*/
|
|
12
|
+
abstract readonly isPublic: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* HTTP status code equivalent (for reference)
|
|
15
|
+
*/
|
|
16
|
+
abstract readonly statusCode: number;
|
|
17
|
+
/**
|
|
18
|
+
* Error code for categorization
|
|
19
|
+
*/
|
|
20
|
+
abstract readonly code: string;
|
|
21
|
+
protected constructor(message: string, errorId?: string);
|
|
22
|
+
private generateErrorId;
|
|
23
|
+
/**
|
|
24
|
+
* Get the public-facing error message
|
|
25
|
+
*/
|
|
26
|
+
abstract getPublicMessage(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Get the internal error message (for logging)
|
|
29
|
+
*/
|
|
30
|
+
getInternalMessage(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Convert to MCP error response format
|
|
33
|
+
*/
|
|
34
|
+
toMcpError(isDevelopment?: boolean): {
|
|
35
|
+
content: Array<{
|
|
36
|
+
type: 'text';
|
|
37
|
+
text: string;
|
|
38
|
+
}>;
|
|
39
|
+
isError: true;
|
|
40
|
+
_meta?: {
|
|
41
|
+
errorId: string;
|
|
42
|
+
code: string;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
stack?: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Public errors - safe to expose to clients
|
|
50
|
+
* These include validation errors, not found errors, etc.
|
|
51
|
+
*/
|
|
52
|
+
export declare class PublicMcpError extends McpError {
|
|
53
|
+
readonly isPublic = true;
|
|
54
|
+
readonly statusCode: number;
|
|
55
|
+
readonly code: string;
|
|
56
|
+
constructor(message: string, code?: string, statusCode?: number);
|
|
57
|
+
getPublicMessage(): string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Internal errors - should not expose details to clients
|
|
61
|
+
* These are server errors, unexpected failures, etc.
|
|
62
|
+
*/
|
|
63
|
+
export declare class InternalMcpError extends McpError {
|
|
64
|
+
readonly isPublic = false;
|
|
65
|
+
readonly statusCode = 500;
|
|
66
|
+
readonly code: string;
|
|
67
|
+
constructor(message: string, code?: string);
|
|
68
|
+
getPublicMessage(): string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Tool didn't find an error
|
|
72
|
+
*/
|
|
73
|
+
export declare class ToolNotFoundError extends PublicMcpError {
|
|
74
|
+
constructor(toolName: string);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Invalid input validation error
|
|
78
|
+
*/
|
|
79
|
+
export declare class InvalidInputError extends PublicMcpError {
|
|
80
|
+
readonly validationErrors?: any;
|
|
81
|
+
constructor(message?: string, validationErrors?: any);
|
|
82
|
+
getInternalMessage(): string;
|
|
83
|
+
getPublicMessage(): string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Invalid output validation error (internal - don't expose schema details)
|
|
87
|
+
*/
|
|
88
|
+
export declare class InvalidOutputError extends InternalMcpError {
|
|
89
|
+
private readonly hasCustomErrorId;
|
|
90
|
+
constructor(errorId?: string);
|
|
91
|
+
getPublicMessage(): string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Invalid method error
|
|
95
|
+
*/
|
|
96
|
+
export declare class InvalidMethodError extends PublicMcpError {
|
|
97
|
+
constructor(method: string, expected: string);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Tool execution error (internal)
|
|
101
|
+
*/
|
|
102
|
+
export declare class ToolExecutionError extends InternalMcpError {
|
|
103
|
+
readonly originalError?: Error;
|
|
104
|
+
constructor(toolName: string, originalError?: Error);
|
|
105
|
+
getInternalMessage(): string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Rate limit error
|
|
109
|
+
*/
|
|
110
|
+
export declare class RateLimitError extends PublicMcpError {
|
|
111
|
+
constructor(retryAfter?: number);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Quota exceeded error
|
|
115
|
+
*/
|
|
116
|
+
export declare class QuotaExceededError extends PublicMcpError {
|
|
117
|
+
constructor(quotaType?: string);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Unauthorized error
|
|
121
|
+
*/
|
|
122
|
+
export declare class UnauthorizedError extends PublicMcpError {
|
|
123
|
+
constructor(message?: string);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Generic server error wrapper
|
|
127
|
+
*/
|
|
128
|
+
export declare class GenericServerError extends InternalMcpError {
|
|
129
|
+
readonly originalError?: Error;
|
|
130
|
+
constructor(message: string, originalError?: Error);
|
|
131
|
+
getInternalMessage(): string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Check if the error is a public error that can be safely shown to users
|
|
135
|
+
*/
|
|
136
|
+
export declare function isPublicError(error: any): error is PublicMcpError;
|
|
137
|
+
/**
|
|
138
|
+
* Convert any error to an MCP error
|
|
139
|
+
*/
|
|
140
|
+
export declare function toMcpError(error: any): McpError;
|
|
141
|
+
/**
|
|
142
|
+
* Format error for MCP response
|
|
143
|
+
*/
|
|
144
|
+
export declare function formatMcpErrorResponse(error: any, isDevelopment?: boolean): {
|
|
145
|
+
content: Array<{
|
|
146
|
+
type: "text";
|
|
147
|
+
text: string;
|
|
148
|
+
}>;
|
|
149
|
+
isError: true;
|
|
150
|
+
_meta?: {
|
|
151
|
+
errorId: string;
|
|
152
|
+
code: string;
|
|
153
|
+
timestamp: string;
|
|
154
|
+
stack?: string;
|
|
155
|
+
};
|
|
156
|
+
};
|