modality-kit 0.14.11 → 0.14.13
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/dist/index.js +22 -13
- package/dist/types/index.d.ts +1 -1
- package/dist/types/util_response.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36,20 +36,11 @@ var ContentType = [
|
|
|
36
36
|
"resource_link",
|
|
37
37
|
"resource"
|
|
38
38
|
];
|
|
39
|
-
function
|
|
40
|
-
const data = structuredClone(successData);
|
|
39
|
+
function mergeResponsesContent(content) {
|
|
41
40
|
const contentData = content ? structuredClone(content) : null;
|
|
42
|
-
const
|
|
43
|
-
isError: false,
|
|
44
|
-
content: [
|
|
45
|
-
{
|
|
46
|
-
type: "text",
|
|
47
|
-
text: JSON.stringify(data)
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
};
|
|
41
|
+
const contentBlock = new Array;
|
|
51
42
|
if (Array.isArray(contentData)) {
|
|
52
|
-
|
|
43
|
+
contentBlock.push(...contentData.map((item) => {
|
|
53
44
|
if (typeof item === "string") {
|
|
54
45
|
return { type: "text", text: item };
|
|
55
46
|
} else if (item.type && ContentType.includes(item.type)) {
|
|
@@ -59,11 +50,28 @@ function formatSuccessResponse(successData, content) {
|
|
|
59
50
|
}
|
|
60
51
|
}));
|
|
61
52
|
} else if (contentData != null) {
|
|
62
|
-
|
|
53
|
+
contentBlock.push({
|
|
63
54
|
type: "text",
|
|
64
55
|
text: typeof contentData === "string" ? contentData : JSON.stringify(contentData)
|
|
65
56
|
});
|
|
66
57
|
}
|
|
58
|
+
return contentBlock;
|
|
59
|
+
}
|
|
60
|
+
function formatSuccessResponse(successData, content) {
|
|
61
|
+
const data = structuredClone(successData);
|
|
62
|
+
const result = {
|
|
63
|
+
isError: false,
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: "text",
|
|
67
|
+
text: JSON.stringify(data)
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
const contetnBlock = mergeResponsesContent(content);
|
|
72
|
+
if (contetnBlock.length > 0) {
|
|
73
|
+
result.content.push(...contetnBlock);
|
|
74
|
+
}
|
|
67
75
|
return result;
|
|
68
76
|
}
|
|
69
77
|
function formatErrorResponse(errorData, operation, meta) {
|
|
@@ -6016,6 +6024,7 @@ class SimpleCache {
|
|
|
6016
6024
|
}
|
|
6017
6025
|
export {
|
|
6018
6026
|
withErrorHandling,
|
|
6027
|
+
mergeResponsesContent,
|
|
6019
6028
|
loadVersion,
|
|
6020
6029
|
isTestEnvironment,
|
|
6021
6030
|
getLoggerInstance,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { formatErrorResponse, formatSuccessResponse } from "./util_response";
|
|
1
|
+
export { formatErrorResponse, formatSuccessResponse, mergeResponsesContent } from "./util_response";
|
|
2
2
|
export { getLoggerInstance, type ModalityLogger } from "./util_logger";
|
|
3
3
|
export { withErrorHandling } from "./util_error";
|
|
4
4
|
export { ErrorCode } from "./ErrorCode";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
1
|
+
import type { CallToolResult, ContentBlock } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Utility functions for formatting MCP responses
|
|
4
4
|
*
|
|
@@ -25,6 +25,7 @@ interface ErrorData extends Record<string, any> {
|
|
|
25
25
|
message: string;
|
|
26
26
|
operation?: string;
|
|
27
27
|
}
|
|
28
|
+
export declare function mergeResponsesContent(content: any): ContentBlock[];
|
|
28
29
|
export declare function formatSuccessResponse(successData: SuccessData, content?: any): CallToolResult;
|
|
29
30
|
/**
|
|
30
31
|
* Format an error response for MCP tools using generic error data
|
package/package.json
CHANGED