powerplatform-mcp 0.4.3 → 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 +34 -5
- 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
|
|
@@ -92,8 +118,10 @@ server.prompt("entity-overview", "Get an overview of a Power Platform entity", {
|
|
|
92
118
|
`- Primary Name: ${metadata.PrimaryNameAttribute}`;
|
|
93
119
|
// Get key attributes
|
|
94
120
|
const keyAttributes = attributes.value
|
|
95
|
-
.
|
|
96
|
-
|
|
121
|
+
.map((attr) => {
|
|
122
|
+
const attrType = attr["@odata.type"] || attr.odata?.type || "Unknown type";
|
|
123
|
+
return `- ${attr.LogicalName}: ${attrType}`;
|
|
124
|
+
})
|
|
97
125
|
.join('\n');
|
|
98
126
|
// Get relationships summary
|
|
99
127
|
const relationships = await service.getEntityRelationships(entityName);
|
|
@@ -544,9 +572,11 @@ server.tool("use-powerplatform-prompt", "Use a predefined prompt template for Po
|
|
|
544
572
|
`- Primary Name: ${metadata.PrimaryNameAttribute}`;
|
|
545
573
|
// Get key attributes
|
|
546
574
|
const keyAttributes = attributes.value
|
|
547
|
-
.filter((attr) => attr.IsValidForRead === true && !attr.AttributeOf)
|
|
548
575
|
//.slice(0, 10) // Limit to first 10 important attributes
|
|
549
|
-
.map((attr) =>
|
|
576
|
+
.map((attr) => {
|
|
577
|
+
const attrType = attr["@odata.type"] || attr.odata?.type || "Unknown type";
|
|
578
|
+
return `- ${attr.LogicalName}: ${attrType}`;
|
|
579
|
+
})
|
|
550
580
|
.join('\n');
|
|
551
581
|
// Get relationships summary
|
|
552
582
|
const relationships = await service.getEntityRelationships(entityName);
|
|
@@ -591,7 +621,6 @@ server.tool("use-powerplatform-prompt", "Use a predefined prompt template for Po
|
|
|
591
621
|
// Get a few important fields for the select example
|
|
592
622
|
const attributes = await service.getEntityAttributes(entityName);
|
|
593
623
|
const selectFields = attributes.value
|
|
594
|
-
.filter((attr) => attr.IsValidForRead === true && !attr.AttributeOf)
|
|
595
624
|
.slice(0, 5) // Just take first 5 for example
|
|
596
625
|
.map((attr) => attr.LogicalName)
|
|
597
626
|
.join(',');
|