@frontmcp/sdk 0.6.0 → 0.6.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 +1 -0
- package/package.json +13 -6
- package/src/auth/session/index.d.ts +1 -0
- package/src/auth/session/index.js +3 -1
- package/src/auth/session/index.js.map +1 -1
- package/src/auth/session/vercel-kv-session.store.d.ts +96 -0
- package/src/auth/session/vercel-kv-session.store.js +216 -0
- package/src/auth/session/vercel-kv-session.store.js.map +1 -0
- package/src/common/decorators/front-mcp.decorator.js +14 -17
- package/src/common/decorators/front-mcp.decorator.js.map +1 -1
- package/src/common/metadata/front-mcp.metadata.d.ts +705 -23
- package/src/common/metadata/front-mcp.metadata.js +1 -0
- package/src/common/metadata/front-mcp.metadata.js.map +1 -1
- package/src/common/metadata/prompt.metadata.d.ts +4 -0
- package/src/common/metadata/resource.metadata.d.ts +8 -0
- package/src/common/metadata/tool-ui.metadata.d.ts +2 -2
- package/src/common/metadata/tool-ui.metadata.js +1 -1
- package/src/common/metadata/tool-ui.metadata.js.map +1 -1
- package/src/common/metadata/tool.metadata.d.ts +4 -0
- package/src/common/schemas/http-output.schema.d.ts +24 -6
- package/src/common/tokens/front-mcp.tokens.js +1 -0
- package/src/common/tokens/front-mcp.tokens.js.map +1 -1
- package/src/common/types/options/redis.options.d.ts +173 -5
- package/src/common/types/options/redis.options.js +157 -11
- package/src/common/types/options/redis.options.js.map +1 -1
- package/src/common/types/options/server-info.options.d.ts +4 -0
- package/src/common/types/options/transport.options.d.ts +68 -4
- package/src/common/utils/global-config.utils.d.ts +36 -0
- package/src/common/utils/global-config.utils.js +44 -0
- package/src/common/utils/global-config.utils.js.map +1 -0
- package/src/common/utils/index.d.ts +1 -0
- package/src/common/utils/index.js +1 -0
- package/src/common/utils/index.js.map +1 -1
- package/src/completion/flows/complete.flow.d.ts +6 -8
- package/src/errors/index.d.ts +1 -1
- package/src/errors/index.js +2 -1
- package/src/errors/index.js.map +1 -1
- package/src/errors/mcp.error.d.ts +9 -0
- package/src/errors/mcp.error.js +19 -1
- package/src/errors/mcp.error.js.map +1 -1
- package/src/front-mcp/front-mcp.providers.d.ts +208 -0
- package/src/front-mcp/index.d.ts +1 -0
- package/src/front-mcp/index.js +3 -0
- package/src/front-mcp/index.js.map +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/index.js.map +1 -1
- package/src/logging/flows/set-level.flow.d.ts +6 -8
- package/src/prompt/flows/get-prompt.flow.d.ts +14 -8
- package/src/prompt/flows/prompts-list.flow.d.ts +8 -7
- package/src/resource/flows/read-resource.flow.d.ts +8 -9
- package/src/resource/flows/resource-templates-list.flow.d.ts +8 -7
- package/src/resource/flows/resources-list.flow.d.ts +8 -7
- package/src/resource/flows/subscribe-resource.flow.d.ts +6 -8
- package/src/resource/flows/unsubscribe-resource.flow.d.ts +6 -8
- package/src/store/adapters/store.vercel-kv.adapter.d.ts +86 -0
- package/src/store/adapters/store.vercel-kv.adapter.js +155 -0
- package/src/store/adapters/store.vercel-kv.adapter.js.map +1 -0
- package/src/store/index.d.ts +2 -0
- package/src/store/index.js +2 -0
- package/src/store/index.js.map +1 -1
- package/src/store/store.factory.d.ts +86 -0
- package/src/store/store.factory.js +194 -0
- package/src/store/store.factory.js.map +1 -0
- package/src/tool/flows/call-tool.flow.d.ts +18 -9
- package/src/tool/flows/call-tool.flow.js +2 -2
- package/src/tool/flows/call-tool.flow.js.map +1 -1
- package/src/tool/flows/tools-list.flow.d.ts +9 -8
- package/src/tool/flows/tools-list.flow.js +2 -2
- package/src/tool/flows/tools-list.flow.js.map +1 -1
- package/src/tool/ui/index.d.ts +4 -4
- package/src/tool/ui/index.js +4 -4
- package/src/tool/ui/index.js.map +1 -1
- package/src/tool/ui/platform-adapters.d.ts +2 -2
- package/src/tool/ui/platform-adapters.js +3 -3
- package/src/tool/ui/platform-adapters.js.map +1 -1
- package/src/tool/ui/template-helpers.d.ts +5 -7
- package/src/tool/ui/template-helpers.js +9 -26
- package/src/tool/ui/template-helpers.js.map +1 -1
- package/src/tool/ui/ui-resource.handler.d.ts +1 -1
- package/src/tool/ui/ui-resource.handler.js +5 -5
- package/src/tool/ui/ui-resource.handler.js.map +1 -1
- package/src/transport/mcp-handlers/complete-request.handler.d.ts +4 -15
- package/src/transport/mcp-handlers/get-prompt-request.handler.d.ts +5 -15
- package/src/transport/mcp-handlers/index.d.ts +67 -195
- package/src/transport/mcp-handlers/list-prompts-request.handler.d.ts +5 -15
- package/src/transport/mcp-handlers/list-resource-templates-request.handler.d.ts +5 -15
- package/src/transport/mcp-handlers/list-resources-request.handler.d.ts +5 -15
- package/src/transport/mcp-handlers/list-tools-request.handler.d.ts +5 -15
- package/src/transport/mcp-handlers/logging-set-level-request.handler.d.ts +3 -14
- package/src/transport/mcp-handlers/read-resource-request.handler.d.ts +4 -15
- package/src/transport/mcp-handlers/subscribe-request.handler.d.ts +3 -14
- package/src/transport/mcp-handlers/unsubscribe-request.handler.d.ts +3 -14
- package/src/transport/transport.registry.d.ts +5 -1
- package/src/transport/transport.registry.js +52 -23
- package/src/transport/transport.registry.js.map +1 -1
|
@@ -7,7 +7,8 @@ export type { SessionMode, TransportIdMode, PlatformMappingEntry, PlatformDetect
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const transportPersistenceConfigSchema: z.ZodObject<{
|
|
9
9
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
-
redis: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
redis: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
11
|
+
provider: z.ZodLiteral<"redis">;
|
|
11
12
|
host: z.ZodString;
|
|
12
13
|
port: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
13
14
|
password: z.ZodOptional<z.ZodString>;
|
|
@@ -15,7 +16,38 @@ export declare const transportPersistenceConfigSchema: z.ZodObject<{
|
|
|
15
16
|
tls: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
16
17
|
keyPrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
17
18
|
defaultTtlMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
18
|
-
}, z.core.$strip
|
|
19
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
20
|
+
provider: z.ZodLiteral<"vercel-kv">;
|
|
21
|
+
url: z.ZodOptional<z.ZodString>;
|
|
22
|
+
token: z.ZodOptional<z.ZodString>;
|
|
23
|
+
keyPrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
24
|
+
defaultTtlMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
25
|
+
}, z.core.$strip>, z.ZodPipe<z.ZodObject<{
|
|
26
|
+
host: z.ZodString;
|
|
27
|
+
port: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
28
|
+
password: z.ZodOptional<z.ZodString>;
|
|
29
|
+
db: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
30
|
+
tls: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
31
|
+
keyPrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
32
|
+
defaultTtlMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
33
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
34
|
+
provider: "redis";
|
|
35
|
+
host: string;
|
|
36
|
+
port: number;
|
|
37
|
+
db: number;
|
|
38
|
+
tls: boolean;
|
|
39
|
+
keyPrefix: string;
|
|
40
|
+
defaultTtlMs: number;
|
|
41
|
+
password?: string | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
host: string;
|
|
44
|
+
port: number;
|
|
45
|
+
db: number;
|
|
46
|
+
tls: boolean;
|
|
47
|
+
keyPrefix: string;
|
|
48
|
+
defaultTtlMs: number;
|
|
49
|
+
password?: string | undefined;
|
|
50
|
+
}>>]>>;
|
|
19
51
|
defaultTtlMs: z.ZodDefault<z.ZodNumber>;
|
|
20
52
|
}, z.core.$strip>;
|
|
21
53
|
/**
|
|
@@ -50,7 +82,22 @@ export declare const transportOptionsSchema: z.ZodObject<{
|
|
|
50
82
|
requireSessionForStreamable: z.ZodDefault<z.ZodBoolean>;
|
|
51
83
|
persistence: z.ZodOptional<z.ZodObject<{
|
|
52
84
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
53
|
-
redis: z.ZodOptional<z.ZodObject<{
|
|
85
|
+
redis: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
86
|
+
provider: z.ZodLiteral<"redis">;
|
|
87
|
+
host: z.ZodString;
|
|
88
|
+
port: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
89
|
+
password: z.ZodOptional<z.ZodString>;
|
|
90
|
+
db: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
91
|
+
tls: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
92
|
+
keyPrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
93
|
+
defaultTtlMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
94
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
95
|
+
provider: z.ZodLiteral<"vercel-kv">;
|
|
96
|
+
url: z.ZodOptional<z.ZodString>;
|
|
97
|
+
token: z.ZodOptional<z.ZodString>;
|
|
98
|
+
keyPrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
99
|
+
defaultTtlMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
100
|
+
}, z.core.$strip>, z.ZodPipe<z.ZodObject<{
|
|
54
101
|
host: z.ZodString;
|
|
55
102
|
port: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
56
103
|
password: z.ZodOptional<z.ZodString>;
|
|
@@ -58,7 +105,24 @@ export declare const transportOptionsSchema: z.ZodObject<{
|
|
|
58
105
|
tls: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
59
106
|
keyPrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
60
107
|
defaultTtlMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
61
|
-
}, z.core.$strip
|
|
108
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
109
|
+
provider: "redis";
|
|
110
|
+
host: string;
|
|
111
|
+
port: number;
|
|
112
|
+
db: number;
|
|
113
|
+
tls: boolean;
|
|
114
|
+
keyPrefix: string;
|
|
115
|
+
defaultTtlMs: number;
|
|
116
|
+
password?: string | undefined;
|
|
117
|
+
}, {
|
|
118
|
+
host: string;
|
|
119
|
+
port: number;
|
|
120
|
+
db: number;
|
|
121
|
+
tls: boolean;
|
|
122
|
+
keyPrefix: string;
|
|
123
|
+
defaultTtlMs: number;
|
|
124
|
+
password?: string | undefined;
|
|
125
|
+
}>>]>>;
|
|
62
126
|
defaultTtlMs: z.ZodDefault<z.ZodNumber>;
|
|
63
127
|
}, z.core.$strip>>;
|
|
64
128
|
}, z.core.$strip>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global Configuration Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions for plugins to access global configuration from @FrontMcp decorator.
|
|
5
|
+
*/
|
|
6
|
+
import type { FrontMcpConfigType } from '../metadata';
|
|
7
|
+
import type { RedisOptions } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Extract store configuration from global FrontMcp configuration.
|
|
10
|
+
*
|
|
11
|
+
* This helper is used by plugins that want to use the global redis/store
|
|
12
|
+
* configuration instead of requiring explicit configuration.
|
|
13
|
+
*
|
|
14
|
+
* @param pluginName - Name of the plugin requesting the config (for error messages)
|
|
15
|
+
* @param config - The FrontMcp configuration object
|
|
16
|
+
* @returns The redis/store configuration
|
|
17
|
+
* @throws GlobalConfigNotFoundError if redis is not configured
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // In plugin dynamicProviders:
|
|
22
|
+
* static dynamicProviders = (options: MyPluginOptions) => {
|
|
23
|
+
* if (options.type === 'global-store') {
|
|
24
|
+
* return [{
|
|
25
|
+
* provide: MyStoreToken,
|
|
26
|
+
* inject: () => [FrontMcpConfig],
|
|
27
|
+
* useFactory: (config: FrontMcpConfigType) => {
|
|
28
|
+
* const storeConfig = getGlobalStoreConfig('MyPlugin', config);
|
|
29
|
+
* return new MyStoreProvider(storeConfig);
|
|
30
|
+
* },
|
|
31
|
+
* }];
|
|
32
|
+
* }
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function getGlobalStoreConfig(pluginName: string, config: FrontMcpConfigType): RedisOptions;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Global Configuration Utilities
|
|
4
|
+
*
|
|
5
|
+
* Helper functions for plugins to access global configuration from @FrontMcp decorator.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getGlobalStoreConfig = getGlobalStoreConfig;
|
|
9
|
+
const errors_1 = require("../../errors");
|
|
10
|
+
/**
|
|
11
|
+
* Extract store configuration from global FrontMcp configuration.
|
|
12
|
+
*
|
|
13
|
+
* This helper is used by plugins that want to use the global redis/store
|
|
14
|
+
* configuration instead of requiring explicit configuration.
|
|
15
|
+
*
|
|
16
|
+
* @param pluginName - Name of the plugin requesting the config (for error messages)
|
|
17
|
+
* @param config - The FrontMcp configuration object
|
|
18
|
+
* @returns The redis/store configuration
|
|
19
|
+
* @throws GlobalConfigNotFoundError if redis is not configured
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // In plugin dynamicProviders:
|
|
24
|
+
* static dynamicProviders = (options: MyPluginOptions) => {
|
|
25
|
+
* if (options.type === 'global-store') {
|
|
26
|
+
* return [{
|
|
27
|
+
* provide: MyStoreToken,
|
|
28
|
+
* inject: () => [FrontMcpConfig],
|
|
29
|
+
* useFactory: (config: FrontMcpConfigType) => {
|
|
30
|
+
* const storeConfig = getGlobalStoreConfig('MyPlugin', config);
|
|
31
|
+
* return new MyStoreProvider(storeConfig);
|
|
32
|
+
* },
|
|
33
|
+
* }];
|
|
34
|
+
* }
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function getGlobalStoreConfig(pluginName, config) {
|
|
39
|
+
if (!config.redis) {
|
|
40
|
+
throw new errors_1.GlobalConfigNotFoundError(pluginName, 'redis');
|
|
41
|
+
}
|
|
42
|
+
return config.redis;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=global-config.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-config.utils.js","sourceRoot":"","sources":["../../../../src/common/utils/global-config.utils.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAkCH,oDAKC;AAnCD,yCAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,oBAAoB,CAAC,UAAkB,EAAE,MAA0B;IACjF,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kCAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB,CAAC","sourcesContent":["/**\n * Global Configuration Utilities\n *\n * Helper functions for plugins to access global configuration from @FrontMcp decorator.\n */\n\nimport type { FrontMcpConfigType } from '../metadata';\nimport type { RedisOptions } from '../types';\nimport { GlobalConfigNotFoundError } from '../../errors';\n\n/**\n * Extract store configuration from global FrontMcp configuration.\n *\n * This helper is used by plugins that want to use the global redis/store\n * configuration instead of requiring explicit configuration.\n *\n * @param pluginName - Name of the plugin requesting the config (for error messages)\n * @param config - The FrontMcp configuration object\n * @returns The redis/store configuration\n * @throws GlobalConfigNotFoundError if redis is not configured\n *\n * @example\n * ```typescript\n * // In plugin dynamicProviders:\n * static dynamicProviders = (options: MyPluginOptions) => {\n * if (options.type === 'global-store') {\n * return [{\n * provide: MyStoreToken,\n * inject: () => [FrontMcpConfig],\n * useFactory: (config: FrontMcpConfigType) => {\n * const storeConfig = getGlobalStoreConfig('MyPlugin', config);\n * return new MyStoreProvider(storeConfig);\n * },\n * }];\n * }\n * };\n * ```\n */\nexport function getGlobalStoreConfig(pluginName: string, config: FrontMcpConfigType): RedisOptions {\n if (!config.redis) {\n throw new GlobalConfigNotFoundError(pluginName, 'redis');\n }\n return config.redis;\n}\n"]}
|
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./decide-request-intent.utils"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./path.utils"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./global-config.utils"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/utils/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/utils/index.ts"],"names":[],"mappings":";;;AAAA,wEAA8C;AAC9C,uDAA6B;AAC7B,gEAAsC","sourcesContent":["export * from './decide-request-intent.utils';\nexport * from './path.utils';\nexport * from './global-config.utils';\n"]}
|
|
@@ -4,15 +4,11 @@ declare const inputSchema: z.ZodObject<{
|
|
|
4
4
|
request: z.ZodObject<{
|
|
5
5
|
method: z.ZodLiteral<"completion/complete">;
|
|
6
6
|
params: z.ZodObject<{
|
|
7
|
-
task: z.ZodOptional<z.ZodObject<{
|
|
8
|
-
ttl: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
9
|
-
pollInterval: z.ZodOptional<z.ZodNumber>;
|
|
10
|
-
}, z.core.$loose>>;
|
|
11
7
|
_meta: z.ZodOptional<z.ZodObject<{
|
|
12
8
|
progressToken: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
13
9
|
"io.modelcontextprotocol/related-task": z.ZodOptional<z.ZodObject<{
|
|
14
10
|
taskId: z.ZodString;
|
|
15
|
-
}, z.core.$
|
|
11
|
+
}, z.core.$strip>>;
|
|
16
12
|
}, z.core.$loose>>;
|
|
17
13
|
ref: z.ZodUnion<readonly [z.ZodObject<{
|
|
18
14
|
type: z.ZodLiteral<"ref/prompt">;
|
|
@@ -28,15 +24,16 @@ declare const inputSchema: z.ZodObject<{
|
|
|
28
24
|
context: z.ZodOptional<z.ZodObject<{
|
|
29
25
|
arguments: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
30
26
|
}, z.core.$strip>>;
|
|
31
|
-
}, z.core.$
|
|
27
|
+
}, z.core.$strip>;
|
|
32
28
|
}, z.core.$strip>;
|
|
33
29
|
ctx: z.ZodUnknown;
|
|
34
30
|
}, z.core.$strip>;
|
|
35
31
|
declare const outputSchema: z.ZodObject<{
|
|
36
32
|
_meta: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
progressToken: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
37
34
|
"io.modelcontextprotocol/related-task": z.ZodOptional<z.ZodObject<{
|
|
38
35
|
taskId: z.ZodString;
|
|
39
|
-
}, z.core.$
|
|
36
|
+
}, z.core.$strip>>;
|
|
40
37
|
}, z.core.$loose>>;
|
|
41
38
|
completion: z.ZodObject<{
|
|
42
39
|
values: z.ZodArray<z.ZodString>;
|
|
@@ -58,9 +55,10 @@ declare const stateSchema: z.ZodObject<{
|
|
|
58
55
|
}, z.core.$strip>;
|
|
59
56
|
output: z.ZodObject<{
|
|
60
57
|
_meta: z.ZodOptional<z.ZodObject<{
|
|
58
|
+
progressToken: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
61
59
|
"io.modelcontextprotocol/related-task": z.ZodOptional<z.ZodObject<{
|
|
62
60
|
taskId: z.ZodString;
|
|
63
|
-
}, z.core.$
|
|
61
|
+
}, z.core.$strip>>;
|
|
64
62
|
}, z.core.$loose>>;
|
|
65
63
|
completion: z.ZodObject<{
|
|
66
64
|
values: z.ZodArray<z.ZodString>;
|
package/src/errors/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { McpError, PublicMcpError, InternalMcpError, ToolNotFoundError, ResourceNotFoundError, ResourceReadError, InvalidResourceUriError, InvalidInputError, InvalidOutputError, InvalidMethodError, ToolExecutionError, RateLimitError, QuotaExceededError, UnauthorizedError, GenericServerError, DependencyNotFoundError, InvalidHookFlowError, AuthConfigurationError, PromptNotFoundError, PromptExecutionError, isPublicError, toMcpError, formatMcpErrorResponse, MCP_ERROR_CODES, type McpErrorCode, } from './mcp.error';
|
|
1
|
+
export { McpError, PublicMcpError, InternalMcpError, ToolNotFoundError, ResourceNotFoundError, ResourceReadError, InvalidResourceUriError, InvalidInputError, InvalidOutputError, InvalidMethodError, ToolExecutionError, RateLimitError, QuotaExceededError, UnauthorizedError, GenericServerError, DependencyNotFoundError, InvalidHookFlowError, AuthConfigurationError, PromptNotFoundError, PromptExecutionError, GlobalConfigNotFoundError, isPublicError, toMcpError, formatMcpErrorResponse, MCP_ERROR_CODES, type McpErrorCode, } from './mcp.error';
|
|
2
2
|
export { authorizationRequiredDataSchema, authorizationRequiredParamsSchema, authorizationRequiredMetaSchema, AuthorizationRequiredData, AuthorizationRequiredParams, AuthorizationRequiredMeta, AuthorizationRequiredError, } from './authorization-required.error';
|
|
3
3
|
export { ErrorHandler, ErrorHandlerOptions, createErrorHandler, shouldStopExecution } from './error-handler';
|
package/src/errors/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shouldStopExecution = exports.createErrorHandler = exports.ErrorHandler = exports.AuthorizationRequiredError = exports.authorizationRequiredMetaSchema = exports.authorizationRequiredParamsSchema = exports.authorizationRequiredDataSchema = exports.MCP_ERROR_CODES = exports.formatMcpErrorResponse = exports.toMcpError = exports.isPublicError = exports.PromptExecutionError = exports.PromptNotFoundError = exports.AuthConfigurationError = exports.InvalidHookFlowError = exports.DependencyNotFoundError = exports.GenericServerError = exports.UnauthorizedError = exports.QuotaExceededError = exports.RateLimitError = exports.ToolExecutionError = exports.InvalidMethodError = exports.InvalidOutputError = exports.InvalidInputError = exports.InvalidResourceUriError = exports.ResourceReadError = exports.ResourceNotFoundError = exports.ToolNotFoundError = exports.InternalMcpError = exports.PublicMcpError = exports.McpError = void 0;
|
|
3
|
+
exports.shouldStopExecution = exports.createErrorHandler = exports.ErrorHandler = exports.AuthorizationRequiredError = exports.authorizationRequiredMetaSchema = exports.authorizationRequiredParamsSchema = exports.authorizationRequiredDataSchema = exports.MCP_ERROR_CODES = exports.formatMcpErrorResponse = exports.toMcpError = exports.isPublicError = exports.GlobalConfigNotFoundError = exports.PromptExecutionError = exports.PromptNotFoundError = exports.AuthConfigurationError = exports.InvalidHookFlowError = exports.DependencyNotFoundError = exports.GenericServerError = exports.UnauthorizedError = exports.QuotaExceededError = exports.RateLimitError = exports.ToolExecutionError = exports.InvalidMethodError = exports.InvalidOutputError = exports.InvalidInputError = exports.InvalidResourceUriError = exports.ResourceReadError = exports.ResourceNotFoundError = exports.ToolNotFoundError = exports.InternalMcpError = exports.PublicMcpError = exports.McpError = void 0;
|
|
4
4
|
// Export all error classes
|
|
5
5
|
var mcp_error_1 = require("./mcp.error");
|
|
6
6
|
Object.defineProperty(exports, "McpError", { enumerable: true, get: function () { return mcp_error_1.McpError; } });
|
|
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "InvalidHookFlowError", { enumerable: true, get:
|
|
|
23
23
|
Object.defineProperty(exports, "AuthConfigurationError", { enumerable: true, get: function () { return mcp_error_1.AuthConfigurationError; } });
|
|
24
24
|
Object.defineProperty(exports, "PromptNotFoundError", { enumerable: true, get: function () { return mcp_error_1.PromptNotFoundError; } });
|
|
25
25
|
Object.defineProperty(exports, "PromptExecutionError", { enumerable: true, get: function () { return mcp_error_1.PromptExecutionError; } });
|
|
26
|
+
Object.defineProperty(exports, "GlobalConfigNotFoundError", { enumerable: true, get: function () { return mcp_error_1.GlobalConfigNotFoundError; } });
|
|
26
27
|
Object.defineProperty(exports, "isPublicError", { enumerable: true, get: function () { return mcp_error_1.isPublicError; } });
|
|
27
28
|
Object.defineProperty(exports, "toMcpError", { enumerable: true, get: function () { return mcp_error_1.toMcpError; } });
|
|
28
29
|
Object.defineProperty(exports, "formatMcpErrorResponse", { enumerable: true, get: function () { return mcp_error_1.formatMcpErrorResponse; } });
|
package/src/errors/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AAC3B,yCA4BqB;AA3BnB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,8GAAA,iBAAiB,OAAA;AACjB,kHAAA,qBAAqB,OAAA;AACrB,8GAAA,iBAAiB,OAAA;AACjB,oHAAA,uBAAuB,OAAA;AACvB,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,oHAAA,uBAAuB,OAAA;AACvB,iHAAA,oBAAoB,OAAA;AACpB,mHAAA,sBAAsB,OAAA;AACtB,gHAAA,mBAAmB,OAAA;AACnB,iHAAA,oBAAoB,OAAA;AACpB,sHAAA,yBAAyB,OAAA;AACzB,0GAAA,aAAa,OAAA;AACb,uGAAA,UAAU,OAAA;AACV,mHAAA,sBAAsB,OAAA;AACtB,cAAc;AACd,4GAAA,eAAe,OAAA;AAIjB,2DAA2D;AAC3D,+EAWwC;AAVtC,UAAU;AACV,+IAAA,+BAA+B,OAAA;AAC/B,iJAAA,iCAAiC,OAAA;AACjC,+IAAA,+BAA+B,OAAA;AAK/B,cAAc;AACd,0IAAA,0BAA0B,OAAA;AAG5B,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 ResourceNotFoundError,\n ResourceReadError,\n InvalidResourceUriError,\n InvalidInputError,\n InvalidOutputError,\n InvalidMethodError,\n ToolExecutionError,\n RateLimitError,\n QuotaExceededError,\n UnauthorizedError,\n GenericServerError,\n DependencyNotFoundError,\n InvalidHookFlowError,\n AuthConfigurationError,\n PromptNotFoundError,\n PromptExecutionError,\n GlobalConfigNotFoundError,\n isPublicError,\n toMcpError,\n formatMcpErrorResponse,\n // Error codes\n MCP_ERROR_CODES,\n type McpErrorCode,\n} from './mcp.error';\n\n// Export authorization required error for progressive auth\nexport {\n // Schemas\n authorizationRequiredDataSchema,\n authorizationRequiredParamsSchema,\n authorizationRequiredMetaSchema,\n // Types (inferred from schemas)\n AuthorizationRequiredData,\n AuthorizationRequiredParams,\n AuthorizationRequiredMeta,\n // Error class\n AuthorizationRequiredError,\n} from './authorization-required.error';\n\n// Export error handler utilities\nexport { ErrorHandler, ErrorHandlerOptions, createErrorHandler, shouldStopExecution } from './error-handler';\n"]}
|
|
@@ -237,6 +237,15 @@ export declare class PromptExecutionError extends InternalMcpError {
|
|
|
237
237
|
constructor(promptName: string, cause?: Error);
|
|
238
238
|
getInternalMessage(): string;
|
|
239
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Global configuration not found error - thrown when a plugin requires
|
|
242
|
+
* global configuration that is not defined in @FrontMcp decorator.
|
|
243
|
+
*/
|
|
244
|
+
export declare class GlobalConfigNotFoundError extends PublicMcpError {
|
|
245
|
+
readonly pluginName: string;
|
|
246
|
+
readonly configKey: string;
|
|
247
|
+
constructor(pluginName: string, configKey: string);
|
|
248
|
+
}
|
|
240
249
|
/**
|
|
241
250
|
* Check if the error is a public error that can be safely shown to users
|
|
242
251
|
*/
|
package/src/errors/mcp.error.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PromptExecutionError = exports.PromptNotFoundError = exports.AuthConfigurationError = exports.RequestContextNotAvailableError = exports.InvalidHookFlowError = exports.DependencyNotFoundError = exports.GenericServerError = exports.UnauthorizedError = exports.QuotaExceededError = exports.RateLimitError = exports.ToolExecutionError = exports.InvalidMethodError = exports.InvalidOutputError = exports.InvalidInputError = exports.InvalidResourceUriError = exports.ResourceReadError = exports.ResourceNotFoundError = exports.ToolNotFoundError = exports.InternalMcpError = exports.PublicMcpError = exports.McpError = exports.MCP_ERROR_CODES = void 0;
|
|
3
|
+
exports.GlobalConfigNotFoundError = exports.PromptExecutionError = exports.PromptNotFoundError = exports.AuthConfigurationError = exports.RequestContextNotAvailableError = exports.InvalidHookFlowError = exports.DependencyNotFoundError = exports.GenericServerError = exports.UnauthorizedError = exports.QuotaExceededError = exports.RateLimitError = exports.ToolExecutionError = exports.InvalidMethodError = exports.InvalidOutputError = exports.InvalidInputError = exports.InvalidResourceUriError = exports.ResourceReadError = exports.ResourceNotFoundError = exports.ToolNotFoundError = exports.InternalMcpError = exports.PublicMcpError = exports.McpError = exports.MCP_ERROR_CODES = void 0;
|
|
4
4
|
exports.isPublicError = isPublicError;
|
|
5
5
|
exports.toMcpError = toMcpError;
|
|
6
6
|
exports.formatMcpErrorResponse = formatMcpErrorResponse;
|
|
@@ -368,6 +368,24 @@ class PromptExecutionError extends InternalMcpError {
|
|
|
368
368
|
}
|
|
369
369
|
exports.PromptExecutionError = PromptExecutionError;
|
|
370
370
|
// ============================================================================
|
|
371
|
+
// Configuration Errors
|
|
372
|
+
// ============================================================================
|
|
373
|
+
/**
|
|
374
|
+
* Global configuration not found error - thrown when a plugin requires
|
|
375
|
+
* global configuration that is not defined in @FrontMcp decorator.
|
|
376
|
+
*/
|
|
377
|
+
class GlobalConfigNotFoundError extends PublicMcpError {
|
|
378
|
+
pluginName;
|
|
379
|
+
configKey;
|
|
380
|
+
constructor(pluginName, configKey) {
|
|
381
|
+
super(`Plugin "${pluginName}" requires global "${configKey}" configuration. ` +
|
|
382
|
+
`Add "${configKey}" to your @FrontMcp decorator options.`, 'GLOBAL_CONFIG_NOT_FOUND', 500);
|
|
383
|
+
this.pluginName = pluginName;
|
|
384
|
+
this.configKey = configKey;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
exports.GlobalConfigNotFoundError = GlobalConfigNotFoundError;
|
|
388
|
+
// ============================================================================
|
|
371
389
|
// Error Utilities
|
|
372
390
|
// ============================================================================
|
|
373
391
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.error.js","sourceRoot":"","sources":["../../../src/errors/mcp.error.ts"],"names":[],"mappings":";;;AAubA,sCAEC;AAKD,gCAUC;AAKD,wDAGC;AAhdD,sBAAsB;AACtB,mCAAqC;AAErC;;;GAGG;AACU,QAAA,eAAe,GAAG;IAC7B,kCAAkC;IAClC,kBAAkB,EAAE,CAAC,KAAK;IAC1B,+BAA+B;IAC/B,eAAe,EAAE,CAAC,KAAK;IACvB,gCAAgC;IAChC,gBAAgB,EAAE,CAAC,KAAK;IACxB,8BAA8B;IAC9B,cAAc,EAAE,CAAC,KAAK;IACtB,8BAA8B;IAC9B,cAAc,EAAE,CAAC,KAAK;IACtB,2BAA2B;IAC3B,WA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AI,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,KAAU,EAAE,gBAAyB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY;IAClH,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["// errors/mcp.error.ts\nimport { randomBytes } from 'crypto';\n\n/**\n * MCP-specific error codes per JSON-RPC specification.\n * These codes are used in the JSON-RPC error response format.\n */\nexport const MCP_ERROR_CODES = {\n /** Resource not found (-32002) */\n RESOURCE_NOT_FOUND: -32002,\n /** Invalid request (-32600) */\n INVALID_REQUEST: -32600,\n /** Method not found (-32601) */\n METHOD_NOT_FOUND: -32601,\n /** Invalid params (-32602) */\n INVALID_PARAMS: -32602,\n /** Internal error (-32603) */\n INTERNAL_ERROR: -32603,\n /** Parse error (-32700) */\n PARSE_ERROR: -32700,\n} as const;\n\nexport type McpErrorCode = (typeof MCP_ERROR_CODES)[keyof typeof MCP_ERROR_CODES];\n\n/**\n * Base class for all MCP-related errors\n */\nexport abstract class McpError extends Error {\n /**\n * Unique error ID for tracking in logs\n */\n errorId: string;\n\n /**\n * Whether this error should expose details to the client\n */\n abstract readonly isPublic: boolean;\n\n /**\n * HTTP status code equivalent (for reference)\n */\n abstract readonly statusCode: number;\n\n /**\n * Error code for categorization\n */\n abstract readonly code: string;\n\n protected constructor(message: string, errorId?: string) {\n super(message);\n this.name = this.constructor.name;\n this.errorId = errorId || this.generateErrorId();\n Error.captureStackTrace(this, this.constructor);\n }\n\n private generateErrorId(): string {\n return `err_${randomBytes(8).toString('hex')}`;\n }\n\n /**\n * Get the public-facing error message\n */\n abstract getPublicMessage(): string;\n\n /**\n * Get the internal error message (for logging)\n */\n getInternalMessage(): string {\n return this.message;\n }\n\n /**\n * Convert to MCP error response format\n */\n toMcpError(isDevelopment = false): {\n content: Array<{ type: 'text'; text: string }>;\n isError: true;\n _meta?: {\n errorId: string;\n code: string;\n timestamp: string;\n stack?: string;\n };\n } {\n const message = isDevelopment ? this.getInternalMessage() : this.getPublicMessage();\n\n return {\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n isError: true,\n _meta: {\n errorId: this.errorId,\n code: this.code,\n timestamp: new Date().toISOString(),\n ...(isDevelopment && { stack: this.stack }),\n },\n };\n }\n}\n\n/**\n * Public errors - safe to expose to clients\n * These include validation errors, not found errors, etc.\n */\nexport class PublicMcpError extends McpError {\n readonly isPublic = true;\n readonly statusCode: number;\n readonly code: string;\n\n constructor(message: string, code = 'PUBLIC_ERROR', statusCode = 400) {\n super(message);\n this.code = code;\n this.statusCode = statusCode;\n }\n\n getPublicMessage(): string {\n return this.message;\n }\n}\n\n/**\n * Internal errors - should not expose details to clients\n * These are server errors, unexpected failures, etc.\n */\nexport class InternalMcpError extends McpError {\n readonly isPublic = false;\n readonly statusCode = 500;\n readonly code: string;\n\n constructor(message: string, code = 'INTERNAL_ERROR') {\n super(message);\n this.code = code;\n }\n\n getPublicMessage(): string {\n return `Internal FrontMCP error. Please contact support with error ID: ${this.errorId}`;\n }\n}\n\n// ============================================================================\n// Specific Error Classes\n// ============================================================================\n\n/**\n * Tool not found error\n */\nexport class ToolNotFoundError extends PublicMcpError {\n constructor(toolName: string) {\n super(`Tool \"${toolName}\" not found`, 'TOOL_NOT_FOUND', 404);\n }\n}\n\n/**\n * Resource not found error\n */\nexport class ResourceNotFoundError extends PublicMcpError {\n readonly uri: string;\n readonly mcpErrorCode = MCP_ERROR_CODES.RESOURCE_NOT_FOUND;\n\n constructor(uri: string) {\n super(`Resource not found: ${uri}`, 'RESOURCE_NOT_FOUND', 404);\n this.uri = uri;\n }\n\n /**\n * Convert to JSON-RPC error format per MCP specification.\n *\n * @example\n * {\n * \"code\": -32002,\n * \"message\": \"Resource not found: file:///missing.txt\",\n * \"data\": { \"uri\": \"file:///missing.txt\" }\n * }\n */\n toJsonRpcError(): {\n code: number;\n message: string;\n data?: { uri: string };\n } {\n return {\n code: this.mcpErrorCode,\n message: this.getPublicMessage(),\n data: { uri: this.uri },\n };\n }\n}\n\n/**\n * Resource read error (internal)\n */\nexport class ResourceReadError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(uri: string, originalError?: Error) {\n super(`Resource \"${uri}\" read failed: ${originalError?.message || 'Unknown error'}`, 'RESOURCE_READ_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Invalid resource URI error\n */\nexport class InvalidResourceUriError extends PublicMcpError {\n constructor(uri: string, reason?: string) {\n super(`Invalid resource URI: ${uri}${reason ? ` (${reason})` : ''}`, 'INVALID_RESOURCE_URI', 400);\n }\n}\n\n/**\n * Invalid input validation error\n */\nexport class InvalidInputError extends PublicMcpError {\n readonly validationErrors?: any;\n\n constructor(message = 'Invalid input: validation failed', validationErrors?: any) {\n super(message, 'INVALID_INPUT', 400);\n this.validationErrors = validationErrors;\n }\n\n override getInternalMessage(): string {\n return this.message + (this.validationErrors ? `\\nDetails: ${JSON.stringify(this.validationErrors, null, 2)}` : '');\n }\n override getPublicMessage(): string {\n if (this.validationErrors) {\n return `${this.message}\\nDetails: ${JSON.stringify(this.validationErrors, null, 2)}`;\n }\n return this.message;\n }\n}\n\n/**\n * Invalid output validation error (internal - don't expose schema details)\n */\nexport class InvalidOutputError extends InternalMcpError {\n private readonly hasCustomErrorId: boolean;\n\n constructor(errorId?: string) {\n super('Tool output validation failed', 'INVALID_OUTPUT');\n this.hasCustomErrorId = !!errorId;\n if (errorId) {\n this.errorId = errorId;\n }\n }\n\n override getPublicMessage(): string {\n // If a custom errorId was provided (e.g., request ID), include it for correlation\n // Otherwise, use a simpler message since the auto-generated ID isn't meaningful to users\n if (this.hasCustomErrorId) {\n return `Output validation failed. Please contact support with error ID: ${this.errorId}`;\n }\n return 'Output validation failed. Please contact support.';\n }\n}\n\n/**\n * Invalid method error\n */\nexport class InvalidMethodError extends PublicMcpError {\n constructor(method: string, expected: string) {\n super(`Invalid method \"${method}\". Expected \"${expected}\"`, 'INVALID_METHOD', 400);\n }\n}\n\n/**\n * Tool execution error (internal)\n */\nexport class ToolExecutionError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(toolName: string, originalError?: Error) {\n super(`Tool \"${toolName}\" execution failed: ${originalError?.message || 'Unknown error'}`, 'TOOL_EXECUTION_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Rate limit error\n */\nexport class RateLimitError extends PublicMcpError {\n constructor(retryAfter?: number) {\n const message = retryAfter ? `Rate limit exceeded. Retry after ${retryAfter} seconds` : 'Rate limit exceeded';\n super(message, 'RATE_LIMIT_EXCEEDED', 429);\n }\n}\n\n/**\n * Quota exceeded error\n */\nexport class QuotaExceededError extends PublicMcpError {\n constructor(quotaType = 'usage') {\n super(`${quotaType} quota exceeded`, 'QUOTA_EXCEEDED', 429);\n }\n}\n\n/**\n * Unauthorized error\n */\nexport class UnauthorizedError extends PublicMcpError {\n constructor(message = 'Unauthorized') {\n super(message, 'UNAUTHORIZED', 401);\n }\n}\n\n/**\n * Generic server error wrapper\n */\nexport class GenericServerError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(message: string, originalError?: Error) {\n super(message, 'SERVER_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Dependency not found error (internal) - thrown when a required dependency\n * is not found in a registry during initialization.\n */\nexport class DependencyNotFoundError extends InternalMcpError {\n constructor(registryName: string, dependencyName: string) {\n super(`Dependency \"${dependencyName}\" not found in ${registryName}`, 'DEPENDENCY_NOT_FOUND');\n }\n}\n\n/**\n * Invalid hook flow error - thrown when a hook is registered with a flow\n * that is not supported by the entry type (e.g., tool hook on resource class).\n */\nexport class InvalidHookFlowError extends InternalMcpError {\n constructor(message: string) {\n super(message, 'INVALID_HOOK_FLOW');\n }\n}\n\n/**\n * Request context not available error - thrown when code attempts to access\n * RequestContext outside of a request scope (i.e., without AsyncLocalStorage context).\n */\nexport class RequestContextNotAvailableError extends InternalMcpError {\n constructor(\n message = 'RequestContext not available. Ensure execution runs within a request scope created by RequestContextStorage.run().',\n ) {\n super(message, 'REQUEST_CONTEXT_NOT_AVAILABLE');\n }\n}\n\n/**\n * Auth configuration error - thrown when auth configuration is invalid\n * (e.g., transparent mode on parent with multiple child providers).\n */\nexport class AuthConfigurationError extends PublicMcpError {\n readonly errors: string[];\n readonly suggestion?: string;\n\n constructor(message: string, options?: { errors?: string[]; suggestion?: string }) {\n super(message, 'AUTH_CONFIGURATION_ERROR', 500);\n this.errors = options?.errors ?? [message];\n this.suggestion = options?.suggestion;\n }\n\n override getPublicMessage(): string {\n let msg = this.message;\n if (this.suggestion) {\n msg += `\\n\\nTo fix this issue:\\n${this.suggestion}`;\n }\n return msg;\n }\n}\n\n// ============================================================================\n// Prompt Errors\n// ============================================================================\n\n/**\n * Prompt not found error.\n */\nexport class PromptNotFoundError extends PublicMcpError {\n constructor(promptName: string) {\n super(`Prompt not found: ${promptName}`, 'PROMPT_NOT_FOUND', 404);\n }\n}\n\n/**\n * Prompt execution error - wraps errors during prompt execution.\n */\nexport class PromptExecutionError extends InternalMcpError {\n readonly promptName: string;\n readonly originalError?: Error;\n\n constructor(promptName: string, cause?: Error) {\n super(\n cause ? `Prompt execution failed: ${cause.message}` : `Prompt execution failed: ${promptName}`,\n 'PROMPT_EXECUTION_FAILED',\n );\n this.promptName = promptName;\n this.originalError = cause;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n// ============================================================================\n// Error Utilities\n// ============================================================================\n\n/**\n * Check if the error is a public error that can be safely shown to users\n */\nexport function isPublicError(error: any): error is PublicMcpError {\n return error instanceof McpError && error.isPublic;\n}\n\n/**\n * Convert any error to an MCP error\n */\nexport function toMcpError(error: any): McpError {\n if (error instanceof McpError) {\n return error;\n }\n\n if (error instanceof Error) {\n return new GenericServerError(error.message, error);\n }\n\n return new GenericServerError(String(error));\n}\n\n/**\n * Format error for MCP response\n */\nexport function formatMcpErrorResponse(error: any, isDevelopment: boolean = process.env['NODE_ENV'] !== 'production') {\n const mcpError = toMcpError(error);\n return mcpError.toMcpError(isDevelopment);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mcp.error.js","sourceRoot":"","sources":["../../../src/errors/mcp.error.ts"],"names":[],"mappings":";;;AA+cA,sCAEC;AAKD,gCAUC;AAKD,wDAGC;AAxeD,sBAAsB;AACtB,mCAAqC;AAErC;;;GAGG;AACU,QAAA,eAAe,GAAG;IAC7B,kCAAkC;IAClC,kBAAkB,EAAE,CAAC,KAAK;IAC1B,+BAA+B;IAC/B,eAAe,EAAE,CAAC,KAAK;IACvB,gCAAgC;IAChC,gBAAgB,EAAE,CAAC,KAAK;IACxB,8BAA8B;IAC9B,cAAc,EAAE,CAAC,KAAK;IACtB,8BAA8B;IAC9B,cAAc,EAAE,CAAC,KAAK;IACtB,2BAA2B;IAC3B,WAAW,EAAE,CAAC,KAAK;CACX,CAAC;AAIX;;GAEG;AACH,MAAsB,QAAS,SAAQ,KAAK;IAC1C;;OAEG;IACH,OAAO,CAAS;IAiBhB,YAAsB,OAAe,EAAE,OAAgB;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,IAAI,CAA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QAC3B,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,KAAU,EAAE,gBAAyB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY;IAClH,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["// errors/mcp.error.ts\nimport { randomBytes } from 'crypto';\n\n/**\n * MCP-specific error codes per JSON-RPC specification.\n * These codes are used in the JSON-RPC error response format.\n */\nexport const MCP_ERROR_CODES = {\n /** Resource not found (-32002) */\n RESOURCE_NOT_FOUND: -32002,\n /** Invalid request (-32600) */\n INVALID_REQUEST: -32600,\n /** Method not found (-32601) */\n METHOD_NOT_FOUND: -32601,\n /** Invalid params (-32602) */\n INVALID_PARAMS: -32602,\n /** Internal error (-32603) */\n INTERNAL_ERROR: -32603,\n /** Parse error (-32700) */\n PARSE_ERROR: -32700,\n} as const;\n\nexport type McpErrorCode = (typeof MCP_ERROR_CODES)[keyof typeof MCP_ERROR_CODES];\n\n/**\n * Base class for all MCP-related errors\n */\nexport abstract class McpError extends Error {\n /**\n * Unique error ID for tracking in logs\n */\n errorId: string;\n\n /**\n * Whether this error should expose details to the client\n */\n abstract readonly isPublic: boolean;\n\n /**\n * HTTP status code equivalent (for reference)\n */\n abstract readonly statusCode: number;\n\n /**\n * Error code for categorization\n */\n abstract readonly code: string;\n\n protected constructor(message: string, errorId?: string) {\n super(message);\n this.name = this.constructor.name;\n this.errorId = errorId || this.generateErrorId();\n Error.captureStackTrace(this, this.constructor);\n }\n\n private generateErrorId(): string {\n return `err_${randomBytes(8).toString('hex')}`;\n }\n\n /**\n * Get the public-facing error message\n */\n abstract getPublicMessage(): string;\n\n /**\n * Get the internal error message (for logging)\n */\n getInternalMessage(): string {\n return this.message;\n }\n\n /**\n * Convert to MCP error response format\n */\n toMcpError(isDevelopment = false): {\n content: Array<{ type: 'text'; text: string }>;\n isError: true;\n _meta?: {\n errorId: string;\n code: string;\n timestamp: string;\n stack?: string;\n };\n } {\n const message = isDevelopment ? this.getInternalMessage() : this.getPublicMessage();\n\n return {\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n isError: true,\n _meta: {\n errorId: this.errorId,\n code: this.code,\n timestamp: new Date().toISOString(),\n ...(isDevelopment && { stack: this.stack }),\n },\n };\n }\n}\n\n/**\n * Public errors - safe to expose to clients\n * These include validation errors, not found errors, etc.\n */\nexport class PublicMcpError extends McpError {\n readonly isPublic = true;\n readonly statusCode: number;\n readonly code: string;\n\n constructor(message: string, code = 'PUBLIC_ERROR', statusCode = 400) {\n super(message);\n this.code = code;\n this.statusCode = statusCode;\n }\n\n getPublicMessage(): string {\n return this.message;\n }\n}\n\n/**\n * Internal errors - should not expose details to clients\n * These are server errors, unexpected failures, etc.\n */\nexport class InternalMcpError extends McpError {\n readonly isPublic = false;\n readonly statusCode = 500;\n readonly code: string;\n\n constructor(message: string, code = 'INTERNAL_ERROR') {\n super(message);\n this.code = code;\n }\n\n getPublicMessage(): string {\n return `Internal FrontMCP error. Please contact support with error ID: ${this.errorId}`;\n }\n}\n\n// ============================================================================\n// Specific Error Classes\n// ============================================================================\n\n/**\n * Tool not found error\n */\nexport class ToolNotFoundError extends PublicMcpError {\n constructor(toolName: string) {\n super(`Tool \"${toolName}\" not found`, 'TOOL_NOT_FOUND', 404);\n }\n}\n\n/**\n * Resource not found error\n */\nexport class ResourceNotFoundError extends PublicMcpError {\n readonly uri: string;\n readonly mcpErrorCode = MCP_ERROR_CODES.RESOURCE_NOT_FOUND;\n\n constructor(uri: string) {\n super(`Resource not found: ${uri}`, 'RESOURCE_NOT_FOUND', 404);\n this.uri = uri;\n }\n\n /**\n * Convert to JSON-RPC error format per MCP specification.\n *\n * @example\n * {\n * \"code\": -32002,\n * \"message\": \"Resource not found: file:///missing.txt\",\n * \"data\": { \"uri\": \"file:///missing.txt\" }\n * }\n */\n toJsonRpcError(): {\n code: number;\n message: string;\n data?: { uri: string };\n } {\n return {\n code: this.mcpErrorCode,\n message: this.getPublicMessage(),\n data: { uri: this.uri },\n };\n }\n}\n\n/**\n * Resource read error (internal)\n */\nexport class ResourceReadError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(uri: string, originalError?: Error) {\n super(`Resource \"${uri}\" read failed: ${originalError?.message || 'Unknown error'}`, 'RESOURCE_READ_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Invalid resource URI error\n */\nexport class InvalidResourceUriError extends PublicMcpError {\n constructor(uri: string, reason?: string) {\n super(`Invalid resource URI: ${uri}${reason ? ` (${reason})` : ''}`, 'INVALID_RESOURCE_URI', 400);\n }\n}\n\n/**\n * Invalid input validation error\n */\nexport class InvalidInputError extends PublicMcpError {\n readonly validationErrors?: any;\n\n constructor(message = 'Invalid input: validation failed', validationErrors?: any) {\n super(message, 'INVALID_INPUT', 400);\n this.validationErrors = validationErrors;\n }\n\n override getInternalMessage(): string {\n return this.message + (this.validationErrors ? `\\nDetails: ${JSON.stringify(this.validationErrors, null, 2)}` : '');\n }\n override getPublicMessage(): string {\n if (this.validationErrors) {\n return `${this.message}\\nDetails: ${JSON.stringify(this.validationErrors, null, 2)}`;\n }\n return this.message;\n }\n}\n\n/**\n * Invalid output validation error (internal - don't expose schema details)\n */\nexport class InvalidOutputError extends InternalMcpError {\n private readonly hasCustomErrorId: boolean;\n\n constructor(errorId?: string) {\n super('Tool output validation failed', 'INVALID_OUTPUT');\n this.hasCustomErrorId = !!errorId;\n if (errorId) {\n this.errorId = errorId;\n }\n }\n\n override getPublicMessage(): string {\n // If a custom errorId was provided (e.g., request ID), include it for correlation\n // Otherwise, use a simpler message since the auto-generated ID isn't meaningful to users\n if (this.hasCustomErrorId) {\n return `Output validation failed. Please contact support with error ID: ${this.errorId}`;\n }\n return 'Output validation failed. Please contact support.';\n }\n}\n\n/**\n * Invalid method error\n */\nexport class InvalidMethodError extends PublicMcpError {\n constructor(method: string, expected: string) {\n super(`Invalid method \"${method}\". Expected \"${expected}\"`, 'INVALID_METHOD', 400);\n }\n}\n\n/**\n * Tool execution error (internal)\n */\nexport class ToolExecutionError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(toolName: string, originalError?: Error) {\n super(`Tool \"${toolName}\" execution failed: ${originalError?.message || 'Unknown error'}`, 'TOOL_EXECUTION_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Rate limit error\n */\nexport class RateLimitError extends PublicMcpError {\n constructor(retryAfter?: number) {\n const message = retryAfter ? `Rate limit exceeded. Retry after ${retryAfter} seconds` : 'Rate limit exceeded';\n super(message, 'RATE_LIMIT_EXCEEDED', 429);\n }\n}\n\n/**\n * Quota exceeded error\n */\nexport class QuotaExceededError extends PublicMcpError {\n constructor(quotaType = 'usage') {\n super(`${quotaType} quota exceeded`, 'QUOTA_EXCEEDED', 429);\n }\n}\n\n/**\n * Unauthorized error\n */\nexport class UnauthorizedError extends PublicMcpError {\n constructor(message = 'Unauthorized') {\n super(message, 'UNAUTHORIZED', 401);\n }\n}\n\n/**\n * Generic server error wrapper\n */\nexport class GenericServerError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(message: string, originalError?: Error) {\n super(message, 'SERVER_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Dependency not found error (internal) - thrown when a required dependency\n * is not found in a registry during initialization.\n */\nexport class DependencyNotFoundError extends InternalMcpError {\n constructor(registryName: string, dependencyName: string) {\n super(`Dependency \"${dependencyName}\" not found in ${registryName}`, 'DEPENDENCY_NOT_FOUND');\n }\n}\n\n/**\n * Invalid hook flow error - thrown when a hook is registered with a flow\n * that is not supported by the entry type (e.g., tool hook on resource class).\n */\nexport class InvalidHookFlowError extends InternalMcpError {\n constructor(message: string) {\n super(message, 'INVALID_HOOK_FLOW');\n }\n}\n\n/**\n * Request context not available error - thrown when code attempts to access\n * RequestContext outside of a request scope (i.e., without AsyncLocalStorage context).\n */\nexport class RequestContextNotAvailableError extends InternalMcpError {\n constructor(\n message = 'RequestContext not available. Ensure execution runs within a request scope created by RequestContextStorage.run().',\n ) {\n super(message, 'REQUEST_CONTEXT_NOT_AVAILABLE');\n }\n}\n\n/**\n * Auth configuration error - thrown when auth configuration is invalid\n * (e.g., transparent mode on parent with multiple child providers).\n */\nexport class AuthConfigurationError extends PublicMcpError {\n readonly errors: string[];\n readonly suggestion?: string;\n\n constructor(message: string, options?: { errors?: string[]; suggestion?: string }) {\n super(message, 'AUTH_CONFIGURATION_ERROR', 500);\n this.errors = options?.errors ?? [message];\n this.suggestion = options?.suggestion;\n }\n\n override getPublicMessage(): string {\n let msg = this.message;\n if (this.suggestion) {\n msg += `\\n\\nTo fix this issue:\\n${this.suggestion}`;\n }\n return msg;\n }\n}\n\n// ============================================================================\n// Prompt Errors\n// ============================================================================\n\n/**\n * Prompt not found error.\n */\nexport class PromptNotFoundError extends PublicMcpError {\n constructor(promptName: string) {\n super(`Prompt not found: ${promptName}`, 'PROMPT_NOT_FOUND', 404);\n }\n}\n\n/**\n * Prompt execution error - wraps errors during prompt execution.\n */\nexport class PromptExecutionError extends InternalMcpError {\n readonly promptName: string;\n readonly originalError?: Error;\n\n constructor(promptName: string, cause?: Error) {\n super(\n cause ? `Prompt execution failed: ${cause.message}` : `Prompt execution failed: ${promptName}`,\n 'PROMPT_EXECUTION_FAILED',\n );\n this.promptName = promptName;\n this.originalError = cause;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n// ============================================================================\n// Configuration Errors\n// ============================================================================\n\n/**\n * Global configuration not found error - thrown when a plugin requires\n * global configuration that is not defined in @FrontMcp decorator.\n */\nexport class GlobalConfigNotFoundError extends PublicMcpError {\n readonly pluginName: string;\n readonly configKey: string;\n\n constructor(pluginName: string, configKey: string) {\n super(\n `Plugin \"${pluginName}\" requires global \"${configKey}\" configuration. ` +\n `Add \"${configKey}\" to your @FrontMcp decorator options.`,\n 'GLOBAL_CONFIG_NOT_FOUND',\n 500,\n );\n this.pluginName = pluginName;\n this.configKey = configKey;\n }\n}\n\n// ============================================================================\n// Error Utilities\n// ============================================================================\n\n/**\n * Check if the error is a public error that can be safely shown to users\n */\nexport function isPublicError(error: any): error is PublicMcpError {\n return error instanceof McpError && error.isPublic;\n}\n\n/**\n * Convert any error to an MCP error\n */\nexport function toMcpError(error: any): McpError {\n if (error instanceof McpError) {\n return error;\n }\n\n if (error instanceof Error) {\n return new GenericServerError(error.message, error);\n }\n\n return new GenericServerError(String(error));\n}\n\n/**\n * Format error for MCP response\n */\nexport function formatMcpErrorResponse(error: any, isDevelopment: boolean = process.env['NODE_ENV'] !== 'production') {\n const mcpError = toMcpError(error);\n return mcpError.toMcpError(isDevelopment);\n}\n"]}
|