@avidian/mcp-openapi 0.1.0 → 0.1.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/dist/index.js +32 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// src/index.ts
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { realpathSync } from "node:fs";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
|
|
6
7
|
// src/config.ts
|
|
@@ -634,19 +635,26 @@ function base64ToBlob(base64) {
|
|
|
634
635
|
import { z } from "zod/v4";
|
|
635
636
|
import { convertJsonSchemaToZod } from "zod-from-json-schema";
|
|
636
637
|
function normalizeJsonSchema(schema) {
|
|
637
|
-
|
|
638
|
+
const seen = new WeakSet;
|
|
639
|
+
return normalizeNode(schema, seen);
|
|
638
640
|
}
|
|
639
|
-
function normalizeNode(node) {
|
|
641
|
+
function normalizeNode(node, seen) {
|
|
640
642
|
if (Array.isArray(node)) {
|
|
641
|
-
|
|
643
|
+
if (seen.has(node))
|
|
644
|
+
return node;
|
|
645
|
+
seen.add(node);
|
|
646
|
+
return node.map((item) => normalizeNode(item, seen));
|
|
642
647
|
}
|
|
643
648
|
if (node === null || typeof node !== "object") {
|
|
644
649
|
return node;
|
|
645
650
|
}
|
|
651
|
+
if (seen.has(node))
|
|
652
|
+
return node;
|
|
653
|
+
seen.add(node);
|
|
646
654
|
const source = node;
|
|
647
655
|
const normalized = {};
|
|
648
656
|
for (const [key, value] of Object.entries(source)) {
|
|
649
|
-
normalized[key] = normalizeNode(value);
|
|
657
|
+
normalized[key] = normalizeNode(value, seen);
|
|
650
658
|
}
|
|
651
659
|
const nullable = normalized.nullable === true || normalized["x-nullable"] === true;
|
|
652
660
|
delete normalized.nullable;
|
|
@@ -665,7 +673,16 @@ function normalizeNode(node) {
|
|
|
665
673
|
return normalized;
|
|
666
674
|
}
|
|
667
675
|
function toZodType(schema, options) {
|
|
668
|
-
|
|
676
|
+
let base;
|
|
677
|
+
if (!schema) {
|
|
678
|
+
base = z.unknown();
|
|
679
|
+
} else {
|
|
680
|
+
try {
|
|
681
|
+
base = convertJsonSchemaToZod(normalizeJsonSchema(schema));
|
|
682
|
+
} catch {
|
|
683
|
+
base = z.unknown();
|
|
684
|
+
}
|
|
685
|
+
}
|
|
669
686
|
const described = options.description !== undefined ? base.describe(options.description) : base;
|
|
670
687
|
return options.required ? described : described.optional();
|
|
671
688
|
}
|
|
@@ -803,8 +820,16 @@ async function main() {
|
|
|
803
820
|
const transport = new StdioServerTransport;
|
|
804
821
|
await server.connect(transport);
|
|
805
822
|
}
|
|
806
|
-
|
|
807
|
-
if (
|
|
823
|
+
function isMainModule() {
|
|
824
|
+
if (process.argv[1] === undefined)
|
|
825
|
+
return false;
|
|
826
|
+
try {
|
|
827
|
+
return fileURLToPath(import.meta.url) === realpathSync(process.argv[1]);
|
|
828
|
+
} catch {
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (isMainModule()) {
|
|
808
833
|
main().catch((error) => {
|
|
809
834
|
console.error(`mcp-openapi: ${errorMessage(error)}`);
|
|
810
835
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avidian/mcp-openapi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "MCP server for OpenAPI/Swagger — gives AI agents the ability to discover, search, and call any REST API described by an OpenAPI document.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|