@gavdi/cap-mcp 0.9.1 → 0.9.2
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/lib/mcp/tools.js +31 -4
- package/package.json +1 -1
package/lib/mcp/tools.js
CHANGED
@@ -73,8 +73,11 @@ function assignBoundOperation(params, model, server) {
|
|
73
73
|
});
|
74
74
|
return {
|
75
75
|
content: Array.isArray(response)
|
76
|
-
? response.map((el) => ({
|
77
|
-
|
76
|
+
? response.map((el) => ({
|
77
|
+
type: "text",
|
78
|
+
text: formatResponseValue(el),
|
79
|
+
}))
|
80
|
+
: [{ type: "text", text: formatResponseValue(response) }],
|
78
81
|
};
|
79
82
|
});
|
80
83
|
}
|
@@ -108,8 +111,11 @@ function assignUnboundOperation(params, model, server) {
|
|
108
111
|
const response = await service.send(model.target, args);
|
109
112
|
return {
|
110
113
|
content: Array.isArray(response)
|
111
|
-
? response.map((el) => ({
|
112
|
-
|
114
|
+
? response.map((el) => ({
|
115
|
+
type: "text",
|
116
|
+
text: formatResponseValue(el),
|
117
|
+
}))
|
118
|
+
: [{ type: "text", text: formatResponseValue(response) }],
|
113
119
|
};
|
114
120
|
});
|
115
121
|
}
|
@@ -127,6 +133,27 @@ function buildToolParameters(params) {
|
|
127
133
|
}
|
128
134
|
return result;
|
129
135
|
}
|
136
|
+
/**
|
137
|
+
* Converts a value to a string representation suitable for MCP responses
|
138
|
+
* Handles objects and arrays by JSON stringifying them instead of using String()
|
139
|
+
* @param value - The value to convert to string
|
140
|
+
* @returns String representation of the value
|
141
|
+
*/
|
142
|
+
function formatResponseValue(value) {
|
143
|
+
if (value === null || value === undefined) {
|
144
|
+
return String(value);
|
145
|
+
}
|
146
|
+
if (typeof value === "object") {
|
147
|
+
try {
|
148
|
+
return JSON.stringify(value, null, 2);
|
149
|
+
}
|
150
|
+
catch (error) {
|
151
|
+
// Fallback to String() if JSON.stringify fails (e.g., circular references)
|
152
|
+
return String(value);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
return String(value);
|
156
|
+
}
|
130
157
|
/**
|
131
158
|
* Constructs a complete Zod schema object for MCP tool input validation
|
132
159
|
* @param params - Record of parameter names to Zod schema types
|