@tmcp/transport-http 0.2.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @tmcp/transport-http
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3847654: fix: answer with conflict for second SSE connection
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [1b50780]
12
+ - tmcp@1.7.1
13
+
14
+ ## 0.2.1
15
+
16
+ ### Patch Changes
17
+
18
+ - f5d8390: fix: optional `getSessionId`
19
+
3
20
  ## 0.2.0
4
21
 
5
22
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmcp/transport-http",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Transport for TMCP using HTTP",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -13,7 +13,7 @@
13
13
  "./package.json": "./package.json"
14
14
  },
15
15
  "peerDependencies": {
16
- "tmcp": "^1.7.0"
16
+ "tmcp": "^1.7.1"
17
17
  },
18
18
  "keywords": [
19
19
  "tmcp",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "publint": "^0.3.12",
30
- "tmcp": "^1.7.0"
30
+ "tmcp": "^1.7.1"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"
package/src/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  */
4
4
  /**
5
5
  * @typedef {{
6
- * getSessionId: () => string
6
+ * getSessionId?: () => string
7
7
  * path?: string
8
8
  * }} HttpTransportOptions
9
9
  */
@@ -23,7 +23,7 @@ export class HttpTransport {
23
23
  #private;
24
24
  }
25
25
  export type HttpTransportOptions = {
26
- getSessionId: () => string;
26
+ getSessionId?: () => string;
27
27
  path?: string;
28
28
  };
29
29
  import type { McpServer } from "tmcp";
package/src/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  /**
6
6
  * @typedef {{
7
- * getSessionId: () => string
7
+ * getSessionId?: () => string
8
8
  * path?: string
9
9
  * }} HttpTransportOptions
10
10
  */
@@ -16,7 +16,7 @@ export class HttpTransport {
16
16
  #server;
17
17
 
18
18
  /**
19
- * @type {HttpTransportOptions}
19
+ * @type {Required<HttpTransportOptions>}
20
20
  */
21
21
  #options;
22
22
 
@@ -41,10 +41,12 @@ export class HttpTransport {
41
41
  */
42
42
  constructor(server, options) {
43
43
  this.#server = server;
44
- this.#options = options || {
45
- getSessionId: () => crypto.randomUUID(),
46
- };
47
- this.#path = this.#options.path || '/mcp';
44
+ const { getSessionId = () => crypto.randomUUID(), path = '/mcp' } =
45
+ options ?? {
46
+ getSessionId: () => crypto.randomUUID(),
47
+ };
48
+ this.#options = { getSessionId, path };
49
+ this.#path = path;
48
50
  this.#server.on('send', ({ request, context: { sessions } }) => {
49
51
  for (let [session_id, controller] of this.#session.entries()) {
50
52
  if (sessions === undefined || sessions.includes(session_id)) {
@@ -85,15 +87,24 @@ export class HttpTransport {
85
87
  // If session already exists, return existing stream
86
88
  const existing_stream = this.#streams.get(session_id);
87
89
  if (existing_stream) {
88
- return new Response(existing_stream, {
89
- headers: {
90
- 'Content-Type': 'text/event-stream',
91
- 'Cache-Control': 'no-cache',
92
- Connection: 'keep-alive',
93
- 'mcp-session-id': session_id,
90
+ return new Response(
91
+ JSON.stringify({
92
+ jsonrpc: '2.0',
93
+ error: {
94
+ code: -32000,
95
+ message:
96
+ 'Conflict: Only one SSE stream is allowed per session',
97
+ },
98
+ id: null,
99
+ }),
100
+ {
101
+ headers: {
102
+ 'Content-Type': 'application/json',
103
+ 'mcp-session-id': session_id,
104
+ },
105
+ status: 409,
94
106
  },
95
- status: 200,
96
- });
107
+ );
97
108
  }
98
109
 
99
110
  // Create new long-lived stream for notifications