Skip to content

Commit 220af80

Browse files
committed
Add http client resiliency
Signed-off-by: Marcos Candeia <[email protected]>
1 parent 0553374 commit 220af80

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deco/mcp",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"exports": "./mod.ts",
55
"tasks": {
66
"check": "deno fmt && deno lint && deno check mod.ts"

mcp/http-client.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export class HttpClientTransport implements Transport {
184184
async send(message: JSONRPCMessage): Promise<void> {
185185
// Create a new abort controller for this request
186186
this._abortController = new AbortController();
187+
let response: Response | undefined;
187188

188189
try {
189190
const commonHeaders = await this._commonHeaders();
@@ -201,7 +202,7 @@ export class HttpClientTransport implements Transport {
201202
signal: this._abortController.signal,
202203
};
203204

204-
const response = await fetch(this._url, init);
205+
response = await fetch(this._url, init);
205206

206207
if (!response.ok) {
207208
if (response.status === 401 && this._authProvider) {
@@ -220,7 +221,8 @@ export class HttpClientTransport implements Transport {
220221
// Handle streaming responses
221222
const contentType = response.headers.get("content-type");
222223
if (contentType?.includes("text/event-stream")) {
223-
await this._handleStreamingResponse(response);
224+
// Don't await streaming response handling - it will continue in the background
225+
this._handleStreamingResponse(response);
224226
return;
225227
}
226228

@@ -236,8 +238,10 @@ export class HttpClientTransport implements Transport {
236238
this.onerror?.(error as Error);
237239
throw error;
238240
} finally {
239-
// Clean up the abort controller if it wasn't used
240-
if (this._abortController) {
241+
// Only clean up the abort controller for non-streaming responses
242+
if (
243+
!response?.headers.get("content-type")?.includes("text/event-stream")
244+
) {
241245
this._abortController = undefined;
242246
}
243247
}

0 commit comments

Comments
 (0)