@forklaunch/express 0.7.3 → 0.7.5

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/lib/index.d.mts CHANGED
@@ -6,22 +6,27 @@ import { OptionsText, OptionsJson, OptionsUrlencoded } from 'body-parser';
6
6
  export { OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
7
7
  import { BusboyConfig } from 'busboy';
8
8
  export { BusboyConfig } from 'busboy';
9
- import { CorsOptions } from 'cors';
10
- export { CorsOptions } from 'cors';
11
9
  import { Express, RequestHandler, Request, Response, NextFunction, Router as Router$1 } from 'express';
12
10
  export { NextFunction, Request, Response } from 'express';
13
11
  import { Server } from 'http';
12
+ import { CorsOptions } from 'cors';
13
+ export { CorsOptions } from 'cors';
14
+ import { FastMCP } from 'fastmcp';
14
15
  import express__default from 'express-serve-static-core';
15
16
  export * from 'express-serve-static-core';
16
17
  import { ParsedQs } from 'qs';
17
18
 
18
- type ExpressOptions = {
19
+ type ExpressOptions<T extends Record<string, unknown> | undefined> = {
19
20
  docs?: DocsConfiguration;
20
21
  busboy?: BusboyConfig;
21
22
  text?: OptionsText;
22
23
  json?: OptionsJson;
23
24
  urlencoded?: OptionsUrlencoded;
24
25
  cors?: CorsOptions;
26
+ mcp?: {
27
+ sessionAuth?: T;
28
+ options?: ConstructorParameters<typeof FastMCP<T>>[0];
29
+ };
25
30
  };
26
31
 
27
32
  /**
@@ -35,7 +40,7 @@ type ExpressOptions = {
35
40
  * app.listen(3000, () => console.log('Server running on port 3000'));
36
41
  * ```
37
42
  */
38
- declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler, Request, Response, NextFunction> {
43
+ declare class Application<SV extends AnySchemaValidator, T extends Record<string, unknown> | undefined> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler, Request, Response, NextFunction> {
39
44
  private docsConfiguration;
40
45
  /**
41
46
  * Creates an instance of Application.
@@ -44,7 +49,7 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
44
49
  * @param {OpenTelemetryCollector<MetricsDefinition>} openTelemetryCollector - Collector for OpenTelemetry metrics.
45
50
  * @param {DocsConfiguration} [docsConfiguration] - Optional configuration for API documentation (Swagger/Scalar).
46
51
  */
47
- constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, options?: ExpressOptions);
52
+ constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, options?: ExpressOptions<T>);
48
53
  /**
49
54
  * Starts the Express server and sets up API documentation (Swagger/Scalar).
50
55
  * This method is overloaded to support various ways of starting the server.
@@ -2039,14 +2044,7 @@ declare const unsubscribe: <SV extends AnySchemaValidator, Name extends string,
2039
2044
  * @param {SV} schemaValidator - The schema validator.
2040
2045
  * @returns {Application<SV>} - The new application instance.
2041
2046
  */
2042
- declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, options?: {
2043
- docs?: DocsConfiguration;
2044
- busboy?: BusboyConfig;
2045
- text?: OptionsText;
2046
- json?: OptionsJson;
2047
- urlencoded?: OptionsUrlencoded;
2048
- cors?: CorsOptions;
2049
- }): Application<SV>;
2047
+ declare function forklaunchExpress<SV extends AnySchemaValidator, T extends Record<string, unknown> | undefined>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, options?: ExpressOptions<T>): Application<SV, T>;
2050
2048
  /**
2051
2049
  * Creates a new instance of Router with the given base path and schema validator.
2052
2050
  *
package/lib/index.d.ts CHANGED
@@ -6,22 +6,27 @@ import { OptionsText, OptionsJson, OptionsUrlencoded } from 'body-parser';
6
6
  export { OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
7
7
  import { BusboyConfig } from 'busboy';
8
8
  export { BusboyConfig } from 'busboy';
9
- import { CorsOptions } from 'cors';
10
- export { CorsOptions } from 'cors';
11
9
  import { Express, RequestHandler, Request, Response, NextFunction, Router as Router$1 } from 'express';
12
10
  export { NextFunction, Request, Response } from 'express';
13
11
  import { Server } from 'http';
12
+ import { CorsOptions } from 'cors';
13
+ export { CorsOptions } from 'cors';
14
+ import { FastMCP } from 'fastmcp';
14
15
  import express__default from 'express-serve-static-core';
15
16
  export * from 'express-serve-static-core';
16
17
  import { ParsedQs } from 'qs';
17
18
 
18
- type ExpressOptions = {
19
+ type ExpressOptions<T extends Record<string, unknown> | undefined> = {
19
20
  docs?: DocsConfiguration;
20
21
  busboy?: BusboyConfig;
21
22
  text?: OptionsText;
22
23
  json?: OptionsJson;
23
24
  urlencoded?: OptionsUrlencoded;
24
25
  cors?: CorsOptions;
26
+ mcp?: {
27
+ sessionAuth?: T;
28
+ options?: ConstructorParameters<typeof FastMCP<T>>[0];
29
+ };
25
30
  };
26
31
 
27
32
  /**
@@ -35,7 +40,7 @@ type ExpressOptions = {
35
40
  * app.listen(3000, () => console.log('Server running on port 3000'));
36
41
  * ```
37
42
  */
38
- declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler, Request, Response, NextFunction> {
43
+ declare class Application<SV extends AnySchemaValidator, T extends Record<string, unknown> | undefined> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler, Request, Response, NextFunction> {
39
44
  private docsConfiguration;
40
45
  /**
41
46
  * Creates an instance of Application.
@@ -44,7 +49,7 @@ declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpre
44
49
  * @param {OpenTelemetryCollector<MetricsDefinition>} openTelemetryCollector - Collector for OpenTelemetry metrics.
45
50
  * @param {DocsConfiguration} [docsConfiguration] - Optional configuration for API documentation (Swagger/Scalar).
46
51
  */
47
- constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, options?: ExpressOptions);
52
+ constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, options?: ExpressOptions<T>);
48
53
  /**
49
54
  * Starts the Express server and sets up API documentation (Swagger/Scalar).
50
55
  * This method is overloaded to support various ways of starting the server.
@@ -2039,14 +2044,7 @@ declare const unsubscribe: <SV extends AnySchemaValidator, Name extends string,
2039
2044
  * @param {SV} schemaValidator - The schema validator.
2040
2045
  * @returns {Application<SV>} - The new application instance.
2041
2046
  */
2042
- declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, options?: {
2043
- docs?: DocsConfiguration;
2044
- busboy?: BusboyConfig;
2045
- text?: OptionsText;
2046
- json?: OptionsJson;
2047
- urlencoded?: OptionsUrlencoded;
2048
- cors?: CorsOptions;
2049
- }): Application<SV>;
2047
+ declare function forklaunchExpress<SV extends AnySchemaValidator, T extends Record<string, unknown> | undefined>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, options?: ExpressOptions<T>): Application<SV, T>;
2050
2048
  /**
2051
2049
  * Creates a new instance of Router with the given base path and schema validator.
2052
2050
  *
package/lib/index.js CHANGED
@@ -40,7 +40,6 @@ module.exports = __toCommonJS(index_exports);
40
40
  var import_common3 = require("@forklaunch/common");
41
41
  var import_http3 = require("@forklaunch/core/http");
42
42
  var import_zod = require("@forklaunch/validator/zod");
43
- var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
44
43
  var import_express_api_reference = require("@scalar/express-api-reference");
45
44
  var import_crypto = __toESM(require("crypto"));
46
45
  var import_express2 = __toESM(require("express"));
@@ -197,49 +196,20 @@ var Application = class extends import_http3.ForklaunchExpressLikeApplication {
197
196
  if (this.schemaValidator instanceof import_zod.ZodSchemaValidator) {
198
197
  const zodSchemaValidator = this.schemaValidator;
199
198
  const routers = this.routers;
200
- this.internal.get("/mcp", async (_req, res) => {
201
- const server = (0, import_http3.generateMcpServer)(
202
- zodSchemaValidator,
203
- protocol,
204
- host,
205
- port,
206
- "1.0.0",
207
- routers
208
- );
209
- res.json(server);
210
- });
211
- this.internal.post("/mcp", async (req, res) => {
212
- try {
213
- const server = (0, import_http3.generateMcpServer)(
214
- zodSchemaValidator,
215
- protocol,
216
- host,
217
- port,
218
- "1.0.0",
219
- routers
220
- );
221
- const transport = new import_streamableHttp.StreamableHTTPServerTransport({
222
- sessionIdGenerator: void 0
223
- });
224
- res.on("close", () => {
225
- transport.close();
226
- server.close();
227
- });
228
- await server.connect(transport);
229
- await transport.handleRequest(req, res, req.body);
230
- } catch (error) {
231
- console.error("Error handling MCP request:", error);
232
- if (!res.headersSent) {
233
- res.status(500).json({
234
- jsonrpc: "2.0",
235
- error: {
236
- code: -32603,
237
- message: "Internal server error"
238
- },
239
- id: null
240
- });
241
- }
242
- }
199
+ const mcpServer = (0, import_http3.generateMcpServer)(
200
+ zodSchemaValidator,
201
+ protocol,
202
+ host,
203
+ port,
204
+ "1.0.0",
205
+ routers
206
+ );
207
+ mcpServer.start({
208
+ httpStream: {
209
+ endpoint: "/mcp",
210
+ port: port + 1
211
+ },
212
+ transportType: "httpStream"
243
213
  });
244
214
  }
245
215
  if (this.docsConfiguration == null || this.docsConfiguration.type === "scalar") {
package/lib/index.mjs CHANGED
@@ -9,7 +9,6 @@ import {
9
9
  meta
10
10
  } from "@forklaunch/core/http";
11
11
  import { ZodSchemaValidator } from "@forklaunch/validator/zod";
12
- import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
13
12
  import { apiReference } from "@scalar/express-api-reference";
14
13
  import crypto from "crypto";
15
14
  import express2 from "express";
@@ -168,49 +167,20 @@ var Application = class extends ForklaunchExpressLikeApplication {
168
167
  if (this.schemaValidator instanceof ZodSchemaValidator) {
169
168
  const zodSchemaValidator = this.schemaValidator;
170
169
  const routers = this.routers;
171
- this.internal.get("/mcp", async (_req, res) => {
172
- const server = generateMcpServer(
173
- zodSchemaValidator,
174
- protocol,
175
- host,
176
- port,
177
- "1.0.0",
178
- routers
179
- );
180
- res.json(server);
181
- });
182
- this.internal.post("/mcp", async (req, res) => {
183
- try {
184
- const server = generateMcpServer(
185
- zodSchemaValidator,
186
- protocol,
187
- host,
188
- port,
189
- "1.0.0",
190
- routers
191
- );
192
- const transport = new StreamableHTTPServerTransport({
193
- sessionIdGenerator: void 0
194
- });
195
- res.on("close", () => {
196
- transport.close();
197
- server.close();
198
- });
199
- await server.connect(transport);
200
- await transport.handleRequest(req, res, req.body);
201
- } catch (error) {
202
- console.error("Error handling MCP request:", error);
203
- if (!res.headersSent) {
204
- res.status(500).json({
205
- jsonrpc: "2.0",
206
- error: {
207
- code: -32603,
208
- message: "Internal server error"
209
- },
210
- id: null
211
- });
212
- }
213
- }
170
+ const mcpServer = generateMcpServer(
171
+ zodSchemaValidator,
172
+ protocol,
173
+ host,
174
+ port,
175
+ "1.0.0",
176
+ routers
177
+ );
178
+ mcpServer.start({
179
+ httpStream: {
180
+ endpoint: "/mcp",
181
+ port: port + 1
182
+ },
183
+ transportType: "httpStream"
214
184
  });
215
185
  }
216
186
  if (this.docsConfiguration == null || this.docsConfiguration.type === "scalar") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/express",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Forklaunch framework for express.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -25,22 +25,23 @@
25
25
  "lib/**"
26
26
  ],
27
27
  "dependencies": {
28
- "@modelcontextprotocol/sdk": "^1.15.0",
29
- "@scalar/express-api-reference": "^0.8.9",
28
+ "@modelcontextprotocol/sdk": "^1.15.1",
29
+ "@scalar/express-api-reference": "^0.8.10",
30
30
  "@types/multer": "^2.0.0",
31
31
  "body-parser": "^2.2.0",
32
32
  "busboy": "^1.6.0",
33
33
  "cors": "^2.8.5",
34
34
  "express": "^5.1.0",
35
+ "fastmcp": "^3.8.5",
35
36
  "multer": "2.0.1",
36
37
  "qs": "^6.14.0",
37
38
  "swagger-ui-express": "^5.0.1",
38
- "@forklaunch/common": "0.4.3",
39
- "@forklaunch/validator": "0.7.5",
40
- "@forklaunch/core": "0.11.3"
39
+ "@forklaunch/common": "0.4.5",
40
+ "@forklaunch/validator": "0.7.7",
41
+ "@forklaunch/core": "0.11.5"
41
42
  },
42
43
  "devDependencies": {
43
- "@eslint/js": "^9.30.1",
44
+ "@eslint/js": "^9.31.0",
44
45
  "@types/body-parser": "^1.19.6",
45
46
  "@types/busboy": "^1.5.4",
46
47
  "@types/cors": "^2.8.19",
@@ -50,7 +51,7 @@
50
51
  "@types/qs": "^6.14.0",
51
52
  "@types/range-parser": "^1.2.7",
52
53
  "@types/swagger-ui-express": "^4.1.8",
53
- "@typescript/native-preview": "7.0.0-dev.20250709.1",
54
+ "@typescript/native-preview": "7.0.0-dev.20250712.1",
54
55
  "jest": "^30.0.4",
55
56
  "kill-port-process": "^3.2.1",
56
57
  "prettier": "^3.6.2",