@leanmcp/core 0.3.5 → 0.3.6

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/dist/index.d.mts CHANGED
@@ -474,9 +474,18 @@ declare class MCPServer {
474
474
  method: string;
475
475
  params?: {
476
476
  [x: string]: unknown;
477
+ task?: {
478
+ [x: string]: unknown;
479
+ ttl?: number | null | undefined;
480
+ pollInterval?: number | undefined;
481
+ } | undefined;
477
482
  _meta?: {
478
483
  [x: string]: unknown;
479
484
  progressToken?: string | number | undefined;
485
+ "io.modelcontextprotocol/related-task"?: {
486
+ [x: string]: unknown;
487
+ taskId: string;
488
+ } | undefined;
480
489
  } | undefined;
481
490
  } | undefined;
482
491
  }, {
@@ -485,12 +494,20 @@ declare class MCPServer {
485
494
  [x: string]: unknown;
486
495
  _meta?: {
487
496
  [x: string]: unknown;
497
+ "io.modelcontextprotocol/related-task"?: {
498
+ [x: string]: unknown;
499
+ taskId: string;
500
+ } | undefined;
488
501
  } | undefined;
489
502
  } | undefined;
490
503
  }, {
491
504
  [x: string]: unknown;
492
505
  _meta?: {
493
506
  [x: string]: unknown;
507
+ "io.modelcontextprotocol/related-task"?: {
508
+ [x: string]: unknown;
509
+ taskId: string;
510
+ } | undefined;
494
511
  } | undefined;
495
512
  }>;
496
513
  }
@@ -509,9 +526,18 @@ declare class MCPServerRuntime {
509
526
  method: string;
510
527
  params?: {
511
528
  [x: string]: unknown;
529
+ task?: {
530
+ [x: string]: unknown;
531
+ ttl?: number | null | undefined;
532
+ pollInterval?: number | undefined;
533
+ } | undefined;
512
534
  _meta?: {
513
535
  [x: string]: unknown;
514
536
  progressToken?: string | number | undefined;
537
+ "io.modelcontextprotocol/related-task"?: {
538
+ [x: string]: unknown;
539
+ taskId: string;
540
+ } | undefined;
515
541
  } | undefined;
516
542
  } | undefined;
517
543
  }, {
@@ -520,12 +546,20 @@ declare class MCPServerRuntime {
520
546
  [x: string]: unknown;
521
547
  _meta?: {
522
548
  [x: string]: unknown;
549
+ "io.modelcontextprotocol/related-task"?: {
550
+ [x: string]: unknown;
551
+ taskId: string;
552
+ } | undefined;
523
553
  } | undefined;
524
554
  } | undefined;
525
555
  }, {
526
556
  [x: string]: unknown;
527
557
  _meta?: {
528
558
  [x: string]: unknown;
559
+ "io.modelcontextprotocol/related-task"?: {
560
+ [x: string]: unknown;
561
+ taskId: string;
562
+ } | undefined;
529
563
  } | undefined;
530
564
  }>;
531
565
  getTools(): RegisteredTool[];
package/dist/index.d.ts CHANGED
@@ -474,9 +474,18 @@ declare class MCPServer {
474
474
  method: string;
475
475
  params?: {
476
476
  [x: string]: unknown;
477
+ task?: {
478
+ [x: string]: unknown;
479
+ ttl?: number | null | undefined;
480
+ pollInterval?: number | undefined;
481
+ } | undefined;
477
482
  _meta?: {
478
483
  [x: string]: unknown;
479
484
  progressToken?: string | number | undefined;
485
+ "io.modelcontextprotocol/related-task"?: {
486
+ [x: string]: unknown;
487
+ taskId: string;
488
+ } | undefined;
480
489
  } | undefined;
481
490
  } | undefined;
482
491
  }, {
@@ -485,12 +494,20 @@ declare class MCPServer {
485
494
  [x: string]: unknown;
486
495
  _meta?: {
487
496
  [x: string]: unknown;
497
+ "io.modelcontextprotocol/related-task"?: {
498
+ [x: string]: unknown;
499
+ taskId: string;
500
+ } | undefined;
488
501
  } | undefined;
489
502
  } | undefined;
490
503
  }, {
491
504
  [x: string]: unknown;
492
505
  _meta?: {
493
506
  [x: string]: unknown;
507
+ "io.modelcontextprotocol/related-task"?: {
508
+ [x: string]: unknown;
509
+ taskId: string;
510
+ } | undefined;
494
511
  } | undefined;
495
512
  }>;
496
513
  }
@@ -509,9 +526,18 @@ declare class MCPServerRuntime {
509
526
  method: string;
510
527
  params?: {
511
528
  [x: string]: unknown;
529
+ task?: {
530
+ [x: string]: unknown;
531
+ ttl?: number | null | undefined;
532
+ pollInterval?: number | undefined;
533
+ } | undefined;
512
534
  _meta?: {
513
535
  [x: string]: unknown;
514
536
  progressToken?: string | number | undefined;
537
+ "io.modelcontextprotocol/related-task"?: {
538
+ [x: string]: unknown;
539
+ taskId: string;
540
+ } | undefined;
515
541
  } | undefined;
516
542
  } | undefined;
517
543
  }, {
@@ -520,12 +546,20 @@ declare class MCPServerRuntime {
520
546
  [x: string]: unknown;
521
547
  _meta?: {
522
548
  [x: string]: unknown;
549
+ "io.modelcontextprotocol/related-task"?: {
550
+ [x: string]: unknown;
551
+ taskId: string;
552
+ } | undefined;
523
553
  } | undefined;
524
554
  } | undefined;
525
555
  }, {
526
556
  [x: string]: unknown;
527
557
  _meta?: {
528
558
  [x: string]: unknown;
559
+ "io.modelcontextprotocol/related-task"?: {
560
+ [x: string]: unknown;
561
+ taskId: string;
562
+ } | undefined;
529
563
  } | undefined;
530
564
  }>;
531
565
  getTools(): RegisteredTool[];
package/dist/index.js CHANGED
@@ -483,17 +483,66 @@ var init_validation = __esm({
483
483
  function isInitializeRequest(body) {
484
484
  return body && body.method === "initialize";
485
485
  }
486
+ function getCallerFile() {
487
+ const originalPrepareStackTrace = Error.prepareStackTrace;
488
+ try {
489
+ const err = new Error();
490
+ Error.prepareStackTrace = (_, stack2) => stack2;
491
+ const stack = err.stack;
492
+ for (let i = 0; i < stack.length; i++) {
493
+ let fileName = stack[i].getFileName();
494
+ if (!fileName) continue;
495
+ if (fileName.startsWith("file://")) {
496
+ try {
497
+ const url = new URL(fileName);
498
+ fileName = decodeURIComponent(url.pathname);
499
+ if (process.platform === "win32" && fileName.startsWith("/")) {
500
+ fileName = fileName.substring(1);
501
+ }
502
+ } catch (e) {
503
+ fileName = fileName.replace("file://", "");
504
+ if (process.platform === "win32" && fileName.startsWith("/")) {
505
+ fileName = fileName.substring(1);
506
+ }
507
+ }
508
+ }
509
+ const normalizedPath = fileName.replace(/\\/g, "/");
510
+ const isLeanMCPCore = normalizedPath.includes("@leanmcp/core") || normalizedPath.includes("leanmcp-sdk/packages/core");
511
+ const isValidExtension = fileName.endsWith(".ts") || fileName.endsWith(".js") || fileName.endsWith(".mjs");
512
+ if (!isLeanMCPCore && isValidExtension) {
513
+ return fileName;
514
+ }
515
+ }
516
+ return null;
517
+ } finally {
518
+ Error.prepareStackTrace = originalPrepareStackTrace;
519
+ }
520
+ }
486
521
  async function createHTTPServer(serverInput, options) {
487
522
  let serverFactory;
488
523
  let httpOptions;
524
+ let resolvedMcpDir;
489
525
  if (typeof serverInput === "function") {
490
526
  serverFactory = serverInput;
491
527
  httpOptions = options || {};
492
528
  } else {
493
529
  const serverOptions = serverInput;
494
530
  const { MCPServer: MCPServer2 } = await Promise.resolve().then(() => (init_index(), index_exports));
531
+ if (!serverOptions.mcpDir) {
532
+ const callerFile = getCallerFile();
533
+ if (callerFile) {
534
+ const path2 = await import("path");
535
+ const callerDir = path2.dirname(callerFile);
536
+ resolvedMcpDir = path2.join(callerDir, "mcp");
537
+ }
538
+ } else {
539
+ resolvedMcpDir = serverOptions.mcpDir;
540
+ }
495
541
  serverFactory = /* @__PURE__ */ __name(async () => {
496
- const mcpServer2 = new MCPServer2(serverOptions);
542
+ const mcpServer2 = new MCPServer2({
543
+ ...serverOptions,
544
+ mcpDir: resolvedMcpDir || serverOptions.mcpDir
545
+ });
497
546
  return mcpServer2.getServer();
498
547
  }, "serverFactory");
499
548
  httpOptions = {
@@ -521,6 +570,7 @@ async function createHTTPServer(serverInput, options) {
521
570
  validatePort(basePort);
522
571
  const transports = {};
523
572
  let mcpServer = null;
573
+ let statelessServerFactory = null;
524
574
  const logger = httpOptions.logger || new Logger({
525
575
  level: httpOptions.logging ? LogLevel.INFO : LogLevel.NONE,
526
576
  prefix: "HTTP"
@@ -698,7 +748,7 @@ async function createHTTPServer(serverInput, options) {
698
748
  else if (params?.uri) logMessage += ` [${params.uri}]`;
699
749
  logger.info(logMessage);
700
750
  try {
701
- const freshServer = await serverFactory();
751
+ const freshServer = await statelessServerFactory();
702
752
  if (freshServer && typeof freshServer.waitForInit === "function") {
703
753
  await freshServer.waitForInit();
704
754
  }
@@ -758,6 +808,9 @@ async function createHTTPServer(serverInput, options) {
758
808
  if (mcpServer && typeof mcpServer.waitForInit === "function") {
759
809
  await mcpServer.waitForInit();
760
810
  }
811
+ if (isStateless) {
812
+ statelessServerFactory = serverFactory;
813
+ }
761
814
  const { listener, port } = await startServerWithPortRetry();
762
815
  activeListener = listener;
763
816
  process.env.PORT = String(port);
@@ -800,6 +853,7 @@ var init_http_server = __esm({
800
853
  init_logger();
801
854
  init_validation();
802
855
  __name(isInitializeRequest, "isInitializeRequest");
856
+ __name(getCallerFile, "getCallerFile");
803
857
  __name(createHTTPServer, "createHTTPServer");
804
858
  }
805
859
  });
package/dist/index.mjs CHANGED
@@ -444,17 +444,67 @@ function isInitializeRequest(body) {
444
444
  return body && body.method === "initialize";
445
445
  }
446
446
  __name(isInitializeRequest, "isInitializeRequest");
447
+ function getCallerFile() {
448
+ const originalPrepareStackTrace = Error.prepareStackTrace;
449
+ try {
450
+ const err = new Error();
451
+ Error.prepareStackTrace = (_, stack2) => stack2;
452
+ const stack = err.stack;
453
+ for (let i = 0; i < stack.length; i++) {
454
+ let fileName = stack[i].getFileName();
455
+ if (!fileName) continue;
456
+ if (fileName.startsWith("file://")) {
457
+ try {
458
+ const url = new URL(fileName);
459
+ fileName = decodeURIComponent(url.pathname);
460
+ if (process.platform === "win32" && fileName.startsWith("/")) {
461
+ fileName = fileName.substring(1);
462
+ }
463
+ } catch (e) {
464
+ fileName = fileName.replace("file://", "");
465
+ if (process.platform === "win32" && fileName.startsWith("/")) {
466
+ fileName = fileName.substring(1);
467
+ }
468
+ }
469
+ }
470
+ const normalizedPath = fileName.replace(/\\/g, "/");
471
+ const isLeanMCPCore = normalizedPath.includes("@leanmcp/core") || normalizedPath.includes("leanmcp-sdk/packages/core");
472
+ const isValidExtension = fileName.endsWith(".ts") || fileName.endsWith(".js") || fileName.endsWith(".mjs");
473
+ if (!isLeanMCPCore && isValidExtension) {
474
+ return fileName;
475
+ }
476
+ }
477
+ return null;
478
+ } finally {
479
+ Error.prepareStackTrace = originalPrepareStackTrace;
480
+ }
481
+ }
482
+ __name(getCallerFile, "getCallerFile");
447
483
  async function createHTTPServer(serverInput, options) {
448
484
  let serverFactory;
449
485
  let httpOptions;
486
+ let resolvedMcpDir;
450
487
  if (typeof serverInput === "function") {
451
488
  serverFactory = serverInput;
452
489
  httpOptions = options || {};
453
490
  } else {
454
491
  const serverOptions = serverInput;
455
492
  const { MCPServer: MCPServer2 } = await import("./index.mjs");
493
+ if (!serverOptions.mcpDir) {
494
+ const callerFile = getCallerFile();
495
+ if (callerFile) {
496
+ const path2 = await import("path");
497
+ const callerDir = path2.dirname(callerFile);
498
+ resolvedMcpDir = path2.join(callerDir, "mcp");
499
+ }
500
+ } else {
501
+ resolvedMcpDir = serverOptions.mcpDir;
502
+ }
456
503
  serverFactory = /* @__PURE__ */ __name(async () => {
457
- const mcpServer2 = new MCPServer2(serverOptions);
504
+ const mcpServer2 = new MCPServer2({
505
+ ...serverOptions,
506
+ mcpDir: resolvedMcpDir || serverOptions.mcpDir
507
+ });
458
508
  return mcpServer2.getServer();
459
509
  }, "serverFactory");
460
510
  httpOptions = {
@@ -482,6 +532,7 @@ async function createHTTPServer(serverInput, options) {
482
532
  validatePort(basePort);
483
533
  const transports = {};
484
534
  let mcpServer = null;
535
+ let statelessServerFactory = null;
485
536
  const logger = httpOptions.logger || new Logger({
486
537
  level: httpOptions.logging ? LogLevel.INFO : LogLevel.NONE,
487
538
  prefix: "HTTP"
@@ -659,7 +710,7 @@ async function createHTTPServer(serverInput, options) {
659
710
  else if (params?.uri) logMessage += ` [${params.uri}]`;
660
711
  logger.info(logMessage);
661
712
  try {
662
- const freshServer = await serverFactory();
713
+ const freshServer = await statelessServerFactory();
663
714
  if (freshServer && typeof freshServer.waitForInit === "function") {
664
715
  await freshServer.waitForInit();
665
716
  }
@@ -719,6 +770,9 @@ async function createHTTPServer(serverInput, options) {
719
770
  if (mcpServer && typeof mcpServer.waitForInit === "function") {
720
771
  await mcpServer.waitForInit();
721
772
  }
773
+ if (isStateless) {
774
+ statelessServerFactory = serverFactory;
775
+ }
722
776
  const { listener, port } = await startServerWithPortRetry();
723
777
  activeListener = listener;
724
778
  process.env.PORT = String(port);
package/package.json CHANGED
@@ -1,71 +1,71 @@
1
- {
2
- "name": "@leanmcp/core",
3
- "version": "0.3.5",
4
- "description": "Core library implementing decorators, reflection, and MCP runtime server",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "require": "./dist/index.js",
12
- "import": "./dist/index.mjs"
13
- }
14
- },
15
- "files": [
16
- "dist",
17
- "README.md",
18
- "LICENSE"
19
- ],
20
- "scripts": {
21
- "build": "tsup src/index.ts --format esm,cjs --dts",
22
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
23
- "test": "jest --passWithNoTests",
24
- "test:watch": "jest --watch"
25
- },
26
- "dependencies": {
27
- "@modelcontextprotocol/sdk": "^1.0.0",
28
- "ajv": "^8.12.0",
29
- "dotenv": "^16.3.1",
30
- "reflect-metadata": "^0.2.1"
31
- },
32
- "peerDependencies": {
33
- "cors": "^2.8.5",
34
- "express": "^5.0.0"
35
- },
36
- "peerDependenciesMeta": {
37
- "express": {
38
- "optional": true
39
- },
40
- "cors": {
41
- "optional": true
42
- }
43
- },
44
- "devDependencies": {
45
- "@types/cors": "^2.8.0",
46
- "@types/express": "^5.0.0",
47
- "@types/node": "^20.0.0"
48
- },
49
- "repository": {
50
- "type": "git",
51
- "url": "git+https://github.com/LeanMCP/leanmcp-sdk.git",
52
- "directory": "packages/core"
53
- },
54
- "homepage": "https://github.com/LeanMCP/leanmcp-sdk#readme",
55
- "bugs": {
56
- "url": "https://github.com/LeanMCP/leanmcp-sdk/issues"
57
- },
58
- "keywords": [
59
- "mcp",
60
- "model-context-protocol",
61
- "typescript",
62
- "decorators",
63
- "server",
64
- "runtime"
65
- ],
66
- "author": "LeanMCP <admin@leanmcp.com>",
67
- "license": "MIT",
68
- "publishConfig": {
69
- "access": "public"
70
- }
71
- }
1
+ {
2
+ "name": "@leanmcp/core",
3
+ "version": "0.3.6",
4
+ "description": "Core library implementing decorators, reflection, and MCP runtime server",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsup src/index.ts --format esm,cjs --dts",
22
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
23
+ "test": "jest --passWithNoTests",
24
+ "test:watch": "jest --watch"
25
+ },
26
+ "dependencies": {
27
+ "@modelcontextprotocol/sdk": "^1.0.0",
28
+ "ajv": "^8.12.0",
29
+ "dotenv": "^16.3.1",
30
+ "reflect-metadata": "^0.2.1"
31
+ },
32
+ "peerDependencies": {
33
+ "cors": "^2.8.5",
34
+ "express": "^5.0.0"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "express": {
38
+ "optional": true
39
+ },
40
+ "cors": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "devDependencies": {
45
+ "@types/cors": "^2.8.0",
46
+ "@types/express": "^5.0.0",
47
+ "@types/node": "^20.0.0"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/LeanMCP/leanmcp-sdk.git",
52
+ "directory": "packages/core"
53
+ },
54
+ "homepage": "https://github.com/LeanMCP/leanmcp-sdk#readme",
55
+ "bugs": {
56
+ "url": "https://github.com/LeanMCP/leanmcp-sdk/issues"
57
+ },
58
+ "keywords": [
59
+ "mcp",
60
+ "model-context-protocol",
61
+ "typescript",
62
+ "decorators",
63
+ "server",
64
+ "runtime"
65
+ ],
66
+ "author": "LeanMCP <admin@leanmcp.com>",
67
+ "license": "MIT",
68
+ "publishConfig": {
69
+ "access": "public"
70
+ }
71
+ }