@0xmonaco/mcp-server 0.1.1 → 0.3.0
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 +7 -11
- package/bin/cli.js +38 -35
- package/package.json +2 -2
- package/src/connect.js +37 -37
- package/src/index.js +41 -41
- package/src/initialize.js +6 -6
- package/src/search.d.ts +1 -3
- package/src/search.js +104 -104
- package/src/tools/helpers.d.ts +5 -16
- package/src/tools/helpers.js +241 -241
- package/src/tools/index.d.ts +1 -4
- package/src/tools/index.js +175 -175
- package/src/tools/zod.d.ts +2 -9
- package/src/tools/zod.js +176 -176
- package/src/tools.json +6 -6
- package/src/utils.d.ts +3 -12
- package/src/utils.js +52 -52
package/src/tools/index.js
CHANGED
|
@@ -1,185 +1,185 @@
|
|
|
1
1
|
var __awaiter =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
34
|
import axios, { isAxiosError } from "axios";
|
|
35
35
|
import dashify from "dashify";
|
|
36
36
|
import fs from "node:fs";
|
|
37
37
|
import path from "node:path";
|
|
38
38
|
import { fileURLToPath } from "node:url";
|
|
39
39
|
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
convertEndpointToCategorizedZod,
|
|
41
|
+
convertSecurityParameterSection,
|
|
42
|
+
convertStrToTitle,
|
|
43
|
+
findNextIteration,
|
|
44
|
+
loadEnv,
|
|
45
45
|
} from "./helpers.js";
|
|
46
46
|
export function createTools(server, existingTools) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const toolsDir = path.join(fileURLToPath(import.meta.url), "..", "..");
|
|
49
|
+
let tools = JSON.parse(
|
|
50
|
+
fs.readFileSync(path.join(toolsDir, "tools.json"), "utf-8"),
|
|
51
|
+
);
|
|
52
|
+
tools = tools.filter((tool) => tool.endpoint);
|
|
53
|
+
tools.forEach(({ uuid, endpoint }) => {
|
|
54
|
+
const envVars = loadEnv(uuid);
|
|
55
|
+
const {
|
|
56
|
+
url: urlSchema,
|
|
57
|
+
method: methodSchema,
|
|
58
|
+
paths: pathsSchema,
|
|
59
|
+
queries: queriesSchema,
|
|
60
|
+
body: bodySchema,
|
|
61
|
+
headers: headersSchema,
|
|
62
|
+
cookies: cookiesSchema,
|
|
63
|
+
} = convertEndpointToCategorizedZod(uuid, endpoint);
|
|
64
|
+
const serverArgumentsSchemas = Object.assign(
|
|
65
|
+
Object.assign(
|
|
66
|
+
Object.assign(
|
|
67
|
+
Object.assign(Object.assign({}, pathsSchema), queriesSchema),
|
|
68
|
+
bodySchema,
|
|
69
|
+
),
|
|
70
|
+
headersSchema,
|
|
71
|
+
),
|
|
72
|
+
cookiesSchema,
|
|
73
|
+
);
|
|
74
|
+
if (!endpoint.title) {
|
|
75
|
+
endpoint.title = `${endpoint.method} ${convertStrToTitle(endpoint.path)}`;
|
|
76
|
+
}
|
|
77
|
+
if (existingTools.has(endpoint.title)) {
|
|
78
|
+
const lastCount = findNextIteration(existingTools, endpoint.title);
|
|
79
|
+
endpoint.title = `${endpoint.title}---${lastCount}`;
|
|
80
|
+
}
|
|
81
|
+
if (endpoint.title.length > 64) {
|
|
82
|
+
endpoint.title = endpoint.title.slice(0, -64);
|
|
83
|
+
}
|
|
84
|
+
existingTools.add(endpoint.title);
|
|
85
|
+
server.tool(
|
|
86
|
+
dashify(endpoint.title),
|
|
87
|
+
endpoint.description || endpoint.title,
|
|
88
|
+
serverArgumentsSchemas,
|
|
89
|
+
(inputArgs) =>
|
|
90
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
var _a;
|
|
92
|
+
const inputParams = {};
|
|
93
|
+
const inputHeaders = {};
|
|
94
|
+
const inputCookies = {};
|
|
95
|
+
let urlWithPathParams = urlSchema;
|
|
96
|
+
let inputBody = undefined;
|
|
97
|
+
if ("body" in inputArgs) {
|
|
98
|
+
inputBody = inputArgs.body;
|
|
99
|
+
delete inputArgs.body;
|
|
100
|
+
}
|
|
101
|
+
Object.entries(inputArgs).forEach(([key, value]) => {
|
|
102
|
+
if (key in pathsSchema) {
|
|
103
|
+
urlWithPathParams = urlWithPathParams.replace(
|
|
104
|
+
`{${key}}`,
|
|
105
|
+
value,
|
|
106
|
+
);
|
|
107
|
+
} else if (key in queriesSchema) {
|
|
108
|
+
inputParams[key] = value;
|
|
109
|
+
} else if (key in headersSchema) {
|
|
110
|
+
inputHeaders[key] = value;
|
|
111
|
+
} else if (key in cookiesSchema) {
|
|
112
|
+
inputCookies[key] = value;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const securityParamSections =
|
|
116
|
+
(_a = endpoint.request.security[0]) === null || _a === void 0
|
|
117
|
+
? void 0
|
|
118
|
+
: _a.parameters;
|
|
119
|
+
if (securityParamSections) {
|
|
120
|
+
const headerRes = convertSecurityParameterSection(
|
|
121
|
+
securityParamSections.header,
|
|
122
|
+
envVars,
|
|
123
|
+
"header",
|
|
124
|
+
);
|
|
125
|
+
headerRes.forEach(({ key, value }) => {
|
|
126
|
+
if (value) {
|
|
127
|
+
inputHeaders[key] = value;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
const cookieRes = convertSecurityParameterSection(
|
|
131
|
+
securityParamSections.cookie,
|
|
132
|
+
envVars,
|
|
133
|
+
"cookie",
|
|
134
|
+
);
|
|
135
|
+
cookieRes.forEach(({ key, value }) => {
|
|
136
|
+
if (value) {
|
|
137
|
+
inputCookies[key] = value;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
const queryRes = convertSecurityParameterSection(
|
|
141
|
+
securityParamSections.query,
|
|
142
|
+
envVars,
|
|
143
|
+
"query",
|
|
144
|
+
);
|
|
145
|
+
queryRes.forEach(({ key, value }) => {
|
|
146
|
+
if (value) {
|
|
147
|
+
inputParams[key] = value;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const response = yield axios({
|
|
153
|
+
url: urlWithPathParams,
|
|
154
|
+
method: methodSchema,
|
|
155
|
+
params: inputParams,
|
|
156
|
+
data: inputBody,
|
|
157
|
+
headers: inputHeaders,
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
content: [
|
|
161
|
+
{
|
|
162
|
+
type: "text",
|
|
163
|
+
text: JSON.stringify(response.data, undefined, 2),
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
};
|
|
167
|
+
} catch (error) {
|
|
168
|
+
const errMsg = JSON.stringify(error, undefined, 2);
|
|
169
|
+
return {
|
|
170
|
+
isError: true,
|
|
171
|
+
content: [
|
|
172
|
+
{
|
|
173
|
+
type: "text",
|
|
174
|
+
text: isAxiosError(error)
|
|
175
|
+
? `${error.message}\n\n${errMsg}`
|
|
176
|
+
: errMsg,
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
185
|
}
|
package/src/tools/zod.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DataSchema,
|
|
3
|
-
DataSchemaArray,
|
|
4
|
-
IncrementalDataSchema,
|
|
5
|
-
IncrementalDataSchemaArray,
|
|
6
|
-
} from "@mintlify/validation";
|
|
1
|
+
import { DataSchema, DataSchemaArray, IncrementalDataSchema, IncrementalDataSchemaArray } from "@mintlify/validation";
|
|
7
2
|
import { z } from "zod";
|
|
8
3
|
type SchemaInput = DataSchema | IncrementalDataSchema;
|
|
9
|
-
export declare function dataSchemaArrayToZod(
|
|
10
|
-
schemas: DataSchemaArray | IncrementalDataSchemaArray,
|
|
11
|
-
): z.ZodTypeAny;
|
|
4
|
+
export declare function dataSchemaArrayToZod(schemas: DataSchemaArray | IncrementalDataSchemaArray): z.ZodTypeAny;
|
|
12
5
|
export declare function dataSchemaToZod(schema: SchemaInput): z.ZodTypeAny;
|
|
13
6
|
export {};
|