n8n-nodes-browser-smart-automation 0.1.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/dist/McpClient/McpClient.node.js +333 -0
- package/dist/McpClient/McpClient.node.js.map +1 -0
- package/dist/McpClient/listSearch.js +58 -0
- package/dist/McpClient/listSearch.js.map +1 -0
- package/dist/McpClient/resourceMapping.js +61 -0
- package/dist/McpClient/resourceMapping.js.map +1 -0
- package/dist/McpClient/utils.js +248 -0
- package/dist/McpClient/utils.js.map +1 -0
- package/dist/McpClientTool/McpClientTool.node.js +417 -0
- package/dist/McpClientTool/McpClientTool.node.js.map +1 -0
- package/dist/McpClientTool/loadOptions.js +61 -0
- package/dist/McpClientTool/loadOptions.js.map +1 -0
- package/dist/McpClientTool/types.js +17 -0
- package/dist/McpClientTool/types.js.map +1 -0
- package/dist/McpClientTool/utils.js +120 -0
- package/dist/McpClientTool/utils.js.map +1 -0
- package/dist/McpTrigger/FlushingTransport.js +61 -0
- package/dist/McpTrigger/FlushingTransport.js.map +1 -0
- package/dist/McpTrigger/McpServer.js +246 -0
- package/dist/McpTrigger/McpServer.js.map +1 -0
- package/dist/McpTrigger/McpTrigger.node.js +196 -0
- package/dist/McpTrigger/McpTrigger.node.js.map +1 -0
- package/dist/shared/descriptions.js +89 -0
- package/dist/shared/descriptions.js.map +1 -0
- package/dist/shared/helpers.js +47 -0
- package/dist/shared/helpers.js.map +1 -0
- package/dist/shared/httpProxyAgent.js +31 -0
- package/dist/shared/httpProxyAgent.js.map +1 -0
- package/dist/shared/logWrapper.js +31 -0
- package/dist/shared/logWrapper.js.map +1 -0
- package/dist/shared/schemaParsing.js +32 -0
- package/dist/shared/schemaParsing.js.map +1 -0
- package/dist/shared/sharedFields.js +41 -0
- package/dist/shared/sharedFields.js.map +1 -0
- package/dist/shared/types.js +17 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/shared/utils.js +231 -0
- package/dist/shared/utils.js.map +1 -0
- package/jest.config.js +24 -0
- package/nodes/McpClient/McpClient.node.ts +327 -0
- package/nodes/McpClient/__test__/McpClient.node.test.ts +221 -0
- package/nodes/McpClient/__test__/utils.test.ts +302 -0
- package/nodes/McpClient/listSearch.ts +48 -0
- package/nodes/McpClient/resourceMapping.ts +48 -0
- package/nodes/McpClient/utils.ts +281 -0
- package/nodes/McpClientTool/McpClientTool.node.ts +468 -0
- package/nodes/McpClientTool/__test__/McpClientTool.node.test.ts +730 -0
- package/nodes/McpClientTool/loadOptions.ts +45 -0
- package/nodes/McpClientTool/types.ts +1 -0
- package/nodes/McpClientTool/utils.ts +116 -0
- package/nodes/McpTrigger/FlushingTransport.ts +61 -0
- package/nodes/McpTrigger/McpServer.ts +317 -0
- package/nodes/McpTrigger/McpTrigger.node.ts +204 -0
- package/nodes/McpTrigger/__test__/FlushingTransport.test.ts +102 -0
- package/nodes/McpTrigger/__test__/McpServer.test.ts +532 -0
- package/nodes/McpTrigger/__test__/McpTrigger.node.test.ts +171 -0
- package/nodes/mcp.dark.svg +7 -0
- package/nodes/mcp.svg +7 -0
- package/nodes/shared/__test__/utils.test.ts +318 -0
- package/nodes/shared/descriptions.ts +65 -0
- package/nodes/shared/helpers.ts +31 -0
- package/nodes/shared/httpProxyAgent.ts +11 -0
- package/nodes/shared/logWrapper.ts +13 -0
- package/nodes/shared/schemaParsing.ts +9 -0
- package/nodes/shared/sharedFields.ts +20 -0
- package/nodes/shared/types.ts +12 -0
- package/nodes/shared/utils.ts +296 -0
- package/officail/package.json +255 -0
- package/package.json +46 -0
- package/tsconfig.json +32 -0
- package/tsup.config.ts +11 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import type { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
|
2
|
+
import type {
|
|
3
|
+
ResourceMapperField,
|
|
4
|
+
FieldType,
|
|
5
|
+
INodePropertyOptions,
|
|
6
|
+
IDataObject,
|
|
7
|
+
} from 'n8n-workflow';
|
|
8
|
+
|
|
9
|
+
function pickFirstSchema(schema: JSONSchema7Definition): JSONSchema7Definition {
|
|
10
|
+
if (typeof schema === 'object' && (schema?.anyOf || schema?.oneOf)) {
|
|
11
|
+
if (Array.isArray(schema.anyOf) && schema.anyOf[0] !== undefined) {
|
|
12
|
+
return schema.anyOf[0];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(schema.oneOf) && schema.oneOf[0] !== undefined) {
|
|
16
|
+
return schema.oneOf[0];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return schema;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function mergeTwoSchemas(
|
|
24
|
+
a?: JSONSchema7Definition,
|
|
25
|
+
b?: JSONSchema7Definition,
|
|
26
|
+
): JSONSchema7Definition | undefined {
|
|
27
|
+
if (a === undefined) {
|
|
28
|
+
return b;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (b === undefined) {
|
|
32
|
+
return a;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
a = pickFirstSchema(a);
|
|
36
|
+
b = pickFirstSchema(b);
|
|
37
|
+
if (a === false || b === false) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (a === true || b === true) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (a.type === 'object' && b.type === 'object') {
|
|
46
|
+
const properties = { ...(a.properties ?? {}), ...(b.properties ?? {}) };
|
|
47
|
+
const required = [...(a.required ?? []), ...(b.required ?? [])];
|
|
48
|
+
const additionalProperties = mergeTwoSchemas(a.additionalProperties, b.additionalProperties);
|
|
49
|
+
return { ...a, ...b, properties, required, additionalProperties };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (a.type === 'array' && b.type === 'array') {
|
|
53
|
+
if (Array.isArray(a.items) && Array.isArray(b.items)) {
|
|
54
|
+
// Two tuples -> pick the longer one
|
|
55
|
+
return a.items.length > b.items.length ? a : b;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (Array.isArray(a.items) || Array.isArray(b.items)) {
|
|
59
|
+
// One tuple -> pick the tuple
|
|
60
|
+
return Array.isArray(a.items) ? a : b;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const items = mergeTwoSchemas(a.items, b.items);
|
|
64
|
+
return { ...a, ...b, items };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function mergeAllOfSchemas(schemas: JSONSchema7Definition[]): JSONSchema7Definition | undefined {
|
|
71
|
+
if (schemas.length === 0) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (schemas.length === 1) {
|
|
76
|
+
return schemas[0];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return schemas.reduce(
|
|
80
|
+
(acc, schema) => mergeTwoSchemas(acc, schema),
|
|
81
|
+
undefined as JSONSchema7Definition | undefined,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function jsonSchemaTypeToDefaultValue(
|
|
86
|
+
schema: JSONSchema7Definition,
|
|
87
|
+
): string | number | boolean | object | null {
|
|
88
|
+
if (schema === false) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (schema === true) {
|
|
93
|
+
return 'any';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (schema.allOf) {
|
|
97
|
+
const mergedSchema = mergeAllOfSchemas(schema.allOf);
|
|
98
|
+
if (mergedSchema !== undefined) {
|
|
99
|
+
return jsonSchemaTypeToDefaultValue(mergedSchema);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (schema.anyOf) {
|
|
104
|
+
const anyOfSchemas = schema.anyOf;
|
|
105
|
+
for (const anyOfSchema of anyOfSchemas) {
|
|
106
|
+
const defaultValue = jsonSchemaTypeToDefaultValue(anyOfSchema);
|
|
107
|
+
if (defaultValue !== null) {
|
|
108
|
+
return defaultValue;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (schema.oneOf) {
|
|
114
|
+
const oneOfSchemas = schema.oneOf;
|
|
115
|
+
for (const oneOfSchema of oneOfSchemas) {
|
|
116
|
+
const defaultValue = jsonSchemaTypeToDefaultValue(oneOfSchema);
|
|
117
|
+
if (defaultValue !== null) {
|
|
118
|
+
return defaultValue;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (schema.enum && Array.isArray(schema.enum)) {
|
|
124
|
+
return schema.enum[0];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (Array.isArray(schema.type)) {
|
|
128
|
+
const types = schema.type;
|
|
129
|
+
for (const type of types) {
|
|
130
|
+
const defaultValue = jsonSchemaTypeToDefaultValue({ type });
|
|
131
|
+
if (defaultValue !== null) {
|
|
132
|
+
return defaultValue;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (schema.type === 'number' || schema.type === 'integer') {
|
|
138
|
+
if (schema.minimum !== undefined) {
|
|
139
|
+
return schema.minimum;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (schema.maximum !== undefined) {
|
|
143
|
+
return schema.maximum;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (schema.type === 'boolean') {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (schema.type === 'string') {
|
|
154
|
+
if (schema.format === 'date-time') {
|
|
155
|
+
return '2025-01-01T00:00:00Z';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (schema.format === 'uri' || schema.format === 'url') {
|
|
159
|
+
return 'https://example.com';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (schema.format === 'date') {
|
|
163
|
+
return '2025-01-01';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (schema.format === 'time') {
|
|
167
|
+
return '00:00:00';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return 'string';
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (schema.type === 'array') {
|
|
174
|
+
if (!schema.items) {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (Array.isArray(schema.items)) {
|
|
179
|
+
return schema.items.map((item) => jsonSchemaTypeToDefaultValue(item));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return [jsonSchemaTypeToDefaultValue(schema.items)];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (schema.type === 'object') {
|
|
186
|
+
const properties = schema.properties ?? {};
|
|
187
|
+
const exampleObject: IDataObject = {};
|
|
188
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
189
|
+
const propertyValue = jsonSchemaTypeToDefaultValue(propertySchema);
|
|
190
|
+
if (propertyValue !== null) {
|
|
191
|
+
exampleObject[key] = propertyValue;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (schema.additionalProperties) {
|
|
196
|
+
const additionalProperties = jsonSchemaTypeToDefaultValue(schema.additionalProperties);
|
|
197
|
+
if (additionalProperties !== null) {
|
|
198
|
+
exampleObject['<additionalProperty>'] = additionalProperties;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return exampleObject;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function jsonSchemaTypeToFieldType(schema: JSONSchema7): FieldType {
|
|
209
|
+
if (schema.type === 'string' && schema.format === 'date-time') {
|
|
210
|
+
return 'dateTime';
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (schema.type === 'number' || schema.type === 'integer') {
|
|
214
|
+
return 'number';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (schema.type === 'boolean' || schema.type === 'array' || schema.type === 'object') {
|
|
218
|
+
return schema.type;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return 'string';
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function convertJsonSchemaToResourceMapperFields(
|
|
225
|
+
schema: JSONSchema7,
|
|
226
|
+
): ResourceMapperField[] {
|
|
227
|
+
const fields: ResourceMapperField[] = [];
|
|
228
|
+
if (schema.type !== 'object' || !schema.properties) {
|
|
229
|
+
return fields;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
233
|
+
for (const [key, propertySchema] of Object.entries(schema.properties)) {
|
|
234
|
+
if (propertySchema === false) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (propertySchema === true) {
|
|
239
|
+
fields.push({
|
|
240
|
+
id: key,
|
|
241
|
+
displayName: key,
|
|
242
|
+
defaultMatch: false,
|
|
243
|
+
required: required.includes(key),
|
|
244
|
+
display: true,
|
|
245
|
+
type: 'string', // use string as a "catch all" for any values
|
|
246
|
+
});
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const schemaType = jsonSchemaTypeToFieldType(propertySchema);
|
|
251
|
+
let defaultValue: string | undefined;
|
|
252
|
+
if (schemaType === 'object' || schemaType === 'array') {
|
|
253
|
+
const result = jsonSchemaTypeToDefaultValue(propertySchema);
|
|
254
|
+
if (result !== null) {
|
|
255
|
+
defaultValue = JSON.stringify(result, null, 2);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const field: ResourceMapperField = {
|
|
260
|
+
id: key,
|
|
261
|
+
displayName: propertySchema.title ?? key,
|
|
262
|
+
defaultMatch: false,
|
|
263
|
+
required: required.includes(key),
|
|
264
|
+
display: true,
|
|
265
|
+
type: schemaType,
|
|
266
|
+
defaultValue,
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
if (propertySchema.enum && Array.isArray(propertySchema.enum)) {
|
|
270
|
+
field.type = 'options';
|
|
271
|
+
field.options = propertySchema.enum.map((value) => ({
|
|
272
|
+
name: value,
|
|
273
|
+
value,
|
|
274
|
+
})) as INodePropertyOptions[];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
fields.push(field);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return fields;
|
|
281
|
+
}
|