@samanhappy/mcphub 0.10.0 → 0.10.1

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.
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Utility functions for converting parameter types based on JSON schema definitions
3
+ */
4
+ /**
5
+ * Convert parameters to their proper types based on the tool's input schema
6
+ * This ensures that form-submitted string values are converted to the correct types
7
+ * (e.g., numbers, booleans, arrays) before being passed to MCP tools.
8
+ *
9
+ * @param params - The parameters to convert (typically from form submission)
10
+ * @param inputSchema - The JSON schema definition for the tool's input
11
+ * @returns The converted parameters with proper types
12
+ */
13
+ export function convertParametersToTypes(params, inputSchema) {
14
+ if (!inputSchema || typeof inputSchema !== 'object' || !inputSchema.properties) {
15
+ return params;
16
+ }
17
+ const convertedParams = {};
18
+ const properties = inputSchema.properties;
19
+ for (const [key, value] of Object.entries(params)) {
20
+ const propDef = properties[key];
21
+ if (!propDef || typeof propDef !== 'object') {
22
+ // No schema definition found, keep as is
23
+ convertedParams[key] = value;
24
+ continue;
25
+ }
26
+ const propType = propDef.type;
27
+ try {
28
+ switch (propType) {
29
+ case 'integer':
30
+ case 'number':
31
+ // Convert string to number
32
+ if (typeof value === 'string') {
33
+ const numValue = propType === 'integer' ? parseInt(value, 10) : parseFloat(value);
34
+ convertedParams[key] = isNaN(numValue) ? value : numValue;
35
+ }
36
+ else {
37
+ convertedParams[key] = value;
38
+ }
39
+ break;
40
+ case 'boolean':
41
+ // Convert string to boolean
42
+ if (typeof value === 'string') {
43
+ convertedParams[key] = value.toLowerCase() === 'true' || value === '1';
44
+ }
45
+ else {
46
+ convertedParams[key] = value;
47
+ }
48
+ break;
49
+ case 'array':
50
+ // Handle array conversion if needed (e.g., comma-separated strings)
51
+ if (typeof value === 'string' && value.includes(',')) {
52
+ convertedParams[key] = value.split(',').map((item) => item.trim());
53
+ }
54
+ else {
55
+ convertedParams[key] = value;
56
+ }
57
+ break;
58
+ case 'object':
59
+ // Handle object conversion if needed
60
+ if (typeof value === 'string') {
61
+ try {
62
+ convertedParams[key] = JSON.parse(value);
63
+ }
64
+ catch {
65
+ // If parsing fails, keep as is
66
+ convertedParams[key] = value;
67
+ }
68
+ }
69
+ else {
70
+ convertedParams[key] = value;
71
+ }
72
+ break;
73
+ default:
74
+ // For string and other types, keep as is
75
+ convertedParams[key] = value;
76
+ break;
77
+ }
78
+ }
79
+ catch (error) {
80
+ // If conversion fails, keep the original value
81
+ console.warn(`Failed to convert parameter '${key}' to type '${propType}':`, error);
82
+ convertedParams[key] = value;
83
+ }
84
+ }
85
+ return convertedParams;
86
+ }
87
+ //# sourceMappingURL=parameterConversion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameterConversion.js","sourceRoot":"","sources":["../../src/utils/parameterConversion.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAA2B,EAC3B,WAAgC;IAEhC,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC;QAC/E,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,eAAe,GAAwB,EAAE,CAAC;IAChD,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC;IAE1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC5C,yCAAyC;YACzC,eAAe,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAC7B,SAAS;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAE9B,IAAI,CAAC;YACH,QAAQ,QAAQ,EAAE,CAAC;gBACj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