@kelpi/mcp 0.1.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/README.md +312 -0
- package/bin/kelpi-mcp +3 -0
- package/dist/__tests__/integration-api/fixtures.d.ts +382 -0
- package/dist/__tests__/integration-api/fixtures.d.ts.map +1 -0
- package/dist/__tests__/integration-api/fixtures.js +478 -0
- package/dist/__tests__/integration-api/fixtures.js.map +1 -0
- package/dist/__tests__/integration-api/index.d.ts +19 -0
- package/dist/__tests__/integration-api/index.d.ts.map +1 -0
- package/dist/__tests__/integration-api/index.js +33 -0
- package/dist/__tests__/integration-api/index.js.map +1 -0
- package/dist/__tests__/integration-api/setup.d.ts +176 -0
- package/dist/__tests__/integration-api/setup.d.ts.map +1 -0
- package/dist/__tests__/integration-api/setup.js +329 -0
- package/dist/__tests__/integration-api/setup.js.map +1 -0
- package/dist/__tests__/setup.d.ts +2 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +11 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/__tests__/unit/test-utils.d.ts +46 -0
- package/dist/__tests__/unit/test-utils.d.ts.map +1 -0
- package/dist/__tests__/unit/test-utils.js +50 -0
- package/dist/__tests__/unit/test-utils.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api-client.d.ts +17 -0
- package/dist/lib/api-client.d.ts.map +1 -0
- package/dist/lib/api-client.js +169 -0
- package/dist/lib/api-client.js.map +1 -0
- package/dist/lib/auth-state.d.ts +54 -0
- package/dist/lib/auth-state.d.ts.map +1 -0
- package/dist/lib/auth-state.js +131 -0
- package/dist/lib/auth-state.js.map +1 -0
- package/dist/lib/config.d.ts +39 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +170 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/error-formatter.d.ts +40 -0
- package/dist/lib/error-formatter.d.ts.map +1 -0
- package/dist/lib/error-formatter.js +149 -0
- package/dist/lib/error-formatter.js.map +1 -0
- package/dist/lib/errors.d.ts +44 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +56 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/tool-helpers.d.ts +49 -0
- package/dist/lib/tool-helpers.d.ts.map +1 -0
- package/dist/lib/tool-helpers.js +101 -0
- package/dist/lib/tool-helpers.js.map +1 -0
- package/dist/lib/tool-registry.d.ts +111 -0
- package/dist/lib/tool-registry.d.ts.map +1 -0
- package/dist/lib/tool-registry.js +112 -0
- package/dist/lib/tool-registry.js.map +1 -0
- package/dist/lib/version.d.ts +13 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +13 -0
- package/dist/lib/version.js.map +1 -0
- package/dist/prompts/flow-generator.d.ts +45 -0
- package/dist/prompts/flow-generator.d.ts.map +1 -0
- package/dist/prompts/flow-generator.js +177 -0
- package/dist/prompts/flow-generator.js.map +1 -0
- package/dist/prompts/index.d.ts +7 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +7 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/server.d.ts +66 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +140 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/auth/index.d.ts +18 -0
- package/dist/tools/auth/index.d.ts.map +1 -0
- package/dist/tools/auth/index.js +50 -0
- package/dist/tools/auth/index.js.map +1 -0
- package/dist/tools/auth/login.d.ts +37 -0
- package/dist/tools/auth/login.d.ts.map +1 -0
- package/dist/tools/auth/login.js +257 -0
- package/dist/tools/auth/login.js.map +1 -0
- package/dist/tools/auth/schemas.d.ts +69 -0
- package/dist/tools/auth/schemas.d.ts.map +1 -0
- package/dist/tools/auth/schemas.js +36 -0
- package/dist/tools/auth/schemas.js.map +1 -0
- package/dist/tools/auth/status.d.ts +11 -0
- package/dist/tools/auth/status.d.ts.map +1 -0
- package/dist/tools/auth/status.js +50 -0
- package/dist/tools/auth/status.js.map +1 -0
- package/dist/tools/contacts/create.d.ts +11 -0
- package/dist/tools/contacts/create.d.ts.map +1 -0
- package/dist/tools/contacts/create.js +47 -0
- package/dist/tools/contacts/create.js.map +1 -0
- package/dist/tools/contacts/index.d.ts +10 -0
- package/dist/tools/contacts/index.d.ts.map +1 -0
- package/dist/tools/contacts/index.js +40 -0
- package/dist/tools/contacts/index.js.map +1 -0
- package/dist/tools/contacts/schemas.d.ts +37 -0
- package/dist/tools/contacts/schemas.d.ts.map +1 -0
- package/dist/tools/contacts/schemas.js +15 -0
- package/dist/tools/contacts/schemas.js.map +1 -0
- package/dist/tools/events/index.d.ts +10 -0
- package/dist/tools/events/index.d.ts.map +1 -0
- package/dist/tools/events/index.js +42 -0
- package/dist/tools/events/index.js.map +1 -0
- package/dist/tools/events/schemas.d.ts +37 -0
- package/dist/tools/events/schemas.d.ts.map +1 -0
- package/dist/tools/events/schemas.js +17 -0
- package/dist/tools/events/schemas.js.map +1 -0
- package/dist/tools/events/track.d.ts +11 -0
- package/dist/tools/events/track.d.ts.map +1 -0
- package/dist/tools/events/track.js +41 -0
- package/dist/tools/events/track.js.map +1 -0
- package/dist/tools/flows/activate.d.ts +11 -0
- package/dist/tools/flows/activate.d.ts.map +1 -0
- package/dist/tools/flows/activate.js +46 -0
- package/dist/tools/flows/activate.js.map +1 -0
- package/dist/tools/flows/create.d.ts +11 -0
- package/dist/tools/flows/create.d.ts.map +1 -0
- package/dist/tools/flows/create.js +72 -0
- package/dist/tools/flows/create.js.map +1 -0
- package/dist/tools/flows/index.d.ts +24 -0
- package/dist/tools/flows/index.d.ts.map +1 -0
- package/dist/tools/flows/index.js +183 -0
- package/dist/tools/flows/index.js.map +1 -0
- package/dist/tools/flows/list.d.ts +11 -0
- package/dist/tools/flows/list.d.ts.map +1 -0
- package/dist/tools/flows/list.js +34 -0
- package/dist/tools/flows/list.js.map +1 -0
- package/dist/tools/flows/schemas.d.ts +621 -0
- package/dist/tools/flows/schemas.d.ts.map +1 -0
- package/dist/tools/flows/schemas.js +135 -0
- package/dist/tools/flows/schemas.js.map +1 -0
- package/dist/tools/flows/transform.d.ts +39 -0
- package/dist/tools/flows/transform.d.ts.map +1 -0
- package/dist/tools/flows/transform.js +139 -0
- package/dist/tools/flows/transform.js.map +1 -0
- package/dist/tools/index.d.ts +34 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +46 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/sdk/index.d.ts +18 -0
- package/dist/tools/sdk/index.d.ts.map +1 -0
- package/dist/tools/sdk/index.js +69 -0
- package/dist/tools/sdk/index.js.map +1 -0
- package/dist/tools/sdk/public-key.d.ts +11 -0
- package/dist/tools/sdk/public-key.d.ts.map +1 -0
- package/dist/tools/sdk/public-key.js +24 -0
- package/dist/tools/sdk/public-key.js.map +1 -0
- package/dist/tools/sdk/schemas.d.ts +48 -0
- package/dist/tools/sdk/schemas.d.ts.map +1 -0
- package/dist/tools/sdk/schemas.js +35 -0
- package/dist/tools/sdk/schemas.js.map +1 -0
- package/dist/tools/sdk/snippet.d.ts +11 -0
- package/dist/tools/sdk/snippet.d.ts.map +1 -0
- package/dist/tools/sdk/snippet.js +50 -0
- package/dist/tools/sdk/snippet.js.map +1 -0
- package/dist/tools/sdk/templates/index.d.ts +5 -0
- package/dist/tools/sdk/templates/index.d.ts.map +1 -0
- package/dist/tools/sdk/templates/index.js +5 -0
- package/dist/tools/sdk/templates/index.js.map +1 -0
- package/dist/tools/sdk/templates/nextjs.d.ts +5 -0
- package/dist/tools/sdk/templates/nextjs.d.ts.map +1 -0
- package/dist/tools/sdk/templates/nextjs.js +71 -0
- package/dist/tools/sdk/templates/nextjs.js.map +1 -0
- package/dist/tools/sdk/templates/node.d.ts +9 -0
- package/dist/tools/sdk/templates/node.d.ts.map +1 -0
- package/dist/tools/sdk/templates/node.js +170 -0
- package/dist/tools/sdk/templates/node.js.map +1 -0
- package/dist/tools/sdk/templates/react.d.ts +5 -0
- package/dist/tools/sdk/templates/react.d.ts.map +1 -0
- package/dist/tools/sdk/templates/react.js +54 -0
- package/dist/tools/sdk/templates/react.js.map +1 -0
- package/dist/tools/sdk/templates/vanilla.d.ts +5 -0
- package/dist/tools/sdk/templates/vanilla.d.ts.map +1 -0
- package/dist/tools/sdk/templates/vanilla.js +61 -0
- package/dist/tools/sdk/templates/vanilla.js.map +1 -0
- package/dist/tools/templates/create.d.ts +11 -0
- package/dist/tools/templates/create.d.ts.map +1 -0
- package/dist/tools/templates/create.js +39 -0
- package/dist/tools/templates/create.js.map +1 -0
- package/dist/tools/templates/index.d.ts +17 -0
- package/dist/tools/templates/index.d.ts.map +1 -0
- package/dist/tools/templates/index.js +68 -0
- package/dist/tools/templates/index.js.map +1 -0
- package/dist/tools/templates/list.d.ts +11 -0
- package/dist/tools/templates/list.d.ts.map +1 -0
- package/dist/tools/templates/list.js +31 -0
- package/dist/tools/templates/list.js.map +1 -0
- package/dist/tools/templates/schemas.d.ts +90 -0
- package/dist/tools/templates/schemas.d.ts.map +1 -0
- package/dist/tools/templates/schemas.js +37 -0
- package/dist/tools/templates/schemas.js.map +1 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatted error with user-friendly message and optional hint
|
|
3
|
+
*/
|
|
4
|
+
export interface FormattedError {
|
|
5
|
+
/** User-friendly error message */
|
|
6
|
+
message: string;
|
|
7
|
+
/** Error code for programmatic handling */
|
|
8
|
+
code: string;
|
|
9
|
+
/** Actionable hint for the user to resolve the error */
|
|
10
|
+
hint?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Error codes for different error types
|
|
14
|
+
*/
|
|
15
|
+
export declare const ErrorCodes: {
|
|
16
|
+
readonly AUTH_REQUIRED: "AUTH_REQUIRED";
|
|
17
|
+
readonly INVALID_API_KEY: "INVALID_API_KEY";
|
|
18
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
19
|
+
readonly CONFLICT: "CONFLICT";
|
|
20
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
21
|
+
readonly SERVER_ERROR: "SERVER_ERROR";
|
|
22
|
+
readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
|
|
23
|
+
readonly RATE_LIMITED: "RATE_LIMITED";
|
|
24
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
25
|
+
readonly CONFIG_ERROR: "CONFIG_ERROR";
|
|
26
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
27
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Format errors for user-friendly display in MCP responses.
|
|
31
|
+
*
|
|
32
|
+
* This function takes any error type and converts it into a structured
|
|
33
|
+
* FormattedError with a user-friendly message, error code, and optional
|
|
34
|
+
* actionable hint.
|
|
35
|
+
*
|
|
36
|
+
* @param error - The error to format (can be any type)
|
|
37
|
+
* @returns FormattedError with message, code, and optional hint
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatError(error: unknown): FormattedError;
|
|
40
|
+
//# sourceMappingURL=error-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-formatter.d.ts","sourceRoot":"","sources":["../../src/lib/error-formatter.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;CAab,CAAC;AAEX;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CA+C1D"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { AuthError, ApiError, ConfigError, TimeoutError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Error codes for different error types
|
|
4
|
+
*/
|
|
5
|
+
export const ErrorCodes = {
|
|
6
|
+
AUTH_REQUIRED: 'AUTH_REQUIRED',
|
|
7
|
+
INVALID_API_KEY: 'INVALID_API_KEY',
|
|
8
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
9
|
+
CONFLICT: 'CONFLICT',
|
|
10
|
+
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
11
|
+
SERVER_ERROR: 'SERVER_ERROR',
|
|
12
|
+
SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
|
|
13
|
+
RATE_LIMITED: 'RATE_LIMITED',
|
|
14
|
+
FORBIDDEN: 'FORBIDDEN',
|
|
15
|
+
CONFIG_ERROR: 'CONFIG_ERROR',
|
|
16
|
+
TIMEOUT: 'TIMEOUT',
|
|
17
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Format errors for user-friendly display in MCP responses.
|
|
21
|
+
*
|
|
22
|
+
* This function takes any error type and converts it into a structured
|
|
23
|
+
* FormattedError with a user-friendly message, error code, and optional
|
|
24
|
+
* actionable hint.
|
|
25
|
+
*
|
|
26
|
+
* @param error - The error to format (can be any type)
|
|
27
|
+
* @returns FormattedError with message, code, and optional hint
|
|
28
|
+
*/
|
|
29
|
+
export function formatError(error) {
|
|
30
|
+
// Handle AuthError
|
|
31
|
+
if (error instanceof AuthError) {
|
|
32
|
+
return {
|
|
33
|
+
message: 'Authentication required',
|
|
34
|
+
code: ErrorCodes.AUTH_REQUIRED,
|
|
35
|
+
hint: 'Run kelpi_login first to authenticate',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Handle ApiError
|
|
39
|
+
if (error instanceof ApiError) {
|
|
40
|
+
return formatApiError(error);
|
|
41
|
+
}
|
|
42
|
+
// Handle ConfigError
|
|
43
|
+
if (error instanceof ConfigError) {
|
|
44
|
+
return {
|
|
45
|
+
message: error.message,
|
|
46
|
+
code: ErrorCodes.CONFIG_ERROR,
|
|
47
|
+
hint: 'Run kelpi_login to configure your credentials',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Handle TimeoutError
|
|
51
|
+
if (error instanceof TimeoutError) {
|
|
52
|
+
const seconds = Math.round(error.timeout / 1000);
|
|
53
|
+
return {
|
|
54
|
+
message: `Request timed out after ${seconds} seconds`,
|
|
55
|
+
code: ErrorCodes.TIMEOUT,
|
|
56
|
+
hint: 'Check your network connection and try again',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Handle generic Error objects
|
|
60
|
+
if (error instanceof Error) {
|
|
61
|
+
return {
|
|
62
|
+
message: error.message,
|
|
63
|
+
code: ErrorCodes.UNKNOWN_ERROR,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Handle non-Error values (string, null, undefined, objects)
|
|
67
|
+
return {
|
|
68
|
+
message: 'An unexpected error occurred',
|
|
69
|
+
code: ErrorCodes.UNKNOWN_ERROR,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Format API errors based on HTTP status code
|
|
74
|
+
*/
|
|
75
|
+
function formatApiError(error) {
|
|
76
|
+
const { status, validationErrors, message } = error;
|
|
77
|
+
// 400 Bad Request with validation errors
|
|
78
|
+
if (validationErrors && validationErrors.length > 0) {
|
|
79
|
+
const formattedErrors = validationErrors
|
|
80
|
+
.map((e) => `${e.field}: ${e.message}`)
|
|
81
|
+
.join(', ');
|
|
82
|
+
return {
|
|
83
|
+
message: formattedErrors,
|
|
84
|
+
code: ErrorCodes.VALIDATION_ERROR,
|
|
85
|
+
hint: 'Fix the validation errors and try again',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// 401 Unauthorized
|
|
89
|
+
if (status === 401) {
|
|
90
|
+
return {
|
|
91
|
+
message: 'API key is invalid or expired',
|
|
92
|
+
code: ErrorCodes.INVALID_API_KEY,
|
|
93
|
+
hint: 'Run kelpi_login to get a new API key',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// 403 Forbidden
|
|
97
|
+
if (status === 403) {
|
|
98
|
+
return {
|
|
99
|
+
message: message || 'Access denied',
|
|
100
|
+
code: ErrorCodes.FORBIDDEN,
|
|
101
|
+
hint: 'Check your API key permissions',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// 404 Not Found
|
|
105
|
+
if (status === 404) {
|
|
106
|
+
return {
|
|
107
|
+
message: message || 'Resource not found',
|
|
108
|
+
code: ErrorCodes.NOT_FOUND,
|
|
109
|
+
hint: 'Check that the ID is correct',
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// 409 Conflict
|
|
113
|
+
if (status === 409) {
|
|
114
|
+
return {
|
|
115
|
+
message: message || 'Resource already exists',
|
|
116
|
+
code: ErrorCodes.CONFLICT,
|
|
117
|
+
hint: 'Use a different identifier or update the existing resource',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// 429 Rate Limited
|
|
121
|
+
if (status === 429) {
|
|
122
|
+
return {
|
|
123
|
+
message: message || 'Rate limit exceeded',
|
|
124
|
+
code: ErrorCodes.RATE_LIMITED,
|
|
125
|
+
hint: 'Please wait before making more requests',
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// 503 Service Unavailable
|
|
129
|
+
if (status === 503) {
|
|
130
|
+
return {
|
|
131
|
+
message: message || 'Service temporarily unavailable',
|
|
132
|
+
code: ErrorCodes.SERVICE_UNAVAILABLE,
|
|
133
|
+
hint: 'Please try again in a few moments',
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// 5xx Server Errors
|
|
137
|
+
if (status >= 500) {
|
|
138
|
+
return {
|
|
139
|
+
message: message || 'Internal server error',
|
|
140
|
+
code: ErrorCodes.SERVER_ERROR,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Default case for other status codes
|
|
144
|
+
return {
|
|
145
|
+
message: message || 'Request failed',
|
|
146
|
+
code: ErrorCodes.UNKNOWN_ERROR,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=error-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-formatter.js","sourceRoot":"","sources":["../../src/lib/error-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAc7E;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa,EAAE,eAAe;IAC9B,eAAe,EAAE,iBAAiB;IAClC,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,gBAAgB,EAAE,kBAAkB;IACpC,YAAY,EAAE,cAAc;IAC5B,mBAAmB,EAAE,qBAAqB;IAC1C,YAAY,EAAE,cAAc;IAC5B,SAAS,EAAE,WAAW;IACtB,YAAY,EAAE,cAAc;IAC5B,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,eAAe;CACtB,CAAC;AAEX;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,mBAAmB;IACnB,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;QAC/B,OAAO;YACL,OAAO,EAAE,yBAAyB;YAClC,IAAI,EAAE,UAAU,CAAC,aAAa;YAC9B,IAAI,EAAE,uCAAuC;SAC9C,CAAC;IACJ,CAAC;IAED,kBAAkB;IAClB,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,qBAAqB;IACrB,IAAI,KAAK,YAAY,WAAW,EAAE,CAA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,UAAU,CAAC,YAAY;SAC9B,CAAC;IACJ,CAAC;IAED,sCAAsC;IACtC,OAAO;QACL,OAAO,EAAE,OAAO,IAAI,gBAAgB;QACpC,IAAI,EAAE,UAAU,CAAC,aAAa;KAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ValidationError } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base error class for all Kelpi MCP errors
|
|
4
|
+
*/
|
|
5
|
+
export declare class KelpiError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
constructor(message: string, code: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Error class for configuration-related errors
|
|
11
|
+
*/
|
|
12
|
+
export declare class ConfigError extends KelpiError {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validation details from Zod's flatten() format
|
|
17
|
+
*/
|
|
18
|
+
export interface ValidationDetails {
|
|
19
|
+
formErrors?: string[];
|
|
20
|
+
fieldErrors?: Record<string, string[]>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error class for API HTTP errors
|
|
24
|
+
*/
|
|
25
|
+
export declare class ApiError extends KelpiError {
|
|
26
|
+
readonly status: number;
|
|
27
|
+
readonly validationErrors?: ValidationError[];
|
|
28
|
+
readonly details?: ValidationDetails;
|
|
29
|
+
constructor(message: string, status: number, validationErrors?: ValidationError[], details?: ValidationDetails);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Authentication error for 401 responses or invalid credentials
|
|
33
|
+
*/
|
|
34
|
+
export declare class AuthError extends KelpiError {
|
|
35
|
+
constructor(message: string);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Timeout error for requests that exceed the timeout duration
|
|
39
|
+
*/
|
|
40
|
+
export declare class TimeoutError extends KelpiError {
|
|
41
|
+
readonly timeout: number;
|
|
42
|
+
constructor(message: string, timeout: number);
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAK1C;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,UAAU;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,UAAU;IACtC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrD,SAAgB,OAAO,CAAC,EAAE,iBAAiB,CAAC;gBAG1C,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,gBAAgB,CAAC,EAAE,eAAe,EAAE,EACpC,OAAO,CAAC,EAAE,iBAAiB;CAQ9B;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,UAAU;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,SAAgB,OAAO,EAAE,MAAM,CAAC;gBAEpB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK7C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Kelpi MCP errors
|
|
3
|
+
*/
|
|
4
|
+
export class KelpiError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(message, code) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'KelpiError';
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Error class for configuration-related errors
|
|
14
|
+
*/
|
|
15
|
+
export class ConfigError extends KelpiError {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message, 'CONFIG_ERROR');
|
|
18
|
+
this.name = 'ConfigError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Error class for API HTTP errors
|
|
23
|
+
*/
|
|
24
|
+
export class ApiError extends KelpiError {
|
|
25
|
+
status;
|
|
26
|
+
validationErrors;
|
|
27
|
+
details;
|
|
28
|
+
constructor(message, status, validationErrors, details) {
|
|
29
|
+
super(message, 'API_ERROR');
|
|
30
|
+
this.name = 'ApiError';
|
|
31
|
+
this.status = status;
|
|
32
|
+
this.validationErrors = validationErrors;
|
|
33
|
+
this.details = details;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Authentication error for 401 responses or invalid credentials
|
|
38
|
+
*/
|
|
39
|
+
export class AuthError extends KelpiError {
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message, 'AUTH_ERROR');
|
|
42
|
+
this.name = 'AuthError';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Timeout error for requests that exceed the timeout duration
|
|
47
|
+
*/
|
|
48
|
+
export class TimeoutError extends KelpiError {
|
|
49
|
+
timeout;
|
|
50
|
+
constructor(message, timeout) {
|
|
51
|
+
super(message, 'TIMEOUT_ERROR');
|
|
52
|
+
this.name = 'TimeoutError';
|
|
53
|
+
this.timeout = timeout;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../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GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ToolResult } from './tool-registry.js';
|
|
2
|
+
import { ApiError, type ApiClient } from './api-client.js';
|
|
3
|
+
import type { ZodError } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* Context provided to authenticated tool handlers
|
|
6
|
+
*/
|
|
7
|
+
export interface AuthenticatedContext {
|
|
8
|
+
client: ApiClient;
|
|
9
|
+
apiUrl: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a successful text response
|
|
13
|
+
*/
|
|
14
|
+
export declare function successResponse(data: unknown): ToolResult;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a plain text response (not JSON)
|
|
17
|
+
*/
|
|
18
|
+
export declare function textResponse(text: string): ToolResult;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an error response with standard format
|
|
21
|
+
*/
|
|
22
|
+
export declare function errorResponse(error: string, message: string, extra?: Record<string, unknown>): ToolResult;
|
|
23
|
+
/**
|
|
24
|
+
* Creates an authentication required error response
|
|
25
|
+
*/
|
|
26
|
+
export declare function authRequiredResponse(action: string): ToolResult;
|
|
27
|
+
/**
|
|
28
|
+
* Formats Zod validation errors into a standard response
|
|
29
|
+
*/
|
|
30
|
+
export declare function validationErrorResponse(zodError: ZodError, defaultMessage?: string): ToolResult;
|
|
31
|
+
/**
|
|
32
|
+
* Formats an ApiError into a standard error response
|
|
33
|
+
*/
|
|
34
|
+
export declare function apiErrorResponse(err: ApiError, action: string): ToolResult;
|
|
35
|
+
/**
|
|
36
|
+
* Formats any error into a standard error response
|
|
37
|
+
*/
|
|
38
|
+
export declare function unknownErrorResponse(err: unknown, action: string): ToolResult;
|
|
39
|
+
/**
|
|
40
|
+
* Wraps a handler that requires authentication.
|
|
41
|
+
* Loads config, checks for API key, and creates an API client.
|
|
42
|
+
* Returns early with auth error if not authenticated.
|
|
43
|
+
*/
|
|
44
|
+
export declare function withAuth(action: string, handler: (ctx: AuthenticatedContext) => Promise<ToolResult>): Promise<ToolResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Handles errors from API calls with standard formatting
|
|
47
|
+
*/
|
|
48
|
+
export declare function handleApiError(err: unknown, action: string): ToolResult;
|
|
49
|
+
//# sourceMappingURL=tool-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/tool-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAmB,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CAIzD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAIrD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,UAAU,CAUZ;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAK/D;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,QAAQ,EAClB,cAAc,SAAkB,GAC/B,UAAU,CASZ;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAoB1E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAK7E;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,OAAO,CAAC,UAAU,CAAC,GAC1D,OAAO,CAAC,UAAU,CAAC,CAWrB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAKvE"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { loadConfig, getApiUrl } from './config.js';
|
|
2
|
+
import { createApiClient, ApiError } from './api-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a successful text response
|
|
5
|
+
*/
|
|
6
|
+
export function successResponse(data) {
|
|
7
|
+
return {
|
|
8
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a plain text response (not JSON)
|
|
13
|
+
*/
|
|
14
|
+
export function textResponse(text) {
|
|
15
|
+
return {
|
|
16
|
+
content: [{ type: 'text', text }],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates an error response with standard format
|
|
21
|
+
*/
|
|
22
|
+
export function errorResponse(error, message, extra) {
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
{
|
|
26
|
+
type: 'text',
|
|
27
|
+
text: JSON.stringify({ error, message, ...extra }, null, 2),
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
isError: true,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates an authentication required error response
|
|
35
|
+
*/
|
|
36
|
+
export function authRequiredResponse(action) {
|
|
37
|
+
return errorResponse('Not authenticated', `Please run kelpi_login to authenticate before ${action}.`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Formats Zod validation errors into a standard response
|
|
41
|
+
*/
|
|
42
|
+
export function validationErrorResponse(zodError, defaultMessage = 'Invalid input') {
|
|
43
|
+
const errors = zodError.errors.map((e) => ({
|
|
44
|
+
path: e.path.join('.'),
|
|
45
|
+
message: e.message,
|
|
46
|
+
}));
|
|
47
|
+
return errorResponse('Validation failed', errors[0]?.message || defaultMessage, {
|
|
48
|
+
validation_errors: errors,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Formats an ApiError into a standard error response
|
|
53
|
+
*/
|
|
54
|
+
export function apiErrorResponse(err, action) {
|
|
55
|
+
const response = {
|
|
56
|
+
error: `Failed to ${action}`,
|
|
57
|
+
message: err.message,
|
|
58
|
+
status: err.status,
|
|
59
|
+
};
|
|
60
|
+
if (err.validationErrors) {
|
|
61
|
+
response.validation_errors = err.validationErrors;
|
|
62
|
+
}
|
|
63
|
+
// Include Zod validation details if present (from Kelpi API)
|
|
64
|
+
if (err.details) {
|
|
65
|
+
response.details = err.details;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
|
|
69
|
+
isError: true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Formats any error into a standard error response
|
|
74
|
+
*/
|
|
75
|
+
export function unknownErrorResponse(err, action) {
|
|
76
|
+
return errorResponse(`Failed to ${action}`, err instanceof Error ? err.message : 'Unknown error');
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Wraps a handler that requires authentication.
|
|
80
|
+
* Loads config, checks for API key, and creates an API client.
|
|
81
|
+
* Returns early with auth error if not authenticated.
|
|
82
|
+
*/
|
|
83
|
+
export async function withAuth(action, handler) {
|
|
84
|
+
const config = await loadConfig();
|
|
85
|
+
if (!config.api_key) {
|
|
86
|
+
return authRequiredResponse(action);
|
|
87
|
+
}
|
|
88
|
+
const apiUrl = config.api_url || (await getApiUrl());
|
|
89
|
+
const client = createApiClient({ apiKey: config.api_key, apiUrl });
|
|
90
|
+
return handler({ client, apiUrl });
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Handles errors from API calls with standard formatting
|
|
94
|
+
*/
|
|
95
|
+
export function handleApiError(err, action) {
|
|
96
|
+
if (err instanceof ApiError) {
|
|
97
|
+
return apiErrorResponse(err, action);
|
|
98
|
+
}
|
|
99
|
+
return unknownErrorResponse(err, action);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=tool-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-helpers.js","sourceRoot":"","sources":["../../src/lib/tool-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAkB,MAAM,iBAAiB,CAAC;AAW5E;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACjE,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAa,EACb,OAAe,EACf,KAA+B;IAE/B,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;aAC5D;SACF;QACD,OAAO,EAAE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,IAAI;KACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAY,EAAE,MAAc;IAC/D,OAAO,aAAa,CAClB,aAAa,MAAM,EAAE,EACrB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CACrD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,MAAc,EACd,OAA2D;IAE3D,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAElC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,SAAS,EAAE,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAEnE,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,GAAY,EAAE,MAAc;IACzD,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;QAC5B,OAAO,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z, type ZodType } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Result content item for tool responses
|
|
4
|
+
*/
|
|
5
|
+
export interface ToolContentItem {
|
|
6
|
+
type: 'text' | 'image' | 'resource';
|
|
7
|
+
text?: string;
|
|
8
|
+
data?: string;
|
|
9
|
+
mimeType?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Tool execution result
|
|
13
|
+
*/
|
|
14
|
+
export interface ToolResult {
|
|
15
|
+
content: ToolContentItem[];
|
|
16
|
+
isError?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Tool definition with Zod schema for input validation
|
|
20
|
+
* Uses ZodType to support both ZodObject and ZodEffects (from .refine())
|
|
21
|
+
*/
|
|
22
|
+
export interface ToolDefinition {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
inputSchema: ZodType<Record<string, unknown>>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Tool handler function type
|
|
29
|
+
*/
|
|
30
|
+
export type ToolHandler = (input: Record<string, unknown>) => Promise<ToolResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Tool with its definition and handler.
|
|
33
|
+
* Used for registration and exported for use in tool modules.
|
|
34
|
+
*/
|
|
35
|
+
export interface ToolWithHandler {
|
|
36
|
+
definition: ToolDefinition;
|
|
37
|
+
handler: ToolHandler;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Registered tool with definition and handler
|
|
41
|
+
* @deprecated Use ToolWithHandler instead
|
|
42
|
+
*/
|
|
43
|
+
export type RegisteredTool = ToolWithHandler;
|
|
44
|
+
/**
|
|
45
|
+
* MCP-compatible tool format for listing
|
|
46
|
+
*/
|
|
47
|
+
export interface McpTool {
|
|
48
|
+
name: string;
|
|
49
|
+
description: string;
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: 'object';
|
|
52
|
+
properties: Record<string, unknown>;
|
|
53
|
+
required?: string[];
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validation result type
|
|
58
|
+
*/
|
|
59
|
+
export type ValidationResult = {
|
|
60
|
+
success: true;
|
|
61
|
+
data: Record<string, unknown>;
|
|
62
|
+
} | {
|
|
63
|
+
success: false;
|
|
64
|
+
error: z.ZodError;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Custom error class for tool registry operations
|
|
68
|
+
*/
|
|
69
|
+
export declare class ToolRegistryError extends Error {
|
|
70
|
+
readonly code?: string;
|
|
71
|
+
constructor(message: string, code?: string);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Registry for managing MCP tools with Zod validation
|
|
75
|
+
*/
|
|
76
|
+
export declare class ToolRegistry {
|
|
77
|
+
private tools;
|
|
78
|
+
/**
|
|
79
|
+
* Register a tool with its definition and handler
|
|
80
|
+
*/
|
|
81
|
+
register(definition: ToolDefinition, handler: ToolHandler): void;
|
|
82
|
+
/**
|
|
83
|
+
* Get a registered tool by name
|
|
84
|
+
*/
|
|
85
|
+
get(name: string): RegisteredTool | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* List all registered tools in MCP-compatible format
|
|
88
|
+
*/
|
|
89
|
+
list(): McpTool[];
|
|
90
|
+
/**
|
|
91
|
+
* Validate input against a tool's schema
|
|
92
|
+
*/
|
|
93
|
+
validateInput(toolName: string, input: unknown): ValidationResult;
|
|
94
|
+
/**
|
|
95
|
+
* Execute a tool with validated input
|
|
96
|
+
*/
|
|
97
|
+
execute(toolName: string, input: unknown): Promise<ToolResult>;
|
|
98
|
+
/**
|
|
99
|
+
* Check if a tool is registered
|
|
100
|
+
*/
|
|
101
|
+
has(name: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Get the number of registered tools
|
|
104
|
+
*/
|
|
105
|
+
get size(): number;
|
|
106
|
+
/**
|
|
107
|
+
* Clear all registered tools
|
|
108
|
+
*/
|
|
109
|
+
clear(): void;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=tool-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../src/lib/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAGtC;;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