@mainwp/mcp 1.0.0-beta.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/LICENSE +674 -0
- package/README.md +1034 -0
- package/dist/abilities.d.ts +144 -0
- package/dist/abilities.d.ts.map +1 -0
- package/dist/abilities.js +529 -0
- package/dist/abilities.js.map +1 -0
- package/dist/config.d.ts +135 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +405 -0
- package/dist/config.js.map +1 -0
- package/dist/confirmation-responses.d.ts +44 -0
- package/dist/confirmation-responses.d.ts.map +1 -0
- package/dist/confirmation-responses.js +120 -0
- package/dist/confirmation-responses.js.map +1 -0
- package/dist/errors.d.ts +118 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +206 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +506 -0
- package/dist/index.js.map +1 -0
- package/dist/logging.d.ts +34 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +74 -0
- package/dist/logging.js.map +1 -0
- package/dist/naming.d.ts +23 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +37 -0
- package/dist/naming.js.map +1 -0
- package/dist/prompts.d.ts +22 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +414 -0
- package/dist/prompts.js.map +1 -0
- package/dist/retry.d.ts +77 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +206 -0
- package/dist/retry.js.map +1 -0
- package/dist/security.d.ts +41 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +154 -0
- package/dist/security.js.map +1 -0
- package/dist/tools.d.ts +82 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +861 -0
- package/dist/tools.js.map +1 -0
- package/package.json +73 -0
- package/settings.example.json +30 -0
- package/settings.schema.json +129 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confirmation Flow Response Builders
|
|
3
|
+
*
|
|
4
|
+
* Centralized construction of domain-level JSON payloads for the two-phase
|
|
5
|
+
* confirmation flow. These are workflow responses returned as successful
|
|
6
|
+
* tool results to guide the AI's next action - distinct from protocol-level
|
|
7
|
+
* MCP errors in errors.ts.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Response when safe mode blocks a destructive operation
|
|
11
|
+
*/
|
|
12
|
+
export function buildSafeModeBlockedResponse(ctx) {
|
|
13
|
+
return {
|
|
14
|
+
error: 'SAFE_MODE_BLOCKED',
|
|
15
|
+
message: `Safe mode blocked destructive operation: ${ctx.tool}`,
|
|
16
|
+
details: {
|
|
17
|
+
tool: ctx.tool,
|
|
18
|
+
ability: ctx.ability,
|
|
19
|
+
reason: 'Destructive operations are disabled in safe mode.',
|
|
20
|
+
resolution: 'To execute this operation, disable safe mode by setting MAINWP_SAFE_MODE=false or use a non-production environment.',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Response when user_confirmed is used on a tool without confirm parameter support
|
|
26
|
+
*/
|
|
27
|
+
export function buildInvalidParameterResponse(ctx) {
|
|
28
|
+
return {
|
|
29
|
+
error: 'INVALID_PARAMETER',
|
|
30
|
+
message: 'user_confirmed parameter not supported for this tool',
|
|
31
|
+
details: {
|
|
32
|
+
tool: ctx.tool,
|
|
33
|
+
ability: ctx.ability,
|
|
34
|
+
reason: 'This tool does not support the confirmation flow (no confirm parameter)',
|
|
35
|
+
resolution: 'Remove user_confirmed parameter and call the tool directly',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Response when user_confirmed and dry_run are both set (conflicting intent)
|
|
41
|
+
*/
|
|
42
|
+
export function buildConflictingParametersResponse(ctx) {
|
|
43
|
+
return {
|
|
44
|
+
error: 'CONFLICTING_PARAMETERS',
|
|
45
|
+
message: 'Cannot use user_confirmed and dry_run together',
|
|
46
|
+
details: {
|
|
47
|
+
tool: ctx.tool,
|
|
48
|
+
ability: ctx.ability,
|
|
49
|
+
reason: 'dry_run is for read-only previews, user_confirmed is for confirmed execution',
|
|
50
|
+
resolution: 'Remove dry_run to execute with confirmation, or remove user_confirmed to preview only',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Response when a preview is generated and confirmation is required
|
|
56
|
+
*/
|
|
57
|
+
export function buildConfirmationRequiredResponse(ctx, preview, token) {
|
|
58
|
+
return {
|
|
59
|
+
status: 'CONFIRMATION_REQUIRED',
|
|
60
|
+
next_action: 'show_preview_and_confirm',
|
|
61
|
+
message: 'Preview generated. Review the changes below and confirm to proceed.',
|
|
62
|
+
preview,
|
|
63
|
+
confirmation_token: token,
|
|
64
|
+
instructions: 'Show the preview to the user. If they approve, call this tool again with ' +
|
|
65
|
+
'user_confirmed: true and confirmation_token: "<token above>".',
|
|
66
|
+
metadata: {
|
|
67
|
+
tool: ctx.tool,
|
|
68
|
+
ability: ctx.ability,
|
|
69
|
+
expiresIn: '5 minutes',
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Response when user_confirmed is set but no preview was requested first
|
|
75
|
+
*/
|
|
76
|
+
export function buildPreviewRequiredResponse(ctx) {
|
|
77
|
+
return {
|
|
78
|
+
error: 'PREVIEW_REQUIRED',
|
|
79
|
+
next_action: 'request_preview_first',
|
|
80
|
+
message: 'No preview found. You must first call with confirm: true to generate a preview.',
|
|
81
|
+
details: {
|
|
82
|
+
tool: ctx.tool,
|
|
83
|
+
ability: ctx.ability,
|
|
84
|
+
reason: 'user_confirmed: true requires a prior preview request',
|
|
85
|
+
resolution: 'Call the tool with confirm: true (without user_confirmed) to generate a preview first.',
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Response when the preview has expired (older than 5 minutes)
|
|
91
|
+
*/
|
|
92
|
+
export function buildPreviewExpiredResponse(ctx) {
|
|
93
|
+
return {
|
|
94
|
+
error: 'PREVIEW_EXPIRED',
|
|
95
|
+
next_action: 'request_new_preview',
|
|
96
|
+
message: 'Preview has expired. Please request a new preview.',
|
|
97
|
+
details: {
|
|
98
|
+
tool: ctx.tool,
|
|
99
|
+
ability: ctx.ability,
|
|
100
|
+
reason: 'Preview expired after 5 minutes',
|
|
101
|
+
resolution: 'Call the tool again with confirm: true to generate a fresh preview.',
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Response when an idempotent operation had no effect (already in desired state)
|
|
107
|
+
*/
|
|
108
|
+
export function buildNoChangeResponse(ctx, code, reason) {
|
|
109
|
+
return {
|
|
110
|
+
status: 'NO_CHANGE',
|
|
111
|
+
message: `Operation had no effect: ${ctx.tool}`,
|
|
112
|
+
details: {
|
|
113
|
+
tool: ctx.tool,
|
|
114
|
+
ability: ctx.ability,
|
|
115
|
+
code,
|
|
116
|
+
reason,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=confirmation-responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmation-responses.js","sourceRoot":"","sources":["../src/confirmation-responses.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAAC,GAAwB;IACnE,OAAO;QACL,KAAK,EAAE,mBAAmB;QAC1B,OAAO,EAAE,4CAA4C,GAAG,CAAC,IAAI,EAAE;QAC/D,OAAO,EAAE;YACP,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,mDAAmD;YAC3D,UAAU,EACR,qHAAqH;SACxH;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAAC,GAAwB;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EG;AACH,MAAM,UAAU,2BAA2B,CAAC,GAAwB;IAClE,OAAO;QACL,KAAK,EAAE,iBAAiB;QACxB,WAAW,EAAE,qBAAqB;QAClC,OAAO,EAAE,oDAAoD;QAC7D,OAAO,EAAE;YACP,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,iCAAiC;YACzC,UAAU,EAAE,qEAAqE;SAClF;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,GAAwB,EACxB,IAAY,EACZ,MAAc;IAEd,OAAO;QACL,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,4BAA4B,GAAG,CAAC,IAAI,EAAE;QAC/C,OAAO,EAAE;YACP,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI;YACJ,MAAM;SACP;KACF,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Error Handling
|
|
3
|
+
*
|
|
4
|
+
* Standardized error codes following JSON-RPC 2.0 specification
|
|
5
|
+
* and MCP conventions for consistent error reporting.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* JSON-RPC 2.0 standard error codes
|
|
9
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
10
|
+
*/
|
|
11
|
+
export declare const MCP_ERROR_CODES: {
|
|
12
|
+
readonly PARSE_ERROR: -32700;
|
|
13
|
+
readonly INVALID_REQUEST: -32600;
|
|
14
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
15
|
+
readonly INVALID_PARAMS: -32602;
|
|
16
|
+
readonly INTERNAL_ERROR: -32603;
|
|
17
|
+
readonly SERVER_ERROR: -32000;
|
|
18
|
+
readonly TIMEOUT: -32001;
|
|
19
|
+
readonly RESOURCE_NOT_FOUND: -32002;
|
|
20
|
+
readonly TOOL_NOT_FOUND: -32003;
|
|
21
|
+
readonly PROMPT_NOT_FOUND: -32004;
|
|
22
|
+
readonly ABILITY_NOT_FOUND: -32005;
|
|
23
|
+
readonly RESOURCE_EXHAUSTED: -32006;
|
|
24
|
+
readonly PERMISSION_DENIED: -32008;
|
|
25
|
+
readonly UNAUTHORIZED: -32010;
|
|
26
|
+
readonly RATE_LIMITED: -32029;
|
|
27
|
+
readonly CANCELLED: -32099;
|
|
28
|
+
};
|
|
29
|
+
export type McpErrorCode = (typeof MCP_ERROR_CODES)[keyof typeof MCP_ERROR_CODES];
|
|
30
|
+
/**
|
|
31
|
+
* Structured error response matching MCP/JSON-RPC specification
|
|
32
|
+
*/
|
|
33
|
+
export interface McpErrorResponse {
|
|
34
|
+
error: {
|
|
35
|
+
code: McpErrorCode;
|
|
36
|
+
message: string;
|
|
37
|
+
data?: Record<string, unknown>;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Custom error class for MCP errors with code support
|
|
42
|
+
*/
|
|
43
|
+
export declare class McpError extends Error {
|
|
44
|
+
readonly code: McpErrorCode;
|
|
45
|
+
readonly data?: Record<string, unknown>;
|
|
46
|
+
constructor(code: McpErrorCode, message: string, data?: Record<string, unknown>);
|
|
47
|
+
/**
|
|
48
|
+
* Convert to MCP error response format
|
|
49
|
+
*/
|
|
50
|
+
toResponse(): McpErrorResponse;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Factory for creating common MCP errors
|
|
54
|
+
*/
|
|
55
|
+
export declare const McpErrorFactory: {
|
|
56
|
+
/**
|
|
57
|
+
* Invalid parameters error (validation failures)
|
|
58
|
+
*/
|
|
59
|
+
invalidParams(message: string, data?: Record<string, unknown>): McpError;
|
|
60
|
+
/**
|
|
61
|
+
* Tool not found error
|
|
62
|
+
*/
|
|
63
|
+
toolNotFound(toolName: string): McpError;
|
|
64
|
+
/**
|
|
65
|
+
* Resource not found error
|
|
66
|
+
*/
|
|
67
|
+
resourceNotFound(uri: string): McpError;
|
|
68
|
+
/**
|
|
69
|
+
* Prompt not found error
|
|
70
|
+
*/
|
|
71
|
+
promptNotFound(promptName: string): McpError;
|
|
72
|
+
/**
|
|
73
|
+
* Ability not found error
|
|
74
|
+
*/
|
|
75
|
+
abilityNotFound(abilityName: string): McpError;
|
|
76
|
+
/**
|
|
77
|
+
* Resource exhausted error (e.g., session data limit exceeded)
|
|
78
|
+
*/
|
|
79
|
+
resourceExhausted(message: string, data?: Record<string, unknown>): McpError;
|
|
80
|
+
/**
|
|
81
|
+
* Internal server error
|
|
82
|
+
*/
|
|
83
|
+
internal(message: string, data?: Record<string, unknown>): McpError;
|
|
84
|
+
/**
|
|
85
|
+
* Operation cancelled error
|
|
86
|
+
*/
|
|
87
|
+
cancelled(): McpError;
|
|
88
|
+
/**
|
|
89
|
+
* Permission denied error
|
|
90
|
+
*/
|
|
91
|
+
permissionDenied(message?: string): McpError;
|
|
92
|
+
/**
|
|
93
|
+
* Unauthorized error
|
|
94
|
+
*/
|
|
95
|
+
unauthorized(message?: string): McpError;
|
|
96
|
+
/**
|
|
97
|
+
* Rate limited error
|
|
98
|
+
*/
|
|
99
|
+
rateLimited(): McpError;
|
|
100
|
+
/**
|
|
101
|
+
* Timeout error
|
|
102
|
+
*/
|
|
103
|
+
timeout(message?: string): McpError;
|
|
104
|
+
/**
|
|
105
|
+
* Server error (generic)
|
|
106
|
+
*/
|
|
107
|
+
server(message: string, data?: Record<string, unknown>): McpError;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Convert any error to an MCP error response
|
|
111
|
+
*/
|
|
112
|
+
export declare function toMcpErrorResponse(error: unknown, sanitize?: (msg: string) => string): McpErrorResponse;
|
|
113
|
+
/**
|
|
114
|
+
* Format an MCP error response as JSON string for tool responses.
|
|
115
|
+
* Uses compact JSON (no whitespace) for consistency with responseFormat='compact' default.
|
|
116
|
+
*/
|
|
117
|
+
export declare function formatErrorResponse(error: unknown, sanitize?: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;sBACe,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ;IAInE;;OAEG;iBACU,QAAQ;IAIrB;;OAEG;wCAC8C,QAAQ;IAIzD;;OAEG;oCACqC,QAAQ;IAIhD;;OAEG;mBACY,QAAQ;IAIvB;;OAEG;+BACqC,QAAQ;IAIhD;;OAEG;oBACa,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ;CAGlE,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GACjC,gBAAgB,CA+ClB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAE9F"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Error Handling
|
|
3
|
+
*
|
|
4
|
+
* Standardized error codes following JSON-RPC 2.0 specification
|
|
5
|
+
* and MCP conventions for consistent error reporting.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* JSON-RPC 2.0 standard error codes
|
|
9
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
10
|
+
*/
|
|
11
|
+
export const MCP_ERROR_CODES = {
|
|
12
|
+
// Standard JSON-RPC errors (-32700 to -32600)
|
|
13
|
+
PARSE_ERROR: -32700,
|
|
14
|
+
INVALID_REQUEST: -32600,
|
|
15
|
+
METHOD_NOT_FOUND: -32601,
|
|
16
|
+
INVALID_PARAMS: -32602,
|
|
17
|
+
INTERNAL_ERROR: -32603,
|
|
18
|
+
// Server errors (reserved range: -32000 to -32099)
|
|
19
|
+
SERVER_ERROR: -32000,
|
|
20
|
+
TIMEOUT: -32001,
|
|
21
|
+
RESOURCE_NOT_FOUND: -32002,
|
|
22
|
+
TOOL_NOT_FOUND: -32003,
|
|
23
|
+
PROMPT_NOT_FOUND: -32004,
|
|
24
|
+
ABILITY_NOT_FOUND: -32005,
|
|
25
|
+
RESOURCE_EXHAUSTED: -32006,
|
|
26
|
+
PERMISSION_DENIED: -32008,
|
|
27
|
+
UNAUTHORIZED: -32010,
|
|
28
|
+
RATE_LIMITED: -32029,
|
|
29
|
+
CANCELLED: -32099,
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Custom error class for MCP errors with code support
|
|
33
|
+
*/
|
|
34
|
+
export class McpError extends Error {
|
|
35
|
+
code;
|
|
36
|
+
data;
|
|
37
|
+
constructor(code, message, data) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = 'McpError';
|
|
40
|
+
this.code = code;
|
|
41
|
+
this.data = data;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert to MCP error response format
|
|
45
|
+
*/
|
|
46
|
+
toResponse() {
|
|
47
|
+
const response = {
|
|
48
|
+
error: {
|
|
49
|
+
code: this.code,
|
|
50
|
+
message: this.message,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
if (this.data) {
|
|
54
|
+
response.error.data = this.data;
|
|
55
|
+
}
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Factory for creating common MCP errors
|
|
61
|
+
*/
|
|
62
|
+
export const McpErrorFactory = {
|
|
63
|
+
/**
|
|
64
|
+
* Invalid parameters error (validation failures)
|
|
65
|
+
*/
|
|
66
|
+
invalidParams(message, data) {
|
|
67
|
+
return new McpError(MCP_ERROR_CODES.INVALID_PARAMS, message, data);
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Tool not found error
|
|
71
|
+
*/
|
|
72
|
+
toolNotFound(toolName) {
|
|
73
|
+
return new McpError(MCP_ERROR_CODES.TOOL_NOT_FOUND, `Tool not found: ${toolName}`, {
|
|
74
|
+
tool: toolName,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Resource not found error
|
|
79
|
+
*/
|
|
80
|
+
resourceNotFound(uri) {
|
|
81
|
+
return new McpError(MCP_ERROR_CODES.RESOURCE_NOT_FOUND, `Resource not found: ${uri}`, { uri });
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Prompt not found error
|
|
85
|
+
*/
|
|
86
|
+
promptNotFound(promptName) {
|
|
87
|
+
return new McpError(MCP_ERROR_CODES.PROMPT_NOT_FOUND, `Prompt not found: ${promptName}`, {
|
|
88
|
+
prompt: promptName,
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Ability not found error
|
|
93
|
+
*/
|
|
94
|
+
abilityNotFound(abilityName) {
|
|
95
|
+
return new McpError(MCP_ERROR_CODES.ABILITY_NOT_FOUND, `Ability not found: ${abilityName}`, {
|
|
96
|
+
ability: abilityName,
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Resource exhausted error (e.g., session data limit exceeded)
|
|
101
|
+
*/
|
|
102
|
+
resourceExhausted(message, data) {
|
|
103
|
+
return new McpError(MCP_ERROR_CODES.RESOURCE_EXHAUSTED, message, data);
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* Internal server error
|
|
107
|
+
*/
|
|
108
|
+
internal(message, data) {
|
|
109
|
+
return new McpError(MCP_ERROR_CODES.INTERNAL_ERROR, message, data);
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Operation cancelled error
|
|
113
|
+
*/
|
|
114
|
+
cancelled() {
|
|
115
|
+
return new McpError(MCP_ERROR_CODES.CANCELLED, 'Operation cancelled');
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* Permission denied error
|
|
119
|
+
*/
|
|
120
|
+
permissionDenied(message = 'Permission denied') {
|
|
121
|
+
return new McpError(MCP_ERROR_CODES.PERMISSION_DENIED, message);
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Unauthorized error
|
|
125
|
+
*/
|
|
126
|
+
unauthorized(message = 'Unauthorized') {
|
|
127
|
+
return new McpError(MCP_ERROR_CODES.UNAUTHORIZED, message);
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Rate limited error
|
|
131
|
+
*/
|
|
132
|
+
rateLimited() {
|
|
133
|
+
return new McpError(MCP_ERROR_CODES.RATE_LIMITED, 'Rate limit exceeded');
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* Timeout error
|
|
137
|
+
*/
|
|
138
|
+
timeout(message = 'Request timed out') {
|
|
139
|
+
return new McpError(MCP_ERROR_CODES.TIMEOUT, message);
|
|
140
|
+
},
|
|
141
|
+
/**
|
|
142
|
+
* Server error (generic)
|
|
143
|
+
*/
|
|
144
|
+
server(message, data) {
|
|
145
|
+
return new McpError(MCP_ERROR_CODES.SERVER_ERROR, message, data);
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Convert any error to an MCP error response
|
|
150
|
+
*/
|
|
151
|
+
export function toMcpErrorResponse(error, sanitize) {
|
|
152
|
+
if (error instanceof McpError) {
|
|
153
|
+
// If sanitize function provided, apply it to the message
|
|
154
|
+
if (sanitize) {
|
|
155
|
+
return {
|
|
156
|
+
error: {
|
|
157
|
+
code: error.code,
|
|
158
|
+
message: sanitize(error.message),
|
|
159
|
+
...(error.data && { data: error.data }),
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return error.toResponse();
|
|
164
|
+
}
|
|
165
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
166
|
+
const sanitizedMessage = sanitize ? sanitize(message) : message;
|
|
167
|
+
// Try to infer error code from message
|
|
168
|
+
let code = MCP_ERROR_CODES.INTERNAL_ERROR;
|
|
169
|
+
if (message.includes('cancelled') || message.includes('aborted')) {
|
|
170
|
+
code = MCP_ERROR_CODES.CANCELLED;
|
|
171
|
+
}
|
|
172
|
+
else if (message.includes('not found') || message.includes('Unknown')) {
|
|
173
|
+
code = MCP_ERROR_CODES.RESOURCE_NOT_FOUND;
|
|
174
|
+
}
|
|
175
|
+
else if (message.includes('limit exceeded') || message.includes('exhausted')) {
|
|
176
|
+
code = MCP_ERROR_CODES.RESOURCE_EXHAUSTED;
|
|
177
|
+
}
|
|
178
|
+
else if (message.includes('invalid') ||
|
|
179
|
+
message.includes('must be') ||
|
|
180
|
+
message.includes('exceeds')) {
|
|
181
|
+
code = MCP_ERROR_CODES.INVALID_PARAMS;
|
|
182
|
+
}
|
|
183
|
+
else if (message.includes('unauthorized') || message.includes('authentication')) {
|
|
184
|
+
code = MCP_ERROR_CODES.UNAUTHORIZED;
|
|
185
|
+
}
|
|
186
|
+
else if (message.includes('permission') || message.includes('forbidden')) {
|
|
187
|
+
code = MCP_ERROR_CODES.PERMISSION_DENIED;
|
|
188
|
+
}
|
|
189
|
+
else if (message.includes('timeout')) {
|
|
190
|
+
code = MCP_ERROR_CODES.TIMEOUT;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
error: {
|
|
194
|
+
code,
|
|
195
|
+
message: sanitizedMessage,
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Format an MCP error response as JSON string for tool responses.
|
|
201
|
+
* Uses compact JSON (no whitespace) for consistency with responseFormat='compact' default.
|
|
202
|
+
*/
|
|
203
|
+
export function formatErrorResponse(error, sanitize) {
|
|
204
|
+
return JSON.stringify(toMcpErrorResponse(error, sanitize));
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,8CAA8C;IAC9C,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;QACvC,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC;IACjC,CAAC;IAED,OAAO;QACL,KAAK,EAAE;YACL,IAAI;YACJ,OAAO,EAAE,gBAAgB;SAC1B;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc,EAAE,QAAkC;IACpF,OAAO,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* MainWP MCP Server
|
|
4
|
+
*
|
|
5
|
+
* Model Context Protocol server that exposes MainWP Dashboard abilities
|
|
6
|
+
* as MCP tools for AI assistants like Claude.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* MAINWP_URL=https://dashboard.local MAINWP_TOKEN=xxx node dist/index.js
|
|
10
|
+
*
|
|
11
|
+
* Environment Variables:
|
|
12
|
+
* - MAINWP_URL: Base URL of MainWP Dashboard (required)
|
|
13
|
+
* - MAINWP_TOKEN: Bearer token for authentication (required)
|
|
14
|
+
* - MAINWP_SKIP_SSL_VERIFY: Set to "true" to skip SSL verification (optional)
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG"}
|