@smithery/sdk 1.5.6 → 1.5.7

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.
@@ -102,7 +102,6 @@ export function createStatefulServer(createMcpServer, options) {
102
102
  $id: `${req.protocol}://${req.get("host")}/.well-known/mcp-config`,
103
103
  title: "MCP Session Configuration",
104
104
  description: "Schema for the /mcp endpoint configuration",
105
- "x-mcp-version": "1.0",
106
105
  "x-query-style": "dot+bracket",
107
106
  ...baseSchema,
108
107
  };
@@ -98,7 +98,6 @@ export function createStatelessServer(createMcpServer, options) {
98
98
  $id: `${req.protocol}://${req.get("host")}/.well-known/mcp-config`,
99
99
  title: "MCP Session Configuration",
100
100
  description: "Schema for the /mcp endpoint configuration",
101
- "x-mcp-version": "1.0",
102
101
  "x-query-style": "dot+bracket",
103
102
  ...baseSchema,
104
103
  };
@@ -9,28 +9,27 @@ export interface SmitheryUrlOptions {
9
9
  * Creates a URL to connect to the Smithery MCP server.
10
10
  * @param baseUrl The base URL of the Smithery server
11
11
  * @param options Optional configuration object
12
- * @returns A URL object with properly encoded parameters. Example: https://server.smithery.ai/{namespace}/mcp?config=BASE64_ENCODED_CONFIG&api_key=API_KEY
12
+ * @returns A URL with config encoded using dot-notation query params (e.g. model.name=gpt-4&debug=true)
13
13
  */
14
14
  export declare function createSmitheryUrl(baseUrl: string, options?: SmitheryUrlOptions): URL;
15
15
  /**
16
- * Parses the config from an express request by checking the query parameter "config".
17
- * @param req The express request
18
- * @returns The config
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.
19
23
  */
20
24
  export declare function parseExpressRequestConfig(req: ExpressRequest): Record<string, unknown>;
21
25
  /**
22
26
  * Parses and validates config from an Express request with optional Zod schema validation
23
- * Supports both base64-encoded config and dot-notation config parameters
27
+ * Supports dot-notation config parameters (e.g., foo=bar, a.b=c)
24
28
  * @param req The express request
25
29
  * @param schema Optional Zod schema for validation
26
30
  * @returns Result with either parsed data or error response
27
31
  */
28
32
  export declare function parseAndValidateConfig<T = Record<string, unknown>>(req: ExpressRequest, schema?: z.ZodSchema<T>): import("okay-error").Err<{
29
- title: string;
30
- status: number;
31
- detail: string;
32
- instance: string;
33
- }> | import("okay-error").Err<{
34
33
  readonly title: "Invalid configuration parameters";
35
34
  readonly status: 422;
36
35
  readonly detail: "One or more config parameters are invalid.";
@@ -1,19 +1,54 @@
1
1
  import _ from "lodash";
2
2
  import { err, ok } from "okay-error";
3
3
  import { zodToJsonSchema } from "zod-to-json-schema";
4
+ function isPlainObject(value) {
5
+ return value !== null && typeof value === "object" && !Array.isArray(value);
6
+ }
7
+ function appendConfigAsDotParams(url, config) {
8
+ function add(pathParts, value) {
9
+ if (Array.isArray(value)) {
10
+ for (let index = 0; index < value.length; index++) {
11
+ add([...pathParts, String(index)], value[index]);
12
+ }
13
+ return;
14
+ }
15
+ if (isPlainObject(value)) {
16
+ for (const [key, nested] of Object.entries(value)) {
17
+ add([...pathParts, key], nested);
18
+ }
19
+ return;
20
+ }
21
+ const key = pathParts.join(".");
22
+ let stringValue;
23
+ switch (typeof value) {
24
+ case "string":
25
+ stringValue = value;
26
+ break;
27
+ case "number":
28
+ case "boolean":
29
+ stringValue = String(value);
30
+ break;
31
+ default:
32
+ stringValue = JSON.stringify(value);
33
+ }
34
+ url.searchParams.set(key, stringValue);
35
+ }
36
+ if (isPlainObject(config)) {
37
+ for (const [key, value] of Object.entries(config)) {
38
+ add([key], value);
39
+ }
40
+ }
41
+ }
4
42
  /**
5
43
  * Creates a URL to connect to the Smithery MCP server.
6
44
  * @param baseUrl The base URL of the Smithery server
7
45
  * @param options Optional configuration object
8
- * @returns A URL object with properly encoded parameters. Example: https://server.smithery.ai/{namespace}/mcp?config=BASE64_ENCODED_CONFIG&api_key=API_KEY
46
+ * @returns A URL with config encoded using dot-notation query params (e.g. model.name=gpt-4&debug=true)
9
47
  */
10
48
  export function createSmitheryUrl(baseUrl, options) {
11
49
  const url = new URL(`${baseUrl}/mcp`);
12
50
  if (options?.config) {
13
- const param = typeof window !== "undefined"
14
- ? btoa(JSON.stringify(options.config))
15
- : Buffer.from(JSON.stringify(options.config)).toString("base64");
16
- url.searchParams.set("config", param);
51
+ appendConfigAsDotParams(url, options.config);
17
52
  }
18
53
  if (options?.apiKey) {
19
54
  url.searchParams.set("api_key", options.apiKey);
@@ -24,42 +59,48 @@ export function createSmitheryUrl(baseUrl, options) {
24
59
  return url;
25
60
  }
26
61
  /**
27
- * Parses the config from an express request by checking the query parameter "config".
28
- * @param req The express request
29
- * @returns The config
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.
30
85
  */
31
86
  export function parseExpressRequestConfig(req) {
32
- return JSON.parse(Buffer.from(req.query.config, "base64").toString());
87
+ return parseConfigFromEntries(Object.entries(req.query));
33
88
  }
34
89
  /**
35
90
  * Parses and validates config from an Express request with optional Zod schema validation
36
- * Supports both base64-encoded config and dot-notation config parameters
91
+ * Supports dot-notation config parameters (e.g., foo=bar, a.b=c)
37
92
  * @param req The express request
38
93
  * @param schema Optional Zod schema for validation
39
94
  * @returns Result with either parsed data or error response
40
95
  */
41
96
  export function parseAndValidateConfig(req, schema) {
42
97
  // Parse config from request parameters
43
- let config = {};
44
- // 1. Process base64-encoded config parameter if present
45
- if (req.query.config) {
46
- try {
47
- config = parseExpressRequestConfig(req);
48
- }
49
- catch (configError) {
50
- return err({
51
- title: "Invalid config parameter",
52
- status: 400,
53
- detail: "Failed to parse config parameter",
54
- instance: req.originalUrl,
55
- });
56
- }
57
- }
58
- // 2. Process dot-notation config parameters (foo=bar, a.b=c)
98
+ const config = {};
99
+ // Process dot-notation config parameters (foo=bar, a.b=c)
59
100
  // This allows URL params like ?server.host=localhost&server.port=8080&debug=true
60
101
  for (const [key, value] of Object.entries(req.query)) {
61
102
  // Skip reserved parameters
62
- if (key === "config" || key === "api_key" || key === "profile")
103
+ if (key === "api_key" || key === "profile")
63
104
  continue;
64
105
  const pathParts = key.split(".");
65
106
  // Handle array values from Express query parsing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithery/sdk",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
4
4
  "description": "SDK to develop with Smithery",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",