@agiflowai/one-mcp 0.3.12 → 0.3.14

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
@@ -1,5 +1,6 @@
1
1
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
2
  import { CallToolResult, GetPromptResult, ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
3
+ import { z } from "zod";
3
4
 
4
5
  //#region src/types/index.d.ts
5
6
 
@@ -65,6 +66,97 @@ interface HttpTransportHandler$1 extends TransportHandler {
65
66
  getPort(): number;
66
67
  getHost(): string;
67
68
  }
69
+ /**
70
+ * Runtime state persisted for HTTP one-mcp instances.
71
+ * @property serverId - Unique one-mcp server identifier
72
+ * @property host - Host bound by the HTTP transport
73
+ * @property port - Port bound by the HTTP transport
74
+ * @property transport - Transport mode for the runtime record
75
+ * @property shutdownToken - Secret token required for admin shutdown requests
76
+ * @property startedAt - ISO timestamp when the runtime started
77
+ * @property pid - Process ID of the running one-mcp process
78
+ * @property configPath - Optional path to the config file used to start the server
79
+ */
80
+ interface RuntimeStateRecord {
81
+ serverId: string;
82
+ host: string;
83
+ port: number;
84
+ transport: 'http';
85
+ shutdownToken: string;
86
+ startedAt: string;
87
+ pid: number;
88
+ configPath?: string;
89
+ }
90
+ /**
91
+ * Optional admin settings for HTTP transport lifecycle actions.
92
+ * @property serverId - Server identifier surfaced via health responses
93
+ * @property shutdownToken - Secret token accepted by the admin shutdown endpoint
94
+ * @property onShutdownRequested - Callback invoked after a valid shutdown request is received
95
+ */
96
+ interface HttpTransportAdminOptions {
97
+ serverId?: string;
98
+ shutdownToken?: string;
99
+ onShutdownRequested?: () => Promise<void>;
100
+ }
101
+ /**
102
+ * Health payload exposed by HTTP transport.
103
+ * @property status - Health status string for liveness checks
104
+ * @property transport - Transport mode for the serving endpoint
105
+ * @property serverId - Optional server identifier for target verification
106
+ */
107
+ interface HttpTransportHealthResponse {
108
+ status: 'ok';
109
+ transport: 'http';
110
+ serverId?: string;
111
+ }
112
+ /**
113
+ * Admin shutdown response payload.
114
+ * @property ok - Whether shutdown request handling succeeded
115
+ * @property message - Human-readable outcome message
116
+ * @property serverId - Optional server identifier associated with this response
117
+ */
118
+ interface HttpTransportShutdownResponse {
119
+ ok: boolean;
120
+ message: string;
121
+ serverId?: string;
122
+ }
123
+ /**
124
+ * Runtime record lookup filters.
125
+ * @property host - Optional host filter for runtime discovery
126
+ * @property port - Optional port filter for runtime discovery
127
+ */
128
+ interface RuntimeLookupOptions {
129
+ host?: string;
130
+ port?: number;
131
+ }
132
+ /**
133
+ * Runtime service contract.
134
+ */
135
+ interface RuntimeStateManager {
136
+ /**
137
+ * Persist a runtime state record.
138
+ * @param record - Runtime metadata to persist
139
+ * @returns Promise that resolves when write completes
140
+ */
141
+ write(record: RuntimeStateRecord): Promise<void>;
142
+ /**
143
+ * Read a runtime state record by server ID.
144
+ * @param serverId - Target one-mcp server identifier
145
+ * @returns Matching runtime record, or null when no record exists
146
+ */
147
+ read(serverId: string): Promise<RuntimeStateRecord | null>;
148
+ /**
149
+ * List all persisted runtime records.
150
+ * @returns Array of runtime records
151
+ */
152
+ list(): Promise<RuntimeStateRecord[]>;
153
+ /**
154
+ * Remove a runtime state record by server ID.
155
+ * @param serverId - Target one-mcp server identifier
156
+ * @returns Promise that resolves when delete completes
157
+ */
158
+ remove(serverId: string): Promise<void>;
159
+ }
68
160
  /**
69
161
  * Remote MCP server configuration types
70
162
  */
@@ -332,20 +424,35 @@ interface ServerOptions {
332
424
  definitionsCachePath?: string;
333
425
  clearDefinitionsCache?: boolean;
334
426
  proxyMode?: 'meta' | 'flat' | 'search';
427
+ onServerIdResolved?: (serverId: string) => Promise<void> | void;
335
428
  }
336
429
  declare function createServer(options?: ServerOptions): Promise<Server>;
337
430
  //#endregion
338
- //#region src/transports/stdio.d.ts
431
+ //#region src/transports/http.d.ts
339
432
  /**
340
- * Stdio transport handler for MCP server
341
- * Used for command-line and direct integrations
433
+ * HTTP transport handler using Streamable HTTP (protocol version 2025-03-26)
434
+ * Provides stateful session management with resumability support
342
435
  */
343
- declare class StdioTransportHandler implements TransportHandler {
436
+ declare class HttpTransportHandler implements HttpTransportHandler$1 {
437
+ private serverFactory;
438
+ private app;
344
439
  private server;
345
- private transport;
346
- constructor(server: Server);
440
+ private sessionManager;
441
+ private config;
442
+ private adminOptions?;
443
+ private adminRateLimiter;
444
+ constructor(serverFactory: Server | (() => 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;
347
452
  start(): Promise<void>;
348
453
  stop(): Promise<void>;
454
+ getPort(): number;
455
+ getHost(): string;
349
456
  }
350
457
  //#endregion
351
458
  //#region src/transports/sse.d.ts
@@ -371,27 +478,35 @@ declare class SseTransportHandler implements HttpTransportHandler$1 {
371
478
  getHost(): string;
372
479
  }
373
480
  //#endregion
374
- //#region src/transports/http.d.ts
481
+ //#region src/transports/stdio.d.ts
375
482
  /**
376
- * HTTP transport handler using Streamable HTTP (protocol version 2025-03-26)
377
- * Provides stateful session management with resumability support
483
+ * Stdio transport handler for MCP server
484
+ * Used for command-line and direct integrations
378
485
  */
379
- declare class HttpTransportHandler implements HttpTransportHandler$1 {
380
- private serverFactory;
381
- private app;
486
+ declare class StdioTransportHandler implements TransportHandler {
382
487
  private server;
383
- private sessionManager;
384
- private config;
385
- constructor(serverFactory: Server | (() => Server), config: TransportConfig);
386
- private setupMiddleware;
387
- private setupRoutes;
388
- private handlePostRequest;
389
- private handleGetRequest;
390
- private handleDeleteRequest;
488
+ private transport;
489
+ constructor(server: Server);
391
490
  start(): Promise<void>;
392
491
  stop(): Promise<void>;
393
- getPort(): number;
394
- getHost(): string;
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;
395
510
  }
396
511
  //#endregion
397
512
  //#region src/services/McpClientManagerService.d.ts
@@ -926,4 +1041,199 @@ declare class ConfigFetcherService {
926
1041
  isCacheValid(): boolean;
927
1042
  }
928
1043
  //#endregion
929
- export { CachedFileSkillInfo, CachedPromptSkillInfo, CachedServerDefinition, ConfigFetcherService, DefinitionsCacheFile, DefinitionsCacheService, DescribeToolsTool, HttpTransportHandler, McpClientConnection, McpClientManagerService, McpHttpConfig, McpPromptInfo, McpResourceInfo, McpServerConfig, McpServerTransportConfig, McpServerTransportType, McpSseConfig, McpStdioConfig, McpToolInfo, PromptConfig, PromptSkillConfig, RemoteMcpConfiguration, SearchListToolsTool, type ServerOptions, Skill, SkillMetadata, SkillService, SkillsConfig, SseTransportHandler, StdioTransportHandler, TRANSPORT_MODE, Tool, ToolDefinition, TransportConfig, TransportHandler, TransportMode, UseToolTool, createServer };
1044
+ //#region src/services/RuntimeStateService.d.ts
1045
+ /**
1046
+ * Runtime state persistence implementation.
1047
+ */
1048
+ declare class RuntimeStateService implements RuntimeStateManager {
1049
+ private runtimeDir;
1050
+ constructor(runtimeDir?: string);
1051
+ /**
1052
+ * Resolve default runtime directory under the user's home cache path.
1053
+ * @returns Absolute runtime directory path
1054
+ */
1055
+ static getDefaultRuntimeDir(): string;
1056
+ /**
1057
+ * Build runtime state file path for a given server ID.
1058
+ * @param serverId - Target one-mcp server identifier
1059
+ * @returns Absolute runtime file path
1060
+ */
1061
+ private getRecordPath;
1062
+ /**
1063
+ * Persist a runtime state record.
1064
+ * @param record - Runtime metadata to persist
1065
+ * @returns Promise that resolves when write completes
1066
+ */
1067
+ write(record: RuntimeStateRecord): Promise<void>;
1068
+ /**
1069
+ * Read a runtime state record by server ID.
1070
+ * @param serverId - Target one-mcp server identifier
1071
+ * @returns Matching runtime record, or null when no record exists
1072
+ */
1073
+ read(serverId: string): Promise<RuntimeStateRecord | null>;
1074
+ /**
1075
+ * List all persisted runtime records.
1076
+ * @returns Array of runtime records
1077
+ */
1078
+ list(): Promise<RuntimeStateRecord[]>;
1079
+ /**
1080
+ * Remove a runtime state record by server ID.
1081
+ * @param serverId - Target one-mcp server identifier
1082
+ * @returns Promise that resolves when delete completes
1083
+ */
1084
+ remove(serverId: string): Promise<void>;
1085
+ }
1086
+ //#endregion
1087
+ //#region src/services/StopServerService.d.ts
1088
+ /**
1089
+ * Stop request options.
1090
+ * @property serverId - Explicit one-mcp server identifier to stop
1091
+ * @property host - Host fallback for runtime lookup
1092
+ * @property port - Port fallback for runtime lookup
1093
+ * @property token - Optional shutdown token override
1094
+ * @property force - Skip server ID verification against /health when true
1095
+ * @property timeoutMs - Maximum time to wait for shutdown completion
1096
+ */
1097
+ interface StopServerRequest {
1098
+ serverId?: string;
1099
+ host?: string;
1100
+ port?: number;
1101
+ token?: string;
1102
+ force?: boolean;
1103
+ timeoutMs?: number;
1104
+ }
1105
+ /**
1106
+ * Stop command result payload.
1107
+ * @property ok - Whether the shutdown completed successfully
1108
+ * @property serverId - Stopped one-mcp server identifier
1109
+ * @property host - Host that served the runtime
1110
+ * @property port - Port that served the runtime
1111
+ * @property message - Human-readable shutdown result message
1112
+ */
1113
+ interface StopServerResult {
1114
+ ok: true;
1115
+ serverId: string;
1116
+ host: string;
1117
+ port: number;
1118
+ message: string;
1119
+ }
1120
+ /**
1121
+ * Service for resolving runtime targets and stopping them safely.
1122
+ */
1123
+ declare class StopServerService {
1124
+ private runtimeStateService;
1125
+ constructor(runtimeStateService?: RuntimeStateManager);
1126
+ /**
1127
+ * Resolve a target runtime and stop it cooperatively.
1128
+ * @param request - Stop request options
1129
+ * @returns Stop result payload
1130
+ */
1131
+ stop(request: StopServerRequest): Promise<StopServerResult>;
1132
+ /**
1133
+ * Resolve a runtime record from explicit ID or a unique host/port pair.
1134
+ * @param request - Stop request options
1135
+ * @returns Matching runtime record
1136
+ */
1137
+ private resolveRuntime;
1138
+ /**
1139
+ * Read the runtime health payload.
1140
+ * @param runtime - Runtime to query
1141
+ * @param timeoutMs - Request timeout in milliseconds
1142
+ * @returns Reachability status and optional payload
1143
+ */
1144
+ private fetchHealth;
1145
+ /**
1146
+ * Send authenticated shutdown request to the admin endpoint.
1147
+ * @param runtime - Runtime to stop
1148
+ * @param shutdownToken - Bearer token for the admin endpoint
1149
+ * @param timeoutMs - Request timeout in milliseconds
1150
+ * @returns Parsed shutdown response payload
1151
+ */
1152
+ private requestShutdown;
1153
+ /**
1154
+ * Poll until the target runtime is no longer reachable.
1155
+ * @param runtime - Runtime expected to stop
1156
+ * @param timeoutMs - Maximum wait time in milliseconds
1157
+ * @returns Promise that resolves when shutdown is observed
1158
+ */
1159
+ private waitForShutdown;
1160
+ /**
1161
+ * Perform a fetch with an abort timeout.
1162
+ * @param url - Target URL
1163
+ * @param init - Fetch options
1164
+ * @param timeoutMs - Timeout in milliseconds
1165
+ * @returns Fetch response
1166
+ */
1167
+ private fetchWithTimeout;
1168
+ }
1169
+ //#endregion
1170
+ //#region src/utils/findConfigFile.d.ts
1171
+ /**
1172
+ * Config File Finder Utility
1173
+ *
1174
+ * DESIGN PATTERNS:
1175
+ * - Utility function pattern for reusable logic
1176
+ * - Fail-fast pattern with early returns
1177
+ * - Environment variable configuration pattern
1178
+ *
1179
+ * CODING STANDARDS:
1180
+ * - Use sync filesystem operations for config discovery (performance)
1181
+ * - Check PROJECT_PATH environment variable first
1182
+ * - Fall back to current working directory
1183
+ * - Support both .yaml and .json extensions
1184
+ * - Return null if no config file is found
1185
+ *
1186
+ * AVOID:
1187
+ * - Throwing errors (return null instead for optional config)
1188
+ * - Hardcoded file names without extension variants
1189
+ * - Ignoring environment variables
1190
+ */
1191
+ /**
1192
+ * Find MCP configuration file by checking PROJECT_PATH first, then cwd
1193
+ * Looks for both mcp-config.yaml and mcp-config.json
1194
+ *
1195
+ * @returns Absolute path to config file, or null if not found
1196
+ */
1197
+ declare function findConfigFile(): string | null;
1198
+ //#endregion
1199
+ //#region src/utils/generateServerId.d.ts
1200
+ /**
1201
+ * generateServerId Utilities
1202
+ *
1203
+ * DESIGN PATTERNS:
1204
+ * - Pure functions with no side effects
1205
+ * - Single responsibility per function
1206
+ * - Functional programming approach
1207
+ *
1208
+ * CODING STANDARDS:
1209
+ * - Export individual functions, not classes
1210
+ * - Use descriptive function names with verbs
1211
+ * - Add JSDoc comments for complex logic
1212
+ * - Keep functions small and focused
1213
+ *
1214
+ * AVOID:
1215
+ * - Side effects (mutating external state)
1216
+ * - Stateful logic (use services for state)
1217
+ * - Complex external dependencies
1218
+ */
1219
+ /**
1220
+ * Generate a short, human-readable server ID.
1221
+ *
1222
+ * Uses Node.js crypto.randomBytes for cryptographically secure randomness
1223
+ * with rejection sampling to avoid modulo bias.
1224
+ *
1225
+ * The generated ID:
1226
+ * - Is 6 characters long by default
1227
+ * - Uses only lowercase alphanumeric characters
1228
+ * - Excludes confusing characters (0, O, 1, l, I)
1229
+ *
1230
+ * @param length - Length of the ID to generate (default: 6)
1231
+ * @returns A random, human-readable ID
1232
+ *
1233
+ * @example
1234
+ * generateServerId() // "abc234"
1235
+ * generateServerId(4) // "x7mn"
1236
+ */
1237
+ declare function generateServerId(length?: number): string;
1238
+ //#endregion
1239
+ 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 };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { c as DescribeToolsTool, d as DefinitionsCacheService, i as createServer, l as SkillService, m as ConfigFetcherService, n as SseTransportHandler, o as UseToolTool, r as StdioTransportHandler, s as SearchListToolsTool, t as HttpTransportHandler, u as McpClientManagerService } from "./http-ClRbCldm.mjs";
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-D7Yq1bTx.mjs";
2
2
 
3
- export { ConfigFetcherService, DefinitionsCacheService, DescribeToolsTool, HttpTransportHandler, McpClientManagerService, SearchListToolsTool, SkillService, SseTransportHandler, StdioTransportHandler, UseToolTool, createServer };
3
+ export { ConfigFetcherService, DefinitionsCacheService, DescribeToolsTool, HttpTransportHandler, McpClientManagerService, RuntimeStateService, SearchListToolsTool, SkillService, SseTransportHandler, StdioHttpTransportHandler, StdioTransportHandler, StopServerService, TRANSPORT_MODE, UseToolTool, createServer, findConfigFile, generateServerId };