@tmcp/transport-http 0.4.0 → 0.4.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @tmcp/transport-http
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 77d3257: fix: respond immediately to allow for requests from the server
8
+
3
9
  ## 0.4.0
4
10
 
5
11
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmcp/transport-http",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Transport for TMCP using HTTP",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -189,17 +189,27 @@ export class HttpTransport {
189
189
  },
190
190
  });
191
191
 
192
- const response = await this.#controller_storage.run(
193
- controller,
194
- () => this.#server.receive(body, session_id),
195
- );
192
+ const handle = async () => {
193
+ const response = await this.#controller_storage.run(
194
+ controller,
195
+ () => this.#server.receive(body, session_id),
196
+ );
197
+
198
+ controller?.enqueue(
199
+ 'data: ' + JSON.stringify(response) + '\n\n',
200
+ );
201
+ controller?.close();
202
+ };
203
+
204
+ handle();
196
205
 
197
- controller?.enqueue('data: ' + JSON.stringify(response) + '\n\n');
198
- controller?.close();
206
+ const messages = Array.isArray(body) ? body : [body];
199
207
 
200
208
  // Determine status code based on response type
201
209
  // 202 Accepted for notifications/responses, 200 OK for standard requests
202
- const status = response == null || response.id == null ? 202 : 200;
210
+ const status = !messages.some((message) => message.id != null)
211
+ ? 202
212
+ : 200;
203
213
 
204
214
  return new Response(stream, {
205
215
  headers: {