integrate-sdk 0.6.9 → 0.7.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/dist/adapters/auto-routes.js +35 -0
- package/dist/adapters/base-handler.js +35 -0
- package/dist/adapters/nextjs.js +52 -0
- package/dist/adapters/node.js +35 -0
- package/dist/adapters/solid-start.js +106 -27
- package/dist/adapters/svelte-kit.js +106 -27
- package/dist/index.js +107 -27
- package/dist/oauth.js +35 -0
- package/dist/server.js +107 -27
- package/dist/src/adapters/base-handler.d.ts +34 -0
- package/dist/src/adapters/base-handler.d.ts.map +1 -1
- package/dist/src/adapters/nextjs.d.ts +26 -0
- package/dist/src/adapters/nextjs.d.ts.map +1 -1
- package/dist/src/client.d.ts +6 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +18 -0
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1014,6 +1014,7 @@ class MCPClient {
|
|
|
1014
1014
|
connecting = null;
|
|
1015
1015
|
oauthManager;
|
|
1016
1016
|
eventEmitter = new SimpleEventEmitter;
|
|
1017
|
+
apiRouteBase;
|
|
1017
1018
|
github;
|
|
1018
1019
|
gmail;
|
|
1019
1020
|
server;
|
|
@@ -1025,6 +1026,7 @@ class MCPClient {
|
|
|
1025
1026
|
});
|
|
1026
1027
|
const oauthApiBase = config.oauthApiBase || "/api/integrate/oauth";
|
|
1027
1028
|
const defaultRedirectUri = this.getDefaultRedirectUri(oauthApiBase);
|
|
1029
|
+
this.apiRouteBase = config.apiRouteBase || "/api/integrate";
|
|
1028
1030
|
this.plugins = config.plugins.map((plugin) => {
|
|
1029
1031
|
if (plugin.oauth && !plugin.oauth.redirectUri) {
|
|
1030
1032
|
return {
|
|
@@ -1116,12 +1118,8 @@ class MCPClient {
|
|
|
1116
1118
|
if (!this.availableTools.has(name)) {
|
|
1117
1119
|
throw new Error(`Tool "${name}" is not available on the server. Available tools: ${Array.from(this.availableTools.keys()).join(", ")}`);
|
|
1118
1120
|
}
|
|
1119
|
-
const params = {
|
|
1120
|
-
name,
|
|
1121
|
-
arguments: args
|
|
1122
|
-
};
|
|
1123
1121
|
try {
|
|
1124
|
-
const response = await this.
|
|
1122
|
+
const response = await this.callToolThroughHandler(name, args);
|
|
1125
1123
|
return response;
|
|
1126
1124
|
} catch (error) {
|
|
1127
1125
|
const parsedError = parseServerError(error, { toolName: name });
|
|
@@ -1180,18 +1178,58 @@ class MCPClient {
|
|
|
1180
1178
|
if (!this.availableTools.has(name)) {
|
|
1181
1179
|
throw new Error(`Tool "${name}" is not available on the server. Available tools: ${Array.from(this.availableTools.keys()).join(", ")}`);
|
|
1182
1180
|
}
|
|
1183
|
-
const params = {
|
|
1184
|
-
name,
|
|
1185
|
-
arguments: args
|
|
1186
|
-
};
|
|
1187
1181
|
try {
|
|
1188
|
-
const response = await this.
|
|
1182
|
+
const response = await this.callToolThroughHandler(name, args);
|
|
1189
1183
|
return response;
|
|
1190
1184
|
} catch (error) {
|
|
1191
1185
|
const parsedError = parseServerError(error, { toolName: name });
|
|
1192
1186
|
throw parsedError;
|
|
1193
1187
|
}
|
|
1194
1188
|
}
|
|
1189
|
+
async callToolThroughHandler(name, args, provider) {
|
|
1190
|
+
const url = `${this.apiRouteBase}/mcp`;
|
|
1191
|
+
const headers = {
|
|
1192
|
+
"Content-Type": "application/json"
|
|
1193
|
+
};
|
|
1194
|
+
if (provider) {
|
|
1195
|
+
const tokenData = this.oauthManager.getProviderToken(provider);
|
|
1196
|
+
if (tokenData) {
|
|
1197
|
+
headers["Authorization"] = `Bearer ${tokenData.accessToken}`;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
const response = await fetch(url, {
|
|
1201
|
+
method: "POST",
|
|
1202
|
+
headers,
|
|
1203
|
+
body: JSON.stringify({
|
|
1204
|
+
name,
|
|
1205
|
+
arguments: args
|
|
1206
|
+
})
|
|
1207
|
+
});
|
|
1208
|
+
if (!response.ok) {
|
|
1209
|
+
let errorMessage = `Request failed: ${response.statusText}`;
|
|
1210
|
+
const error = new Error(errorMessage);
|
|
1211
|
+
error.statusCode = response.status;
|
|
1212
|
+
try {
|
|
1213
|
+
const errorData = await response.json();
|
|
1214
|
+
if (errorData.error) {
|
|
1215
|
+
errorMessage = typeof errorData.error === "string" ? errorData.error : errorData.error.message || errorMessage;
|
|
1216
|
+
error.message = errorMessage;
|
|
1217
|
+
}
|
|
1218
|
+
if (errorData.code) {
|
|
1219
|
+
error.code = errorData.code;
|
|
1220
|
+
}
|
|
1221
|
+
if (errorData.data) {
|
|
1222
|
+
error.data = errorData.data;
|
|
1223
|
+
}
|
|
1224
|
+
if (errorData.error && typeof errorData.error === "object") {
|
|
1225
|
+
error.jsonrpcError = errorData.error;
|
|
1226
|
+
}
|
|
1227
|
+
} catch {}
|
|
1228
|
+
throw error;
|
|
1229
|
+
}
|
|
1230
|
+
const result = await response.json();
|
|
1231
|
+
return result;
|
|
1232
|
+
}
|
|
1195
1233
|
async callToolWithRetry(name, args, retryCount = 0) {
|
|
1196
1234
|
if (!this.initialized) {
|
|
1197
1235
|
throw new Error("Client not initialized. Call connect() first.");
|
|
@@ -1203,35 +1241,24 @@ class MCPClient {
|
|
|
1203
1241
|
throw new Error(`Tool "${name}" is not available on the server. Available tools: ${Array.from(this.availableTools.keys()).join(", ")}`);
|
|
1204
1242
|
}
|
|
1205
1243
|
const provider = this.getProviderForTool(name);
|
|
1206
|
-
if (provider) {
|
|
1207
|
-
const tokenData = this.oauthManager.getProviderToken(provider);
|
|
1208
|
-
if (tokenData) {
|
|
1209
|
-
this.transport.setHeader("Authorization", `Bearer ${tokenData.accessToken}`);
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
const params = {
|
|
1213
|
-
name,
|
|
1214
|
-
arguments: args
|
|
1215
|
-
};
|
|
1216
1244
|
try {
|
|
1217
|
-
const response = await this.
|
|
1245
|
+
const response = await this.callToolThroughHandler(name, args, provider);
|
|
1218
1246
|
if (provider) {
|
|
1219
1247
|
this.authState.set(provider, { authenticated: true });
|
|
1220
1248
|
}
|
|
1221
1249
|
return response;
|
|
1222
1250
|
} catch (error) {
|
|
1223
|
-
const
|
|
1224
|
-
const parsedError = parseServerError(error, { toolName: name, provider: provider2 });
|
|
1251
|
+
const parsedError = parseServerError(error, { toolName: name, provider });
|
|
1225
1252
|
if (isAuthError(parsedError) && retryCount < this.maxReauthRetries) {
|
|
1226
|
-
if (
|
|
1227
|
-
this.authState.set(
|
|
1253
|
+
if (provider) {
|
|
1254
|
+
this.authState.set(provider, {
|
|
1228
1255
|
authenticated: false,
|
|
1229
1256
|
lastError: parsedError
|
|
1230
1257
|
});
|
|
1231
1258
|
}
|
|
1232
|
-
if (this.onReauthRequired &&
|
|
1259
|
+
if (this.onReauthRequired && provider) {
|
|
1233
1260
|
const reauthSuccess = await this.onReauthRequired({
|
|
1234
|
-
provider
|
|
1261
|
+
provider,
|
|
1235
1262
|
error: parsedError,
|
|
1236
1263
|
toolName: name
|
|
1237
1264
|
});
|
|
@@ -1684,6 +1711,41 @@ class OAuthHandler {
|
|
|
1684
1711
|
const data = await response.json();
|
|
1685
1712
|
return data;
|
|
1686
1713
|
}
|
|
1714
|
+
async handleToolCall(request, authHeader) {
|
|
1715
|
+
const url = new URL("/tools/call", this.serverUrl);
|
|
1716
|
+
const headers = this.getHeaders({
|
|
1717
|
+
"Content-Type": "application/json"
|
|
1718
|
+
});
|
|
1719
|
+
if (authHeader && authHeader.startsWith("Bearer ")) {
|
|
1720
|
+
headers["Authorization"] = authHeader;
|
|
1721
|
+
}
|
|
1722
|
+
const jsonRpcRequest = {
|
|
1723
|
+
jsonrpc: "2.0",
|
|
1724
|
+
id: Date.now() + Math.random(),
|
|
1725
|
+
method: "tools/call",
|
|
1726
|
+
params: {
|
|
1727
|
+
name: request.name,
|
|
1728
|
+
arguments: request.arguments || {}
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
const response = await fetch(url.toString(), {
|
|
1732
|
+
method: "POST",
|
|
1733
|
+
headers,
|
|
1734
|
+
body: JSON.stringify(jsonRpcRequest)
|
|
1735
|
+
});
|
|
1736
|
+
if (!response.ok) {
|
|
1737
|
+
const error = await response.text();
|
|
1738
|
+
throw new Error(`MCP server failed to execute tool call: ${error}`);
|
|
1739
|
+
}
|
|
1740
|
+
const jsonRpcResponse = await response.json();
|
|
1741
|
+
if (jsonRpcResponse.error) {
|
|
1742
|
+
const error = new Error(jsonRpcResponse.error.message || "Tool call failed");
|
|
1743
|
+
error.code = jsonRpcResponse.error.code;
|
|
1744
|
+
error.data = jsonRpcResponse.error.data;
|
|
1745
|
+
throw error;
|
|
1746
|
+
}
|
|
1747
|
+
return jsonRpcResponse.result;
|
|
1748
|
+
}
|
|
1687
1749
|
}
|
|
1688
1750
|
// src/adapters/nextjs.ts
|
|
1689
1751
|
function createNextOAuthHandler(config) {
|
|
@@ -1760,6 +1822,9 @@ function createNextOAuthHandler(config) {
|
|
|
1760
1822
|
if (action === "disconnect") {
|
|
1761
1823
|
return handlers.disconnect(req);
|
|
1762
1824
|
}
|
|
1825
|
+
if (action === "mcp") {
|
|
1826
|
+
return handlers.mcp(req);
|
|
1827
|
+
}
|
|
1763
1828
|
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
1764
1829
|
},
|
|
1765
1830
|
async GET(req, context) {
|
|
@@ -1772,6 +1837,17 @@ function createNextOAuthHandler(config) {
|
|
|
1772
1837
|
}
|
|
1773
1838
|
};
|
|
1774
1839
|
},
|
|
1840
|
+
async mcp(req) {
|
|
1841
|
+
try {
|
|
1842
|
+
const body = await req.json();
|
|
1843
|
+
const authHeader = req.headers.get("authorization");
|
|
1844
|
+
const result = await handler.handleToolCall(body, authHeader);
|
|
1845
|
+
return Response.json(result);
|
|
1846
|
+
} catch (error) {
|
|
1847
|
+
console.error("[MCP Tool Call] Error:", error);
|
|
1848
|
+
return Response.json({ error: error.message || "Failed to execute tool call" }, { status: error.statusCode || 500 });
|
|
1849
|
+
}
|
|
1850
|
+
},
|
|
1775
1851
|
toNextJsHandler(redirectConfig) {
|
|
1776
1852
|
const defaultRedirectUrl = redirectConfig?.redirectUrl || "/";
|
|
1777
1853
|
const errorRedirectUrl = redirectConfig?.errorRedirectUrl || "/auth-error";
|
|
@@ -1792,6 +1868,9 @@ function createNextOAuthHandler(config) {
|
|
|
1792
1868
|
}
|
|
1793
1869
|
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
1794
1870
|
}
|
|
1871
|
+
if (segments.length === 1 && segments[0] === "mcp") {
|
|
1872
|
+
return handlers.mcp(req);
|
|
1873
|
+
}
|
|
1795
1874
|
return Response.json({ error: `Invalid route: /${segments.join("/")}` }, { status: 404 });
|
|
1796
1875
|
},
|
|
1797
1876
|
async GET(req, context) {
|
|
@@ -2259,6 +2338,7 @@ function createMCPServer(config) {
|
|
|
2259
2338
|
if (segments.length === 2 && segments[0] !== "oauth") {
|
|
2260
2339
|
return Response.json({ error: `Invalid route: /${segments.join("/")}` }, { status: 404 });
|
|
2261
2340
|
}
|
|
2341
|
+
if (segments.length === 1 && segments[0] === "mcp") {}
|
|
2262
2342
|
}
|
|
2263
2343
|
if (method === "GET" && action === "callback") {
|
|
2264
2344
|
const url = new URL(request.url);
|
package/dist/oauth.js
CHANGED
|
@@ -139,6 +139,41 @@ class OAuthHandler {
|
|
|
139
139
|
const data = await response.json();
|
|
140
140
|
return data;
|
|
141
141
|
}
|
|
142
|
+
async handleToolCall(request, authHeader) {
|
|
143
|
+
const url = new URL("/tools/call", this.serverUrl);
|
|
144
|
+
const headers = this.getHeaders({
|
|
145
|
+
"Content-Type": "application/json"
|
|
146
|
+
});
|
|
147
|
+
if (authHeader && authHeader.startsWith("Bearer ")) {
|
|
148
|
+
headers["Authorization"] = authHeader;
|
|
149
|
+
}
|
|
150
|
+
const jsonRpcRequest = {
|
|
151
|
+
jsonrpc: "2.0",
|
|
152
|
+
id: Date.now() + Math.random(),
|
|
153
|
+
method: "tools/call",
|
|
154
|
+
params: {
|
|
155
|
+
name: request.name,
|
|
156
|
+
arguments: request.arguments || {}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const response = await fetch(url.toString(), {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers,
|
|
162
|
+
body: JSON.stringify(jsonRpcRequest)
|
|
163
|
+
});
|
|
164
|
+
if (!response.ok) {
|
|
165
|
+
const error = await response.text();
|
|
166
|
+
throw new Error(`MCP server failed to execute tool call: ${error}`);
|
|
167
|
+
}
|
|
168
|
+
const jsonRpcResponse = await response.json();
|
|
169
|
+
if (jsonRpcResponse.error) {
|
|
170
|
+
const error = new Error(jsonRpcResponse.error.message || "Tool call failed");
|
|
171
|
+
error.code = jsonRpcResponse.error.code;
|
|
172
|
+
error.data = jsonRpcResponse.error.data;
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
return jsonRpcResponse.result;
|
|
176
|
+
}
|
|
142
177
|
}
|
|
143
178
|
|
|
144
179
|
// src/adapters/auto-routes.ts
|
package/dist/server.js
CHANGED
|
@@ -1014,6 +1014,7 @@ class MCPClient {
|
|
|
1014
1014
|
connecting = null;
|
|
1015
1015
|
oauthManager;
|
|
1016
1016
|
eventEmitter = new SimpleEventEmitter;
|
|
1017
|
+
apiRouteBase;
|
|
1017
1018
|
github;
|
|
1018
1019
|
gmail;
|
|
1019
1020
|
server;
|
|
@@ -1025,6 +1026,7 @@ class MCPClient {
|
|
|
1025
1026
|
});
|
|
1026
1027
|
const oauthApiBase = config.oauthApiBase || "/api/integrate/oauth";
|
|
1027
1028
|
const defaultRedirectUri = this.getDefaultRedirectUri(oauthApiBase);
|
|
1029
|
+
this.apiRouteBase = config.apiRouteBase || "/api/integrate";
|
|
1028
1030
|
this.plugins = config.plugins.map((plugin) => {
|
|
1029
1031
|
if (plugin.oauth && !plugin.oauth.redirectUri) {
|
|
1030
1032
|
return {
|
|
@@ -1116,12 +1118,8 @@ class MCPClient {
|
|
|
1116
1118
|
if (!this.availableTools.has(name)) {
|
|
1117
1119
|
throw new Error(`Tool "${name}" is not available on the server. Available tools: ${Array.from(this.availableTools.keys()).join(", ")}`);
|
|
1118
1120
|
}
|
|
1119
|
-
const params = {
|
|
1120
|
-
name,
|
|
1121
|
-
arguments: args
|
|
1122
|
-
};
|
|
1123
1121
|
try {
|
|
1124
|
-
const response = await this.
|
|
1122
|
+
const response = await this.callToolThroughHandler(name, args);
|
|
1125
1123
|
return response;
|
|
1126
1124
|
} catch (error) {
|
|
1127
1125
|
const parsedError = parseServerError(error, { toolName: name });
|
|
@@ -1180,18 +1178,58 @@ class MCPClient {
|
|
|
1180
1178
|
if (!this.availableTools.has(name)) {
|
|
1181
1179
|
throw new Error(`Tool "${name}" is not available on the server. Available tools: ${Array.from(this.availableTools.keys()).join(", ")}`);
|
|
1182
1180
|
}
|
|
1183
|
-
const params = {
|
|
1184
|
-
name,
|
|
1185
|
-
arguments: args
|
|
1186
|
-
};
|
|
1187
1181
|
try {
|
|
1188
|
-
const response = await this.
|
|
1182
|
+
const response = await this.callToolThroughHandler(name, args);
|
|
1189
1183
|
return response;
|
|
1190
1184
|
} catch (error) {
|
|
1191
1185
|
const parsedError = parseServerError(error, { toolName: name });
|
|
1192
1186
|
throw parsedError;
|
|
1193
1187
|
}
|
|
1194
1188
|
}
|
|
1189
|
+
async callToolThroughHandler(name, args, provider) {
|
|
1190
|
+
const url = `${this.apiRouteBase}/mcp`;
|
|
1191
|
+
const headers = {
|
|
1192
|
+
"Content-Type": "application/json"
|
|
1193
|
+
};
|
|
1194
|
+
if (provider) {
|
|
1195
|
+
const tokenData = this.oauthManager.getProviderToken(provider);
|
|
1196
|
+
if (tokenData) {
|
|
1197
|
+
headers["Authorization"] = `Bearer ${tokenData.accessToken}`;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
const response = await fetch(url, {
|
|
1201
|
+
method: "POST",
|
|
1202
|
+
headers,
|
|
1203
|
+
body: JSON.stringify({
|
|
1204
|
+
name,
|
|
1205
|
+
arguments: args
|
|
1206
|
+
})
|
|
1207
|
+
});
|
|
1208
|
+
if (!response.ok) {
|
|
1209
|
+
let errorMessage = `Request failed: ${response.statusText}`;
|
|
1210
|
+
const error = new Error(errorMessage);
|
|
1211
|
+
error.statusCode = response.status;
|
|
1212
|
+
try {
|
|
1213
|
+
const errorData = await response.json();
|
|
1214
|
+
if (errorData.error) {
|
|
1215
|
+
errorMessage = typeof errorData.error === "string" ? errorData.error : errorData.error.message || errorMessage;
|
|
1216
|
+
error.message = errorMessage;
|
|
1217
|
+
}
|
|
1218
|
+
if (errorData.code) {
|
|
1219
|
+
error.code = errorData.code;
|
|
1220
|
+
}
|
|
1221
|
+
if (errorData.data) {
|
|
1222
|
+
error.data = errorData.data;
|
|
1223
|
+
}
|
|
1224
|
+
if (errorData.error && typeof errorData.error === "object") {
|
|
1225
|
+
error.jsonrpcError = errorData.error;
|
|
1226
|
+
}
|
|
1227
|
+
} catch {}
|
|
1228
|
+
throw error;
|
|
1229
|
+
}
|
|
1230
|
+
const result = await response.json();
|
|
1231
|
+
return result;
|
|
1232
|
+
}
|
|
1195
1233
|
async callToolWithRetry(name, args, retryCount = 0) {
|
|
1196
1234
|
if (!this.initialized) {
|
|
1197
1235
|
throw new Error("Client not initialized. Call connect() first.");
|
|
@@ -1203,35 +1241,24 @@ class MCPClient {
|
|
|
1203
1241
|
throw new Error(`Tool "${name}" is not available on the server. Available tools: ${Array.from(this.availableTools.keys()).join(", ")}`);
|
|
1204
1242
|
}
|
|
1205
1243
|
const provider = this.getProviderForTool(name);
|
|
1206
|
-
if (provider) {
|
|
1207
|
-
const tokenData = this.oauthManager.getProviderToken(provider);
|
|
1208
|
-
if (tokenData) {
|
|
1209
|
-
this.transport.setHeader("Authorization", `Bearer ${tokenData.accessToken}`);
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
const params = {
|
|
1213
|
-
name,
|
|
1214
|
-
arguments: args
|
|
1215
|
-
};
|
|
1216
1244
|
try {
|
|
1217
|
-
const response = await this.
|
|
1245
|
+
const response = await this.callToolThroughHandler(name, args, provider);
|
|
1218
1246
|
if (provider) {
|
|
1219
1247
|
this.authState.set(provider, { authenticated: true });
|
|
1220
1248
|
}
|
|
1221
1249
|
return response;
|
|
1222
1250
|
} catch (error) {
|
|
1223
|
-
const
|
|
1224
|
-
const parsedError = parseServerError(error, { toolName: name, provider: provider2 });
|
|
1251
|
+
const parsedError = parseServerError(error, { toolName: name, provider });
|
|
1225
1252
|
if (isAuthError(parsedError) && retryCount < this.maxReauthRetries) {
|
|
1226
|
-
if (
|
|
1227
|
-
this.authState.set(
|
|
1253
|
+
if (provider) {
|
|
1254
|
+
this.authState.set(provider, {
|
|
1228
1255
|
authenticated: false,
|
|
1229
1256
|
lastError: parsedError
|
|
1230
1257
|
});
|
|
1231
1258
|
}
|
|
1232
|
-
if (this.onReauthRequired &&
|
|
1259
|
+
if (this.onReauthRequired && provider) {
|
|
1233
1260
|
const reauthSuccess = await this.onReauthRequired({
|
|
1234
|
-
provider
|
|
1261
|
+
provider,
|
|
1235
1262
|
error: parsedError,
|
|
1236
1263
|
toolName: name
|
|
1237
1264
|
});
|
|
@@ -1685,6 +1712,41 @@ class OAuthHandler {
|
|
|
1685
1712
|
const data = await response.json();
|
|
1686
1713
|
return data;
|
|
1687
1714
|
}
|
|
1715
|
+
async handleToolCall(request, authHeader) {
|
|
1716
|
+
const url = new URL("/tools/call", this.serverUrl);
|
|
1717
|
+
const headers = this.getHeaders({
|
|
1718
|
+
"Content-Type": "application/json"
|
|
1719
|
+
});
|
|
1720
|
+
if (authHeader && authHeader.startsWith("Bearer ")) {
|
|
1721
|
+
headers["Authorization"] = authHeader;
|
|
1722
|
+
}
|
|
1723
|
+
const jsonRpcRequest = {
|
|
1724
|
+
jsonrpc: "2.0",
|
|
1725
|
+
id: Date.now() + Math.random(),
|
|
1726
|
+
method: "tools/call",
|
|
1727
|
+
params: {
|
|
1728
|
+
name: request.name,
|
|
1729
|
+
arguments: request.arguments || {}
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
const response = await fetch(url.toString(), {
|
|
1733
|
+
method: "POST",
|
|
1734
|
+
headers,
|
|
1735
|
+
body: JSON.stringify(jsonRpcRequest)
|
|
1736
|
+
});
|
|
1737
|
+
if (!response.ok) {
|
|
1738
|
+
const error = await response.text();
|
|
1739
|
+
throw new Error(`MCP server failed to execute tool call: ${error}`);
|
|
1740
|
+
}
|
|
1741
|
+
const jsonRpcResponse = await response.json();
|
|
1742
|
+
if (jsonRpcResponse.error) {
|
|
1743
|
+
const error = new Error(jsonRpcResponse.error.message || "Tool call failed");
|
|
1744
|
+
error.code = jsonRpcResponse.error.code;
|
|
1745
|
+
error.data = jsonRpcResponse.error.data;
|
|
1746
|
+
throw error;
|
|
1747
|
+
}
|
|
1748
|
+
return jsonRpcResponse.result;
|
|
1749
|
+
}
|
|
1688
1750
|
}
|
|
1689
1751
|
|
|
1690
1752
|
// src/adapters/nextjs.ts
|
|
@@ -1762,6 +1824,9 @@ function createNextOAuthHandler(config) {
|
|
|
1762
1824
|
if (action === "disconnect") {
|
|
1763
1825
|
return handlers.disconnect(req);
|
|
1764
1826
|
}
|
|
1827
|
+
if (action === "mcp") {
|
|
1828
|
+
return handlers.mcp(req);
|
|
1829
|
+
}
|
|
1765
1830
|
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
1766
1831
|
},
|
|
1767
1832
|
async GET(req, context) {
|
|
@@ -1774,6 +1839,17 @@ function createNextOAuthHandler(config) {
|
|
|
1774
1839
|
}
|
|
1775
1840
|
};
|
|
1776
1841
|
},
|
|
1842
|
+
async mcp(req) {
|
|
1843
|
+
try {
|
|
1844
|
+
const body = await req.json();
|
|
1845
|
+
const authHeader = req.headers.get("authorization");
|
|
1846
|
+
const result = await handler.handleToolCall(body, authHeader);
|
|
1847
|
+
return Response.json(result);
|
|
1848
|
+
} catch (error) {
|
|
1849
|
+
console.error("[MCP Tool Call] Error:", error);
|
|
1850
|
+
return Response.json({ error: error.message || "Failed to execute tool call" }, { status: error.statusCode || 500 });
|
|
1851
|
+
}
|
|
1852
|
+
},
|
|
1777
1853
|
toNextJsHandler(redirectConfig) {
|
|
1778
1854
|
const defaultRedirectUrl = redirectConfig?.redirectUrl || "/";
|
|
1779
1855
|
const errorRedirectUrl = redirectConfig?.errorRedirectUrl || "/auth-error";
|
|
@@ -1794,6 +1870,9 @@ function createNextOAuthHandler(config) {
|
|
|
1794
1870
|
}
|
|
1795
1871
|
return Response.json({ error: `Unknown action: ${action}` }, { status: 404 });
|
|
1796
1872
|
}
|
|
1873
|
+
if (segments.length === 1 && segments[0] === "mcp") {
|
|
1874
|
+
return handlers.mcp(req);
|
|
1875
|
+
}
|
|
1797
1876
|
return Response.json({ error: `Invalid route: /${segments.join("/")}` }, { status: 404 });
|
|
1798
1877
|
},
|
|
1799
1878
|
async GET(req, context) {
|
|
@@ -2086,6 +2165,7 @@ function createMCPServer(config) {
|
|
|
2086
2165
|
if (segments.length === 2 && segments[0] !== "oauth") {
|
|
2087
2166
|
return Response.json({ error: `Invalid route: /${segments.join("/")}` }, { status: 404 });
|
|
2088
2167
|
}
|
|
2168
|
+
if (segments.length === 1 && segments[0] === "mcp") {}
|
|
2089
2169
|
}
|
|
2090
2170
|
if (method === "GET" && action === "callback") {
|
|
2091
2171
|
const url = new URL(request.url);
|
|
@@ -85,6 +85,29 @@ export interface DisconnectResponse {
|
|
|
85
85
|
success: boolean;
|
|
86
86
|
provider: string;
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Request body for MCP tool call endpoint
|
|
90
|
+
*/
|
|
91
|
+
export interface ToolCallRequest {
|
|
92
|
+
name: string;
|
|
93
|
+
arguments?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Response from MCP tool call endpoint
|
|
97
|
+
* Matches MCPToolCallResponse structure
|
|
98
|
+
*/
|
|
99
|
+
export interface ToolCallResponse {
|
|
100
|
+
content: Array<{
|
|
101
|
+
type: "text" | "image" | "resource";
|
|
102
|
+
text?: string;
|
|
103
|
+
data?: string;
|
|
104
|
+
mimeType?: string;
|
|
105
|
+
[key: string]: unknown;
|
|
106
|
+
}>;
|
|
107
|
+
isError?: boolean;
|
|
108
|
+
structuredContent?: Record<string, unknown>;
|
|
109
|
+
_meta?: Record<string, unknown>;
|
|
110
|
+
}
|
|
88
111
|
/**
|
|
89
112
|
* OAuth Handler
|
|
90
113
|
* Handles OAuth authorization flows by proxying requests to MCP server
|
|
@@ -144,5 +167,16 @@ export declare class OAuthHandler {
|
|
|
144
167
|
* @throws Error if MCP server request fails
|
|
145
168
|
*/
|
|
146
169
|
handleDisconnect(request: DisconnectRequest, accessToken: string): Promise<DisconnectResponse>;
|
|
170
|
+
/**
|
|
171
|
+
* Handle MCP tool call
|
|
172
|
+
* Forwards tool call requests to MCP server with API key and provider token
|
|
173
|
+
*
|
|
174
|
+
* @param request - Tool call request with name and arguments
|
|
175
|
+
* @param authHeader - Authorization header from client (Bearer token)
|
|
176
|
+
* @returns Tool call response
|
|
177
|
+
*
|
|
178
|
+
* @throws Error if MCP server request fails
|
|
179
|
+
*/
|
|
180
|
+
handleToolCall(request: ToolCallRequest, authHeader: string | null): Promise<ToolCallResponse>;
|
|
147
181
|
}
|
|
148
182
|
//# sourceMappingURL=base-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-handler.d.ts","sourceRoot":"","sources":["../../../src/adapters/base-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;QACxB,iDAAiD;QACjD,QAAQ,EAAE,MAAM,CAAC;QACjB,qDAAqD;QACrD,YAAY,EAAE,MAAM,CAAC;QACrB,qCAAqC;QACrC,WAAW,CAAC,EAAE,MAA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,CAAC;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;;GAIG;AACH,qBAAa,YAAY;IAIX,OAAO,CAAC,MAAM;IAH1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;gBAEb,MAAM,EAAE,kBAAkB;IAW9C;;OAEG;IACH,OAAO,CAAC,UAAU;IAalB;;;;;;;;;OASG;IACG,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA2C5E;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2CzE;;;;;;;;;OASG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IA4BlF;;;;;;;;;;OAUG;IACG,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA4BpG;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAiDrG"}
|
|
@@ -265,6 +265,31 @@ export declare function createNextOAuthHandler(config: OAuthHandlerConfig): {
|
|
|
265
265
|
}>;
|
|
266
266
|
}): Promise<NextResponse>;
|
|
267
267
|
};
|
|
268
|
+
/**
|
|
269
|
+
* POST /api/integrate/mcp
|
|
270
|
+
*
|
|
271
|
+
* Handle MCP tool call requests from client
|
|
272
|
+
*
|
|
273
|
+
* Request body:
|
|
274
|
+
* ```json
|
|
275
|
+
* {
|
|
276
|
+
* "name": "github_list_own_repos",
|
|
277
|
+
* "arguments": {}
|
|
278
|
+
* }
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* Headers:
|
|
282
|
+
* - Authorization: Bearer <provider_access_token>
|
|
283
|
+
*
|
|
284
|
+
* Response:
|
|
285
|
+
* ```json
|
|
286
|
+
* {
|
|
287
|
+
* "content": [{"type": "text", "text": "..."}],
|
|
288
|
+
* "isError": false
|
|
289
|
+
* }
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
mcp(req: NextRequest): Promise<NextResponse>;
|
|
268
293
|
/**
|
|
269
294
|
* Create unified catch-all route handler
|
|
270
295
|
*
|
|
@@ -299,6 +324,7 @@ export declare function createNextOAuthHandler(config: OAuthHandlerConfig): {
|
|
|
299
324
|
* - GET /api/integrate/oauth/callback - Provider OAuth redirect
|
|
300
325
|
* - GET /api/integrate/oauth/status - Check authorization status
|
|
301
326
|
* - POST /api/integrate/oauth/disconnect - Disconnect provider
|
|
327
|
+
* - POST /api/integrate/mcp - Execute MCP tool calls
|
|
302
328
|
*/
|
|
303
329
|
toNextJsHandler(redirectConfig?: {
|
|
304
330
|
/** URL to redirect to after OAuth callback (default: '/') */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../../../src/adapters/nextjs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG1E,KAAK,WAAW,GAAG,GAAG,CAAC;AACvB,KAAK,YAAY,GAAG,GAAG,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB;IAI7D;;;;;;;;;;;;;;;;;;;;;;;;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AY,CAAC;;EA+F/B"}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export declare class MCPClient<TPlugins extends readonly MCPPlugin[] = readonly
|
|
|
57
57
|
private connecting;
|
|
58
58
|
private oauthManager;
|
|
59
59
|
private eventEmitter;
|
|
60
|
+
private apiRouteBase;
|
|
60
61
|
readonly github: PluginNamespaces<TPlugins> extends {
|
|
61
62
|
github: GitHubPluginClient;
|
|
62
63
|
} ? GitHubPluginClient : never;
|
|
@@ -125,6 +126,11 @@ export declare class MCPClient<TPlugins extends readonly MCPPlugin[] = readonly
|
|
|
125
126
|
* ```
|
|
126
127
|
*/
|
|
127
128
|
callServerTool(name: string, args?: Record<string, unknown>): Promise<MCPToolCallResponse>;
|
|
129
|
+
/**
|
|
130
|
+
* Call a tool through the API handler (server-side route)
|
|
131
|
+
* Routes tool calls through /api/integrate/mcp instead of directly to MCP server
|
|
132
|
+
*/
|
|
133
|
+
private callToolThroughHandler;
|
|
128
134
|
/**
|
|
129
135
|
* Internal method to call a tool with retry logic
|
|
130
136
|
*/
|
package/dist/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,OAAO,EAEP,mBAAmB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,OAAO,EAEP,mBAAmB,EAGpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4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195
195
|
*/
|
|
196
196
|
oauthApiBase?: string;
|
|
197
|
+
/**
|
|
198
|
+
* Base URL for API routes (including MCP tool calls)
|
|
199
|
+
* Used to route tool calls through server-side handlers instead of directly to MCP server
|
|
200
|
+
*
|
|
201
|
+
* The SDK will call:
|
|
202
|
+
* - POST {apiRouteBase}/mcp - Execute MCP tool calls
|
|
203
|
+
*
|
|
204
|
+
* @default '/api/integrate'
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const client = createMCPClient({
|
|
209
|
+
* plugins: [githubPlugin({ ... })],
|
|
210
|
+
* apiRouteBase: '/api/integrate'
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
apiRouteBase?: string;
|
|
197
215
|
/**
|
|
198
216
|
* Automatically detect and handle OAuth callbacks from URL hash fragments
|
|
199
217
|
* When true, the SDK will automatically process #oauth_callback={...} in the URL
|