powerplatform-mcp 0.4.4 → 0.4.5
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/build/PowerPlatformService.js +32 -2
- package/build/index.js +26 -0
- package/package.json +1 -1
|
@@ -45,6 +45,28 @@ export class PowerPlatformService {
|
|
|
45
45
|
throw new Error('Authentication failed');
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Handle JSON-RPC error response
|
|
50
|
+
* @param error JSON-RPC error object
|
|
51
|
+
* @returns Formatted error information
|
|
52
|
+
*/
|
|
53
|
+
handleJsonRpcError(error) {
|
|
54
|
+
// Log the error for debugging
|
|
55
|
+
console.error('JSON-RPC error:', error);
|
|
56
|
+
// Handle specific error codes
|
|
57
|
+
switch (error.code) {
|
|
58
|
+
case -32601:
|
|
59
|
+
return `Method not found: ${error.message}. Please check that you're calling a supported API method.`;
|
|
60
|
+
case -32602:
|
|
61
|
+
return `Invalid params: ${error.message}. Please check your request parameters.`;
|
|
62
|
+
case -32603:
|
|
63
|
+
return `Internal error: ${error.message}. Please try again later.`;
|
|
64
|
+
case -32000:
|
|
65
|
+
return `Server error: ${error.message}. Please check server logs for more details.`;
|
|
66
|
+
default:
|
|
67
|
+
return `RPC error ${error.code}: ${error.message}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
48
70
|
/**
|
|
49
71
|
* Make an authenticated request to the PowerPlatform API
|
|
50
72
|
*/
|
|
@@ -64,8 +86,16 @@ export class PowerPlatformService {
|
|
|
64
86
|
return response.data;
|
|
65
87
|
}
|
|
66
88
|
catch (error) {
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
// Type guard for axios error with response data
|
|
90
|
+
if (error && error.code && typeof error.code === 'number' && error.message) {
|
|
91
|
+
const jsonRpcError = error.response.data.error;
|
|
92
|
+
const errorMessage = this.handleJsonRpcError(jsonRpcError);
|
|
93
|
+
throw new Error(errorMessage);
|
|
94
|
+
}
|
|
95
|
+
// For any other type of error, convert to string safely
|
|
96
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
97
|
+
console.error('PowerPlatform API request failed:', errorMessage);
|
|
98
|
+
throw new Error(`PowerPlatform API request failed: ${errorMessage}`);
|
|
69
99
|
}
|
|
70
100
|
}
|
|
71
101
|
/**
|
package/build/index.js
CHANGED
|
@@ -39,6 +39,32 @@ function getPowerPlatformService() {
|
|
|
39
39
|
}
|
|
40
40
|
return powerPlatformService;
|
|
41
41
|
}
|
|
42
|
+
// Global error handler for JSON-RPC errors
|
|
43
|
+
function handleJsonRpcError(error) {
|
|
44
|
+
if (error && error.code && typeof error.code === 'number' && error.message) {
|
|
45
|
+
const service = getPowerPlatformService();
|
|
46
|
+
const errorMessage = service.handleJsonRpcError({
|
|
47
|
+
code: error.code,
|
|
48
|
+
message: error.message,
|
|
49
|
+
data: error.data
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
role: "assistant",
|
|
53
|
+
content: {
|
|
54
|
+
type: "text",
|
|
55
|
+
text: errorMessage
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Default error response for non-JSON-RPC errors
|
|
60
|
+
return {
|
|
61
|
+
role: "assistant",
|
|
62
|
+
content: {
|
|
63
|
+
type: "text",
|
|
64
|
+
text: `Error: ${error?.message || 'Unknown error occurred'}`
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
42
68
|
// Pre-defined PowerPlatform Prompts
|
|
43
69
|
const powerPlatformPrompts = {
|
|
44
70
|
// Entity exploration prompts
|