@tmcp/transport-http 0.4.1 → 0.5.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/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "@tmcp/transport-http",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Transport for TMCP using HTTP",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
- "types": "src/index.d.ts",
7
+ "types": "src/types/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./src/index.d.ts",
10
+ "types": "./src/types/index.d.ts",
11
11
  "default": "./src/index.js"
12
12
  },
13
13
  "./package.json": "./package.json"
14
14
  },
15
+ "files": [
16
+ "src/**/*"
17
+ ],
15
18
  "peerDependencies": {
16
- "tmcp": "^1.7.1"
19
+ "tmcp": "^1.9.0"
17
20
  },
18
21
  "keywords": [
19
22
  "tmcp",
@@ -26,15 +29,22 @@
26
29
  "directory": "packages/transport-http"
27
30
  },
28
31
  "devDependencies": {
32
+ "@modelcontextprotocol/sdk": "^1.16.0",
29
33
  "@types/node": "^24.0.15",
34
+ "dts-buddy": "^0.6.2",
30
35
  "publint": "^0.3.12",
31
- "tmcp": "^1.7.1"
36
+ "valibot": "^1.1.0",
37
+ "vitest": "^3.2.4",
38
+ "@tmcp/adapter-valibot": "^0.1.3",
39
+ "@tmcp/auth": "^0.1.1",
40
+ "tmcp": "^1.9.0"
32
41
  },
33
42
  "publishConfig": {
34
43
  "access": "public"
35
44
  },
36
45
  "scripts": {
37
- "generate:types": "tsc ./src/*.js --declaration --emitDeclarationOnly --target esnext --allowJs --moduleresolution nodenext --module nodenext && publint",
38
- "prepublish": "pnpm generate:types"
46
+ "generate:types": "dts-buddy && publint",
47
+ "prepublish": "pnpm generate:types",
48
+ "test": "vitest --run"
39
49
  }
40
50
  }
package/src/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  /**
2
- * @import { McpServer, ClientCapabilities } from "tmcp";
2
+ * @import { AuthInfo, McpServer } from "tmcp";
3
+ * @import { OAuth } from "@tmcp/auth";
3
4
  */
4
5
 
5
6
  /**
6
7
  * @typedef {{
7
8
  * getSessionId?: () => string
8
9
  * path?: string
10
+ * oauth?: OAuth<"built">
9
11
  * }} HttpTransportOptions
10
12
  */
11
13
 
12
14
  import { AsyncLocalStorage } from 'node:async_hooks';
13
-
14
15
  export class HttpTransport {
15
16
  /**
16
17
  * @type {McpServer<any>}
@@ -18,7 +19,7 @@ export class HttpTransport {
18
19
  #server;
19
20
 
20
21
  /**
21
- * @type {Required<HttpTransportOptions>}
22
+ * @type {Required<Omit<HttpTransportOptions, 'oauth'>>}
22
23
  */
23
24
  #options;
24
25
 
@@ -41,6 +42,11 @@ export class HttpTransport {
41
42
  */
42
43
  #controller_storage = new AsyncLocalStorage();
43
44
 
45
+ /**
46
+ * @type {OAuth<"built"> | undefined}
47
+ */
48
+ #oauth;
49
+
44
50
  /**
45
51
  *
46
52
  * @param {McpServer<any>} server
@@ -48,10 +54,18 @@ export class HttpTransport {
48
54
  */
49
55
  constructor(server, options) {
50
56
  this.#server = server;
51
- const { getSessionId = () => crypto.randomUUID(), path = '/mcp' } =
52
- options ?? {
53
- getSessionId: () => crypto.randomUUID(),
54
- };
57
+ const {
58
+ getSessionId = () => crypto.randomUUID(),
59
+ path = '/mcp',
60
+ oauth,
61
+ } = options ?? {
62
+ getSessionId: () => crypto.randomUUID(),
63
+ };
64
+
65
+ if (oauth) {
66
+ this.#oauth = oauth;
67
+ }
68
+
55
69
  this.#options = { getSessionId, path };
56
70
  this.#path = path;
57
71
  this.#server.on('send', ({ request, context: { sessions } }) => {
@@ -150,8 +164,9 @@ export class HttpTransport {
150
164
  *
151
165
  * @param {string} session_id
152
166
  * @param {Request} request
167
+ * @param {AuthInfo | null} auth_info
153
168
  */
154
- async #handle_post(session_id, request) {
169
+ async #handle_post(session_id, request, auth_info) {
155
170
  // Check Content-Type header
156
171
  const content_type = request.headers.get('content-type');
157
172
  if (!content_type || !content_type.includes('application/json')) {
@@ -192,7 +207,11 @@ export class HttpTransport {
192
207
  const handle = async () => {
193
208
  const response = await this.#controller_storage.run(
194
209
  controller,
195
- () => this.#server.receive(body, session_id),
210
+ () =>
211
+ this.#server.receive(body, {
212
+ sessionId: session_id,
213
+ auth: auth_info ?? undefined,
214
+ }),
196
215
  );
197
216
 
198
217
  controller?.enqueue(
@@ -274,10 +293,38 @@ export class HttpTransport {
274
293
  async respond(request) {
275
294
  const url = new URL(request.url);
276
295
 
296
+ /**
297
+ * @type {AuthInfo | null}
298
+ */
299
+ let auth_info = null;
300
+
301
+ // Check if OAuth helper should handle this request
302
+ if (this.#oauth) {
303
+ try {
304
+ const response = await this.#oauth.respond(request);
305
+ if (response) {
306
+ return response;
307
+ }
308
+ } catch (error) {
309
+ return new Response(
310
+ JSON.stringify({
311
+ error: 'server_error',
312
+ error_description: /** @type {Error} */ (error).message,
313
+ }),
314
+ {
315
+ status: 500,
316
+ headers: { 'Content-Type': 'application/json' },
317
+ },
318
+ );
319
+ }
320
+ auth_info = await this.#oauth.verify(request);
321
+ }
322
+
277
323
  // Check if the request path matches the configured MCP path
278
324
  if (url.pathname !== this.#path) {
279
325
  return null;
280
326
  }
327
+
281
328
  const method = request.method;
282
329
  const session_id =
283
330
  request.headers.get('mcp-session-id') ||
@@ -295,7 +342,7 @@ export class HttpTransport {
295
342
 
296
343
  // Handle POST request - process message and respond through event stream
297
344
  if (method === 'POST') {
298
- return this.#handle_post(session_id, request);
345
+ return this.#handle_post(session_id, request, auth_info);
299
346
  }
300
347
 
301
348
  // Method not supported
@@ -0,0 +1,20 @@
1
+ declare module '@tmcp/transport-http' {
2
+ import type { McpServer } from 'tmcp';
3
+ import type { OAuth } from '@tmcp/auth';
4
+ export class HttpTransport {
5
+
6
+ constructor(server: McpServer<any>, options?: HttpTransportOptions);
7
+
8
+ respond(request: Request): Promise<Response | null>;
9
+ #private;
10
+ }
11
+ export type HttpTransportOptions = {
12
+ getSessionId?: () => string;
13
+ path?: string;
14
+ oauth?: OAuth<"built">;
15
+ };
16
+
17
+ export {};
18
+ }
19
+
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,15 @@
1
+ {
2
+ "version": 3,
3
+ "file": "index.d.ts",
4
+ "names": [
5
+ "HttpTransport"
6
+ ],
7
+ "sources": [
8
+ "../index.js"
9
+ ],
10
+ "sourcesContent": [
11
+ null
12
+ ],
13
+ "mappings": ";;;cAcaA,aAAaA",
14
+ "ignoreList": []
15
+ }
package/CHANGELOG.md DELETED
@@ -1,49 +0,0 @@
1
- # @tmcp/transport-http
2
-
3
- ## 0.4.1
4
-
5
- ### Patch Changes
6
-
7
- - 77d3257: fix: respond immediately to allow for requests from the server
8
-
9
- ## 0.4.0
10
-
11
- ### Minor Changes
12
-
13
- - 8f09cd2: fix: send requests back on the same stream if available
14
-
15
- ## 0.3.0
16
-
17
- ### Minor Changes
18
-
19
- - 3847654: fix: answer with conflict for second SSE connection
20
-
21
- ### Patch Changes
22
-
23
- - Updated dependencies [1b50780]
24
- - tmcp@1.7.1
25
-
26
- ## 0.2.1
27
-
28
- ### Patch Changes
29
-
30
- - f5d8390: fix: optional `getSessionId`
31
-
32
- ## 0.2.0
33
-
34
- ### Minor Changes
35
-
36
- - d12964e: breaking: correctly handle http requests
37
-
38
- ### Patch Changes
39
-
40
- - Updated dependencies [d921480]
41
- - tmcp@1.7.0
42
-
43
- ## 0.1.1
44
-
45
- ### Patch Changes
46
-
47
- - 41fb096: fix: use new sessions management
48
- - Updated dependencies [41fb096]
49
- - tmcp@1.4.0
package/jsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "nodenext",
5
- "moduleResolution": "nodenext",
6
- "allowJs": true,
7
- "checkJs": true,
8
- "declaration": true,
9
- "emitDeclarationOnly": false,
10
- "strict": true,
11
- "noEmit": true,
12
- "skipLibCheck": true
13
- },
14
- "include": ["src/**/*"],
15
- "exclude": ["node_modules"]
16
- }
package/src/index.d.ts DELETED
@@ -1,20 +0,0 @@
1
- export class HttpTransport {
2
- /**
3
- *
4
- * @param {McpServer<any>} server
5
- * @param {HttpTransportOptions} [options]
6
- */
7
- constructor(server: McpServer<any>, options?: HttpTransportOptions);
8
- /**
9
- *
10
- * @param {Request} request
11
- * @returns {Promise<Response | null>}
12
- */
13
- respond(request: Request): Promise<Response | null>;
14
- #private;
15
- }
16
- export type HttpTransportOptions = {
17
- getSessionId?: () => string;
18
- path?: string;
19
- };
20
- import type { McpServer } from "tmcp";