@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.
Files changed (159) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +10 -5
  3. package/client.d.mts +5 -5
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +5 -5
  6. package/client.d.ts.map +1 -1
  7. package/client.js +1 -1
  8. package/client.js.map +1 -1
  9. package/client.mjs +1 -1
  10. package/client.mjs.map +1 -1
  11. package/lib/mcp-transport.d.mts +57 -69
  12. package/lib/mcp-transport.d.mts.map +1 -1
  13. package/lib/mcp-transport.d.ts +57 -69
  14. package/lib/mcp-transport.d.ts.map +1 -1
  15. package/lib/mcp-transport.js +106 -204
  16. package/lib/mcp-transport.js.map +1 -1
  17. package/lib/mcp-transport.mjs +103 -202
  18. package/lib/mcp-transport.mjs.map +1 -1
  19. package/package.json +1 -1
  20. package/resources/beta/connect/connect.d.mts +4 -4
  21. package/resources/beta/connect/connect.d.ts +4 -4
  22. package/resources/beta/connect/connect.js +4 -4
  23. package/resources/beta/connect/connect.mjs +4 -4
  24. package/resources/beta/connect/connections.d.mts +5 -1
  25. package/resources/beta/connect/connections.d.mts.map +1 -1
  26. package/resources/beta/connect/connections.d.ts +5 -1
  27. package/resources/beta/connect/connections.d.ts.map +1 -1
  28. package/resources/beta/connect/index.d.mts +1 -1
  29. package/resources/beta/connect/index.d.ts +1 -1
  30. package/resources/beta/connect/index.js +3 -3
  31. package/resources/beta/connect/index.mjs +1 -1
  32. package/resources/beta/connect/{rpc.d.mts → mcp.d.mts} +9 -9
  33. package/resources/beta/connect/{rpc.d.mts.map → mcp.d.mts.map} +1 -1
  34. package/resources/beta/connect/{rpc.d.ts → mcp.d.ts} +9 -9
  35. package/resources/beta/connect/{rpc.d.ts.map → mcp.d.ts.map} +1 -1
  36. package/resources/beta/connect/{rpc.js → mcp.js} +8 -8
  37. package/resources/beta/connect/{rpc.js.map → mcp.js.map} +1 -1
  38. package/resources/beta/connect/{rpc.mjs → mcp.mjs} +6 -6
  39. package/resources/beta/connect/{rpc.mjs.map → mcp.mjs.map} +1 -1
  40. package/resources/beta/connect/tools.d.mts +0 -3
  41. package/resources/beta/connect/tools.d.mts.map +1 -1
  42. package/resources/beta/connect/tools.d.ts +0 -3
  43. package/resources/beta/connect/tools.d.ts.map +1 -1
  44. package/resources/index.d.mts +3 -3
  45. package/resources/index.d.mts.map +1 -1
  46. package/resources/index.d.ts +3 -3
  47. package/resources/index.d.ts.map +1 -1
  48. package/resources/index.js +1 -1
  49. package/resources/index.js.map +1 -1
  50. package/resources/index.mjs +1 -1
  51. package/resources/index.mjs.map +1 -1
  52. package/resources/namespaces/index.d.mts +3 -0
  53. package/resources/namespaces/index.d.mts.map +1 -0
  54. package/resources/namespaces/index.d.ts +3 -0
  55. package/resources/namespaces/index.d.ts.map +1 -0
  56. package/resources/namespaces/index.js +9 -0
  57. package/resources/namespaces/index.js.map +1 -0
  58. package/resources/namespaces/index.mjs +4 -0
  59. package/resources/namespaces/index.mjs.map +1 -0
  60. package/resources/namespaces/namespaces.d.mts +60 -0
  61. package/resources/namespaces/namespaces.d.mts.map +1 -0
  62. package/resources/namespaces/namespaces.d.ts +60 -0
  63. package/resources/namespaces/namespaces.d.ts.map +1 -0
  64. package/resources/namespaces/namespaces.js +54 -0
  65. package/resources/namespaces/namespaces.js.map +1 -0
  66. package/resources/namespaces/namespaces.mjs +49 -0
  67. package/resources/namespaces/namespaces.mjs.map +1 -0
  68. package/resources/namespaces/servers.d.mts +46 -0
  69. package/resources/namespaces/servers.d.mts.map +1 -0
  70. package/resources/namespaces/servers.d.ts +46 -0
  71. package/resources/namespaces/servers.d.ts.map +1 -0
  72. package/resources/namespaces/servers.js +25 -0
  73. package/resources/namespaces/servers.js.map +1 -0
  74. package/resources/namespaces/servers.mjs +21 -0
  75. package/resources/namespaces/servers.mjs.map +1 -0
  76. package/resources/namespaces.d.mts +1 -39
  77. package/resources/namespaces.d.mts.map +1 -1
  78. package/resources/namespaces.d.ts +1 -39
  79. package/resources/namespaces.d.ts.map +1 -1
  80. package/resources/namespaces.js +2 -26
  81. package/resources/namespaces.js.map +1 -1
  82. package/resources/namespaces.mjs +1 -24
  83. package/resources/namespaces.mjs.map +1 -1
  84. package/resources/servers/deployments.d.mts +55 -9
  85. package/resources/servers/deployments.d.mts.map +1 -1
  86. package/resources/servers/deployments.d.ts +55 -9
  87. package/resources/servers/deployments.d.ts.map +1 -1
  88. package/resources/servers/deployments.js +42 -8
  89. package/resources/servers/deployments.js.map +1 -1
  90. package/resources/servers/deployments.mjs +42 -8
  91. package/resources/servers/deployments.mjs.map +1 -1
  92. package/resources/servers/index.d.mts +4 -3
  93. package/resources/servers/index.d.mts.map +1 -1
  94. package/resources/servers/index.d.ts +4 -3
  95. package/resources/servers/index.d.ts.map +1 -1
  96. package/resources/servers/index.js +3 -1
  97. package/resources/servers/index.js.map +1 -1
  98. package/resources/servers/index.mjs +1 -0
  99. package/resources/servers/index.mjs.map +1 -1
  100. package/resources/servers/logs.d.mts +15 -4
  101. package/resources/servers/logs.d.mts.map +1 -1
  102. package/resources/servers/logs.d.ts +15 -4
  103. package/resources/servers/logs.d.ts.map +1 -1
  104. package/resources/servers/logs.js +10 -2
  105. package/resources/servers/logs.js.map +1 -1
  106. package/resources/servers/logs.mjs +10 -2
  107. package/resources/servers/logs.mjs.map +1 -1
  108. package/resources/servers/repo.d.mts +98 -0
  109. package/resources/servers/repo.d.mts.map +1 -0
  110. package/resources/servers/repo.d.ts +98 -0
  111. package/resources/servers/repo.d.ts.map +1 -0
  112. package/resources/servers/repo.js +55 -0
  113. package/resources/servers/repo.js.map +1 -0
  114. package/resources/servers/repo.mjs +51 -0
  115. package/resources/servers/repo.mjs.map +1 -0
  116. package/resources/servers/secrets.d.mts +46 -4
  117. package/resources/servers/secrets.d.mts.map +1 -1
  118. package/resources/servers/secrets.d.ts +46 -4
  119. package/resources/servers/secrets.d.ts.map +1 -1
  120. package/resources/servers/secrets.js +36 -6
  121. package/resources/servers/secrets.js.map +1 -1
  122. package/resources/servers/secrets.mjs +36 -6
  123. package/resources/servers/secrets.mjs.map +1 -1
  124. package/resources/servers/servers.d.mts +57 -10
  125. package/resources/servers/servers.d.mts.map +1 -1
  126. package/resources/servers/servers.d.ts +57 -10
  127. package/resources/servers/servers.d.ts.map +1 -1
  128. package/resources/servers/servers.js +47 -8
  129. package/resources/servers/servers.js.map +1 -1
  130. package/resources/servers/servers.mjs +47 -8
  131. package/resources/servers/servers.mjs.map +1 -1
  132. package/resources/tokens.d.mts +18 -18
  133. package/resources/tokens.d.mts.map +1 -1
  134. package/resources/tokens.d.ts +18 -18
  135. package/resources/tokens.d.ts.map +1 -1
  136. package/src/client.ts +14 -8
  137. package/src/lib/mcp-transport.ts +131 -236
  138. package/src/resources/beta/connect/connect.ts +6 -6
  139. package/src/resources/beta/connect/connections.ts +6 -1
  140. package/src/resources/beta/connect/index.ts +1 -1
  141. package/src/resources/beta/connect/{rpc.ts → mcp.ts} +9 -9
  142. package/src/resources/beta/connect/tools.ts +0 -2
  143. package/src/resources/index.ts +5 -2
  144. package/src/resources/namespaces/index.ts +14 -0
  145. package/src/resources/namespaces/namespaces.ts +92 -0
  146. package/src/resources/namespaces/servers.ts +71 -0
  147. package/src/resources/namespaces.ts +1 -61
  148. package/src/resources/servers/deployments.ts +76 -15
  149. package/src/resources/servers/index.ts +14 -0
  150. package/src/resources/servers/logs.ts +18 -9
  151. package/src/resources/servers/repo.ts +143 -0
  152. package/src/resources/servers/secrets.ts +55 -7
  153. package/src/resources/servers/servers.ts +92 -8
  154. package/src/resources/tokens.ts +17 -17
  155. package/src/version.ts +1 -1
  156. package/version.d.mts +1 -1
  157. package/version.d.ts +1 -1
  158. package/version.js +1 -1
  159. package/version.mjs +1 -1
@@ -1,49 +1,43 @@
1
1
  /**
2
- * SmitheryTransport - An MCP Transport that routes JSON-RPC messages through Smithery Connect.
2
+ * Smithery Connect Create an MCP connection that routes through Smithery Connect.
3
3
  *
4
- * This allows you to use the official MCP SDK's Client class with Smithery Connect as the transport layer.
5
- *
6
- * **Important:** Smithery Connect handles MCP initialization server-side when a connection is created.
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 Smithery from '@smithery/api';
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
- * // Or with explicit client
22
- * const smithery = new Smithery({ apiKey: process.env.SMITHERY_API_KEY });
23
- * const transport2 = new SmitheryTransport({
24
- * client: smithery,
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
- * const mcpClient = new Client({ name: 'my-app', version: '1.0.0' }, { capabilities: {} });
31
- * await mcpClient.connect(transport);
18
+ * const client = new Client({ name: 'my-app', version: '1.0.0' }, { capabilities: {} });
19
+ * await client.connect(transport);
32
20
  *
33
- * // Now use the MCP SDK's ergonomic API
34
- * const { tools } = await mcpClient.listTools();
35
- * const result = await mcpClient.callTool({ name: 'my-tool', arguments: {} });
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 type { Transport, TransportSendOptions } from '@modelcontextprotocol/sdk/shared/transport.js';
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 SmitheryTransportOptions {
38
+ export interface CreateConnectionOptions {
45
39
  /**
46
- * The Smithery client instance to use for making RPC calls.
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 and a new connection will be created.
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
- // MCP protocol version
78
- const LATEST_PROTOCOL_VERSION = '2024-11-05';
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
- onmessage?: (message: JSONRPCMessage) => void;
91
- onerror?: (error: Error) => void;
92
- onclose?: () => void;
69
+ /** The connection ID (for reuse across sessions). */
70
+ connectionId: string;
93
71
 
94
- sessionId?: string;
72
+ /** The raw MCP endpoint URL (for non-MCP-SDK use cases). */
73
+ url: string;
74
+ }
95
75
 
96
- /**
97
- * Returns the connection ID. If no connectionId was provided in options,
98
- * this returns the auto-generated ID after the first message is sent.
99
- */
100
- get connectionId(): string | undefined {
101
- return this._connectionId;
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
- constructor(options: SmitheryTransportOptions) {
105
- this._client = options.client ?? new Smithery();
106
- this._namespace = options.namespace;
107
- this._connectionId = options.connectionId;
108
- this._mcpUrl = options.mcpUrl;
109
-
110
- // Validate: mcpUrl is required if connectionId is not provided
111
- if (!this._connectionId && !this._mcpUrl) {
112
- throw new Error('mcpUrl is required when connectionId is not provided');
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
- this._capabilities = options.capabilities ?? {
116
- // Default to advertising common capabilities
117
- // The actual MCP server behind Smithery Connect will handle the real capabilities
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
- async start(): Promise<void> {
125
- if (this._started) {
126
- throw new Error(
127
- 'SmitheryTransport already started! If using Client class, note that connect() calls start() automatically.',
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 (this._closed) {
131
- throw new Error('Transport has been closed');
133
+ if (connection.status.state === 'error') {
134
+ throw new Error(`MCP connection failed: ${connection.status.message}`);
132
135
  }
133
-
134
- this._started = true;
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
- * Lazily ensures a namespace is available.
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
- * Lazily ensures the Smithery Connect connection exists.
159
- * Called on first message to defer network IO until actually needed.
160
- */
161
- private async _ensureConnection(): Promise<void> {
162
- if (this._connection) {
163
- return;
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
- const namespace = await this._ensureNamespace();
158
+ return { transport, connectionId, url };
159
+ }
167
160
 
168
- if (this._connectionId) {
169
- // Connection ID provided: try to get, or create if mcpUrl is provided
170
- try {
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
- async send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void> {
197
- if (!this._started) {
198
- throw new Error('Transport not started');
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
- // Intercept 'notifications/initialized' - no response needed, just acknowledge
240
- if (message.method === 'notifications/initialized') {
241
- return;
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
- // Build the RPC call params, only including id if it's defined
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
- const normalizedError = error instanceof Error ? error : new Error(String(error));
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
- async close(): Promise<void> {
296
- this._closed = true;
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 RpcAPI from './rpc';
18
- import { JsonRpcRequest, JsonRpcResponse, Rpc, RpcCallParams } from './rpc';
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
- rpc: RpcAPI.Rpc = new RpcAPI.Rpc(this._client);
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.Rpc = Rpc;
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
- Rpc as Rpc,
53
+ Mcp as Mcp,
54
54
  type JsonRpcRequest as JsonRpcRequest,
55
55
  type JsonRpcResponse as JsonRpcResponse,
56
- type RpcCallParams as RpcCallParams,
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
- * Connection status after initialization (only returned on create)
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 { Rpc, type JsonRpcRequest, type JsonRpcResponse, type RpcCallParams } from './rpc';
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 Rpc extends APIResource {
8
+ export class Mcp extends APIResource {
9
9
  /**
10
- * Execute a JSON-RPC call on an MCP connection. Requires service token with rpc
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.rpc.call(
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: RpcCallParams, options?: RequestOptions): APIPromise<JsonRpcResponse> {
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}/rpc`, { body, ...options });
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 RpcCallParams {
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 Rpc {
82
+ export declare namespace Mcp {
83
83
  export {
84
84
  type JsonRpcRequest as JsonRpcRequest,
85
85
  type JsonRpcResponse as JsonRpcResponse,
86
- type RpcCallParams as RpcCallParams,
86
+ type McpCallParams as McpCallParams,
87
87
  };
88
88
  }
@@ -49,8 +49,6 @@ export namespace ToolSearchResponse {
49
49
  name: string;
50
50
 
51
51
  description?: string;
52
-
53
- inputSchema?: { [key: string]: unknown };
54
52
  }
55
53
  }
56
54
  }
@@ -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';