@smithery/sdk 1.5.7 → 1.5.9
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/shared/config.d.ts +2 -10
- package/dist/shared/config.js +28 -53
- package/package.json +1 -1
package/dist/shared/config.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface SmitheryUrlOptions {
|
|
|
5
5
|
profile?: string;
|
|
6
6
|
config?: object;
|
|
7
7
|
}
|
|
8
|
+
export declare function appendConfigAsDotParams(url: URL, config: unknown): void;
|
|
8
9
|
/**
|
|
9
10
|
* Creates a URL to connect to the Smithery MCP server.
|
|
10
11
|
* @param baseUrl The base URL of the Smithery server
|
|
@@ -12,16 +13,6 @@ export interface SmitheryUrlOptions {
|
|
|
12
13
|
* @returns A URL with config encoded using dot-notation query params (e.g. model.name=gpt-4&debug=true)
|
|
13
14
|
*/
|
|
14
15
|
export declare function createSmitheryUrl(baseUrl: string, options?: SmitheryUrlOptions): URL;
|
|
15
|
-
/**
|
|
16
|
-
* General-purpose parser for config from key-value entries (e.g., URLSearchParams.entries()).
|
|
17
|
-
* Reserved keys (api_key, profile, config) are ignored.
|
|
18
|
-
*/
|
|
19
|
-
export declare function parseConfigFromEntries(entries: Iterable<[string, unknown]>): Record<string, unknown>;
|
|
20
|
-
/**
|
|
21
|
-
* Parses the config from an Express request using dot-notation parameters.
|
|
22
|
-
* Reserved keys (api_key, profile, config) are ignored.
|
|
23
|
-
*/
|
|
24
|
-
export declare function parseExpressRequestConfig(req: ExpressRequest): Record<string, unknown>;
|
|
25
16
|
/**
|
|
26
17
|
* Parses and validates config from an Express request with optional Zod schema validation
|
|
27
18
|
* Supports dot-notation config parameters (e.g., foo=bar, a.b=c)
|
|
@@ -47,3 +38,4 @@ export declare function parseAndValidateConfig<T = Record<string, unknown>>(req:
|
|
|
47
38
|
received: unknown;
|
|
48
39
|
}[];
|
|
49
40
|
}> | import("okay-error").Ok<T>;
|
|
41
|
+
export declare function parseConfigFromQuery(query: Iterable<[string, unknown]>): Record<string, unknown>;
|
package/dist/shared/config.js
CHANGED
|
@@ -4,7 +4,7 @@ import { zodToJsonSchema } from "zod-to-json-schema";
|
|
|
4
4
|
function isPlainObject(value) {
|
|
5
5
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
6
|
}
|
|
7
|
-
function appendConfigAsDotParams(url, config) {
|
|
7
|
+
export function appendConfigAsDotParams(url, config) {
|
|
8
8
|
function add(pathParts, value) {
|
|
9
9
|
if (Array.isArray(value)) {
|
|
10
10
|
for (let index = 0; index < value.length; index++) {
|
|
@@ -58,34 +58,6 @@ export function createSmitheryUrl(baseUrl, options) {
|
|
|
58
58
|
}
|
|
59
59
|
return url;
|
|
60
60
|
}
|
|
61
|
-
/**
|
|
62
|
-
* General-purpose parser for config from key-value entries (e.g., URLSearchParams.entries()).
|
|
63
|
-
* Reserved keys (api_key, profile, config) are ignored.
|
|
64
|
-
*/
|
|
65
|
-
export function parseConfigFromEntries(entries) {
|
|
66
|
-
const parsed = {};
|
|
67
|
-
for (const [key, raw] of entries) {
|
|
68
|
-
if (key === "api_key" || key === "profile" || key === "config")
|
|
69
|
-
continue;
|
|
70
|
-
const rawValue = Array.isArray(raw) ? raw[0] : raw;
|
|
71
|
-
if (typeof rawValue !== "string")
|
|
72
|
-
continue;
|
|
73
|
-
let castValue = rawValue;
|
|
74
|
-
try {
|
|
75
|
-
castValue = JSON.parse(rawValue);
|
|
76
|
-
}
|
|
77
|
-
catch { }
|
|
78
|
-
_.set(parsed, key.split("."), castValue);
|
|
79
|
-
}
|
|
80
|
-
return parsed;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Parses the config from an Express request using dot-notation parameters.
|
|
84
|
-
* Reserved keys (api_key, profile, config) are ignored.
|
|
85
|
-
*/
|
|
86
|
-
export function parseExpressRequestConfig(req) {
|
|
87
|
-
return parseConfigFromEntries(Object.entries(req.query));
|
|
88
|
-
}
|
|
89
61
|
/**
|
|
90
62
|
* Parses and validates config from an Express request with optional Zod schema validation
|
|
91
63
|
* Supports dot-notation config parameters (e.g., foo=bar, a.b=c)
|
|
@@ -94,30 +66,7 @@ export function parseExpressRequestConfig(req) {
|
|
|
94
66
|
* @returns Result with either parsed data or error response
|
|
95
67
|
*/
|
|
96
68
|
export function parseAndValidateConfig(req, schema) {
|
|
97
|
-
|
|
98
|
-
const config = {};
|
|
99
|
-
// Process dot-notation config parameters (foo=bar, a.b=c)
|
|
100
|
-
// This allows URL params like ?server.host=localhost&server.port=8080&debug=true
|
|
101
|
-
for (const [key, value] of Object.entries(req.query)) {
|
|
102
|
-
// Skip reserved parameters
|
|
103
|
-
if (key === "api_key" || key === "profile")
|
|
104
|
-
continue;
|
|
105
|
-
const pathParts = key.split(".");
|
|
106
|
-
// Handle array values from Express query parsing
|
|
107
|
-
const rawValue = Array.isArray(value) ? value[0] : value;
|
|
108
|
-
if (typeof rawValue !== "string")
|
|
109
|
-
continue;
|
|
110
|
-
// Try to parse value as JSON (for booleans, numbers, objects)
|
|
111
|
-
let parsedValue = rawValue;
|
|
112
|
-
try {
|
|
113
|
-
parsedValue = JSON.parse(rawValue);
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// If parsing fails, use the raw string value
|
|
117
|
-
}
|
|
118
|
-
// Use lodash's set method to handle nested paths
|
|
119
|
-
_.set(config, pathParts, parsedValue);
|
|
120
|
-
}
|
|
69
|
+
const config = parseConfigFromQuery(Object.entries(req.query));
|
|
121
70
|
// Validate config against schema if provided
|
|
122
71
|
if (schema) {
|
|
123
72
|
const result = schema.safeParse(config);
|
|
@@ -155,3 +104,29 @@ export function parseAndValidateConfig(req, schema) {
|
|
|
155
104
|
}
|
|
156
105
|
return ok(config);
|
|
157
106
|
}
|
|
107
|
+
// Process dot-notation config parameters from query parameters (foo=bar, a.b=c)
|
|
108
|
+
// This allows URL params like ?server.host=localhost&server.port=8080&debug=true
|
|
109
|
+
export function parseConfigFromQuery(query) {
|
|
110
|
+
const config = {};
|
|
111
|
+
for (const [key, value] of query) {
|
|
112
|
+
// Skip reserved parameters
|
|
113
|
+
if (key === "api_key" || key === "profile")
|
|
114
|
+
continue;
|
|
115
|
+
const pathParts = key.split(".");
|
|
116
|
+
// Handle array values from Express query parsing
|
|
117
|
+
const rawValue = Array.isArray(value) ? value[0] : value;
|
|
118
|
+
if (typeof rawValue !== "string")
|
|
119
|
+
continue;
|
|
120
|
+
// Try to parse value as JSON (for booleans, numbers, objects)
|
|
121
|
+
let parsedValue = rawValue;
|
|
122
|
+
try {
|
|
123
|
+
parsedValue = JSON.parse(rawValue);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// If parsing fails, use the raw string value
|
|
127
|
+
}
|
|
128
|
+
// Use lodash's set method to handle nested paths
|
|
129
|
+
_.set(config, pathParts, parsedValue);
|
|
130
|
+
}
|
|
131
|
+
return config;
|
|
132
|
+
}
|