mcp-use 1.7.2-canary.0 → 1.8.0-canary.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/.tsbuildinfo +1 -1
- package/dist/{chunk-2JBWOW4S.js → chunk-DWTSQOEC.js} +21 -3
- package/dist/{chunk-MKLN5UDK.js → chunk-HDYKWLGV.js} +1 -1
- package/dist/{chunk-2AOGMX4T.js → chunk-LWAQBWXN.js} +1 -1
- package/dist/{chunk-N6GWWEUC.js → chunk-X2HZKCNO.js} +1 -1
- package/dist/index.cjs +21 -3
- package/dist/index.js +4 -4
- package/dist/src/agents/index.js +2 -2
- package/dist/src/browser.cjs +21 -3
- package/dist/src/browser.js +2 -2
- package/dist/src/client/prompts.js +2 -2
- package/dist/src/connectors/base.d.ts +4 -4
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/react/index.cjs +21 -3
- package/dist/src/react/index.js +3 -3
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts +4 -4
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +1 -1
- package/dist/src/server/index.cjs +242 -62
- package/dist/src/server/index.js +242 -62
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/src/server/index.js
CHANGED
|
@@ -105,39 +105,45 @@ function createAppsSdkResource(uri, htmlTemplate, metadata) {
|
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
__name(createAppsSdkResource, "createAppsSdkResource");
|
|
108
|
-
function createUIResourceFromDefinition(definition, params, config) {
|
|
108
|
+
async function createUIResourceFromDefinition(definition, params, config) {
|
|
109
109
|
const buildIdPart = config.buildId ? `-${config.buildId}` : "";
|
|
110
110
|
const uri = definition.type === "appsSdk" ? `ui://widget/${definition.name}${buildIdPart}.html` : `ui://widget/${definition.name}${buildIdPart}`;
|
|
111
111
|
const encoding = definition.encoding || "text";
|
|
112
112
|
switch (definition.type) {
|
|
113
113
|
case "externalUrl": {
|
|
114
114
|
const widgetUrl = buildWidgetUrl(definition.widget, params, config);
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
return await Promise.resolve(
|
|
116
|
+
createExternalUrlResource(
|
|
117
|
+
uri,
|
|
118
|
+
widgetUrl,
|
|
119
|
+
encoding,
|
|
120
|
+
definition.adapters,
|
|
121
|
+
definition.appsSdkMetadata
|
|
122
|
+
)
|
|
121
123
|
);
|
|
122
124
|
}
|
|
123
125
|
case "rawHtml": {
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
return await Promise.resolve(
|
|
127
|
+
createRawHtmlResource(
|
|
128
|
+
uri,
|
|
129
|
+
definition.htmlContent,
|
|
130
|
+
encoding,
|
|
131
|
+
definition.adapters,
|
|
132
|
+
definition.appsSdkMetadata
|
|
133
|
+
)
|
|
130
134
|
);
|
|
131
135
|
}
|
|
132
136
|
case "remoteDom": {
|
|
133
137
|
const framework = definition.framework || "react";
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
return await Promise.resolve(
|
|
139
|
+
createRemoteDomResource(
|
|
140
|
+
uri,
|
|
141
|
+
definition.script,
|
|
142
|
+
framework,
|
|
143
|
+
encoding,
|
|
144
|
+
definition.adapters,
|
|
145
|
+
definition.appsSdkMetadata
|
|
146
|
+
)
|
|
141
147
|
);
|
|
142
148
|
}
|
|
143
149
|
case "appsSdk": {
|
|
@@ -775,7 +781,32 @@ var McpServer = class {
|
|
|
775
781
|
}
|
|
776
782
|
}
|
|
777
783
|
}
|
|
778
|
-
|
|
784
|
+
let progressToken = extra?._meta?.progressToken;
|
|
785
|
+
let sendNotification = extra?.sendNotification;
|
|
786
|
+
if (!progressToken || !sendNotification) {
|
|
787
|
+
let session;
|
|
788
|
+
if (requestContext) {
|
|
789
|
+
for (const [, s] of this.sessions.entries()) {
|
|
790
|
+
if (s.context === requestContext) {
|
|
791
|
+
session = s;
|
|
792
|
+
break;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
} else {
|
|
796
|
+
const firstSession = this.sessions.values().next().value;
|
|
797
|
+
if (firstSession) {
|
|
798
|
+
session = firstSession;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (session) {
|
|
802
|
+
if (!progressToken && session.progressToken) {
|
|
803
|
+
progressToken = session.progressToken;
|
|
804
|
+
}
|
|
805
|
+
if (!sendNotification && session.sendNotification) {
|
|
806
|
+
sendNotification = session.sendNotification;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
779
810
|
const enhancedContext = requestContext ? Object.create(requestContext) : {};
|
|
780
811
|
enhancedContext.sample = async (sampleParams, options) => {
|
|
781
812
|
const {
|
|
@@ -786,7 +817,7 @@ var McpServer = class {
|
|
|
786
817
|
let progressCount = 0;
|
|
787
818
|
let completed = false;
|
|
788
819
|
let progressInterval = null;
|
|
789
|
-
if (progressToken &&
|
|
820
|
+
if (progressToken && sendNotification) {
|
|
790
821
|
progressInterval = setInterval(async () => {
|
|
791
822
|
if (completed) return;
|
|
792
823
|
progressCount++;
|
|
@@ -802,21 +833,26 @@ var McpServer = class {
|
|
|
802
833
|
}
|
|
803
834
|
}
|
|
804
835
|
try {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
836
|
+
if (sendNotification) {
|
|
837
|
+
await sendNotification({
|
|
838
|
+
method: "notifications/progress",
|
|
839
|
+
params: {
|
|
840
|
+
progressToken,
|
|
841
|
+
progress: progressData.progress,
|
|
842
|
+
total: progressData.total,
|
|
843
|
+
message: progressData.message
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
}
|
|
814
847
|
} catch {
|
|
815
848
|
}
|
|
816
849
|
}, progressIntervalMs);
|
|
817
850
|
}
|
|
818
851
|
try {
|
|
819
|
-
const
|
|
852
|
+
const sdkTimeout = timeout && timeout !== Infinity ? timeout : 2147483647;
|
|
853
|
+
const samplePromise = this.createMessage(sampleParams, {
|
|
854
|
+
timeout: sdkTimeout
|
|
855
|
+
});
|
|
820
856
|
if (timeout && timeout !== Infinity) {
|
|
821
857
|
const timeoutPromise = new Promise((_, reject) => {
|
|
822
858
|
setTimeout(
|
|
@@ -834,16 +870,18 @@ var McpServer = class {
|
|
|
834
870
|
}
|
|
835
871
|
}
|
|
836
872
|
};
|
|
837
|
-
enhancedContext.reportProgress = progressToken &&
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
873
|
+
enhancedContext.reportProgress = progressToken && sendNotification ? async (progress, total, message) => {
|
|
874
|
+
if (sendNotification) {
|
|
875
|
+
await sendNotification({
|
|
876
|
+
method: "notifications/progress",
|
|
877
|
+
params: {
|
|
878
|
+
progressToken,
|
|
879
|
+
progress,
|
|
880
|
+
total,
|
|
881
|
+
message
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
}
|
|
847
885
|
} : void 0;
|
|
848
886
|
const executeCallback = /* @__PURE__ */ __name(async () => {
|
|
849
887
|
if (actualCallback.length >= 2) {
|
|
@@ -948,7 +986,6 @@ var McpServer = class {
|
|
|
948
986
|
* ```
|
|
949
987
|
*/
|
|
950
988
|
async createMessage(params, options) {
|
|
951
|
-
console.log("createMessage", params, options);
|
|
952
989
|
return await this.server.server.createMessage(params, options);
|
|
953
990
|
}
|
|
954
991
|
/**
|
|
@@ -1054,7 +1091,10 @@ var McpServer = class {
|
|
|
1054
1091
|
annotations: definition.annotations,
|
|
1055
1092
|
readCallback: /* @__PURE__ */ __name(async () => {
|
|
1056
1093
|
const params = definition.type === "externalUrl" ? this.applyDefaultProps(definition.props) : {};
|
|
1057
|
-
const uiResource = this.createWidgetUIResource(
|
|
1094
|
+
const uiResource = await this.createWidgetUIResource(
|
|
1095
|
+
definition,
|
|
1096
|
+
params
|
|
1097
|
+
);
|
|
1058
1098
|
uiResource.resource.uri = resourceUri;
|
|
1059
1099
|
return {
|
|
1060
1100
|
contents: [uiResource.resource]
|
|
@@ -1077,7 +1117,7 @@ var McpServer = class {
|
|
|
1077
1117
|
description: definition.description,
|
|
1078
1118
|
annotations: definition.annotations,
|
|
1079
1119
|
readCallback: /* @__PURE__ */ __name(async (uri, params) => {
|
|
1080
|
-
const uiResource = this.createWidgetUIResource(definition, {});
|
|
1120
|
+
const uiResource = await this.createWidgetUIResource(definition, {});
|
|
1081
1121
|
uiResource.resource.uri = uri.toString();
|
|
1082
1122
|
return {
|
|
1083
1123
|
contents: [uiResource.resource]
|
|
@@ -1107,7 +1147,10 @@ var McpServer = class {
|
|
|
1107
1147
|
inputs: this.convertPropsToInputs(definition.props),
|
|
1108
1148
|
_meta: Object.keys(toolMetadata).length > 0 ? toolMetadata : void 0,
|
|
1109
1149
|
cb: /* @__PURE__ */ __name(async (params) => {
|
|
1110
|
-
const uiResource = this.createWidgetUIResource(
|
|
1150
|
+
const uiResource = await this.createWidgetUIResource(
|
|
1151
|
+
definition,
|
|
1152
|
+
params
|
|
1153
|
+
);
|
|
1111
1154
|
if (definition.type === "appsSdk") {
|
|
1112
1155
|
const randomId = Math.random().toString(36).substring(2, 15);
|
|
1113
1156
|
const uniqueUri = this.generateWidgetUri(
|
|
@@ -1157,7 +1200,7 @@ var McpServer = class {
|
|
|
1157
1200
|
* @param params - Parameters to pass to the widget via URL
|
|
1158
1201
|
* @returns UIResource object compatible with MCP-UI
|
|
1159
1202
|
*/
|
|
1160
|
-
createWidgetUIResource(definition, params) {
|
|
1203
|
+
async createWidgetUIResource(definition, params) {
|
|
1161
1204
|
let configBaseUrl = `http://${this.serverHost}`;
|
|
1162
1205
|
let configPort = this.serverPort || 3001;
|
|
1163
1206
|
if (this.serverBaseUrl) {
|
|
@@ -1174,7 +1217,7 @@ var McpServer = class {
|
|
|
1174
1217
|
port: configPort,
|
|
1175
1218
|
buildId: this.buildId
|
|
1176
1219
|
};
|
|
1177
|
-
const uiResource = createUIResourceFromDefinition(
|
|
1220
|
+
const uiResource = await createUIResourceFromDefinition(
|
|
1178
1221
|
definition,
|
|
1179
1222
|
params,
|
|
1180
1223
|
urlConfig
|
|
@@ -1778,7 +1821,15 @@ if (container && Component) {
|
|
|
1778
1821
|
html = await fsHelpers.readFileSync(indexPath, "utf8");
|
|
1779
1822
|
const mcpUrl = this.getServerBaseUrl();
|
|
1780
1823
|
if (mcpUrl && html) {
|
|
1781
|
-
|
|
1824
|
+
let htmlWithoutComments = html;
|
|
1825
|
+
let prevHtmlWithoutComments;
|
|
1826
|
+
do {
|
|
1827
|
+
prevHtmlWithoutComments = htmlWithoutComments;
|
|
1828
|
+
htmlWithoutComments = htmlWithoutComments.replace(
|
|
1829
|
+
/<!--[\s\S]*?-->/g,
|
|
1830
|
+
""
|
|
1831
|
+
);
|
|
1832
|
+
} while (prevHtmlWithoutComments !== htmlWithoutComments);
|
|
1782
1833
|
const baseTagRegex = /<base\s+[^>]*\/?>/i;
|
|
1783
1834
|
if (baseTagRegex.test(htmlWithoutComments)) {
|
|
1784
1835
|
const actualBaseTagMatch = html.match(/<base\s+[^>]*\/?>/i);
|
|
@@ -1950,7 +2001,8 @@ if (container && Component) {
|
|
|
1950
2001
|
const { allowedOrigins, enableDnsRebindingProtection } = getTransportConfig();
|
|
1951
2002
|
const transport = new StreamableHTTPServerTransport({
|
|
1952
2003
|
sessionIdGenerator: /* @__PURE__ */ __name(() => generateUUID(), "sessionIdGenerator"),
|
|
1953
|
-
enableJsonResponse:
|
|
2004
|
+
enableJsonResponse: false,
|
|
2005
|
+
// Allow SSE streaming for progress notifications
|
|
1954
2006
|
allowedOrigins,
|
|
1955
2007
|
enableDnsRebindingProtection,
|
|
1956
2008
|
onsessioninitialized: /* @__PURE__ */ __name((id) => {
|
|
@@ -1975,7 +2027,8 @@ if (container && Component) {
|
|
|
1975
2027
|
const transport = new StreamableHTTPServerTransport({
|
|
1976
2028
|
sessionIdGenerator: /* @__PURE__ */ __name(() => oldSessionId, "sessionIdGenerator"),
|
|
1977
2029
|
// Reuse old session ID!
|
|
1978
|
-
enableJsonResponse:
|
|
2030
|
+
enableJsonResponse: false,
|
|
2031
|
+
// Allow SSE streaming for progress notifications
|
|
1979
2032
|
allowedOrigins,
|
|
1980
2033
|
enableDnsRebindingProtection,
|
|
1981
2034
|
// We'll manually store the session, so don't rely on onsessioninitialized
|
|
@@ -2088,6 +2141,13 @@ if (container && Component) {
|
|
|
2088
2141
|
const headers = {};
|
|
2089
2142
|
let ended = false;
|
|
2090
2143
|
let headersSent = false;
|
|
2144
|
+
let isSSEStream = false;
|
|
2145
|
+
let streamWriter = null;
|
|
2146
|
+
let streamingResponse = null;
|
|
2147
|
+
let sseStreamReady = null;
|
|
2148
|
+
const sseStreamPromise = new Promise((resolve) => {
|
|
2149
|
+
sseStreamReady = resolve;
|
|
2150
|
+
});
|
|
2091
2151
|
const expressReq = {
|
|
2092
2152
|
...req,
|
|
2093
2153
|
url: new URL(req.url).pathname + new URL(req.url).search,
|
|
@@ -2110,14 +2170,33 @@ if (container && Component) {
|
|
|
2110
2170
|
}, "status"),
|
|
2111
2171
|
setHeader: /* @__PURE__ */ __name((name, value) => {
|
|
2112
2172
|
if (!headersSent) {
|
|
2113
|
-
headers[name] = Array.isArray(value) ? value.join(", ") : value;
|
|
2173
|
+
headers[name.toLowerCase()] = Array.isArray(value) ? value.join(", ") : value;
|
|
2174
|
+
if (name.toLowerCase() === "content-type" && (Array.isArray(value) ? value.join(", ") : value).includes(
|
|
2175
|
+
"text/event-stream"
|
|
2176
|
+
)) {
|
|
2177
|
+
isSSEStream = true;
|
|
2178
|
+
const { readable, writable } = new globalThis.TransformStream();
|
|
2179
|
+
streamWriter = writable.getWriter();
|
|
2180
|
+
streamingResponse = new Response(readable, {
|
|
2181
|
+
status: statusCode,
|
|
2182
|
+
headers
|
|
2183
|
+
});
|
|
2184
|
+
if (sseStreamReady) {
|
|
2185
|
+
sseStreamReady(streamingResponse);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2114
2188
|
}
|
|
2115
2189
|
}, "setHeader"),
|
|
2116
|
-
getHeader: /* @__PURE__ */ __name((name) => headers[name], "getHeader"),
|
|
2190
|
+
getHeader: /* @__PURE__ */ __name((name) => headers[name.toLowerCase()], "getHeader"),
|
|
2117
2191
|
write: /* @__PURE__ */ __name((chunk, encoding, callback) => {
|
|
2118
|
-
if (!ended) {
|
|
2192
|
+
if (!ended || isSSEStream) {
|
|
2119
2193
|
const data = typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
2120
|
-
|
|
2194
|
+
if (isSSEStream && streamWriter) {
|
|
2195
|
+
streamWriter.write(data).catch(() => {
|
|
2196
|
+
});
|
|
2197
|
+
} else {
|
|
2198
|
+
responseBody.push(data);
|
|
2199
|
+
}
|
|
2121
2200
|
}
|
|
2122
2201
|
if (typeof encoding === "function") {
|
|
2123
2202
|
encoding();
|
|
@@ -2129,9 +2208,16 @@ if (container && Component) {
|
|
|
2129
2208
|
end: /* @__PURE__ */ __name((chunk, encoding, callback) => {
|
|
2130
2209
|
if (chunk && !ended) {
|
|
2131
2210
|
const data = typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
2132
|
-
|
|
2211
|
+
if (isSSEStream && streamWriter) {
|
|
2212
|
+
streamWriter.write(data).catch(() => {
|
|
2213
|
+
});
|
|
2214
|
+
} else {
|
|
2215
|
+
responseBody.push(data);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
if (!isSSEStream) {
|
|
2219
|
+
ended = true;
|
|
2133
2220
|
}
|
|
2134
|
-
ended = true;
|
|
2135
2221
|
if (typeof encoding === "function") {
|
|
2136
2222
|
encoding();
|
|
2137
2223
|
} else if (callback) {
|
|
@@ -2152,7 +2238,28 @@ if (container && Component) {
|
|
|
2152
2238
|
expressRes.statusCode = code;
|
|
2153
2239
|
headersSent = true;
|
|
2154
2240
|
if (_headers) {
|
|
2155
|
-
|
|
2241
|
+
if (Array.isArray(_headers)) {
|
|
2242
|
+
for (const [name, value] of _headers) {
|
|
2243
|
+
headers[name.toLowerCase()] = value;
|
|
2244
|
+
}
|
|
2245
|
+
} else {
|
|
2246
|
+
for (const [key, value] of Object.entries(_headers)) {
|
|
2247
|
+
headers[key.toLowerCase()] = value;
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
const contentType = headers["content-type"];
|
|
2251
|
+
if (contentType && contentType.includes("text/event-stream")) {
|
|
2252
|
+
isSSEStream = true;
|
|
2253
|
+
const { readable, writable } = new globalThis.TransformStream();
|
|
2254
|
+
streamWriter = writable.getWriter();
|
|
2255
|
+
streamingResponse = new Response(readable, {
|
|
2256
|
+
status: statusCode,
|
|
2257
|
+
headers
|
|
2258
|
+
});
|
|
2259
|
+
if (sseStreamReady) {
|
|
2260
|
+
sseStreamReady(streamingResponse);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2156
2263
|
}
|
|
2157
2264
|
return expressRes;
|
|
2158
2265
|
}, "writeHead"),
|
|
@@ -2170,6 +2277,9 @@ if (container && Component) {
|
|
|
2170
2277
|
expressReq,
|
|
2171
2278
|
expressRes,
|
|
2172
2279
|
getResponse: /* @__PURE__ */ __name(() => {
|
|
2280
|
+
if (isSSEStream && streamingResponse) {
|
|
2281
|
+
return streamingResponse;
|
|
2282
|
+
}
|
|
2173
2283
|
if (ended) {
|
|
2174
2284
|
if (responseBody.length > 0) {
|
|
2175
2285
|
const body = isDeno ? Buffer.concat(responseBody) : Buffer.concat(responseBody);
|
|
@@ -2185,12 +2295,20 @@ if (container && Component) {
|
|
|
2185
2295
|
}
|
|
2186
2296
|
}
|
|
2187
2297
|
return null;
|
|
2188
|
-
}, "getResponse")
|
|
2298
|
+
}, "getResponse"),
|
|
2299
|
+
isSSEStream: /* @__PURE__ */ __name(() => isSSEStream, "isSSEStream"),
|
|
2300
|
+
waitForSSEStream: /* @__PURE__ */ __name(() => sseStreamPromise, "waitForSSEStream")
|
|
2189
2301
|
};
|
|
2190
2302
|
}, "createExpressLikeObjects");
|
|
2191
2303
|
const mountEndpoint = /* @__PURE__ */ __name((endpoint) => {
|
|
2192
2304
|
this.app.post(endpoint, async (c) => {
|
|
2193
|
-
const {
|
|
2305
|
+
const {
|
|
2306
|
+
expressReq,
|
|
2307
|
+
expressRes,
|
|
2308
|
+
getResponse,
|
|
2309
|
+
isSSEStream,
|
|
2310
|
+
waitForSSEStream
|
|
2311
|
+
} = createExpressLikeObjects(c);
|
|
2194
2312
|
let body = {};
|
|
2195
2313
|
try {
|
|
2196
2314
|
body = await c.req.json();
|
|
@@ -2233,20 +2351,82 @@ if (container && Component) {
|
|
|
2233
2351
|
const session = this.sessions.get(sessionId);
|
|
2234
2352
|
session.lastAccessedAt = Date.now();
|
|
2235
2353
|
session.context = c;
|
|
2354
|
+
session.honoContext = c;
|
|
2355
|
+
session.expressRes = expressRes;
|
|
2356
|
+
if (body?.method === "tools/call" && body?.params?._meta?.progressToken) {
|
|
2357
|
+
session.progressToken = body.params._meta.progressToken;
|
|
2358
|
+
console.log(
|
|
2359
|
+
`Received progressToken ${session.progressToken} for tool call: ${body.params?.name}`
|
|
2360
|
+
);
|
|
2361
|
+
} else {
|
|
2362
|
+
session.progressToken = void 0;
|
|
2363
|
+
if (body?.method === "tools/call") {
|
|
2364
|
+
console.log(
|
|
2365
|
+
`No progressToken in tool call request: ${body.params?.name}`
|
|
2366
|
+
);
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2236
2369
|
}
|
|
2237
2370
|
if (expressRes._closeHandler) {
|
|
2238
2371
|
c.req.raw.signal?.addEventListener("abort", () => {
|
|
2239
2372
|
transport.close();
|
|
2240
2373
|
});
|
|
2241
2374
|
}
|
|
2375
|
+
let streamingResponse = null;
|
|
2376
|
+
let shouldReturnStream = false;
|
|
2242
2377
|
await runWithContext(c, async () => {
|
|
2243
|
-
|
|
2244
|
-
transport,
|
|
2378
|
+
const handleRequestPromise = transport.handleRequest(
|
|
2245
2379
|
expressReq,
|
|
2246
2380
|
expressRes,
|
|
2247
2381
|
expressReq.body
|
|
2248
2382
|
);
|
|
2383
|
+
try {
|
|
2384
|
+
const sseStream = await Promise.race([
|
|
2385
|
+
waitForSSEStream(),
|
|
2386
|
+
new Promise((resolve) => {
|
|
2387
|
+
setTimeout(() => resolve(null), 50);
|
|
2388
|
+
})
|
|
2389
|
+
]);
|
|
2390
|
+
if (sseStream) {
|
|
2391
|
+
streamingResponse = sseStream;
|
|
2392
|
+
shouldReturnStream = true;
|
|
2393
|
+
handleRequestPromise.catch((err) => {
|
|
2394
|
+
});
|
|
2395
|
+
return;
|
|
2396
|
+
} else {
|
|
2397
|
+
if (isSSEStream()) {
|
|
2398
|
+
const response2 = getResponse();
|
|
2399
|
+
if (response2) {
|
|
2400
|
+
streamingResponse = response2;
|
|
2401
|
+
shouldReturnStream = true;
|
|
2402
|
+
handleRequestPromise.catch(() => {
|
|
2403
|
+
});
|
|
2404
|
+
return;
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
} catch {
|
|
2409
|
+
}
|
|
2410
|
+
await new Promise((resolve) => {
|
|
2411
|
+
const originalEnd = expressRes.end;
|
|
2412
|
+
let ended = false;
|
|
2413
|
+
expressRes.end = (...args) => {
|
|
2414
|
+
if (!ended) {
|
|
2415
|
+
originalEnd.apply(expressRes, args);
|
|
2416
|
+
ended = true;
|
|
2417
|
+
resolve();
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2420
|
+
handleRequestPromise.finally(() => {
|
|
2421
|
+
if (!ended) {
|
|
2422
|
+
expressRes.end();
|
|
2423
|
+
}
|
|
2424
|
+
});
|
|
2425
|
+
});
|
|
2249
2426
|
});
|
|
2427
|
+
if (shouldReturnStream && streamingResponse) {
|
|
2428
|
+
return streamingResponse;
|
|
2429
|
+
}
|
|
2250
2430
|
const response = getResponse();
|
|
2251
2431
|
if (response) {
|
|
2252
2432
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../../src/server/mcp-server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EAEpB,MAAM,oCAAoC,CAAC;AAG5C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;KACjB,KAAK,IAAI,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,MAAM,EAAE,CACN,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EACtC,OAAO,CAAC,EAAE,aAAa,KACpB,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAElC;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AACD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAsB,KAAK,IAAI,IAAI,QAAQ,EAAa,MAAM,MAAM,CAAC;AAa5E,OAAO,KAAK,EAEV,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,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J;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAIH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG;IAAE,KAAK,EAAE,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;CAAE,GAC5E,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAI3B,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAC7B,iBAAiB,CAAC,KAAK,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-use",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.0-canary.0",
|
|
5
5
|
"description": "Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents, Clients and Servers with support for ChatGPT Apps, Code Mode, OAuth, Notifications, Sampling, Observability and more.",
|
|
6
6
|
"author": "mcp-use, Inc.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -112,8 +112,8 @@
|
|
|
112
112
|
"posthog-node": "^5.14.1",
|
|
113
113
|
"ws": "^8.18.3",
|
|
114
114
|
"zod": "^4.1.13",
|
|
115
|
-
"@mcp-use/cli": "2.4.
|
|
116
|
-
"@mcp-use/inspector": "0.
|
|
115
|
+
"@mcp-use/cli": "2.4.6-canary.0",
|
|
116
|
+
"@mcp-use/inspector": "0.10.0-canary.0"
|
|
117
117
|
},
|
|
118
118
|
"optionalDependencies": {
|
|
119
119
|
"chalk": "^5.6.2",
|