@tmcp/transport-http 0.7.0 → 0.7.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/package.json +5 -5
- package/src/index.js +16 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmcp/transport-http",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Transport for TMCP using HTTP",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"src/**/*"
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"tmcp": "^1.15.
|
|
19
|
+
"tmcp": "^1.15.3"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"tmcp",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.17.1",
|
|
37
|
-
"@remix-run/node-fetch-server": "^0.
|
|
37
|
+
"@remix-run/node-fetch-server": "^0.11.0",
|
|
38
38
|
"@types/node": "^24.0.15",
|
|
39
39
|
"dts-buddy": "^0.6.2",
|
|
40
40
|
"publint": "^0.3.12",
|
|
41
41
|
"valibot": "^1.1.0",
|
|
42
|
-
"vitest": "^
|
|
42
|
+
"vitest": "^4.0.0",
|
|
43
43
|
"@tmcp/adapter-valibot": "^0.1.4",
|
|
44
44
|
"@tmcp/auth": "^0.3.3",
|
|
45
|
-
"tmcp": "^1.15.
|
|
45
|
+
"tmcp": "^1.15.3"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
package/src/index.js
CHANGED
|
@@ -213,6 +213,7 @@ export class HttpTransport {
|
|
|
213
213
|
*/
|
|
214
214
|
async #handle_get(session_id) {
|
|
215
215
|
const sessions = this.#options.sessionManager;
|
|
216
|
+
const text_encoder = this.#text_encoder;
|
|
216
217
|
// If session already exists, return error
|
|
217
218
|
const existing_session = await sessions.has(session_id);
|
|
218
219
|
if (existing_session) {
|
|
@@ -240,6 +241,8 @@ export class HttpTransport {
|
|
|
240
241
|
const stream = new ReadableStream({
|
|
241
242
|
async start(controller) {
|
|
242
243
|
await sessions.create(session_id, controller);
|
|
244
|
+
// send a comment to flush the headers immediately
|
|
245
|
+
controller.enqueue(text_encoder.encode(': connected\n\n'));
|
|
243
246
|
},
|
|
244
247
|
async cancel() {
|
|
245
248
|
await sessions.delete(session_id);
|
|
@@ -325,18 +328,21 @@ export class HttpTransport {
|
|
|
325
328
|
|
|
326
329
|
const messages = Array.isArray(body) ? body : [body];
|
|
327
330
|
|
|
331
|
+
const has_request = messages.some((message) => message.id != null);
|
|
332
|
+
|
|
328
333
|
// Determine status code based on response type
|
|
329
334
|
// 202 Accepted for notifications/responses, 200 OK for standard requests
|
|
330
|
-
const status = !
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
335
|
+
const status = !has_request ? 202 : 200;
|
|
336
|
+
|
|
337
|
+
return new Response(has_request ? stream : null, {
|
|
338
|
+
headers: has_request
|
|
339
|
+
? {
|
|
340
|
+
'Content-Type': 'text/event-stream',
|
|
341
|
+
'Cache-Control': 'no-cache',
|
|
342
|
+
connection: 'keep-alive',
|
|
343
|
+
'mcp-session-id': session_id,
|
|
344
|
+
}
|
|
345
|
+
: undefined,
|
|
340
346
|
status,
|
|
341
347
|
});
|
|
342
348
|
} catch (error) {
|