@winstonsayno/mcp-gateway 0.0.0-stage → 0.3.0

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/LICENSE +21 -0
  3. package/README.md +377 -2
  4. package/dashboard/README.md +27 -0
  5. package/dashboard/index.html +415 -0
  6. package/dist/auth/middleware.d.ts +24 -0
  7. package/dist/auth/middleware.d.ts.map +1 -0
  8. package/dist/auth/middleware.js +108 -0
  9. package/dist/auth/middleware.js.map +1 -0
  10. package/dist/auth/ratelimit.d.ts +19 -0
  11. package/dist/auth/ratelimit.d.ts.map +1 -0
  12. package/dist/auth/ratelimit.js +81 -0
  13. package/dist/auth/ratelimit.js.map +1 -0
  14. package/dist/cli.d.ts +6 -0
  15. package/dist/cli.d.ts.map +1 -0
  16. package/dist/cli.js +129 -0
  17. package/dist/cli.js.map +1 -0
  18. package/dist/config/loader.d.ts +13 -0
  19. package/dist/config/loader.d.ts.map +1 -0
  20. package/dist/config/loader.js +268 -0
  21. package/dist/config/loader.js.map +1 -0
  22. package/dist/config/watcher.d.ts +29 -0
  23. package/dist/config/watcher.d.ts.map +1 -0
  24. package/dist/config/watcher.js +96 -0
  25. package/dist/config/watcher.js.map +1 -0
  26. package/dist/gateway/api.d.ts +29 -0
  27. package/dist/gateway/api.d.ts.map +1 -0
  28. package/dist/gateway/api.js +280 -0
  29. package/dist/gateway/api.js.map +1 -0
  30. package/dist/gateway/index.d.ts +49 -0
  31. package/dist/gateway/index.d.ts.map +1 -0
  32. package/dist/gateway/index.js +260 -0
  33. package/dist/gateway/index.js.map +1 -0
  34. package/dist/gateway/supervisor.d.ts +58 -0
  35. package/dist/gateway/supervisor.d.ts.map +1 -0
  36. package/dist/gateway/supervisor.js +205 -0
  37. package/dist/gateway/supervisor.js.map +1 -0
  38. package/dist/index.d.ts +15 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +12 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/middleware/cors.d.ts +19 -0
  43. package/dist/middleware/cors.d.ts.map +1 -0
  44. package/dist/middleware/cors.js +65 -0
  45. package/dist/middleware/cors.js.map +1 -0
  46. package/dist/middleware/error-handler.d.ts +40 -0
  47. package/dist/middleware/error-handler.d.ts.map +1 -0
  48. package/dist/middleware/error-handler.js +98 -0
  49. package/dist/middleware/error-handler.js.map +1 -0
  50. package/dist/middleware/request-id.d.ts +23 -0
  51. package/dist/middleware/request-id.d.ts.map +1 -0
  52. package/dist/middleware/request-id.js +30 -0
  53. package/dist/middleware/request-id.js.map +1 -0
  54. package/dist/middleware/timeout.d.ts +12 -0
  55. package/dist/middleware/timeout.d.ts.map +1 -0
  56. package/dist/middleware/timeout.js +39 -0
  57. package/dist/middleware/timeout.js.map +1 -0
  58. package/dist/monitor/index.d.ts +49 -0
  59. package/dist/monitor/index.d.ts.map +1 -0
  60. package/dist/monitor/index.js +204 -0
  61. package/dist/monitor/index.js.map +1 -0
  62. package/dist/proxy/index.d.ts +86 -0
  63. package/dist/proxy/index.d.ts.map +1 -0
  64. package/dist/proxy/index.js +389 -0
  65. package/dist/proxy/index.js.map +1 -0
  66. package/dist/registry/index.d.ts +41 -0
  67. package/dist/registry/index.d.ts.map +1 -0
  68. package/dist/registry/index.js +157 -0
  69. package/dist/registry/index.js.map +1 -0
  70. package/dist/transport/channel.d.ts +61 -0
  71. package/dist/transport/channel.d.ts.map +1 -0
  72. package/dist/transport/channel.js +38 -0
  73. package/dist/transport/channel.js.map +1 -0
  74. package/dist/transport/sse-parser.d.ts +30 -0
  75. package/dist/transport/sse-parser.d.ts.map +1 -0
  76. package/dist/transport/sse-parser.js +107 -0
  77. package/dist/transport/sse-parser.js.map +1 -0
  78. package/dist/transport/sse.d.ts +39 -0
  79. package/dist/transport/sse.d.ts.map +1 -0
  80. package/dist/transport/sse.js +142 -0
  81. package/dist/transport/sse.js.map +1 -0
  82. package/dist/transport/stdio.d.ts +35 -0
  83. package/dist/transport/stdio.d.ts.map +1 -0
  84. package/dist/transport/stdio.js +149 -0
  85. package/dist/transport/stdio.js.map +1 -0
  86. package/dist/transport/streamable-http.d.ts +45 -0
  87. package/dist/transport/streamable-http.d.ts.map +1 -0
  88. package/dist/transport/streamable-http.js +183 -0
  89. package/dist/transport/streamable-http.js.map +1 -0
  90. package/dist/transport/websocket.d.ts +38 -0
  91. package/dist/transport/websocket.d.ts.map +1 -0
  92. package/dist/transport/websocket.js +172 -0
  93. package/dist/transport/websocket.js.map +1 -0
  94. package/dist/utils/logger.d.ts +16 -0
  95. package/dist/utils/logger.d.ts.map +1 -0
  96. package/dist/utils/logger.js +60 -0
  97. package/dist/utils/logger.js.map +1 -0
  98. package/dist/utils/mutex.d.ts +25 -0
  99. package/dist/utils/mutex.d.ts.map +1 -0
  100. package/dist/utils/mutex.js +62 -0
  101. package/dist/utils/mutex.js.map +1 -0
  102. package/dist/utils/semaphore.d.ts +16 -0
  103. package/dist/utils/semaphore.d.ts.map +1 -0
  104. package/dist/utils/semaphore.js +42 -0
  105. package/dist/utils/semaphore.js.map +1 -0
  106. package/dist/utils/types.d.ts +215 -0
  107. package/dist/utils/types.d.ts.map +1 -0
  108. package/dist/utils/types.js +5 -0
  109. package/dist/utils/types.js.map +1 -0
  110. package/dist/utils/version.d.ts +6 -0
  111. package/dist/utils/version.d.ts.map +1 -0
  112. package/dist/utils/version.js +18 -0
  113. package/dist/utils/version.js.map +1 -0
  114. package/package.json +78 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ratelimit.js","sourceRoot":"","sources":["../../src/auth/ratelimit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAc5C,MAAM,UAAU,iBAAiB,CAC/B,MAAwB,EACxB,MAAoB,IAAI,CAAC,GAAG;IAE5B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,WAAW,GAAG,CAAC,CAAC,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AAE,iBAAiB,KAAK,iBAAiB,aAAa,YAAY;gBACzE,UAAU;aACX,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,mBAAmB,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,SAAS,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAC5E,IAAI,EAAE,CAAC;IACT,CAAC,CAAgB,CAAC;IAElB,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE;QACnB,aAAa,CAAC,OAAO,CAAC,CAAC;QACvB,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,mBAAmB,CAC1B,GAAa,EACb,KAAa,EACb,SAAiB,EACjB,OAAe;IAEf,GAAG,CAAC,GAAG,CAAC;QACN,mBAAmB,EAAE,MAAM,CAAC,KAAK,CAAC;QAClC,uBAAuB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;QACvD,mBAAmB,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;KACvD,CAAC,CAAC;AACL,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * mcp-gateway CLI
4
+ */
5
+ import 'dotenv/config';
6
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,eAAe,CAAC"}
package/dist/cli.js ADDED
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * mcp-gateway CLI
4
+ */
5
+ import 'dotenv/config';
6
+ import { Command } from 'commander';
7
+ import { existsSync } from 'fs';
8
+ import { writeFile } from 'fs/promises';
9
+ import { loadConfig, generateDefaultConfig, resolveConfigPath } from './config/loader.js';
10
+ import { ConfigWatcher } from './config/watcher.js';
11
+ import { Gateway } from './gateway/index.js';
12
+ import { logger } from './utils/logger.js';
13
+ import { VERSION } from './utils/version.js';
14
+ const LOG_LEVELS = ['debug', 'info', 'warn', 'error'];
15
+ const program = new Command();
16
+ program
17
+ .name('mcp-gateway')
18
+ .description('A lightweight gateway for managing multiple MCP servers')
19
+ .version(VERSION);
20
+ // ─── start ────────────────────────────────────────────────────────────────────
21
+ program
22
+ .command('start')
23
+ .description('Start the MCP gateway server')
24
+ .option('-c, --config <path>', 'Path to config file')
25
+ .option('-p, --port <number>', 'Override port from config')
26
+ .option('--log-level <level>', 'Log level (debug|info|warn|error)')
27
+ .option('--no-watch', 'Disable config hot reload')
28
+ .action(async (options) => {
29
+ let gateway;
30
+ let watcher;
31
+ try {
32
+ const config = await loadConfig(options.config);
33
+ if (options.port !== undefined) {
34
+ const port = Number(options.port);
35
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
36
+ throw new Error(`Invalid --port "${options.port}"`);
37
+ }
38
+ config.port = port;
39
+ }
40
+ if (options.logLevel) {
41
+ if (!LOG_LEVELS.includes(options.logLevel)) {
42
+ throw new Error(`Invalid --log-level "${options.logLevel}" (expected ${LOG_LEVELS.join('|')})`);
43
+ }
44
+ config.logLevel = options.logLevel;
45
+ }
46
+ const gw = new Gateway(config);
47
+ gateway = gw;
48
+ // Graceful shutdown (idempotent; a second signal forces exit)
49
+ let shuttingDown = false;
50
+ const shutdown = (signal) => {
51
+ if (shuttingDown) {
52
+ logger.warn(`Received ${signal} again, forcing exit`);
53
+ process.exit(1);
54
+ }
55
+ shuttingDown = true;
56
+ logger.info(`Received ${signal}, shutting down gracefully...`);
57
+ watcher?.stop();
58
+ gw.stop().then(() => process.exit(0), (err) => {
59
+ logger.error(`Error during shutdown: ${err instanceof Error ? err.message : String(err)}`);
60
+ process.exit(1);
61
+ });
62
+ };
63
+ process.on('SIGINT', () => shutdown('SIGINT'));
64
+ process.on('SIGTERM', () => shutdown('SIGTERM'));
65
+ await gw.start();
66
+ const configPath = resolveConfigPath(options.config);
67
+ if (options.watch && configPath) {
68
+ const w = new ConfigWatcher(configPath, logger);
69
+ watcher = w;
70
+ w.on('reload', (next) => {
71
+ // CLI overrides keep precedence over the file
72
+ if (options.logLevel)
73
+ next.logLevel = options.logLevel;
74
+ if (options.port !== undefined)
75
+ next.port = config.port;
76
+ gw.reload(next).catch((err) => {
77
+ logger.error(`Hot reload failed: ${err instanceof Error ? err.message : String(err)}`);
78
+ });
79
+ });
80
+ w.start();
81
+ }
82
+ }
83
+ catch (err) {
84
+ logger.error(`Failed to start gateway: ${err instanceof Error ? err.message : String(err)}`);
85
+ watcher?.stop();
86
+ await gateway?.stop().catch(() => { });
87
+ process.exit(1);
88
+ }
89
+ });
90
+ // ─── init ─────────────────────────────────────────────────────────────────────
91
+ program
92
+ .command('init')
93
+ .description('Generate a default configuration file')
94
+ .option('-o, --output <path>', 'Output path', 'mcp-gateway.yml')
95
+ .option('--force', 'Overwrite existing file')
96
+ .action(async (options) => {
97
+ if (existsSync(options.output) && !options.force) {
98
+ logger.error(`File "${options.output}" already exists. Use --force to overwrite.`);
99
+ process.exit(1);
100
+ }
101
+ await writeFile(options.output, generateDefaultConfig(), 'utf-8');
102
+ logger.info(`Created ${options.output}`);
103
+ console.log('\nNext steps:');
104
+ console.log(` 1. Edit ${options.output} to configure your MCP servers`);
105
+ console.log(' 2. Run: mcp-gateway start\n');
106
+ });
107
+ // ─── validate ─────────────────────────────────────────────────────────────────
108
+ program
109
+ .command('validate')
110
+ .description('Validate a configuration file')
111
+ .option('-c, --config <path>', 'Path to config file')
112
+ .action(async (options) => {
113
+ try {
114
+ const config = await loadConfig(options.config);
115
+ console.log(`✓ Configuration is valid`);
116
+ console.log(` Port: ${config.port}`);
117
+ console.log(` Servers: ${config.servers.length}`);
118
+ console.log(` Auth: ${config.auth?.strategy ?? 'none'}`);
119
+ }
120
+ catch (err) {
121
+ logger.error(`Invalid configuration: ${err instanceof Error ? err.message : String(err)}`);
122
+ process.exit(1);
123
+ }
124
+ });
125
+ program.parse(process.argv);
126
+ if (!process.argv.slice(2).length) {
127
+ program.outputHelp();
128
+ }
129
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAE/D,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,aAAa,CAAC;KACnB,WAAW,CAAC,yDAAyD,CAAC;KACtE,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,iFAAiF;AAEjF,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,8BAA8B,CAAC;KAC3C,MAAM,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;KACpD,MAAM,CAAC,qBAAqB,EAAE,2BAA2B,CAAC;KAC1D,MAAM,CAAC,qBAAqB,EAAE,mCAAmC,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C;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Configuration loader
3
+ * Supports YAML, JSON, and environment variable overrides
4
+ */
5
+ import type { GatewayConfig } from '../utils/types.js';
6
+ /**
7
+ * Resolve the config file that `loadConfig` would read: the explicit path if
8
+ * given, otherwise the first match in the default search paths.
9
+ */
10
+ export declare function resolveConfigPath(configPath?: string): string | undefined;
11
+ export declare function loadConfig(configPath?: string): Promise<GatewayConfig>;
12
+ export declare function generateDefaultConfig(): string;
13
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAgIvD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMzE;AAED,wBAAsB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAsB5E;AAkCD,wBAAgB,qBAAqB,IAAI,MAAM,CA8E9C"}
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Configuration loader
3
+ * Supports YAML, JSON, and environment variable overrides
4
+ */
5
+ import { readFile } from 'fs/promises';
6
+ import { existsSync } from 'fs';
7
+ import { resolve } from 'path';
8
+ import { parse as parseYaml } from 'yaml';
9
+ import { z } from 'zod';
10
+ // ─── Zod Schema ───────────────────────────────────────────────────────────────
11
+ const ReconnectSchema = z.object({
12
+ enabled: z.boolean().optional(),
13
+ initialDelayMs: z.number().int().positive().optional(),
14
+ maxDelayMs: z.number().int().positive().optional(),
15
+ multiplier: z.number().min(1).optional(),
16
+ jitter: z.number().min(0).max(1).optional(),
17
+ maxAttempts: z.number().int().min(0).optional(),
18
+ });
19
+ const URL_PROTOCOLS = {
20
+ sse: ['http:', 'https:'],
21
+ 'streamable-http': ['http:', 'https:'],
22
+ websocket: ['ws:', 'wss:'],
23
+ };
24
+ function safeProtocol(url) {
25
+ try {
26
+ return new URL(url).protocol;
27
+ }
28
+ catch {
29
+ return '';
30
+ }
31
+ }
32
+ const McpServerSchema = z.object({
33
+ id: z.string().min(1),
34
+ name: z.string().min(1),
35
+ description: z.string().optional(),
36
+ transport: z.enum(['stdio', 'sse', 'websocket', 'streamable-http']),
37
+ command: z.string().optional(),
38
+ args: z.array(z.string()).optional(),
39
+ url: z.string().url().optional(),
40
+ env: z.record(z.string()).optional(),
41
+ headers: z.record(z.string()).optional(),
42
+ subprotocol: z.string().optional(),
43
+ reconnect: ReconnectSchema.optional(),
44
+ tags: z.array(z.string()).optional(),
45
+ enabled: z.boolean().default(true),
46
+ timeout: z.number().positive().default(30000),
47
+ maxConcurrency: z.number().int().positive().default(10),
48
+ }).superRefine((s, ctx) => {
49
+ if (s.transport === 'stdio' && !s.command) {
50
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['command'], message: 'required for stdio transport' });
51
+ }
52
+ const protocols = URL_PROTOCOLS[s.transport];
53
+ if (protocols) {
54
+ if (!s.url) {
55
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['url'], message: `required for ${s.transport} transport` });
56
+ }
57
+ else if (!protocols.includes(safeProtocol(s.url))) {
58
+ ctx.addIssue({
59
+ code: z.ZodIssueCode.custom,
60
+ path: ['url'],
61
+ message: `${s.transport} transport needs a ${protocols.map((p) => p.replace(':', '://')).join(' or ')} URL`,
62
+ });
63
+ }
64
+ }
65
+ });
66
+ const GatewayConfigSchema = z.object({
67
+ port: z.number().int().min(1).max(65535).default(4000),
68
+ host: z.string().default('0.0.0.0'),
69
+ auth: z
70
+ .object({
71
+ strategy: z.enum(['none', 'api-key', 'jwt', 'oauth2']).default('none'),
72
+ apiKeys: z.array(z.string()).optional(),
73
+ jwtSecret: z.string().optional(),
74
+ protect: z
75
+ .object({
76
+ health: z.boolean().default(false),
77
+ metrics: z.boolean().default(false),
78
+ })
79
+ .optional(),
80
+ })
81
+ .superRefine((a, ctx) => {
82
+ if (a.strategy === 'api-key' && !(a.apiKeys ?? []).some((k) => k.length > 0)) {
83
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['apiKeys'], message: 'at least one key is required for api-key strategy' });
84
+ }
85
+ if (a.strategy === 'jwt' && !a.jwtSecret) {
86
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['jwtSecret'], message: 'required for jwt strategy' });
87
+ }
88
+ if (a.strategy === 'oauth2') {
89
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['strategy'], message: 'oauth2 is not implemented yet (refusing to start without auth)' });
90
+ }
91
+ })
92
+ .optional(),
93
+ rateLimit: z
94
+ .object({
95
+ limit: z.number().int().positive().default(100),
96
+ windowSeconds: z.number().positive().default(60),
97
+ perKey: z.boolean().default(true),
98
+ })
99
+ .optional(),
100
+ monitor: z
101
+ .object({
102
+ prometheus: z.boolean().default(false),
103
+ requestLog: z.boolean().default(true),
104
+ retentionHours: z.number().positive().default(24),
105
+ })
106
+ .optional(),
107
+ servers: z.array(McpServerSchema).default([]),
108
+ corsOrigins: z.array(z.string()).optional(),
109
+ logLevel: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
110
+ reconnect: ReconnectSchema.optional(),
111
+ healthCheckIntervalMs: z.number().int().min(1000).default(30_000),
112
+ dashboard: z.object({ enabled: z.boolean().default(true) }).optional(),
113
+ }).superRefine((c, ctx) => {
114
+ const seen = new Set();
115
+ c.servers.forEach((s, i) => {
116
+ if (seen.has(s.id)) {
117
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['servers', i, 'id'], message: `duplicate server id "${s.id}"` });
118
+ }
119
+ seen.add(s.id);
120
+ });
121
+ });
122
+ // ─── Loader ───────────────────────────────────────────────────────────────────
123
+ const CONFIG_SEARCH_PATHS = [
124
+ 'mcp-gateway.yml',
125
+ 'mcp-gateway.yaml',
126
+ 'mcp-gateway.json',
127
+ '.mcp-gateway.yml',
128
+ '.mcp-gateway.yaml',
129
+ ];
130
+ /**
131
+ * Resolve the config file that `loadConfig` would read: the explicit path if
132
+ * given, otherwise the first match in the default search paths.
133
+ */
134
+ export function resolveConfigPath(configPath) {
135
+ if (configPath)
136
+ return resolve(configPath);
137
+ for (const searchPath of CONFIG_SEARCH_PATHS) {
138
+ if (existsSync(searchPath))
139
+ return resolve(searchPath);
140
+ }
141
+ return undefined;
142
+ }
143
+ export async function loadConfig(configPath) {
144
+ const filePath = resolveConfigPath(configPath);
145
+ let raw = filePath ? await readConfigFile(filePath) : {};
146
+ // An empty YAML file parses to null
147
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
148
+ if (raw !== null && raw !== undefined) {
149
+ throw new Error(`Invalid configuration: ${filePath} must contain a mapping/object at the top level`);
150
+ }
151
+ raw = {};
152
+ }
153
+ // Apply environment variable overrides
154
+ raw = applyEnvOverrides(raw);
155
+ const result = GatewayConfigSchema.safeParse(raw);
156
+ if (!result.success) {
157
+ throw new Error(`Invalid configuration:\n${result.error.issues.map((i) => ` - ${i.path.join('.')}: ${i.message}`).join('\n')}`);
158
+ }
159
+ return result.data;
160
+ }
161
+ async function readConfigFile(filePath) {
162
+ const content = await readFile(filePath, 'utf-8');
163
+ if (filePath.endsWith('.json')) {
164
+ return JSON.parse(content);
165
+ }
166
+ return parseYaml(content);
167
+ }
168
+ function applyEnvOverrides(config) {
169
+ const overrides = { ...config };
170
+ if (process.env.MCP_GATEWAY_PORT) {
171
+ overrides.port = parseInt(process.env.MCP_GATEWAY_PORT, 10);
172
+ }
173
+ if (process.env.MCP_GATEWAY_HOST) {
174
+ overrides.host = process.env.MCP_GATEWAY_HOST;
175
+ }
176
+ if (process.env.MCP_GATEWAY_LOG_LEVEL) {
177
+ overrides.logLevel = process.env.MCP_GATEWAY_LOG_LEVEL;
178
+ }
179
+ if (process.env.MCP_GATEWAY_API_KEYS) {
180
+ // Keeps other auth settings (e.g. auth.protect) from the file.
181
+ overrides.auth = {
182
+ ...(overrides.auth ?? {}),
183
+ strategy: 'api-key',
184
+ apiKeys: process.env.MCP_GATEWAY_API_KEYS.split(',').map((k) => k.trim()).filter(Boolean),
185
+ };
186
+ }
187
+ return overrides;
188
+ }
189
+ export function generateDefaultConfig() {
190
+ return `# mcp-gateway configuration
191
+ # Documentation: https://github.com/HarrisonCN/mcp-gateway/docs
192
+
193
+ port: 4000
194
+ host: 0.0.0.0
195
+ logLevel: info
196
+
197
+ # Authentication (optional; keys can be changed without a restart)
198
+ # auth:
199
+ # strategy: api-key
200
+ # apiKeys:
201
+ # - your-secret-key-here
202
+ # protect:
203
+ # health: false # true = /api/v1/health requires a key (/health/live stays public)
204
+ # metrics: false # true = /api/v1/metrics requires a key (configure your scraper)
205
+
206
+ # Automatic reconnect of crashed / disconnected servers (defaults shown)
207
+ # reconnect:
208
+ # enabled: true
209
+ # initialDelayMs: 1000
210
+ # maxDelayMs: 60000
211
+ # multiplier: 2
212
+ # jitter: 0.2
213
+ # maxAttempts: 0 # 0 = retry forever
214
+
215
+ # Rate limiting (optional)
216
+ # rateLimit:
217
+ # limit: 100
218
+ # windowSeconds: 60
219
+ # perKey: true
220
+
221
+ # Monitoring
222
+ monitor:
223
+ requestLog: true
224
+ prometheus: false
225
+ retentionHours: 24
226
+
227
+ # MCP Servers to manage
228
+ servers:
229
+ - id: filesystem
230
+ name: Filesystem Server
231
+ description: Access local files and directories
232
+ transport: stdio
233
+ command: npx
234
+ args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
235
+ tags: [files, local]
236
+ enabled: true
237
+
238
+ - id: github
239
+ name: GitHub Server
240
+ description: Interact with GitHub repositories
241
+ transport: stdio
242
+ command: npx
243
+ args: ["-y", "@modelcontextprotocol/server-github"]
244
+ env:
245
+ GITHUB_PERSONAL_ACCESS_TOKEN: \${GITHUB_TOKEN}
246
+ tags: [github, vcs]
247
+ enabled: true
248
+
249
+ # Remote servers
250
+ # - id: remote-http
251
+ # name: Remote (Streamable HTTP)
252
+ # transport: streamable-http
253
+ # url: https://mcp.example.com/mcp
254
+ # headers:
255
+ # Authorization: "Bearer \${REMOTE_MCP_TOKEN}"
256
+ #
257
+ # - id: legacy-sse
258
+ # name: Legacy SSE server
259
+ # transport: sse
260
+ # url: http://localhost:8080/sse
261
+ #
262
+ # - id: websocket
263
+ # name: WebSocket server
264
+ # transport: websocket
265
+ # url: ws://localhost:8081
266
+ `;
267
+ }
268
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,iFAAiF;AAEjF,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC/B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACtD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAClD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG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G,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACjC,SAAS,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAChD,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;QACtC,SAAS,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;IACzD,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;QACrC,+DAA+D;QAC/D,SAAS,CAAC,IAAI,GAAG;YACf,GAAG,CAAC,SAAS,CAAC,IAA+B,IAAI,EAAE,CAAC;YACpD,QAAQ,EAAE,SAAS;YACnB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;SAC1F,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4ER,CAAC;AACF,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Config File Watcher — Hot Reload Support
3
+ *
4
+ * Watches the active config file for changes and emits a 'reload' event
5
+ * so the gateway can apply new server registrations without restarting.
6
+ *
7
+ * Many editors save atomically (write temp file + rename), which surfaces as a
8
+ * 'rename' event and silently detaches an fs.watch handle from the path. The
9
+ * watcher therefore treats 'rename' as a change and re-attaches itself.
10
+ *
11
+ * @module config/watcher
12
+ */
13
+ import { EventEmitter } from 'events';
14
+ import type { Logger } from '../utils/logger.js';
15
+ export declare class ConfigWatcher extends EventEmitter {
16
+ private configPath;
17
+ private logger;
18
+ private watcher;
19
+ private debounceTimer;
20
+ private debounceMs;
21
+ private stopped;
22
+ constructor(configPath: string, logger: Logger, debounceMs?: number);
23
+ start(): void;
24
+ private _attach;
25
+ private _schedule;
26
+ private _reload;
27
+ stop(): void;
28
+ }
29
+ //# sourceMappingURL=watcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../../src/config/watcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAIjD,qBAAa,aAAc,SAAQ,YAAY;IAC7C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAQ;gBAEX,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,SAAM;IAOhE,KAAK,IAAI,IAAI;IAOb,OAAO,CAAC,OAAO;IAoBf,OAAO,CAAC,SAAS;YAUH,OAAO;IAerB,IAAI,IAAI,IAAI;CAQb"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Config File Watcher — Hot Reload Support
3
+ *
4
+ * Watches the active config file for changes and emits a 'reload' event
5
+ * so the gateway can apply new server registrations without restarting.
6
+ *
7
+ * Many editors save atomically (write temp file + rename), which surfaces as a
8
+ * 'rename' event and silently detaches an fs.watch handle from the path. The
9
+ * watcher therefore treats 'rename' as a change and re-attaches itself.
10
+ *
11
+ * @module config/watcher
12
+ */
13
+ import fs from 'fs';
14
+ import path from 'path';
15
+ import { EventEmitter } from 'events';
16
+ import { loadConfig } from './loader.js';
17
+ export class ConfigWatcher extends EventEmitter {
18
+ configPath;
19
+ logger;
20
+ watcher = null;
21
+ debounceTimer = null;
22
+ debounceMs;
23
+ stopped = true;
24
+ constructor(configPath, logger, debounceMs = 500) {
25
+ super();
26
+ this.configPath = path.resolve(configPath);
27
+ this.logger = logger;
28
+ this.debounceMs = debounceMs;
29
+ }
30
+ start() {
31
+ if (this.watcher)
32
+ return;
33
+ this.stopped = false;
34
+ this._attach();
35
+ this.logger.info(`Config hot-reload enabled — watching ${this.configPath}`);
36
+ }
37
+ _attach() {
38
+ try {
39
+ this.watcher = fs.watch(this.configPath, (eventType) => {
40
+ if (eventType === 'rename') {
41
+ // File was replaced; the old handle is now stale.
42
+ this.watcher?.close();
43
+ this.watcher = null;
44
+ }
45
+ this._schedule();
46
+ });
47
+ this.watcher.on('error', (err) => {
48
+ this.logger.warn(`Config watcher error: ${err.message}`);
49
+ });
50
+ }
51
+ catch (err) {
52
+ const msg = err instanceof Error ? err.message : String(err);
53
+ this.logger.warn(`Cannot watch ${this.configPath}: ${msg}`);
54
+ this.watcher = null;
55
+ }
56
+ }
57
+ _schedule() {
58
+ if (this.debounceTimer)
59
+ clearTimeout(this.debounceTimer);
60
+ this.debounceTimer = setTimeout(() => {
61
+ this.debounceTimer = null;
62
+ if (this.stopped)
63
+ return;
64
+ if (!this.watcher)
65
+ this._attach();
66
+ void this._reload();
67
+ }, this.debounceMs);
68
+ }
69
+ async _reload() {
70
+ try {
71
+ const newConfig = await loadConfig(this.configPath);
72
+ if (this.stopped)
73
+ return;
74
+ this.logger.info('Config file changed — applying hot reload');
75
+ this.emit('reload', newConfig);
76
+ }
77
+ catch (err) {
78
+ const msg = err instanceof Error ? err.message : String(err);
79
+ this.logger.error(`Config reload failed (keeping current config): ${msg}`);
80
+ // Only emit when someone listens: an 'error'-like event without a
81
+ // listener is fine for custom names, but keep it explicit.
82
+ if (this.listenerCount('reload-error') > 0)
83
+ this.emit('reload-error', err);
84
+ }
85
+ }
86
+ stop() {
87
+ this.stopped = true;
88
+ if (this.debounceTimer)
89
+ clearTimeout(this.debounceTimer);
90
+ this.debounceTimer = null;
91
+ this.watcher?.close();
92
+ this.watcher = null;
93
+ this.logger.debug('Config watcher stopped');
94
+ }
95
+ }
96
+ //# sourceMappingURL=watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher.js","sourceRoot":"","sources":["../../src/config/watcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,OAAO,aAAc,SAAQ,YAAY;IACrC,UAAU,CAAS;IACnB,MAAM,CAAS;IACf,OAAO,GAAwB,IAAI,CAAC;IACpC,aAAa,GAA0B,IAAI,CAAC;IAC5C,UAAU,CAAS;IACnB,OAAO,GAAG,IAAI,CAAC;IAEvB,YAAY,UAAkB,EAAE,MAAc,EAAE,UAAU,GAAG,GAAG;QAC9D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,wCAAwC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC9E,CAAC;IAEO,OAAO;QACb,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,SAA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AkB,MAAM,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACnE,IAAI,IAAI,CAAC,OAAO;gBAAE,OAAO;YACzB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;YAC9D,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kDAAkD,GAAG,EAAE,CAAC,CAAC;YAC3E,kEAAkE;YAClE,2DAA2D;YAC3D,IAAI,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,GAAG,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IAED,IAAI;QACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,IAAI,CAAC,aAAa;YAAE,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Gateway HTTP API
3
+ * Exposes REST endpoints for tool invocation, server management, and monitoring
4
+ */
5
+ import express from 'express';
6
+ import type { GatewayConfig, McpServerConfig } from '../utils/types.js';
7
+ import type { ServerRegistry } from '../registry/index.js';
8
+ import { type McpProxy } from '../proxy/index.js';
9
+ import type { MetricsCollector, ServerStateSample } from '../monitor/index.js';
10
+ import type { ServerSupervisor } from './supervisor.js';
11
+ export type ApiRouter = express.Router & {
12
+ close(): void;
13
+ /**
14
+ * Apply hot-reloadable settings from a new config: auth (strategy, keys,
15
+ * secret, protect flags), rate limits and monitor flags. Invalid auth keeps
16
+ * the current middleware (fail safe).
17
+ */
18
+ update(next: GatewayConfig): void;
19
+ };
20
+ export interface ApiRouterOptions {
21
+ /** Enables POST /servers/:id/reconnect and reconnect info. */
22
+ supervisor?: ServerSupervisor;
23
+ }
24
+ /** Never expose env values (tokens are commonly configured there). */
25
+ export declare function redactServer(server: McpServerConfig): McpServerConfig;
26
+ /** Per-server state for /metrics and Prometheus. */
27
+ export declare function serverStateSamples(registry: ServerRegistry, proxy: McpProxy): ServerStateSample[];
28
+ export declare function createApiRouter(config: GatewayConfig, registry: ServerRegistry, proxy: McpProxy, metrics: MetricsCollector, options?: ApiRouterOptions): ApiRouter;
29
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/gateway/api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAMxD,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG;IACvC,KAAK,IAAI,IAAI,CAAC;IACd;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAUD,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAOrE;AAiBD,oDAAoD;AACpD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,GAAG,iBAAiB,EAAE,CAYjG;AAiBD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,gBAAgB,EACzB,OAAO,GAAE,gBAAqB,GAC7B,SAAS,CAwPX"}