@centia-io/mcp-server 1.0.4 → 1.0.6
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/README.md +18 -6
- package/centia-api.json +514 -202
- package/dist/index.js +46 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -159,6 +159,8 @@ function normalizeJsonSchemaForMCP(schema) {
|
|
|
159
159
|
"date-time",
|
|
160
160
|
"date",
|
|
161
161
|
"time",
|
|
162
|
+
"binary",
|
|
163
|
+
"url",
|
|
162
164
|
]);
|
|
163
165
|
const result = {};
|
|
164
166
|
for (const [k, v] of Object.entries(schema)) {
|
|
@@ -264,6 +266,8 @@ for (const [pathStr, pathItem] of Object.entries(apiSpec.paths)) {
|
|
|
264
266
|
headerParams: [],
|
|
265
267
|
bodyParams: [],
|
|
266
268
|
isBodyFlattened: false,
|
|
269
|
+
contentType: "application/json",
|
|
270
|
+
binaryParams: [],
|
|
267
271
|
};
|
|
268
272
|
// Handle path/query/header parameters
|
|
269
273
|
for (const param of parameters) {
|
|
@@ -286,11 +290,21 @@ for (const [pathStr, pathItem] of Object.entries(apiSpec.paths)) {
|
|
|
286
290
|
toolMeta.headerParams.push(resolvedParam.name);
|
|
287
291
|
}
|
|
288
292
|
// Handle request body
|
|
289
|
-
|
|
290
|
-
|
|
293
|
+
const content = requestBody?.content;
|
|
294
|
+
const jsonContent = content?.["application/json"];
|
|
295
|
+
const multipartContent = content?.["multipart/form-data"];
|
|
296
|
+
if (jsonContent?.schema || multipartContent?.schema) {
|
|
297
|
+
const bodySchema = resolveSchema(jsonContent?.schema || multipartContent?.schema);
|
|
298
|
+
if (multipartContent) {
|
|
299
|
+
toolMeta.contentType = "multipart/form-data";
|
|
300
|
+
}
|
|
291
301
|
if (bodySchema.type === "object" && bodySchema.properties) {
|
|
292
302
|
toolMeta.isBodyFlattened = true;
|
|
293
303
|
for (const [key, value] of Object.entries(bodySchema.properties)) {
|
|
304
|
+
const resolvedValue = resolveSchema(value);
|
|
305
|
+
if (resolvedValue.format === "binary") {
|
|
306
|
+
toolMeta.binaryParams.push(key);
|
|
307
|
+
}
|
|
294
308
|
properties[key] = normalizeJsonSchemaForMCP(sanitizeSchemaForMCP(value));
|
|
295
309
|
toolMeta.bodyParams.push(key);
|
|
296
310
|
}
|
|
@@ -361,7 +375,29 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
361
375
|
}
|
|
362
376
|
// Body
|
|
363
377
|
if (toolMeta.bodyParams.length > 0) {
|
|
364
|
-
if (toolMeta.
|
|
378
|
+
if (toolMeta.contentType === "multipart/form-data") {
|
|
379
|
+
const formData = new FormData();
|
|
380
|
+
for (const paramName of toolMeta.bodyParams) {
|
|
381
|
+
if (safeArgs[paramName] !== undefined) {
|
|
382
|
+
const value = safeArgs[paramName];
|
|
383
|
+
if (toolMeta.binaryParams.includes(paramName) && typeof value === "string") {
|
|
384
|
+
if (fs.existsSync(value)) {
|
|
385
|
+
const fileContent = fs.readFileSync(value);
|
|
386
|
+
const blob = new Blob([fileContent]);
|
|
387
|
+
formData.append(paramName, blob, path.basename(value));
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
formData.append(paramName, value);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
formData.append(paramName, value);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
config.data = formData;
|
|
399
|
+
}
|
|
400
|
+
else if (toolMeta.isBodyFlattened) {
|
|
365
401
|
const body = {};
|
|
366
402
|
for (const paramName of toolMeta.bodyParams) {
|
|
367
403
|
if (safeArgs[paramName] !== undefined) {
|
|
@@ -375,12 +411,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
375
411
|
}
|
|
376
412
|
}
|
|
377
413
|
try {
|
|
378
|
-
const response = await axios({ ...config, url });
|
|
414
|
+
const response = await axios({ ...config, url, maxRedirects: 0, validateStatus: (status) => status < 400 });
|
|
379
415
|
return {
|
|
380
416
|
content: [
|
|
381
417
|
{
|
|
382
418
|
type: "text",
|
|
383
|
-
text: JSON.stringify(response.data, null, 2),
|
|
419
|
+
text: response.data != null ? JSON.stringify(response.data, null, 2) : "OK",
|
|
384
420
|
},
|
|
385
421
|
],
|
|
386
422
|
};
|
|
@@ -391,9 +427,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
391
427
|
content: [
|
|
392
428
|
{
|
|
393
429
|
type: "text",
|
|
394
|
-
text: error.response
|
|
395
|
-
? JSON.stringify(error.response.data, null, 2)
|
|
396
|
-
: error.message,
|
|
430
|
+
text: error.response.data.message || error.message,
|
|
397
431
|
},
|
|
398
432
|
],
|
|
399
433
|
};
|
|
@@ -402,6 +436,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
402
436
|
async function main() {
|
|
403
437
|
const transport = new StdioServerTransport();
|
|
404
438
|
await server.connect(transport);
|
|
439
|
+
await server.sendLoggingMessage({
|
|
440
|
+
level: "info",
|
|
441
|
+
data: "Server started successfully",
|
|
442
|
+
});
|
|
405
443
|
console.error("Centia MCP Server running on stdio");
|
|
406
444
|
}
|
|
407
445
|
main().catch((error) => {
|