@smithery/api 0.27.0 → 0.29.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/CHANGELOG.md +20 -0
- package/README.md +10 -5
- package/client.d.mts +5 -5
- package/client.d.mts.map +1 -1
- package/client.d.ts +5 -5
- package/client.d.ts.map +1 -1
- package/client.js +1 -1
- package/client.js.map +1 -1
- package/client.mjs +1 -1
- package/client.mjs.map +1 -1
- package/lib/mcp-transport.d.mts +57 -69
- package/lib/mcp-transport.d.mts.map +1 -1
- package/lib/mcp-transport.d.ts +57 -69
- package/lib/mcp-transport.d.ts.map +1 -1
- package/lib/mcp-transport.js +106 -204
- package/lib/mcp-transport.js.map +1 -1
- package/lib/mcp-transport.mjs +103 -202
- package/lib/mcp-transport.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/connect/connect.d.mts +4 -4
- package/resources/beta/connect/connect.d.ts +4 -4
- package/resources/beta/connect/connect.js +4 -4
- package/resources/beta/connect/connect.mjs +4 -4
- package/resources/beta/connect/connections.d.mts +5 -1
- package/resources/beta/connect/connections.d.mts.map +1 -1
- package/resources/beta/connect/connections.d.ts +5 -1
- package/resources/beta/connect/connections.d.ts.map +1 -1
- package/resources/beta/connect/index.d.mts +1 -1
- package/resources/beta/connect/index.d.ts +1 -1
- package/resources/beta/connect/index.js +3 -3
- package/resources/beta/connect/index.mjs +1 -1
- package/resources/beta/connect/{rpc.d.mts → mcp.d.mts} +9 -9
- package/resources/beta/connect/{rpc.d.mts.map → mcp.d.mts.map} +1 -1
- package/resources/beta/connect/{rpc.d.ts → mcp.d.ts} +9 -9
- package/resources/beta/connect/{rpc.d.ts.map → mcp.d.ts.map} +1 -1
- package/resources/beta/connect/{rpc.js → mcp.js} +8 -8
- package/resources/beta/connect/{rpc.js.map → mcp.js.map} +1 -1
- package/resources/beta/connect/{rpc.mjs → mcp.mjs} +6 -6
- package/resources/beta/connect/{rpc.mjs.map → mcp.mjs.map} +1 -1
- package/resources/beta/connect/tools.d.mts +0 -3
- package/resources/beta/connect/tools.d.mts.map +1 -1
- package/resources/beta/connect/tools.d.ts +0 -3
- package/resources/beta/connect/tools.d.ts.map +1 -1
- package/resources/index.d.mts +3 -3
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +3 -3
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/namespaces/index.d.mts +3 -0
- package/resources/namespaces/index.d.mts.map +1 -0
- package/resources/namespaces/index.d.ts +3 -0
- package/resources/namespaces/index.d.ts.map +1 -0
- package/resources/namespaces/index.js +9 -0
- package/resources/namespaces/index.js.map +1 -0
- package/resources/namespaces/index.mjs +4 -0
- package/resources/namespaces/index.mjs.map +1 -0
- package/resources/namespaces/namespaces.d.mts +60 -0
- package/resources/namespaces/namespaces.d.mts.map +1 -0
- package/resources/namespaces/namespaces.d.ts +60 -0
- package/resources/namespaces/namespaces.d.ts.map +1 -0
- package/resources/namespaces/namespaces.js +54 -0
- package/resources/namespaces/namespaces.js.map +1 -0
- package/resources/namespaces/namespaces.mjs +49 -0
- package/resources/namespaces/namespaces.mjs.map +1 -0
- package/resources/namespaces/servers.d.mts +46 -0
- package/resources/namespaces/servers.d.mts.map +1 -0
- package/resources/namespaces/servers.d.ts +46 -0
- package/resources/namespaces/servers.d.ts.map +1 -0
- package/resources/namespaces/servers.js +25 -0
- package/resources/namespaces/servers.js.map +1 -0
- package/resources/namespaces/servers.mjs +21 -0
- package/resources/namespaces/servers.mjs.map +1 -0
- package/resources/namespaces.d.mts +1 -39
- package/resources/namespaces.d.mts.map +1 -1
- package/resources/namespaces.d.ts +1 -39
- package/resources/namespaces.d.ts.map +1 -1
- package/resources/namespaces.js +2 -26
- package/resources/namespaces.js.map +1 -1
- package/resources/namespaces.mjs +1 -24
- package/resources/namespaces.mjs.map +1 -1
- package/resources/servers/deployments.d.mts +55 -9
- package/resources/servers/deployments.d.mts.map +1 -1
- package/resources/servers/deployments.d.ts +55 -9
- package/resources/servers/deployments.d.ts.map +1 -1
- package/resources/servers/deployments.js +42 -8
- package/resources/servers/deployments.js.map +1 -1
- package/resources/servers/deployments.mjs +42 -8
- package/resources/servers/deployments.mjs.map +1 -1
- package/resources/servers/index.d.mts +4 -3
- package/resources/servers/index.d.mts.map +1 -1
- package/resources/servers/index.d.ts +4 -3
- package/resources/servers/index.d.ts.map +1 -1
- package/resources/servers/index.js +3 -1
- package/resources/servers/index.js.map +1 -1
- package/resources/servers/index.mjs +1 -0
- package/resources/servers/index.mjs.map +1 -1
- package/resources/servers/logs.d.mts +15 -4
- package/resources/servers/logs.d.mts.map +1 -1
- package/resources/servers/logs.d.ts +15 -4
- package/resources/servers/logs.d.ts.map +1 -1
- package/resources/servers/logs.js +10 -2
- package/resources/servers/logs.js.map +1 -1
- package/resources/servers/logs.mjs +10 -2
- package/resources/servers/logs.mjs.map +1 -1
- package/resources/servers/repo.d.mts +98 -0
- package/resources/servers/repo.d.mts.map +1 -0
- package/resources/servers/repo.d.ts +98 -0
- package/resources/servers/repo.d.ts.map +1 -0
- package/resources/servers/repo.js +55 -0
- package/resources/servers/repo.js.map +1 -0
- package/resources/servers/repo.mjs +51 -0
- package/resources/servers/repo.mjs.map +1 -0
- package/resources/servers/secrets.d.mts +46 -4
- package/resources/servers/secrets.d.mts.map +1 -1
- package/resources/servers/secrets.d.ts +46 -4
- package/resources/servers/secrets.d.ts.map +1 -1
- package/resources/servers/secrets.js +36 -6
- package/resources/servers/secrets.js.map +1 -1
- package/resources/servers/secrets.mjs +36 -6
- package/resources/servers/secrets.mjs.map +1 -1
- package/resources/servers/servers.d.mts +57 -10
- package/resources/servers/servers.d.mts.map +1 -1
- package/resources/servers/servers.d.ts +57 -10
- package/resources/servers/servers.d.ts.map +1 -1
- package/resources/servers/servers.js +47 -8
- package/resources/servers/servers.js.map +1 -1
- package/resources/servers/servers.mjs +47 -8
- package/resources/servers/servers.mjs.map +1 -1
- package/resources/tokens.d.mts +18 -18
- package/resources/tokens.d.mts.map +1 -1
- package/resources/tokens.d.ts +18 -18
- package/resources/tokens.d.ts.map +1 -1
- package/src/client.ts +14 -8
- package/src/lib/mcp-transport.ts +131 -236
- package/src/resources/beta/connect/connect.ts +6 -6
- package/src/resources/beta/connect/connections.ts +6 -1
- package/src/resources/beta/connect/index.ts +1 -1
- package/src/resources/beta/connect/{rpc.ts → mcp.ts} +9 -9
- package/src/resources/beta/connect/tools.ts +0 -2
- package/src/resources/index.ts +5 -2
- package/src/resources/namespaces/index.ts +14 -0
- package/src/resources/namespaces/namespaces.ts +92 -0
- package/src/resources/namespaces/servers.ts +71 -0
- package/src/resources/namespaces.ts +1 -61
- package/src/resources/servers/deployments.ts +76 -15
- package/src/resources/servers/index.ts +14 -0
- package/src/resources/servers/logs.ts +18 -9
- package/src/resources/servers/repo.ts +143 -0
- package/src/resources/servers/secrets.ts +55 -7
- package/src/resources/servers/servers.ts +92 -8
- package/src/resources/tokens.ts +17 -17
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/lib/mcp-transport.ts
CHANGED
|
@@ -1,49 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Smithery Connect — Create an MCP connection that routes through Smithery Connect.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* This transport lazily fetches/creates the connection on first message and uses its server info
|
|
8
|
-
* to satisfy the MCP SDK's initialization flow without re-initializing the already-established connection.
|
|
4
|
+
* Smithery Connect acts as a connection manager and credential vault, handling OAuth
|
|
5
|
+
* orchestration with upstream MCP servers. This module provides a factory function
|
|
6
|
+
* that creates a connection and returns a standard MCP SDK transport.
|
|
9
7
|
*
|
|
10
8
|
* @example
|
|
11
9
|
* ```typescript
|
|
12
10
|
* import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
13
|
-
* import
|
|
14
|
-
* import { SmitheryTransport } from '@smithery/api/mcp';
|
|
15
|
-
*
|
|
16
|
-
* // Simple usage - client auto-created using SMITHERY_API_KEY env var
|
|
17
|
-
* const transport = new SmitheryTransport({
|
|
18
|
-
* mcpUrl: 'https://mcp.example.com/sse',
|
|
19
|
-
* });
|
|
11
|
+
* import { createConnection, SmitheryAuthorizationError } from '@smithery/api/mcp';
|
|
20
12
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* namespace: 'my-namespace',
|
|
26
|
-
* connectionId: 'my-connection',
|
|
27
|
-
* mcpUrl: 'https://mcp.example.com/sse',
|
|
28
|
-
* });
|
|
13
|
+
* try {
|
|
14
|
+
* const { transport } = await createConnection({
|
|
15
|
+
* mcpUrl: 'https://server.smithery.ai/exa/mcp',
|
|
16
|
+
* });
|
|
29
17
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
18
|
+
* const client = new Client({ name: 'my-app', version: '1.0.0' }, { capabilities: {} });
|
|
19
|
+
* await client.connect(transport);
|
|
32
20
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
21
|
+
* const { tools } = await client.listTools();
|
|
22
|
+
* const result = await client.callTool({ name: 'my-tool', arguments: {} });
|
|
23
|
+
* } catch (e) {
|
|
24
|
+
* if (e instanceof SmitheryAuthorizationError) {
|
|
25
|
+
* // The upstream MCP server requires OAuth — redirect the user
|
|
26
|
+
* console.log(`Please authorize: ${e.authorizationUrl}`);
|
|
27
|
+
* // After auth completes, retry with the same connectionId:
|
|
28
|
+
* // await createConnection({ connectionId: e.connectionId });
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
36
31
|
* ```
|
|
37
32
|
*/
|
|
38
33
|
|
|
39
|
-
import
|
|
40
|
-
import type { JSONRPCMessage, JSONRPCResponse, ServerCapabilities } from '@modelcontextprotocol/sdk/types.js';
|
|
34
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
41
35
|
import { Smithery } from '../client';
|
|
42
36
|
import type { Connection } from '../resources/beta/connect/connections';
|
|
43
37
|
|
|
44
|
-
export interface
|
|
38
|
+
export interface CreateConnectionOptions {
|
|
45
39
|
/**
|
|
46
|
-
* The Smithery client instance to use
|
|
40
|
+
* The Smithery client instance to use.
|
|
47
41
|
* If not provided, a new client will be created using the SMITHERY_API_KEY environment variable.
|
|
48
42
|
*/
|
|
49
43
|
client?: Smithery;
|
|
@@ -61,240 +55,141 @@ export interface SmitheryTransportOptions {
|
|
|
61
55
|
connectionId?: string;
|
|
62
56
|
|
|
63
57
|
/**
|
|
64
|
-
* The MCP server URL. Required when creating a new connection.
|
|
58
|
+
* The upstream MCP server URL. Required when creating a new connection.
|
|
65
59
|
* If connectionId is provided, this is used to create the connection if it doesn't exist.
|
|
66
|
-
* If connectionId is not provided, this is required
|
|
60
|
+
* If connectionId is not provided, this is required.
|
|
67
61
|
*/
|
|
68
62
|
mcpUrl?: string;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Optional server capabilities for the initialize response.
|
|
72
|
-
* If not provided, defaults to advertising tools, resources, and prompts support.
|
|
73
|
-
*/
|
|
74
|
-
capabilities?: ServerCapabilities;
|
|
75
63
|
}
|
|
76
64
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export class SmitheryTransport implements Transport {
|
|
81
|
-
private _client: Smithery;
|
|
82
|
-
private _namespace: string | undefined;
|
|
83
|
-
private _connectionId: string | undefined;
|
|
84
|
-
private _mcpUrl: string | undefined;
|
|
85
|
-
private _started = false;
|
|
86
|
-
private _closed = false;
|
|
87
|
-
private _capabilities: ServerCapabilities;
|
|
88
|
-
private _connection: Connection | null = null;
|
|
65
|
+
export interface SmitheryConnection {
|
|
66
|
+
/** A ready-to-use MCP transport with auth headers configured. */
|
|
67
|
+
transport: StreamableHTTPClientTransport;
|
|
89
68
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
onclose?: () => void;
|
|
69
|
+
/** The connection ID (for reuse across sessions). */
|
|
70
|
+
connectionId: string;
|
|
93
71
|
|
|
94
|
-
|
|
72
|
+
/** The raw MCP endpoint URL (for non-MCP-SDK use cases). */
|
|
73
|
+
url: string;
|
|
74
|
+
}
|
|
95
75
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Thrown when the upstream MCP server requires OAuth authorization.
|
|
78
|
+
* Contains the authorization URL to redirect the user to, and the connection ID
|
|
79
|
+
* to reuse when retrying after authorization completes.
|
|
80
|
+
*/
|
|
81
|
+
export class SmitheryAuthorizationError extends Error {
|
|
82
|
+
override name = 'SmitheryAuthorizationError';
|
|
83
|
+
|
|
84
|
+
constructor(
|
|
85
|
+
message: string,
|
|
86
|
+
public readonly authorizationUrl: string,
|
|
87
|
+
public readonly connectionId: string,
|
|
88
|
+
) {
|
|
89
|
+
super(message);
|
|
102
90
|
}
|
|
91
|
+
}
|
|
103
92
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Creates a Smithery Connect connection and returns an MCP transport.
|
|
95
|
+
*
|
|
96
|
+
* This function handles connection creation/retrieval and returns a standard
|
|
97
|
+
* `StreamableHTTPClientTransport` that can be used with any MCP SDK client.
|
|
98
|
+
* Smithery Connect manages the upstream MCP server connection, including
|
|
99
|
+
* OAuth credential storage and refresh.
|
|
100
|
+
*
|
|
101
|
+
* @throws {SmitheryAuthorizationError} If the upstream MCP server requires OAuth.
|
|
102
|
+
* The error contains `authorizationUrl` (where to redirect the user) and
|
|
103
|
+
* `connectionId` (to reuse when retrying after auth completes).
|
|
104
|
+
*/
|
|
105
|
+
export async function createConnection(options: CreateConnectionOptions): Promise<SmitheryConnection> {
|
|
106
|
+
const client = options.client ?? new Smithery();
|
|
114
107
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
tools: {},
|
|
119
|
-
resources: {},
|
|
120
|
-
prompts: {},
|
|
121
|
-
};
|
|
108
|
+
// Validate: mcpUrl is required if connectionId is not provided
|
|
109
|
+
if (!options.connectionId && !options.mcpUrl) {
|
|
110
|
+
throw new Error('mcpUrl is required when connectionId is not provided');
|
|
122
111
|
}
|
|
123
112
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
113
|
+
// Resolve namespace
|
|
114
|
+
const namespace = await resolveNamespace(client, options.namespace);
|
|
115
|
+
|
|
116
|
+
// Create or fetch connection
|
|
117
|
+
const connection = await resolveConnection(client, namespace, options.connectionId, options.mcpUrl);
|
|
118
|
+
const connectionId = connection.connectionId;
|
|
119
|
+
|
|
120
|
+
// Check connection status (present on create/set responses)
|
|
121
|
+
if (connection.status) {
|
|
122
|
+
if (connection.status.state === 'auth_required') {
|
|
123
|
+
const { authorizationUrl } = connection.status;
|
|
124
|
+
if (authorizationUrl) {
|
|
125
|
+
throw new SmitheryAuthorizationError(
|
|
126
|
+
`MCP server requires authorization. Please visit: ${authorizationUrl}`,
|
|
127
|
+
authorizationUrl,
|
|
128
|
+
connectionId,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
throw new Error('MCP server requires authorization.');
|
|
129
132
|
}
|
|
130
|
-
if (
|
|
131
|
-
throw new Error(
|
|
133
|
+
if (connection.status.state === 'error') {
|
|
134
|
+
throw new Error(`MCP connection failed: ${connection.status.message}`);
|
|
132
135
|
}
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
} else if (!connection.serverInfo) {
|
|
137
|
+
// No status field (e.g., fetched via get()) and no serverInfo means the
|
|
138
|
+
// connection never initialized successfully — likely requires authorization.
|
|
139
|
+
// Surface this early rather than returning a broken transport.
|
|
140
|
+
throw new Error(
|
|
141
|
+
'Connection is not initialized. The upstream MCP server may require authorization. ' +
|
|
142
|
+
'Try creating a new connection with mcpUrl to get authorization details.',
|
|
143
|
+
);
|
|
135
144
|
}
|
|
136
145
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
* If no namespace was provided, uses the first existing namespace or creates a new one.
|
|
140
|
-
*/
|
|
141
|
-
private async _ensureNamespace(): Promise<string> {
|
|
142
|
-
if (this._namespace) {
|
|
143
|
-
return this._namespace;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const { namespaces } = await this._client.namespaces.list();
|
|
147
|
-
if (namespaces.length > 0) {
|
|
148
|
-
this._namespace = namespaces[0]!.name;
|
|
149
|
-
} else {
|
|
150
|
-
// Create a new namespace with server-generated name
|
|
151
|
-
const { name } = await this._client.namespaces.create();
|
|
152
|
-
this._namespace = name;
|
|
153
|
-
}
|
|
154
|
-
return this._namespace;
|
|
155
|
-
}
|
|
146
|
+
// Build the MCP endpoint URL
|
|
147
|
+
const url = new URL(`/connect/${namespace}/${connectionId}/mcp`, client.baseURL).href;
|
|
156
148
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
149
|
+
// Create transport with auth headers
|
|
150
|
+
const transport = new StreamableHTTPClientTransport(new URL(url), {
|
|
151
|
+
requestInit: {
|
|
152
|
+
headers: {
|
|
153
|
+
Authorization: `Bearer ${client.apiKey}`,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
});
|
|
165
157
|
|
|
166
|
-
|
|
158
|
+
return { transport, connectionId, url };
|
|
159
|
+
}
|
|
167
160
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this._connection = await this._client.beta.connect.connections.get(this._connectionId, {
|
|
172
|
-
namespace,
|
|
173
|
-
});
|
|
174
|
-
} catch (error) {
|
|
175
|
-
// If connection doesn't exist and we have mcpUrl, create it with the specified ID
|
|
176
|
-
if (this._mcpUrl) {
|
|
177
|
-
this._connection = await this._client.beta.connect.connections.set(this._connectionId, {
|
|
178
|
-
namespace,
|
|
179
|
-
mcpUrl: this._mcpUrl,
|
|
180
|
-
});
|
|
181
|
-
} else {
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
} else {
|
|
186
|
-
// No connection ID: create a new connection with auto-generated ID
|
|
187
|
-
// mcpUrl is guaranteed to be present (validated in constructor)
|
|
188
|
-
this._connection = await this._client.beta.connect.connections.create(namespace, {
|
|
189
|
-
mcpUrl: this._mcpUrl!,
|
|
190
|
-
});
|
|
191
|
-
// Store the generated connection ID for subsequent RPC calls
|
|
192
|
-
this._connectionId = this._connection.connectionId;
|
|
193
|
-
}
|
|
161
|
+
async function resolveNamespace(client: Smithery, namespace?: string): Promise<string> {
|
|
162
|
+
if (namespace) {
|
|
163
|
+
return namespace;
|
|
194
164
|
}
|
|
195
165
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (this._closed) {
|
|
201
|
-
throw new Error('Transport has been closed');
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Only handle outgoing requests and notifications (messages with a method)
|
|
205
|
-
if (!('method' in message)) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Lazily ensure connection exists before processing any message
|
|
210
|
-
await this._ensureConnection();
|
|
211
|
-
|
|
212
|
-
// Intercept 'initialize' request - Smithery Connect handles initialization server-side
|
|
213
|
-
// Return the real serverInfo from the connection
|
|
214
|
-
if (message.method === 'initialize' && 'id' in message && message.id !== undefined) {
|
|
215
|
-
if (this.onmessage) {
|
|
216
|
-
const serverInfo = this._connection?.serverInfo ?? {
|
|
217
|
-
name: 'smithery-connect',
|
|
218
|
-
version: '1.0.0',
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const initializeResponse: JSONRPCResponse = {
|
|
222
|
-
jsonrpc: '2.0',
|
|
223
|
-
id: message.id,
|
|
224
|
-
result: {
|
|
225
|
-
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
226
|
-
serverInfo: {
|
|
227
|
-
name: serverInfo.name,
|
|
228
|
-
version: serverInfo.version,
|
|
229
|
-
},
|
|
230
|
-
capabilities: this._capabilities,
|
|
231
|
-
} as Record<string, unknown>,
|
|
232
|
-
};
|
|
233
|
-
// Use setTimeout to make this async and match real transport behavior
|
|
234
|
-
setTimeout(() => this.onmessage!(initializeResponse), 0);
|
|
235
|
-
}
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
166
|
+
const { namespaces } = await client.namespaces.list();
|
|
167
|
+
if (namespaces.length > 0) {
|
|
168
|
+
return namespaces[0]!.name;
|
|
169
|
+
}
|
|
238
170
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
171
|
+
const { name } = await client.namespaces.create();
|
|
172
|
+
return name;
|
|
173
|
+
}
|
|
243
174
|
|
|
175
|
+
async function resolveConnection(
|
|
176
|
+
client: Smithery,
|
|
177
|
+
namespace: string,
|
|
178
|
+
connectionId?: string,
|
|
179
|
+
mcpUrl?: string,
|
|
180
|
+
): Promise<Connection> {
|
|
181
|
+
if (connectionId) {
|
|
182
|
+
// Connection ID provided: try to get, or create if mcpUrl is provided
|
|
244
183
|
try {
|
|
245
|
-
|
|
246
|
-
// _namespace is guaranteed to be set after _ensureConnection
|
|
247
|
-
const rpcParams: Parameters<typeof this._client.beta.connect.rpc.call>[1] = {
|
|
248
|
-
namespace: this._namespace!,
|
|
249
|
-
jsonrpc: '2.0',
|
|
250
|
-
method: message.method,
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// Only add id if present (for requests, not notifications)
|
|
254
|
-
if ('id' in message && message.id !== undefined) {
|
|
255
|
-
rpcParams.id = message.id;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Only add params if present
|
|
259
|
-
if ('params' in message && message.params !== undefined) {
|
|
260
|
-
rpcParams.params = message.params as Record<string, unknown>;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const response = await this._client.beta.connect.rpc.call(this._connectionId!, rpcParams);
|
|
264
|
-
|
|
265
|
-
// Route the response back via onmessage callback for requests (messages with an id)
|
|
266
|
-
if ('id' in message && message.id !== undefined && this.onmessage) {
|
|
267
|
-
const jsonRpcResponse: JSONRPCResponse = {
|
|
268
|
-
jsonrpc: '2.0',
|
|
269
|
-
id: response.id!,
|
|
270
|
-
result: response.result as Record<string, unknown>,
|
|
271
|
-
};
|
|
272
|
-
this.onmessage(jsonRpcResponse);
|
|
273
|
-
}
|
|
184
|
+
return await client.beta.connect.connections.get(connectionId, { namespace });
|
|
274
185
|
} catch (error) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
// For requests, send an error response via onmessage
|
|
278
|
-
if ('id' in message && message.id !== undefined && this.onmessage) {
|
|
279
|
-
const errorResponse: JSONRPCResponse = {
|
|
280
|
-
jsonrpc: '2.0',
|
|
281
|
-
id: message.id,
|
|
282
|
-
error: {
|
|
283
|
-
code: -32603, // Internal error
|
|
284
|
-
message: normalizedError.message,
|
|
285
|
-
},
|
|
286
|
-
};
|
|
287
|
-
this.onmessage(errorResponse);
|
|
186
|
+
if (mcpUrl) {
|
|
187
|
+
return await client.beta.connect.connections.set(connectionId, { namespace, mcpUrl });
|
|
288
188
|
}
|
|
289
|
-
|
|
290
|
-
// Also report via onerror callback
|
|
291
|
-
this.onerror?.(normalizedError);
|
|
189
|
+
throw error;
|
|
292
190
|
}
|
|
293
191
|
}
|
|
294
192
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
this._started = false;
|
|
298
|
-
this.onclose?.();
|
|
299
|
-
}
|
|
193
|
+
// No connection ID: create a new connection with auto-generated ID
|
|
194
|
+
return await client.beta.connect.connections.create(namespace, { mcpUrl: mcpUrl! });
|
|
300
195
|
}
|
|
@@ -14,20 +14,20 @@ import {
|
|
|
14
14
|
ConnectionsListResponse,
|
|
15
15
|
CreateConnectionRequest,
|
|
16
16
|
} from './connections';
|
|
17
|
-
import * as
|
|
18
|
-
import { JsonRpcRequest, JsonRpcResponse,
|
|
17
|
+
import * as McpAPI from './mcp';
|
|
18
|
+
import { JsonRpcRequest, JsonRpcResponse, Mcp, McpCallParams } from './mcp';
|
|
19
19
|
import * as ToolsAPI from './tools';
|
|
20
20
|
import { ToolSearchParams, ToolSearchResponse, Tools } from './tools';
|
|
21
21
|
|
|
22
22
|
export class Connect extends APIResource {
|
|
23
23
|
tools: ToolsAPI.Tools = new ToolsAPI.Tools(this._client);
|
|
24
24
|
connections: ConnectionsAPI.Connections = new ConnectionsAPI.Connections(this._client);
|
|
25
|
-
|
|
25
|
+
mcp: McpAPI.Mcp = new McpAPI.Mcp(this._client);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
Connect.Tools = Tools;
|
|
29
29
|
Connect.Connections = Connections;
|
|
30
|
-
Connect.
|
|
30
|
+
Connect.Mcp = Mcp;
|
|
31
31
|
|
|
32
32
|
export declare namespace Connect {
|
|
33
33
|
export {
|
|
@@ -50,9 +50,9 @@ export declare namespace Connect {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export {
|
|
53
|
-
|
|
53
|
+
Mcp as Mcp,
|
|
54
54
|
type JsonRpcRequest as JsonRpcRequest,
|
|
55
55
|
type JsonRpcResponse as JsonRpcResponse,
|
|
56
|
-
type
|
|
56
|
+
type McpCallParams as McpCallParams,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
@@ -134,7 +134,7 @@ export interface Connection {
|
|
|
134
134
|
serverInfo?: Connection.ServerInfo;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
137
|
+
* Last known connection status
|
|
138
138
|
*/
|
|
139
139
|
status?:
|
|
140
140
|
| Connection.ConnectionStatusConnected
|
|
@@ -265,6 +265,11 @@ export interface ConnectionListParams {
|
|
|
265
265
|
*/
|
|
266
266
|
limit?: number;
|
|
267
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Filter by exact MCP server URL
|
|
270
|
+
*/
|
|
271
|
+
mcpUrl?: string;
|
|
272
|
+
|
|
268
273
|
/**
|
|
269
274
|
* Filter by exact connection name
|
|
270
275
|
*/
|
|
@@ -13,5 +13,5 @@ export {
|
|
|
13
13
|
type ConnectionGetParams,
|
|
14
14
|
type ConnectionSetParams,
|
|
15
15
|
} from './connections';
|
|
16
|
-
export {
|
|
16
|
+
export { Mcp, type JsonRpcRequest, type JsonRpcResponse, type McpCallParams } from './mcp';
|
|
17
17
|
export { Tools, type ToolSearchResponse, type ToolSearchParams } from './tools';
|
|
@@ -5,14 +5,14 @@ import { APIPromise } from '../../../core/api-promise';
|
|
|
5
5
|
import { RequestOptions } from '../../../internal/request-options';
|
|
6
6
|
import { path } from '../../../internal/utils/path';
|
|
7
7
|
|
|
8
|
-
export class
|
|
8
|
+
export class Mcp extends APIResource {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* scope.
|
|
10
|
+
* Streamable HTTP MCP endpoint. Accepts JSON-RPC requests and notifications.
|
|
11
|
+
* Requires service token with mcp scope.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
|
-
* const jsonRpcResponse = await client.beta.connect.
|
|
15
|
+
* const jsonRpcResponse = await client.beta.connect.mcp.call(
|
|
16
16
|
* 'connectionId',
|
|
17
17
|
* {
|
|
18
18
|
* namespace: 'namespace',
|
|
@@ -22,9 +22,9 @@ export class Rpc extends APIResource {
|
|
|
22
22
|
* );
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
call(connectionID: string, params:
|
|
25
|
+
call(connectionID: string, params: McpCallParams, options?: RequestOptions): APIPromise<JsonRpcResponse> {
|
|
26
26
|
const { namespace, ...body } = params;
|
|
27
|
-
return this._client.post(path`/connect/${namespace}/${connectionID}/
|
|
27
|
+
return this._client.post(path`/connect/${namespace}/${connectionID}/mcp`, { body, ...options });
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -52,7 +52,7 @@ export interface JsonRpcResponse {
|
|
|
52
52
|
result?: unknown;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
export interface
|
|
55
|
+
export interface McpCallParams {
|
|
56
56
|
/**
|
|
57
57
|
* Path param
|
|
58
58
|
*/
|
|
@@ -79,10 +79,10 @@ export interface RpcCallParams {
|
|
|
79
79
|
params?: unknown;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export declare namespace
|
|
82
|
+
export declare namespace Mcp {
|
|
83
83
|
export {
|
|
84
84
|
type JsonRpcRequest as JsonRpcRequest,
|
|
85
85
|
type JsonRpcResponse as JsonRpcResponse,
|
|
86
|
-
type
|
|
86
|
+
type McpCallParams as McpCallParams,
|
|
87
87
|
};
|
|
88
88
|
}
|
package/src/resources/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export {
|
|
|
7
7
|
type NamespaceCreateResponse,
|
|
8
8
|
type NamespaceListResponse,
|
|
9
9
|
type NamespaceSetResponse,
|
|
10
|
-
} from './namespaces';
|
|
10
|
+
} from './namespaces/namespaces';
|
|
11
11
|
export {
|
|
12
12
|
Servers,
|
|
13
13
|
type BuildConfig,
|
|
@@ -17,6 +17,9 @@ export {
|
|
|
17
17
|
type ServerDeleteResponse,
|
|
18
18
|
type ServerGetResponse,
|
|
19
19
|
type ServerListParams,
|
|
20
|
+
type ServerDeleteParams,
|
|
21
|
+
type ServerDownloadParams,
|
|
22
|
+
type ServerGetParams,
|
|
20
23
|
type ServerListResponsesSmitheryPage,
|
|
21
24
|
} from './servers/servers';
|
|
22
25
|
export {
|
|
@@ -32,8 +35,8 @@ export {
|
|
|
32
35
|
type ConnectionScope,
|
|
33
36
|
type CreateTokenRequest,
|
|
34
37
|
type CreateTokenResponse,
|
|
38
|
+
type McpScope,
|
|
35
39
|
type ResourceScope,
|
|
36
|
-
type RpcScope,
|
|
37
40
|
type TokenCreateParams,
|
|
38
41
|
} from './tokens';
|
|
39
42
|
export { Uplink, type UplinkCreateTokenResponse } from './uplink';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
Namespaces,
|
|
5
|
+
type NamespaceCreateResponse,
|
|
6
|
+
type NamespaceListResponse,
|
|
7
|
+
type NamespaceSetResponse,
|
|
8
|
+
} from './namespaces';
|
|
9
|
+
export {
|
|
10
|
+
Servers,
|
|
11
|
+
type CreateServerRequest,
|
|
12
|
+
type CreateServerResponse,
|
|
13
|
+
type ServerCreateParams,
|
|
14
|
+
} from './servers';
|