@smithery/sdk 0.0.24 → 0.0.25

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.
Files changed (2) hide show
  1. package/dist/transport.js +29 -1
  2. package/package.json +1 -1
package/dist/transport.js CHANGED
@@ -7,5 +7,33 @@ import { createSmitheryUrl } from "./config.js";
7
7
  * @returns Transport
8
8
  */
9
9
  export function createTransport(smitheryServerUrl, config) {
10
- return new WebSocketClientTransport(createSmitheryUrl(`${smitheryServerUrl}/ws`, config));
10
+ let url;
11
+ try {
12
+ // First try to parse as-is
13
+ url = new URL(smitheryServerUrl);
14
+ // For WebSocket connections, ws:, wss:, and ws+unix: are valid
15
+ if (url.protocol !== 'ws:' && url.protocol !== 'wss:' && url.protocol !== 'ws+unix:') {
16
+ // Special case: automatically convert http(s) to ws(s)
17
+ if (url.protocol === 'http:' || url.protocol === 'https:') {
18
+ console.warn('Warning: HTTP/HTTPS protocol detected in smitheryServerUrl. ' +
19
+ 'Converting to WebSocket protocol. For better compatibility, ' +
20
+ 'consider providing the URL without protocol.');
21
+ url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
22
+ }
23
+ else {
24
+ throw new Error(`Protocol ${url.protocol} is not supported for WebSocket connections. ` +
25
+ 'Please use ws://, wss://, ws+unix:// (or provide URL without protocol)');
26
+ }
27
+ }
28
+ }
29
+ catch (error) {
30
+ // If initial parsing failed, try with default ws:// protocol
31
+ try {
32
+ url = new URL(`ws://${smitheryServerUrl}`);
33
+ }
34
+ catch {
35
+ throw new Error(`Invalid URL provided: ${smitheryServerUrl}`);
36
+ }
37
+ }
38
+ return new WebSocketClientTransport(createSmitheryUrl(`${url.toString()}/ws`, config));
11
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithery/sdk",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "Connect language models to Model Context Protocols",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",