@0xmonaco/mcp-server 0.1.1 → 0.1.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/CHANGELOG.md +5 -11
- package/bin/cli.js +38 -35
- package/package.json +1 -1
- package/src/connect.js +37 -37
- package/src/index.js +41 -41
- package/src/initialize.js +6 -6
- package/src/search.d.ts +1 -1
- package/src/search.js +104 -104
- package/src/tools/helpers.d.ts +20 -20
- package/src/tools/helpers.js +241 -241
- package/src/tools/index.d.ts +2 -2
- package/src/tools/index.js +175 -175
- package/src/tools/zod.d.ts +5 -5
- package/src/tools/zod.js +176 -176
- package/src/tools.json +6 -6
- package/src/utils.d.ts +10 -10
- package/src/utils.js +52 -52
package/src/tools/zod.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
1
|
import { Blob } from "node:buffer";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
function panic(error) {
|
|
4
|
-
|
|
4
|
+
throw error;
|
|
5
5
|
}
|
|
6
6
|
// WebFile polyfill implementation partly taken from the fetch-blob package:
|
|
7
7
|
// https://github.com/node-fetch/fetch-blob/blob/main/file.js - MIT License
|
|
8
8
|
const WebFile = class File extends Blob {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
9
|
+
constructor(
|
|
10
|
+
init,
|
|
11
|
+
name = panic(new TypeError("File constructor requires name argument")),
|
|
12
|
+
options = {},
|
|
13
|
+
) {
|
|
14
|
+
if (arguments.length < 2) {
|
|
15
|
+
throw new TypeError(
|
|
16
|
+
`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
super(init, options);
|
|
20
|
+
this._lastModified = 0;
|
|
21
|
+
this._name = "";
|
|
22
|
+
// Simulate WebIDL type casting for NaN value in lastModified option.
|
|
23
|
+
const lastModified =
|
|
24
|
+
options.lastModified === undefined
|
|
25
|
+
? Date.now()
|
|
26
|
+
: Number(options.lastModified);
|
|
27
|
+
if (!Number.isNaN(lastModified)) {
|
|
28
|
+
this._lastModified = lastModified;
|
|
29
|
+
}
|
|
30
|
+
this._name = String(name);
|
|
31
|
+
}
|
|
32
|
+
get name() {
|
|
33
|
+
return this._name;
|
|
34
|
+
}
|
|
35
|
+
get lastModified() {
|
|
36
|
+
return this._lastModified;
|
|
37
|
+
}
|
|
38
|
+
get [Symbol.toStringTag]() {
|
|
39
|
+
return "File";
|
|
40
|
+
}
|
|
41
|
+
static [Symbol.hasInstance](object) {
|
|
42
|
+
return (
|
|
43
|
+
!!object &&
|
|
44
|
+
object instanceof Blob &&
|
|
45
|
+
/^(File)$/.test(String(object[Symbol.toStringTag]))
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
48
|
};
|
|
49
49
|
const File = typeof global.File === "undefined" ? WebFile : global.File;
|
|
50
50
|
const ANY = z.any();
|
|
@@ -64,144 +64,144 @@ const STRING = z.string();
|
|
|
64
64
|
const NUMBER = z.number();
|
|
65
65
|
const INTEGER = z.number().int();
|
|
66
66
|
export function dataSchemaArrayToZod(schemas) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
const firstSchema = dataSchemaToZod(schemas[0]);
|
|
68
|
+
if (!schemas[1]) {
|
|
69
|
+
return firstSchema;
|
|
70
|
+
}
|
|
71
|
+
const secondSchema = dataSchemaToZod(schemas[1]);
|
|
72
|
+
const zodSchemas = [firstSchema, secondSchema];
|
|
73
|
+
for (const schema of schemas.slice(2)) {
|
|
74
|
+
zodSchemas.push(dataSchemaToZod(schema));
|
|
75
|
+
}
|
|
76
|
+
return z.union(zodSchemas).array();
|
|
77
77
|
}
|
|
78
78
|
function getEnumSchema(enumList, type) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const zodSchema = z.enum(enumList.map(String));
|
|
80
|
+
if (type === "string") return zodSchema;
|
|
81
|
+
return zodSchema.transform(Number);
|
|
82
82
|
}
|
|
83
83
|
export function dataSchemaToZod(schema) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
84
|
+
if (!("type" in schema) || Object.keys(schema).length === 0) {
|
|
85
|
+
return schema.required ? ANY : ANY_OPT;
|
|
86
|
+
}
|
|
87
|
+
switch (schema.type) {
|
|
88
|
+
case "null":
|
|
89
|
+
return schema.required ? NULL : NULL_OPT;
|
|
90
|
+
case "boolean":
|
|
91
|
+
return schema.required ? BOOLEAN : BOOLEAN_OPT;
|
|
92
|
+
case "enum<string>":
|
|
93
|
+
const strEnumSchema = getEnumSchema(schema.enum, "string");
|
|
94
|
+
return schema.required ? strEnumSchema : strEnumSchema.optional();
|
|
95
|
+
case "enum<number>":
|
|
96
|
+
case "enum<integer>":
|
|
97
|
+
const numEnumSchema = getEnumSchema(schema.enum, "number");
|
|
98
|
+
return schema.required ? numEnumSchema : numEnumSchema.optional();
|
|
99
|
+
case "file":
|
|
100
|
+
return schema.required ? FILE : FILE_OPT;
|
|
101
|
+
case "any":
|
|
102
|
+
return schema.required ? ANY : ANY_OPT;
|
|
103
|
+
case "string":
|
|
104
|
+
if ("enum" in schema && Array.isArray(schema.enum)) {
|
|
105
|
+
return schema.required
|
|
106
|
+
? z.enum(schema.enum)
|
|
107
|
+
: z.enum(schema.enum).optional();
|
|
108
|
+
}
|
|
109
|
+
if (schema.format === "binary") {
|
|
110
|
+
return schema.required ? FILE : FILE_OPT;
|
|
111
|
+
}
|
|
112
|
+
let stringSchema = STRING;
|
|
113
|
+
if (schema.minLength !== undefined) {
|
|
114
|
+
stringSchema = stringSchema.min(schema.minLength);
|
|
115
|
+
}
|
|
116
|
+
if (schema.maxLength !== undefined) {
|
|
117
|
+
stringSchema = stringSchema.max(schema.maxLength);
|
|
118
|
+
}
|
|
119
|
+
if (schema.pattern !== undefined) {
|
|
120
|
+
stringSchema = stringSchema.regex(new RegExp(schema.pattern));
|
|
121
|
+
}
|
|
122
|
+
switch (schema.format) {
|
|
123
|
+
case "email":
|
|
124
|
+
stringSchema = stringSchema.email();
|
|
125
|
+
break;
|
|
126
|
+
case "uri":
|
|
127
|
+
case "url":
|
|
128
|
+
stringSchema = stringSchema.url();
|
|
129
|
+
break;
|
|
130
|
+
case "uuid":
|
|
131
|
+
stringSchema = stringSchema.uuid();
|
|
132
|
+
break;
|
|
133
|
+
case "date-time":
|
|
134
|
+
return schema.required ? DATE : DATE_OPT;
|
|
135
|
+
}
|
|
136
|
+
return schema.required ? stringSchema : stringSchema.optional();
|
|
137
|
+
case "number":
|
|
138
|
+
case "integer":
|
|
139
|
+
if ("enum" in schema && Array.isArray(schema.enum)) {
|
|
140
|
+
const numEnumSchema = getEnumSchema(schema.enum, schema.type);
|
|
141
|
+
return schema.required ? numEnumSchema : numEnumSchema.optional();
|
|
142
|
+
}
|
|
143
|
+
let numberSchema = schema.type === "integer" ? INTEGER : NUMBER;
|
|
144
|
+
if (schema.minimum !== undefined) {
|
|
145
|
+
numberSchema = numberSchema.min(schema.minimum);
|
|
146
|
+
}
|
|
147
|
+
if (schema.maximum !== undefined) {
|
|
148
|
+
numberSchema = numberSchema.max(schema.maximum);
|
|
149
|
+
}
|
|
150
|
+
if (
|
|
151
|
+
schema.exclusiveMinimum !== undefined &&
|
|
152
|
+
schema.minimum !== undefined
|
|
153
|
+
) {
|
|
154
|
+
numberSchema = numberSchema.gt(schema.minimum);
|
|
155
|
+
}
|
|
156
|
+
if (
|
|
157
|
+
schema.exclusiveMaximum !== undefined &&
|
|
158
|
+
schema.maximum !== undefined
|
|
159
|
+
) {
|
|
160
|
+
numberSchema = numberSchema.lt(schema.maximum);
|
|
161
|
+
}
|
|
162
|
+
return schema.required ? numberSchema : numberSchema.optional();
|
|
163
|
+
case "array":
|
|
164
|
+
let itemSchema;
|
|
165
|
+
let arraySchema = z.any().array();
|
|
166
|
+
if (Array.isArray(schema.items)) {
|
|
167
|
+
itemSchema = dataSchemaArrayToZod(schema.items);
|
|
168
|
+
if (schema.items.length > 1) {
|
|
169
|
+
arraySchema = itemSchema;
|
|
170
|
+
} else {
|
|
171
|
+
arraySchema = itemSchema.array();
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
itemSchema = dataSchemaToZod(schema.items);
|
|
175
|
+
arraySchema = itemSchema.array();
|
|
176
|
+
}
|
|
177
|
+
if (schema.minItems !== undefined) {
|
|
178
|
+
arraySchema = arraySchema.min(schema.minItems);
|
|
179
|
+
}
|
|
180
|
+
if (schema.maxItems !== undefined) {
|
|
181
|
+
arraySchema = arraySchema.max(schema.maxItems);
|
|
182
|
+
}
|
|
183
|
+
return schema.required ? arraySchema : arraySchema.optional();
|
|
184
|
+
case "object":
|
|
185
|
+
const shape = {};
|
|
186
|
+
const requiredProperties = schema.requiredProperties;
|
|
187
|
+
const requiredPropertiesSet = new Set(
|
|
188
|
+
requiredProperties !== null && requiredProperties !== void 0
|
|
189
|
+
? requiredProperties
|
|
190
|
+
: [],
|
|
191
|
+
);
|
|
192
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
193
|
+
const zodPropSchema = Array.isArray(propSchema)
|
|
194
|
+
? dataSchemaArrayToZod(propSchema)
|
|
195
|
+
: dataSchemaToZod(propSchema);
|
|
196
|
+
shape[key] = requiredPropertiesSet.has(key)
|
|
197
|
+
? zodPropSchema
|
|
198
|
+
: zodPropSchema.optional();
|
|
199
|
+
}
|
|
200
|
+
if (Object.keys(shape).length === 0) {
|
|
201
|
+
return schema.required ? RECORD_WITH_DEFAULT : RECORD_OPT;
|
|
202
|
+
}
|
|
203
|
+
return schema.required ? z.object(shape) : z.object(shape).optional();
|
|
204
|
+
default:
|
|
205
|
+
return ANY;
|
|
206
|
+
}
|
|
207
207
|
}
|
package/src/tools.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
{
|
|
3
|
+
"tool": {
|
|
4
|
+
"name": "search",
|
|
5
|
+
"description": "Search across the Mint Starter Kit documentation to fetch relevant context for a given query"
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
8
|
]
|
package/src/utils.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { OpenAPI } from "@mintlify/openapi-types";
|
|
2
2
|
import { AxiosResponse } from "axios";
|
|
3
3
|
export type NestedRecord =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
| string
|
|
5
|
+
| {
|
|
6
|
+
[key: string]: NestedRecord;
|
|
7
|
+
};
|
|
8
8
|
export type SimpleRecord = Record<string, NestedRecord>;
|
|
9
9
|
export declare function initializeObject(
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
obj: SimpleRecord,
|
|
11
|
+
path: string[],
|
|
12
12
|
): SimpleRecord;
|
|
13
13
|
export declare function getFileId(
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
spec: OpenAPI.Document,
|
|
15
|
+
index: number,
|
|
16
16
|
): string | number;
|
|
17
17
|
export declare function throwOnAxiosError(
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
response: AxiosResponse<any, any>,
|
|
19
|
+
errMsg: string,
|
|
20
20
|
): void;
|
|
21
21
|
export declare function formatErr(err: unknown): any;
|
package/src/utils.js
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
export function initializeObject(obj, path) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
let current = obj;
|
|
4
|
+
for (const key of path) {
|
|
5
|
+
if (!current[key] || typeof current[key] !== "object") {
|
|
6
|
+
current[key] = {};
|
|
7
|
+
}
|
|
8
|
+
current = current[key];
|
|
9
|
+
}
|
|
10
|
+
return current;
|
|
11
11
|
}
|
|
12
12
|
export function getFileId(spec, index) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
var _a;
|
|
14
|
+
return ((_a = spec.info) === null || _a === void 0 ? void 0 : _a.title) &&
|
|
15
|
+
spec.info.version
|
|
16
|
+
? `${spec.info.title} - ${spec.info.version}`
|
|
17
|
+
: index;
|
|
18
18
|
}
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
20
|
export function throwOnAxiosError(response, errMsg) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if (response.status !== 200) {
|
|
23
|
+
if (
|
|
24
|
+
((_a = response.headers["content-type"]) === null || _a === void 0
|
|
25
|
+
? void 0
|
|
26
|
+
: _a.includes("application/json")) &&
|
|
27
|
+
((_b = response.data) === null || _b === void 0 ? void 0 : _b.error)
|
|
28
|
+
) {
|
|
29
|
+
throw new Error(`${errMsg}: ${response.data.error}`);
|
|
30
|
+
} else {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`${errMsg}: ${response.status} ${response.statusText || ""}`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!response.data) {
|
|
37
|
+
throw new Error(`${errMsg}: ${response.status} ${response.statusText}`);
|
|
38
|
+
}
|
|
39
39
|
}
|
|
40
40
|
export function formatErr(err) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
41
|
+
var _a, _b;
|
|
42
|
+
if (axios.isAxiosError(err)) {
|
|
43
|
+
if (err.message) {
|
|
44
|
+
return err.message;
|
|
45
|
+
} else if (err.response) {
|
|
46
|
+
return (_b =
|
|
47
|
+
(_a = err.response.data) === null || _a === void 0
|
|
48
|
+
? void 0
|
|
49
|
+
: _a.error) !== null && _b !== void 0
|
|
50
|
+
? _b
|
|
51
|
+
: `${err.response.status} ${err.response.statusText}`;
|
|
52
|
+
} else if (err.request) {
|
|
53
|
+
return "No response received from server";
|
|
54
|
+
} else {
|
|
55
|
+
err = "An unknown error occurred";
|
|
56
|
+
}
|
|
57
|
+
} else if (err instanceof Error) {
|
|
58
|
+
return err.message;
|
|
59
|
+
} else {
|
|
60
|
+
return JSON.stringify(err, undefined, 2);
|
|
61
|
+
}
|
|
62
62
|
}
|