@agiflowai/one-mcp 0.3.15 → 0.3.16

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
@@ -406,160 +406,6 @@ interface Skill {
406
406
  basePath: string;
407
407
  }
408
408
  //#endregion
409
- //#region src/server/index.d.ts
410
- /**
411
- * Configuration options for creating an MCP server instance
412
- * @property configFilePath - Path to the MCP configuration file
413
- * @property noCache - Skip cache when fetching remote configuration
414
- * @property skills - Skills configuration with paths array (optional, skills disabled if not provided)
415
- * @property serverId - CLI-provided server ID (takes precedence over config file id)
416
- */
417
- interface ServerOptions {
418
- configFilePath?: string;
419
- noCache?: boolean;
420
- skills?: {
421
- paths: string[];
422
- };
423
- serverId?: string;
424
- definitionsCachePath?: string;
425
- clearDefinitionsCache?: boolean;
426
- proxyMode?: 'meta' | 'flat' | 'search';
427
- onServerIdResolved?: (serverId: string) => Promise<void> | void;
428
- }
429
- declare function createServer(options?: ServerOptions): Promise<Server>;
430
- //#endregion
431
- //#region src/transports/http.d.ts
432
- /**
433
- * HTTP transport handler using Streamable HTTP (protocol version 2025-03-26)
434
- * Provides stateful session management with resumability support
435
- */
436
- declare class HttpTransportHandler implements HttpTransportHandler$1 {
437
- private serverFactory;
438
- private app;
439
- private server;
440
- private sessionManager;
441
- private config;
442
- private adminOptions?;
443
- private adminRateLimiter;
444
- constructor(serverFactory: (() => Server | Promise<Server>), config: TransportConfig, adminOptions?: HttpTransportAdminOptions);
445
- private setupMiddleware;
446
- private setupRoutes;
447
- private isAuthorizedShutdownRequest;
448
- private handleAdminShutdownRequest;
449
- private handlePostRequest;
450
- private handleGetRequest;
451
- private handleDeleteRequest;
452
- start(): Promise<void>;
453
- stop(): Promise<void>;
454
- getPort(): number;
455
- getHost(): string;
456
- }
457
- //#endregion
458
- //#region src/transports/sse.d.ts
459
- /**
460
- * SSE (Server-Sent Events) transport handler
461
- * Legacy transport for backwards compatibility (protocol version 2024-11-05)
462
- * Uses separate endpoints: /sse for SSE stream (GET) and /messages for client messages (POST)
463
- */
464
- declare class SseTransportHandler implements HttpTransportHandler$1 {
465
- private serverFactory;
466
- private app;
467
- private server;
468
- private sessionManager;
469
- private config;
470
- constructor(serverFactory: Server | (() => Server), config: TransportConfig);
471
- private setupMiddleware;
472
- private setupRoutes;
473
- private handleSseConnection;
474
- private handlePostMessage;
475
- start(): Promise<void>;
476
- stop(): Promise<void>;
477
- getPort(): number;
478
- getHost(): string;
479
- }
480
- //#endregion
481
- //#region src/transports/stdio.d.ts
482
- /**
483
- * Stdio transport handler for MCP server
484
- * Used for command-line and direct integrations
485
- */
486
- declare class StdioTransportHandler implements TransportHandler {
487
- private server;
488
- private transport;
489
- constructor(server: Server);
490
- start(): Promise<void>;
491
- stop(): Promise<void>;
492
- }
493
- //#endregion
494
- //#region src/transports/stdio-http.d.ts
495
- interface StdioHttpProxyTransportConfig {
496
- endpoint: URL;
497
- }
498
- /**
499
- * Transport that serves MCP over stdio and forwards MCP requests to an HTTP endpoint.
500
- */
501
- declare class StdioHttpTransportHandler implements TransportHandler {
502
- private readonly endpoint;
503
- private stdioProxyServer;
504
- private stdioTransport;
505
- private httpClient;
506
- constructor(config: StdioHttpProxyTransportConfig);
507
- start(): Promise<void>;
508
- stop(): Promise<void>;
509
- private createProxyServer;
510
- }
511
- //#endregion
512
- //#region src/services/McpClientManagerService.d.ts
513
- /**
514
- * Service for managing MCP client connections to remote servers
515
- */
516
- declare class McpClientManagerService {
517
- private clients;
518
- private serverConfigs;
519
- private connectionPromises;
520
- constructor();
521
- /**
522
- * Cleanup all resources on exit (child processes)
523
- */
524
- private cleanupOnExit;
525
- /**
526
- * Connect to an MCP server based on its configuration with timeout
527
- * Uses the timeout from server config, falling back to default (30s)
528
- */
529
- connectToServer(serverName: string, config: McpServerConfig): Promise<void>;
530
- registerServerConfigs(configs: Record<string, McpServerConfig>): void;
531
- getKnownServerNames(): string[];
532
- ensureConnected(serverName: string): Promise<McpClientConnection>;
533
- private createConnection;
534
- /**
535
- * Perform the actual connection to MCP server
536
- */
537
- private performConnection;
538
- private connectStdioClient;
539
- private connectHttpClient;
540
- private connectSseClient;
541
- /**
542
- * Get a connected client by server name
543
- */
544
- getClient(serverName: string): McpClientConnection | undefined;
545
- /**
546
- * Get all connected clients
547
- */
548
- getAllClients(): McpClientConnection[];
549
- /**
550
- * Disconnect from a specific server
551
- */
552
- disconnectServer(serverName: string): Promise<void>;
553
- /**
554
- * Disconnect from all servers
555
- */
556
- disconnectAll(): Promise<void>;
557
- /**
558
- * Check if a server is connected
559
- */
560
- isConnected(serverName: string): boolean;
561
- }
562
- //#endregion
563
409
  //#region src/services/SkillService.d.ts
564
410
  /**
565
411
  * Service for loading and managing skills from configured skill directories.
@@ -687,6 +533,57 @@ declare class SkillService {
687
533
  private loadSkillFile;
688
534
  }
689
535
  //#endregion
536
+ //#region src/services/McpClientManagerService.d.ts
537
+ /**
538
+ * Service for managing MCP client connections to remote servers
539
+ */
540
+ declare class McpClientManagerService {
541
+ private clients;
542
+ private serverConfigs;
543
+ private connectionPromises;
544
+ /**
545
+ * Synchronously kill all stdio MCP server child processes.
546
+ * Must be called by the owner (e.g. transport/command layer) during shutdown.
547
+ */
548
+ cleanupChildProcesses(): void;
549
+ /**
550
+ * Connect to an MCP server based on its configuration with timeout
551
+ * Uses the timeout from server config, falling back to default (30s)
552
+ */
553
+ connectToServer(serverName: string, config: McpServerConfig): Promise<void>;
554
+ registerServerConfigs(configs: Record<string, McpServerConfig>): void;
555
+ getKnownServerNames(): string[];
556
+ ensureConnected(serverName: string): Promise<McpClientConnection>;
557
+ private createConnection;
558
+ /**
559
+ * Perform the actual connection to MCP server
560
+ */
561
+ private performConnection;
562
+ private connectStdioClient;
563
+ private connectHttpClient;
564
+ private connectSseClient;
565
+ /**
566
+ * Get a connected client by server name
567
+ */
568
+ getClient(serverName: string): McpClientConnection | undefined;
569
+ /**
570
+ * Get all connected clients
571
+ */
572
+ getAllClients(): McpClientConnection[];
573
+ /**
574
+ * Disconnect from a specific server
575
+ */
576
+ disconnectServer(serverName: string): Promise<void>;
577
+ /**
578
+ * Disconnect from all servers
579
+ */
580
+ disconnectAll(): Promise<void>;
581
+ /**
582
+ * Check if a server is connected
583
+ */
584
+ isConnected(serverName: string): boolean;
585
+ }
586
+ //#endregion
690
587
  //#region src/services/DefinitionsCacheService.d.ts
691
588
  interface DefinitionsCacheServiceOptions {
692
589
  cacheData?: DefinitionsCacheFile;
@@ -970,6 +867,147 @@ declare class UseToolTool implements Tool<UseToolToolInput> {
970
867
  execute(input: UseToolToolInput): Promise<CallToolResult>;
971
868
  }
972
869
  //#endregion
870
+ //#region src/server/index.d.ts
871
+ /**
872
+ * Configuration options for creating an MCP server instance
873
+ * @property configFilePath - Path to the MCP configuration file
874
+ * @property noCache - Skip cache when fetching remote configuration
875
+ * @property skills - Skills configuration with paths array (optional, skills disabled if not provided)
876
+ * @property serverId - CLI-provided server ID (takes precedence over config file id)
877
+ */
878
+ interface ServerOptions {
879
+ configFilePath?: string;
880
+ noCache?: boolean;
881
+ skills?: {
882
+ paths: string[];
883
+ };
884
+ serverId?: string;
885
+ definitionsCachePath?: string;
886
+ clearDefinitionsCache?: boolean;
887
+ proxyMode?: 'meta' | 'flat' | 'search';
888
+ onServerIdResolved?: (serverId: string) => Promise<void> | void;
889
+ }
890
+ /**
891
+ * Shared services and tools for multi-session HTTP transport.
892
+ * Created once via initializeSharedServices(), then passed to createSessionServer()
893
+ * for each new client session. This avoids duplicating downstream connections,
894
+ * file watchers, and caches across concurrent sessions.
895
+ */
896
+ interface SharedServices {
897
+ clientManager: McpClientManagerService;
898
+ definitionsCacheService: DefinitionsCacheService;
899
+ skillService?: SkillService;
900
+ describeTools: DescribeToolsTool;
901
+ useTool: UseToolTool;
902
+ searchListTools: SearchListToolsTool;
903
+ serverId: string;
904
+ proxyMode: 'meta' | 'flat' | 'search';
905
+ /**
906
+ * Disposes all shared resources: disconnects downstream servers,
907
+ * stops file watchers. Must be called by the owner on shutdown.
908
+ */
909
+ dispose: () => Promise<void>;
910
+ }
911
+ /**
912
+ * Initialize shared services and tools once for use across multiple sessions.
913
+ * Use with createSessionServer() for HTTP transport where multiple agents
914
+ * connect concurrently. This avoids duplicating downstream connections,
915
+ * file watchers, caches, and tool instances per session.
916
+ */
917
+ declare function initializeSharedServices(options?: ServerOptions): Promise<SharedServices>;
918
+ /**
919
+ * Create a lightweight per-session MCP Server instance that delegates
920
+ * to shared services and tools. Use with initializeSharedServices()
921
+ * for multi-session HTTP transport.
922
+ */
923
+ declare function createSessionServer(shared: SharedServices): Promise<Server>;
924
+ /**
925
+ * Create a single MCP server instance (backward-compatible wrapper).
926
+ * For multi-session HTTP transport, use initializeSharedServices() + createSessionServer() instead.
927
+ */
928
+ declare function createServer(options?: ServerOptions): Promise<Server>;
929
+ //#endregion
930
+ //#region src/transports/http.d.ts
931
+ /**
932
+ * HTTP transport handler using Streamable HTTP (protocol version 2025-03-26)
933
+ * Provides stateful session management with resumability support
934
+ */
935
+ declare class HttpTransportHandler implements HttpTransportHandler$1 {
936
+ private serverFactory;
937
+ private app;
938
+ private server;
939
+ private sessionManager;
940
+ private config;
941
+ private adminOptions?;
942
+ private adminRateLimiter;
943
+ constructor(serverFactory: (() => Server | Promise<Server>), config: TransportConfig, adminOptions?: HttpTransportAdminOptions);
944
+ private setupMiddleware;
945
+ private setupRoutes;
946
+ private isAuthorizedShutdownRequest;
947
+ private handleAdminShutdownRequest;
948
+ private handlePostRequest;
949
+ private handleGetRequest;
950
+ private handleDeleteRequest;
951
+ start(): Promise<void>;
952
+ stop(): Promise<void>;
953
+ getPort(): number;
954
+ getHost(): string;
955
+ }
956
+ //#endregion
957
+ //#region src/transports/sse.d.ts
958
+ /**
959
+ * SSE (Server-Sent Events) transport handler
960
+ * Legacy transport for backwards compatibility (protocol version 2024-11-05)
961
+ * Uses separate endpoints: /sse for SSE stream (GET) and /messages for client messages (POST)
962
+ */
963
+ declare class SseTransportHandler implements HttpTransportHandler$1 {
964
+ private serverFactory;
965
+ private app;
966
+ private server;
967
+ private sessionManager;
968
+ private config;
969
+ constructor(serverFactory: Server | (() => Server), config: TransportConfig);
970
+ private setupMiddleware;
971
+ private setupRoutes;
972
+ private handleSseConnection;
973
+ private handlePostMessage;
974
+ start(): Promise<void>;
975
+ stop(): Promise<void>;
976
+ getPort(): number;
977
+ getHost(): string;
978
+ }
979
+ //#endregion
980
+ //#region src/transports/stdio.d.ts
981
+ /**
982
+ * Stdio transport handler for MCP server
983
+ * Used for command-line and direct integrations
984
+ */
985
+ declare class StdioTransportHandler implements TransportHandler {
986
+ private server;
987
+ private transport;
988
+ constructor(server: Server);
989
+ start(): Promise<void>;
990
+ stop(): Promise<void>;
991
+ }
992
+ //#endregion
993
+ //#region src/transports/stdio-http.d.ts
994
+ interface StdioHttpProxyTransportConfig {
995
+ endpoint: URL;
996
+ }
997
+ /**
998
+ * Transport that serves MCP over stdio and forwards MCP requests to an HTTP endpoint.
999
+ */
1000
+ declare class StdioHttpTransportHandler implements TransportHandler {
1001
+ private readonly endpoint;
1002
+ private stdioProxyServer;
1003
+ private stdioTransport;
1004
+ private httpClient;
1005
+ constructor(config: StdioHttpProxyTransportConfig);
1006
+ start(): Promise<void>;
1007
+ stop(): Promise<void>;
1008
+ private createProxyServer;
1009
+ }
1010
+ //#endregion
973
1011
  //#region src/services/ConfigFetcherService.d.ts
974
1012
  interface ConfigFetcherOptions {
975
1013
  configFilePath?: string;
@@ -1238,4 +1276,4 @@ declare function findConfigFile(): string | null;
1238
1276
  */
1239
1277
  declare function generateServerId(length?: number): string;
1240
1278
  //#endregion
1241
- export { CachedFileSkillInfo, CachedPromptSkillInfo, CachedServerDefinition, ConfigFetcherService, DefinitionsCacheFile, DefinitionsCacheService, DescribeToolsTool, HttpTransportAdminOptions, HttpTransportHandler, HttpTransportHealthResponse, HttpTransportShutdownResponse, McpClientConnection, McpClientManagerService, McpHttpConfig, McpPromptInfo, McpResourceInfo, McpServerConfig, McpServerTransportConfig, McpServerTransportType, McpSseConfig, McpStdioConfig, McpToolInfo, PromptConfig, PromptSkillConfig, RemoteMcpConfiguration, RuntimeLookupOptions, RuntimeStateManager, RuntimeStateRecord, RuntimeStateService, SearchListToolsTool, type ServerOptions, Skill, SkillMetadata, SkillService, SkillsConfig, SseTransportHandler, StdioHttpTransportHandler, StdioTransportHandler, type StopServerRequest, type StopServerResult, StopServerService, TRANSPORT_MODE, Tool, ToolDefinition, TransportConfig, TransportHandler, TransportMode, UseToolTool, createServer, findConfigFile, generateServerId };
1279
+ export { CachedFileSkillInfo, CachedPromptSkillInfo, CachedServerDefinition, ConfigFetcherService, DefinitionsCacheFile, DefinitionsCacheService, DescribeToolsTool, HttpTransportAdminOptions, HttpTransportHandler, HttpTransportHealthResponse, HttpTransportShutdownResponse, McpClientConnection, McpClientManagerService, McpHttpConfig, McpPromptInfo, McpResourceInfo, McpServerConfig, McpServerTransportConfig, McpServerTransportType, McpSseConfig, McpStdioConfig, McpToolInfo, PromptConfig, PromptSkillConfig, RemoteMcpConfiguration, RuntimeLookupOptions, RuntimeStateManager, RuntimeStateRecord, RuntimeStateService, SearchListToolsTool, type ServerOptions, type SharedServices, Skill, SkillMetadata, SkillService, SkillsConfig, SseTransportHandler, StdioHttpTransportHandler, StdioTransportHandler, type StopServerRequest, type StopServerResult, StopServerService, TRANSPORT_MODE, Tool, ToolDefinition, TransportConfig, TransportHandler, TransportMode, UseToolTool, createServer, createSessionServer, findConfigFile, generateServerId, initializeSharedServices };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { _ as findConfigFile, a as SseTransportHandler, c as createServer, d as SearchListToolsTool, f as DescribeToolsTool, g as generateServerId, h as DefinitionsCacheService, i as StdioTransportHandler, m as McpClientManagerService, n as RuntimeStateService, o as HttpTransportHandler, p as SkillService, r as StdioHttpTransportHandler, s as TRANSPORT_MODE, t as StopServerService, u as UseToolTool, v as ConfigFetcherService } from "./src-CH93aUm2.mjs";
1
+ import { _ as DefinitionsCacheService, a as SseTransportHandler, b as ConfigFetcherService, c as createServer, f as UseToolTool, g as McpClientManagerService, h as SkillService, i as StdioTransportHandler, l as createSessionServer, m as DescribeToolsTool, n as RuntimeStateService, o as HttpTransportHandler, p as SearchListToolsTool, r as StdioHttpTransportHandler, s as TRANSPORT_MODE, t as StopServerService, u as initializeSharedServices, v as generateServerId, y as findConfigFile } from "./src-Dn6vMZIk.mjs";
2
2
 
3
- export { ConfigFetcherService, DefinitionsCacheService, DescribeToolsTool, HttpTransportHandler, McpClientManagerService, RuntimeStateService, SearchListToolsTool, SkillService, SseTransportHandler, StdioHttpTransportHandler, StdioTransportHandler, StopServerService, TRANSPORT_MODE, UseToolTool, createServer, findConfigFile, generateServerId };
3
+ export { ConfigFetcherService, DefinitionsCacheService, DescribeToolsTool, HttpTransportHandler, McpClientManagerService, RuntimeStateService, SearchListToolsTool, SkillService, SseTransportHandler, StdioHttpTransportHandler, StdioTransportHandler, StopServerService, TRANSPORT_MODE, UseToolTool, createServer, createSessionServer, findConfigFile, generateServerId, initializeSharedServices };
@@ -1524,23 +1524,11 @@ var McpClientManagerService = class {
1524
1524
  clients = /* @__PURE__ */ new Map();
1525
1525
  serverConfigs = /* @__PURE__ */ new Map();
1526
1526
  connectionPromises = /* @__PURE__ */ new Map();
1527
- constructor() {
1528
- process.on("exit", () => {
1529
- this.cleanupOnExit();
1530
- });
1531
- process.on("SIGINT", () => {
1532
- this.cleanupOnExit();
1533
- process.exit(0);
1534
- });
1535
- process.on("SIGTERM", () => {
1536
- this.cleanupOnExit();
1537
- process.exit(0);
1538
- });
1539
- }
1540
1527
  /**
1541
- * Cleanup all resources on exit (child processes)
1528
+ * Synchronously kill all stdio MCP server child processes.
1529
+ * Must be called by the owner (e.g. transport/command layer) during shutdown.
1542
1530
  */
1543
- cleanupOnExit() {
1531
+ cleanupChildProcesses() {
1544
1532
  for (const [serverName, client] of this.clients) try {
1545
1533
  const childProcess = client["childProcess"];
1546
1534
  if (childProcess && !childProcess.killed) {
@@ -2808,7 +2796,7 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
2808
2796
 
2809
2797
  //#endregion
2810
2798
  //#region package.json
2811
- var version = "0.3.14";
2799
+ var version = "0.3.15";
2812
2800
 
2813
2801
  //#endregion
2814
2802
  //#region src/server/index.ts
@@ -2819,6 +2807,7 @@ var version = "0.3.14";
2819
2807
  * - Factory pattern for server creation
2820
2808
  * - Tool registration pattern
2821
2809
  * - Dependency injection for services
2810
+ * - Shared services pattern for multi-session HTTP transport
2822
2811
  *
2823
2812
  * CODING STANDARDS:
2824
2813
  * - Register all tools, resources, and prompts here
@@ -2922,7 +2911,13 @@ function buildProxyInstructions(serverDefinitions, mode, includeSkillsTool) {
2922
2911
  "Use describe_tools to inspect capabilities and use_tool to execute them."
2923
2912
  ].join("\n\n");
2924
2913
  }
2925
- async function createServer(options) {
2914
+ /**
2915
+ * Initialize shared services and tools once for use across multiple sessions.
2916
+ * Use with createSessionServer() for HTTP transport where multiple agents
2917
+ * connect concurrently. This avoids duplicating downstream connections,
2918
+ * file watchers, caches, and tool instances per session.
2919
+ */
2920
+ async function initializeSharedServices(options) {
2926
2921
  const clientManager = new McpClientManagerService();
2927
2922
  let configSkills;
2928
2923
  let configId;
@@ -2995,13 +2990,47 @@ async function createServer(options) {
2995
2990
  definitionsCacheService = new DefinitionsCacheService(clientManager, skillService);
2996
2991
  }
2997
2992
  else definitionsCacheService = new DefinitionsCacheService(clientManager, skillService);
2993
+ const proxyMode = options?.proxyMode || "meta";
2998
2994
  const describeTools = new DescribeToolsTool(clientManager, skillService, serverId, definitionsCacheService);
2999
- const useToolWithCache = new UseToolTool(clientManager, skillService, serverId, definitionsCacheService);
2995
+ const useTool = new UseToolTool(clientManager, skillService, serverId, definitionsCacheService);
3000
2996
  const searchListTools = new SearchListToolsTool(clientManager, definitionsCacheService);
3001
2997
  toolsRef.describeTools = describeTools;
3002
- const serverDefinitions = await definitionsCacheService.getServerDefinitions();
3003
- const includeSkillsTool = await hasAnySkills(definitionsCacheService, skillService);
3004
- const proxyMode = options?.proxyMode || "meta";
2998
+ if (skillService) skillService.startWatching().catch((error) => {
2999
+ console.error(`[skill-watcher] File watcher failed (non-critical): ${error instanceof Error ? error.message : "Unknown error"}`);
3000
+ });
3001
+ if (!shouldStartFromCache && effectiveDefinitionsCachePath && options?.configFilePath) definitionsCacheService.collectForCache({
3002
+ configPath: options.configFilePath,
3003
+ configHash,
3004
+ oneMcpVersion: version,
3005
+ serverId
3006
+ }).then((definitionsCache) => DefinitionsCacheService.writeToFile(effectiveDefinitionsCachePath, definitionsCache)).then(() => {
3007
+ console.error(`[definitions-cache] Wrote ${effectiveDefinitionsCachePath}`);
3008
+ }).catch((error) => {
3009
+ console.error(`[definitions-cache] Failed to persist ${effectiveDefinitionsCachePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
3010
+ });
3011
+ const dispose = async () => {
3012
+ await clientManager.disconnectAll();
3013
+ if (skillService) skillService.stopWatching();
3014
+ };
3015
+ return {
3016
+ clientManager,
3017
+ definitionsCacheService,
3018
+ skillService,
3019
+ describeTools,
3020
+ useTool,
3021
+ searchListTools,
3022
+ serverId,
3023
+ proxyMode,
3024
+ dispose
3025
+ };
3026
+ }
3027
+ /**
3028
+ * Create a lightweight per-session MCP Server instance that delegates
3029
+ * to shared services and tools. Use with initializeSharedServices()
3030
+ * for multi-session HTTP transport.
3031
+ */
3032
+ async function createSessionServer(shared) {
3033
+ const { clientManager, definitionsCacheService, skillService, describeTools, useTool: useToolWithCache, searchListTools, serverId, proxyMode } = shared;
3005
3034
  const server = new __modelcontextprotocol_sdk_server_index_js.Server({
3006
3035
  name: "@agiflowai/one-mcp",
3007
3036
  version: "0.1.0"
@@ -3011,10 +3040,7 @@ async function createServer(options) {
3011
3040
  resources: {},
3012
3041
  prompts: {}
3013
3042
  },
3014
- instructions: buildProxyInstructions(serverDefinitions, proxyMode, includeSkillsTool)
3015
- });
3016
- if (skillService) skillService.startWatching().catch((error) => {
3017
- console.error(`[skill-watcher] File watcher failed (non-critical): ${error instanceof Error ? error.message : "Unknown error"}`);
3043
+ instructions: buildProxyInstructions(await definitionsCacheService.getServerDefinitions(), proxyMode, await hasAnySkills(definitionsCacheService, skillService))
3018
3044
  });
3019
3045
  server.setRequestHandler(__modelcontextprotocol_sdk_types_js.ListToolsRequestSchema, async () => ({ tools: proxyMode === "flat" ? await (async () => {
3020
3046
  const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
@@ -3051,14 +3077,14 @@ async function createServer(options) {
3051
3077
  throw new Error(`Unknown tool: ${name}`);
3052
3078
  });
3053
3079
  server.setRequestHandler(__modelcontextprotocol_sdk_types_js.ListResourcesRequestSchema, async () => {
3054
- const serverDefinitions$1 = await definitionsCacheService.getServerDefinitions();
3080
+ const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
3055
3081
  const resourceToServers = /* @__PURE__ */ new Map();
3056
- for (const serverDefinition of serverDefinitions$1) for (const resource of serverDefinition.resources) {
3082
+ for (const serverDefinition of currentServerDefinitions) for (const resource of serverDefinition.resources) {
3057
3083
  if (!resourceToServers.has(resource.uri)) resourceToServers.set(resource.uri, []);
3058
3084
  resourceToServers.get(resource.uri)?.push(serverDefinition.serverName);
3059
3085
  }
3060
3086
  const resources = [];
3061
- for (const serverDefinition of serverDefinitions$1) for (const resource of serverDefinition.resources) {
3087
+ for (const serverDefinition of currentServerDefinitions) for (const resource of serverDefinition.resources) {
3062
3088
  const hasClash = (resourceToServers.get(resource.uri) || []).length > 1;
3063
3089
  resources.push({
3064
3090
  ...resource,
@@ -3077,10 +3103,10 @@ async function createServer(options) {
3077
3103
  return await (await clientManager.ensureConnected(matchingServers[0])).readResource(actualUri);
3078
3104
  });
3079
3105
  server.setRequestHandler(__modelcontextprotocol_sdk_types_js.ListPromptsRequestSchema, async () => {
3080
- const serverDefinitions$1 = await definitionsCacheService.getServerDefinitions();
3106
+ const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
3081
3107
  const promptToServers = /* @__PURE__ */ new Map();
3082
3108
  const serverPromptsMap = /* @__PURE__ */ new Map();
3083
- for (const serverDefinition of serverDefinitions$1) {
3109
+ for (const serverDefinition of currentServerDefinitions) {
3084
3110
  serverPromptsMap.set(serverDefinition.serverName, serverDefinition.prompts);
3085
3111
  for (const prompt of serverDefinition.prompts) {
3086
3112
  if (!promptToServers.has(prompt.name)) promptToServers.set(prompt.name, []);
@@ -3088,7 +3114,7 @@ async function createServer(options) {
3088
3114
  }
3089
3115
  }
3090
3116
  const aggregatedPrompts = [];
3091
- for (const serverDefinition of serverDefinitions$1) {
3117
+ for (const serverDefinition of currentServerDefinitions) {
3092
3118
  const prompts = serverPromptsMap.get(serverDefinition.serverName) || [];
3093
3119
  for (const prompt of prompts) {
3094
3120
  const hasClash = (promptToServers.get(prompt.name) || []).length > 1;
@@ -3103,29 +3129,26 @@ async function createServer(options) {
3103
3129
  });
3104
3130
  server.setRequestHandler(__modelcontextprotocol_sdk_types_js.GetPromptRequestSchema, async (request) => {
3105
3131
  const { name, arguments: args } = request.params;
3106
- const serverDefinitions$1 = await definitionsCacheService.getServerDefinitions();
3132
+ const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
3107
3133
  const { serverName, actualToolName: actualPromptName } = parseToolName(name);
3108
3134
  if (serverName) return await (await clientManager.ensureConnected(serverName)).getPrompt(actualPromptName, args);
3109
3135
  const serversWithPrompt = [];
3110
- for (const serverDefinition of serverDefinitions$1) if (serverDefinition.prompts.some((prompt) => prompt.name === name)) serversWithPrompt.push(serverDefinition.serverName);
3136
+ for (const serverDefinition of currentServerDefinitions) if (serverDefinition.prompts.some((prompt) => prompt.name === name)) serversWithPrompt.push(serverDefinition.serverName);
3111
3137
  if (serversWithPrompt.length === 0) throw new Error(`Prompt not found: ${name}`);
3112
3138
  if (serversWithPrompt.length > 1) throw new Error(`Prompt "${name}" exists on multiple servers: ${serversWithPrompt.join(", ")}. Use the prefixed format (e.g., "${serversWithPrompt[0]}__${name}") to specify which server to use.`);
3113
3139
  const client = clientManager.getClient(serversWithPrompt[0]);
3114
3140
  if (!client) return await (await clientManager.ensureConnected(serversWithPrompt[0])).getPrompt(name, args);
3115
3141
  return await client.getPrompt(name, args);
3116
3142
  });
3117
- if (!shouldStartFromCache && effectiveDefinitionsCachePath && options?.configFilePath) definitionsCacheService.collectForCache({
3118
- configPath: options.configFilePath,
3119
- configHash,
3120
- oneMcpVersion: version,
3121
- serverId
3122
- }).then((definitionsCache) => DefinitionsCacheService.writeToFile(effectiveDefinitionsCachePath, definitionsCache)).then(() => {
3123
- console.error(`[definitions-cache] Wrote ${effectiveDefinitionsCachePath}`);
3124
- }).catch((error) => {
3125
- console.error(`[definitions-cache] Failed to persist ${effectiveDefinitionsCachePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
3126
- });
3127
3143
  return server;
3128
3144
  }
3145
+ /**
3146
+ * Create a single MCP server instance (backward-compatible wrapper).
3147
+ * For multi-session HTTP transport, use initializeSharedServices() + createSessionServer() instead.
3148
+ */
3149
+ async function createServer(options) {
3150
+ return createSessionServer(await initializeSharedServices(options));
3151
+ }
3129
3152
 
3130
3153
  //#endregion
3131
3154
  //#region src/types/index.ts
@@ -4205,6 +4228,12 @@ Object.defineProperty(exports, 'createServer', {
4205
4228
  return createServer;
4206
4229
  }
4207
4230
  });
4231
+ Object.defineProperty(exports, 'createSessionServer', {
4232
+ enumerable: true,
4233
+ get: function () {
4234
+ return createSessionServer;
4235
+ }
4236
+ });
4208
4237
  Object.defineProperty(exports, 'findConfigFile', {
4209
4238
  enumerable: true,
4210
4239
  get: function () {
@@ -4217,6 +4246,12 @@ Object.defineProperty(exports, 'generateServerId', {
4217
4246
  return generateServerId;
4218
4247
  }
4219
4248
  });
4249
+ Object.defineProperty(exports, 'initializeSharedServices', {
4250
+ enumerable: true,
4251
+ get: function () {
4252
+ return initializeSharedServices;
4253
+ }
4254
+ });
4220
4255
  Object.defineProperty(exports, 'version', {
4221
4256
  enumerable: true,
4222
4257
  get: function () {