@tmcp/transport-http 0.6.0 → 0.6.2

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/README.md CHANGED
@@ -81,6 +81,50 @@ const transport = new HttpTransport(server, {
81
81
  });
82
82
  ```
83
83
 
84
+ ### With Custom Context
85
+
86
+ You can pass custom context data to your MCP server for each request. This is useful for authentication, user information, database connections, etc.
87
+
88
+ ```javascript
89
+ // Define your custom context type
90
+ interface MyContext {
91
+ userId: string;
92
+ permissions: string[];
93
+ database: DatabaseConnection;
94
+ }
95
+
96
+ // Create server with custom context
97
+ const server = new McpServer(serverInfo, options).withContext<MyContext>();
98
+
99
+ server.tool(
100
+ {
101
+ name: 'get-user-profile',
102
+ description: 'Get the current user profile',
103
+ },
104
+ async () => {
105
+ // Access custom context in your handler
106
+ const { userId, database } = server.ctx.custom!;
107
+ const profile = await database.users.findById(userId);
108
+
109
+ return {
110
+ content: [
111
+ { type: 'text', text: `User profile: ${JSON.stringify(profile)}` }
112
+ ],
113
+ };
114
+ },
115
+ );
116
+
117
+ // Create transport (it will be typed to accept your custom context)
118
+ const transport = new HttpTransport(server);
119
+
120
+ // then in the handler
121
+ const response = await transport.respond(req, {
122
+ userId,
123
+ permissions,
124
+ database: req.locals.db,
125
+ });
126
+ ```
127
+
84
128
  ### Session Management
85
129
 
86
130
  The HTTP transport supports custom session managers for different deployment scenarios:
@@ -154,13 +198,14 @@ interface HttpTransportOptions {
154
198
 
155
199
  #### Methods
156
200
 
157
- ##### `respond(request: Request): Promise<Response | null>`
201
+ ##### `respond(request: Request, customContext?: T): Promise<Response | null>`
158
202
 
159
203
  Processes an HTTP request and returns a Response with Server-Sent Events, or null if the request path doesn't match the configured MCP path.
160
204
 
161
205
  **Parameters:**
162
206
 
163
207
  - `request` - A Web API Request object containing the JSON-RPC message
208
+ - `customContext` - Optional custom context data to pass to the MCP server for this request
164
209
 
165
210
  **Returns:**
166
211
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmcp/transport-http",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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.11.0"
19
+ "tmcp": "^1.12.2"
20
20
  },
21
21
  "keywords": [
22
22
  "tmcp",
@@ -29,7 +29,7 @@
29
29
  "directory": "packages/transport-http"
30
30
  },
31
31
  "dependencies": {
32
- "@tmcp/session-manager": "^0.1.1"
32
+ "@tmcp/session-manager": "^0.1.2"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@modelcontextprotocol/sdk": "^1.17.1",
@@ -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.11.0"
44
+ "tmcp": "^1.12.2"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
package/src/index.js CHANGED
@@ -191,7 +191,7 @@ export class HttpTransport {
191
191
  async #handle_delete(session_id) {
192
192
  await this.#options.sessionManager.delete(session_id);
193
193
  return new Response(null, {
194
- status: 204,
194
+ status: 200,
195
195
  headers: {
196
196
  'mcp-session-id': session_id,
197
197
  },