@tmcp/transport-http 0.5.6 → 0.6.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 +3 -3
- package/src/index.js +17 -5
- package/src/types/index.d.ts +3 -3
- package/src/types/index.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmcp/transport-http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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.
|
|
19
|
+
"tmcp": "^1.11.0"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"tmcp",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"vitest": "^3.2.4",
|
|
42
42
|
"@tmcp/adapter-valibot": "^0.1.4",
|
|
43
43
|
"@tmcp/auth": "^0.3.3",
|
|
44
|
-
"tmcp": "^1.
|
|
44
|
+
"tmcp": "^1.11.0"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
package/src/index.js
CHANGED
|
@@ -27,9 +27,13 @@
|
|
|
27
27
|
|
|
28
28
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
29
29
|
import { InMemorySessionManager } from '@tmcp/session-manager';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @template {Record<string, unknown> | undefined} [TCustom=undefined]
|
|
33
|
+
*/
|
|
30
34
|
export class HttpTransport {
|
|
31
35
|
/**
|
|
32
|
-
* @type {McpServer<any>}
|
|
36
|
+
* @type {McpServer<any, TCustom>}
|
|
33
37
|
*/
|
|
34
38
|
#server;
|
|
35
39
|
|
|
@@ -57,7 +61,7 @@ export class HttpTransport {
|
|
|
57
61
|
|
|
58
62
|
/**
|
|
59
63
|
*
|
|
60
|
-
* @param {McpServer<any>} server
|
|
64
|
+
* @param {McpServer<any, TCustom>} server
|
|
61
65
|
* @param {HttpTransportOptions} [options]
|
|
62
66
|
*/
|
|
63
67
|
constructor(server, options) {
|
|
@@ -250,8 +254,9 @@ export class HttpTransport {
|
|
|
250
254
|
* @param {string} session_id
|
|
251
255
|
* @param {Request} request
|
|
252
256
|
* @param {AuthInfo | null} auth_info
|
|
257
|
+
* @param {TCustom} [ctx]
|
|
253
258
|
*/
|
|
254
|
-
async #handle_post(session_id, request, auth_info) {
|
|
259
|
+
async #handle_post(session_id, request, auth_info, ctx) {
|
|
255
260
|
// Check Content-Type header
|
|
256
261
|
const content_type = request.headers.get('content-type');
|
|
257
262
|
if (!content_type || !content_type.includes('application/json')) {
|
|
@@ -296,6 +301,7 @@ export class HttpTransport {
|
|
|
296
301
|
this.#server.receive(body, {
|
|
297
302
|
sessionId: session_id,
|
|
298
303
|
auth: auth_info ?? undefined,
|
|
304
|
+
custom: ctx,
|
|
299
305
|
}),
|
|
300
306
|
);
|
|
301
307
|
|
|
@@ -375,9 +381,10 @@ export class HttpTransport {
|
|
|
375
381
|
/**
|
|
376
382
|
*
|
|
377
383
|
* @param {Request} request
|
|
384
|
+
* @param {TCustom} [ctx]
|
|
378
385
|
* @returns {Promise<Response | null>}
|
|
379
386
|
*/
|
|
380
|
-
async respond(request) {
|
|
387
|
+
async respond(request, ctx) {
|
|
381
388
|
const url = new URL(request.url);
|
|
382
389
|
|
|
383
390
|
/**
|
|
@@ -441,7 +448,12 @@ export class HttpTransport {
|
|
|
441
448
|
}
|
|
442
449
|
// Handle POST request - process message and respond through event stream
|
|
443
450
|
else if (method === 'POST') {
|
|
444
|
-
response = await this.#handle_post(
|
|
451
|
+
response = await this.#handle_post(
|
|
452
|
+
session_id,
|
|
453
|
+
request,
|
|
454
|
+
auth_info,
|
|
455
|
+
ctx,
|
|
456
|
+
);
|
|
445
457
|
}
|
|
446
458
|
// Method not supported
|
|
447
459
|
else {
|
package/src/types/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ declare module '@tmcp/transport-http' {
|
|
|
2
2
|
import type { McpServer } from 'tmcp';
|
|
3
3
|
import type { OAuth } from '@tmcp/auth';
|
|
4
4
|
import type { SessionManager } from '@tmcp/session-manager';
|
|
5
|
-
export class HttpTransport {
|
|
5
|
+
export class HttpTransport<TCustom extends Record<string, unknown> | undefined = undefined> {
|
|
6
6
|
|
|
7
|
-
constructor(server: McpServer<any>, options?: HttpTransportOptions);
|
|
7
|
+
constructor(server: McpServer<any, TCustom>, options?: HttpTransportOptions);
|
|
8
8
|
|
|
9
|
-
respond(request: Request): Promise<Response | null>;
|
|
9
|
+
respond(request: Request, ctx?: TCustom): Promise<Response | null>;
|
|
10
10
|
#private;
|
|
11
11
|
}
|
|
12
12
|
export type CorsConfig = {
|