@karashiiro/my-cool-proxy 1.0.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.
- package/LICENSE +21 -0
- package/README.md +325 -0
- package/bin/my-cool-proxy.js +2 -0
- package/dist/container/binding-map.d.ts +25 -0
- package/dist/container/binding-map.d.ts.map +1 -0
- package/dist/container/binding-map.js +2 -0
- package/dist/container/binding-map.js.map +1 -0
- package/dist/container/decorators.d.ts +5 -0
- package/dist/container/decorators.d.ts.map +1 -0
- package/dist/container/decorators.js +4 -0
- package/dist/container/decorators.js.map +1 -0
- package/dist/container/inversify.config.d.ts +6 -0
- package/dist/container/inversify.config.d.ts.map +1 -0
- package/dist/container/inversify.config.js +85 -0
- package/dist/container/inversify.config.js.map +1 -0
- package/dist/controllers/mcp-session-controller.d.ts +21 -0
- package/dist/controllers/mcp-session-controller.d.ts.map +1 -0
- package/dist/controllers/mcp-session-controller.js +100 -0
- package/dist/controllers/mcp-session-controller.js.map +1 -0
- package/dist/e2e/fixtures/toy-servers/calculator-server.d.ts +5 -0
- package/dist/e2e/fixtures/toy-servers/calculator-server.d.ts.map +1 -0
- package/dist/e2e/fixtures/toy-servers/calculator-server.js +164 -0
- package/dist/e2e/fixtures/toy-servers/calculator-server.js.map +1 -0
- package/dist/e2e/fixtures/toy-servers/data-server.d.ts +5 -0
- package/dist/e2e/fixtures/toy-servers/data-server.d.ts.map +1 -0
- package/dist/e2e/fixtures/toy-servers/data-server.js +198 -0
- package/dist/e2e/fixtures/toy-servers/data-server.js.map +1 -0
- package/dist/e2e/fixtures/toy-servers/elicitation-server.d.ts +5 -0
- package/dist/e2e/fixtures/toy-servers/elicitation-server.d.ts.map +1 -0
- package/dist/e2e/fixtures/toy-servers/elicitation-server.js +199 -0
- package/dist/e2e/fixtures/toy-servers/elicitation-server.js.map +1 -0
- package/dist/e2e/fixtures/toy-servers/index.d.ts +5 -0
- package/dist/e2e/fixtures/toy-servers/index.d.ts.map +1 -0
- package/dist/e2e/fixtures/toy-servers/index.js +5 -0
- package/dist/e2e/fixtures/toy-servers/index.js.map +1 -0
- package/dist/e2e/fixtures/toy-servers/sampling-server.d.ts +5 -0
- package/dist/e2e/fixtures/toy-servers/sampling-server.d.ts.map +1 -0
- package/dist/e2e/fixtures/toy-servers/sampling-server.js +170 -0
- package/dist/e2e/fixtures/toy-servers/sampling-server.js.map +1 -0
- package/dist/e2e/helpers/client-helpers.d.ts +18 -0
- package/dist/e2e/helpers/client-helpers.d.ts.map +1 -0
- package/dist/e2e/helpers/client-helpers.js +119 -0
- package/dist/e2e/helpers/client-helpers.js.map +1 -0
- package/dist/e2e/helpers/http-server-manager.d.ts +10 -0
- package/dist/e2e/helpers/http-server-manager.d.ts.map +1 -0
- package/dist/e2e/helpers/http-server-manager.js +146 -0
- package/dist/e2e/helpers/http-server-manager.js.map +1 -0
- package/dist/e2e/helpers/port-manager.d.ts +2 -0
- package/dist/e2e/helpers/port-manager.d.ts.map +1 -0
- package/dist/e2e/helpers/port-manager.js +27 -0
- package/dist/e2e/helpers/port-manager.js.map +1 -0
- package/dist/e2e/helpers/test-assertions.d.ts +18 -0
- package/dist/e2e/helpers/test-assertions.d.ts.map +1 -0
- package/dist/e2e/helpers/test-assertions.js +71 -0
- package/dist/e2e/helpers/test-assertions.js.map +1 -0
- package/dist/e2e/helpers/test-config-generator.d.ts +14 -0
- package/dist/e2e/helpers/test-config-generator.d.ts.map +1 -0
- package/dist/e2e/helpers/test-config-generator.js +39 -0
- package/dist/e2e/helpers/test-config-generator.js.map +1 -0
- package/dist/e2e/helpers/toy-server-manager.d.ts +10 -0
- package/dist/e2e/helpers/toy-server-manager.d.ts.map +1 -0
- package/dist/e2e/helpers/toy-server-manager.js +58 -0
- package/dist/e2e/helpers/toy-server-manager.js.map +1 -0
- package/dist/handlers/shutdown-handler.d.ts +8 -0
- package/dist/handlers/shutdown-handler.d.ts.map +1 -0
- package/dist/handlers/shutdown-handler.js +37 -0
- package/dist/handlers/shutdown-handler.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +235 -0
- package/dist/index.js.map +1 -0
- package/dist/lua/runtime-infinite-loop-worker.d.ts +2 -0
- package/dist/lua/runtime-infinite-loop-worker.d.ts.map +1 -0
- package/dist/lua/runtime-infinite-loop-worker.js +33 -0
- package/dist/lua/runtime-infinite-loop-worker.js.map +1 -0
- package/dist/lua/runtime.d.ts +11 -0
- package/dist/lua/runtime.d.ts.map +1 -0
- package/dist/lua/runtime.js +131 -0
- package/dist/lua/runtime.js.map +1 -0
- package/dist/mcp/client-manager.d.ts +23 -0
- package/dist/mcp/client-manager.d.ts.map +1 -0
- package/dist/mcp/client-manager.js +201 -0
- package/dist/mcp/client-manager.js.map +1 -0
- package/dist/mcp/client-session.d.ts +235 -0
- package/dist/mcp/client-session.d.ts.map +1 -0
- package/dist/mcp/client-session.js +148 -0
- package/dist/mcp/client-session.js.map +1 -0
- package/dist/mcp/gateway-server.d.ts +26 -0
- package/dist/mcp/gateway-server.d.ts.map +1 -0
- package/dist/mcp/gateway-server.js +141 -0
- package/dist/mcp/gateway-server.js.map +1 -0
- package/dist/mcp/mcp-formatter-service.d.ts +15 -0
- package/dist/mcp/mcp-formatter-service.d.ts.map +1 -0
- package/dist/mcp/mcp-formatter-service.js +151 -0
- package/dist/mcp/mcp-formatter-service.js.map +1 -0
- package/dist/mcp/prompt-aggregation-service.d.ts +13 -0
- package/dist/mcp/prompt-aggregation-service.d.ts.map +1 -0
- package/dist/mcp/prompt-aggregation-service.js +104 -0
- package/dist/mcp/prompt-aggregation-service.js.map +1 -0
- package/dist/mcp/resource-aggregation-service.d.ts +13 -0
- package/dist/mcp/resource-aggregation-service.d.ts.map +1 -0
- package/dist/mcp/resource-aggregation-service.js +107 -0
- package/dist/mcp/resource-aggregation-service.js.map +1 -0
- package/dist/mcp/tool-discovery-service.d.ts +20 -0
- package/dist/mcp/tool-discovery-service.d.ts.map +1 -0
- package/dist/mcp/tool-discovery-service.js +274 -0
- package/dist/mcp/tool-discovery-service.js.map +1 -0
- package/dist/mcp/transport-manager.d.ts +15 -0
- package/dist/mcp/transport-manager.d.ts.map +1 -0
- package/dist/mcp/transport-manager.js +105 -0
- package/dist/mcp/transport-manager.js.map +1 -0
- package/dist/services/cache-service.d.ts +15 -0
- package/dist/services/cache-service.d.ts.map +1 -0
- package/dist/services/cache-service.js +73 -0
- package/dist/services/cache-service.js.map +1 -0
- package/dist/services/capability-store.d.ts +12 -0
- package/dist/services/capability-store.d.ts.map +1 -0
- package/dist/services/capability-store.js +52 -0
- package/dist/services/capability-store.js.map +1 -0
- package/dist/services/server-info-preloader.d.ts +9 -0
- package/dist/services/server-info-preloader.d.ts.map +1 -0
- package/dist/services/server-info-preloader.js +125 -0
- package/dist/services/server-info-preloader.js.map +1 -0
- package/dist/tools/base-tool.d.ts +11 -0
- package/dist/tools/base-tool.d.ts.map +1 -0
- package/dist/tools/base-tool.js +2 -0
- package/dist/tools/base-tool.js.map +1 -0
- package/dist/tools/execute-lua-tool.d.ts +17 -0
- package/dist/tools/execute-lua-tool.d.ts.map +1 -0
- package/dist/tools/execute-lua-tool.js +111 -0
- package/dist/tools/execute-lua-tool.js.map +1 -0
- package/dist/tools/inspect-tool-response-tool.d.ts +17 -0
- package/dist/tools/inspect-tool-response-tool.d.ts.map +1 -0
- package/dist/tools/inspect-tool-response-tool.js +58 -0
- package/dist/tools/inspect-tool-response-tool.js.map +1 -0
- package/dist/tools/list-server-tools-tool.d.ts +15 -0
- package/dist/tools/list-server-tools-tool.d.ts.map +1 -0
- package/dist/tools/list-server-tools-tool.js +44 -0
- package/dist/tools/list-server-tools-tool.js.map +1 -0
- package/dist/tools/list-servers-tool.d.ts +12 -0
- package/dist/tools/list-servers-tool.d.ts.map +1 -0
- package/dist/tools/list-servers-tool.js +39 -0
- package/dist/tools/list-servers-tool.js.map +1 -0
- package/dist/tools/summary-stats-tool.d.ts +17 -0
- package/dist/tools/summary-stats-tool.d.ts.map +1 -0
- package/dist/tools/summary-stats-tool.js +91 -0
- package/dist/tools/summary-stats-tool.js.map +1 -0
- package/dist/tools/tool-details-tool.d.ts +16 -0
- package/dist/tools/tool-details-tool.d.ts.map +1 -0
- package/dist/tools/tool-details-tool.js +45 -0
- package/dist/tools/tool-details-tool.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +13 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +24 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +20 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/interfaces.d.ts +118 -0
- package/dist/types/interfaces.d.ts.map +1 -0
- package/dist/types/interfaces.js +2 -0
- package/dist/types/interfaces.js.map +1 -0
- package/dist/utils/cli-args.d.ts +6 -0
- package/dist/utils/cli-args.d.ts.map +1 -0
- package/dist/utils/cli-args.js +7 -0
- package/dist/utils/cli-args.js.map +1 -0
- package/dist/utils/config-loader.d.ts +4 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +82 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/config-paths.d.ts +10 -0
- package/dist/utils/config-paths.d.ts.map +1 -0
- package/dist/utils/config-paths.js +34 -0
- package/dist/utils/config-paths.js.map +1 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +46 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/logger.test-helper.d.ts +2 -0
- package/dist/utils/logger.test-helper.d.ts.map +1 -0
- package/dist/utils/logger.test-helper.js +9 -0
- package/dist/utils/logger.test-helper.js.map +1 -0
- package/dist/utils/lua-identifier.d.ts +2 -0
- package/dist/utils/lua-identifier.d.ts.map +1 -0
- package/dist/utils/lua-identifier.js +37 -0
- package/dist/utils/lua-identifier.js.map +1 -0
- package/dist/utils/prompt-name.d.ts +8 -0
- package/dist/utils/prompt-name.d.ts.map +1 -0
- package/dist/utils/prompt-name.js +25 -0
- package/dist/utils/prompt-name.js.map +1 -0
- package/dist/utils/resource-uri.d.ts +10 -0
- package/dist/utils/resource-uri.d.ts.map +1 -0
- package/dist/utils/resource-uri.js +101 -0
- package/dist/utils/resource-uri.js.map +1 -0
- package/dist/utils/response-size-validator.d.ts +3 -0
- package/dist/utils/response-size-validator.d.ts.map +1 -0
- package/dist/utils/response-size-validator.js +39 -0
- package/dist/utils/response-size-validator.js.map +1 -0
- package/dist/utils/schema-formatter.d.ts +3 -0
- package/dist/utils/schema-formatter.d.ts.map +1 -0
- package/dist/utils/schema-formatter.js +40 -0
- package/dist/utils/schema-formatter.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kara
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# my-cool-proxy
|
|
2
|
+
|
|
3
|
+
MCP gateway server that lets you call multiple MCP servers from Lua scripts.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This proxy acts as a gateway between AI agents and multiple MCP (Model Context Protocol) servers. Instead of connecting to each MCP server individually, agents connect to this single proxy and gain access to all configured servers through a unified interface.
|
|
8
|
+
|
|
9
|
+
**Progressive Tool Discovery:** Agents start with zero knowledge about what servers or tools are available. They build context progressively:
|
|
10
|
+
|
|
11
|
+
1. Call `list-servers` - The agent's context now includes names and descriptions of all available MCP servers (e.g., "github", "slack", "database")
|
|
12
|
+
2. Call `list-server-tools(server_name)` - The agent's context expands to include all tool names and descriptions for that specific server
|
|
13
|
+
3. Call `tool-details(server_name, tool_name)` - The agent's context now has complete parameter schemas, return types (if available), and usage examples for a specific tool
|
|
14
|
+
4. Call `execute(lua_script)` - With full context, the agent can write Lua scripts that call the discovered tools
|
|
15
|
+
|
|
16
|
+
Rather than loading all tools and tool descriptions into the context upfront, this defers loading tools until the agent determines those tools are needed.
|
|
17
|
+
|
|
18
|
+
**Tool Chaining with Lua:** Once an agent knows what tools exist, they can compose complex multi-step workflows in a single `execute()` call. The Lua runtime provides access to all discovered servers as globals, with tools callable as async functions.
|
|
19
|
+
|
|
20
|
+
**Sequential tool chaining:**
|
|
21
|
+
|
|
22
|
+
```lua
|
|
23
|
+
local raw_data = api_server.fetch({ id = 123 }):await()
|
|
24
|
+
local processed = processor.transform({ input = raw_data }):await()
|
|
25
|
+
result(processed)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Conditional logic:**
|
|
29
|
+
|
|
30
|
+
```lua
|
|
31
|
+
local status = checker.validate({}):await()
|
|
32
|
+
if status.ok then
|
|
33
|
+
result(processor.run({}):await())
|
|
34
|
+
else
|
|
35
|
+
result(error_handler.notify({ error = status.message }):await())
|
|
36
|
+
end
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Iteration with loops:**
|
|
40
|
+
|
|
41
|
+
```lua
|
|
42
|
+
local results = {}
|
|
43
|
+
for i = 1, 5 do
|
|
44
|
+
results[i] = worker.process({ index = i }):await()
|
|
45
|
+
end
|
|
46
|
+
result({ total = #results, data = results })
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
### 1. Install
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pnpm install
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. Configure
|
|
58
|
+
|
|
59
|
+
Create the config directory and copy the example config:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Linux
|
|
63
|
+
mkdir -p ~/.config/my-cool-proxy
|
|
64
|
+
cp config.example.json ~/.config/my-cool-proxy/config.json
|
|
65
|
+
|
|
66
|
+
# macOS
|
|
67
|
+
mkdir -p ~/Library/Preferences/my-cool-proxy
|
|
68
|
+
cp config.example.json ~/Library/Preferences/my-cool-proxy/config.json
|
|
69
|
+
|
|
70
|
+
# Windows (PowerShell)
|
|
71
|
+
mkdir "$env:APPDATA\my-cool-proxy\Config"
|
|
72
|
+
Copy-Item config.example.json "$env:APPDATA\my-cool-proxy\Config\config.json"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Edit `config.json` to add your MCP servers (see [CONFIG.md](./CONFIG.md) for all options):
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"port": 3000,
|
|
80
|
+
"host": "localhost",
|
|
81
|
+
"mcpClients": {
|
|
82
|
+
"my-server": {
|
|
83
|
+
"type": "http",
|
|
84
|
+
"url": "https://example.com/mcp"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
> **Tip:** Run `node dist/index.js --config-path` to see exactly where your config should be located.
|
|
91
|
+
|
|
92
|
+
### 3. Run
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pnpm dev
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 4. Connect
|
|
99
|
+
|
|
100
|
+
Add to your MCP client config (e.g., Claude Desktop):
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"mcpServers": {
|
|
105
|
+
"my-cool-proxy": {
|
|
106
|
+
"url": "http://localhost:3000/mcp"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 5. Use It
|
|
113
|
+
|
|
114
|
+
The proxy exposes these tools:
|
|
115
|
+
|
|
116
|
+
- `execute` - Run Lua scripts that can call your configured MCP servers
|
|
117
|
+
- `list-servers` - See available servers
|
|
118
|
+
- `list-server-tools` - See tools for a server
|
|
119
|
+
- `tool-details` - Get full tool documentation
|
|
120
|
+
|
|
121
|
+
Example Lua script:
|
|
122
|
+
|
|
123
|
+
```lua
|
|
124
|
+
-- Call a tool and return the result directly
|
|
125
|
+
result(my_server.some_tool({ arg = "value" }):await())
|
|
126
|
+
|
|
127
|
+
-- Or store in a variable first if you need to process it
|
|
128
|
+
local data = my_server.some_tool({ arg = "value" }):await()
|
|
129
|
+
result({ processed = data.something })
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## MCP Client Transport Types
|
|
133
|
+
|
|
134
|
+
## Running the Gateway
|
|
135
|
+
|
|
136
|
+
The gateway supports two modes for how it exposes itself to MCP clients.
|
|
137
|
+
|
|
138
|
+
### HTTP Mode (Default)
|
|
139
|
+
|
|
140
|
+
Run the gateway as an HTTP server that clients connect to remotely:
|
|
141
|
+
|
|
142
|
+
**Configure** - Set `transport: "http"` in config.json (or omit for default):
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"port": 3000,
|
|
147
|
+
"host": "localhost",
|
|
148
|
+
"transport": "http",
|
|
149
|
+
"mcpClients": { ... }
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Run:**
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
pnpm dev
|
|
157
|
+
# or for production:
|
|
158
|
+
pnpm build && node dist/index.js
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Connect from MCP client:**
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"mcpServers": {
|
|
166
|
+
"my-cool-proxy": {
|
|
167
|
+
"url": "http://localhost:3000/mcp"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Stdio Mode
|
|
174
|
+
|
|
175
|
+
Run the gateway as a stdio-based MCP server that clients launch directly. This is ideal when:
|
|
176
|
+
|
|
177
|
+
- You want the MCP client (e.g., Claude Desktop) to manage the gateway lifecycle
|
|
178
|
+
- You're running everything locally and don't need a persistent server
|
|
179
|
+
- You prefer simpler deployment without managing an HTTP server
|
|
180
|
+
|
|
181
|
+
**Key differences from HTTP mode:**
|
|
182
|
+
|
|
183
|
+
- Single session only (no multi-client support)
|
|
184
|
+
- All upstream MCP clients initialize at startup (not lazily)
|
|
185
|
+
- Must build before running (`pnpm dev` won't work - stdout is used for MCP protocol)
|
|
186
|
+
|
|
187
|
+
#### 1. Configure
|
|
188
|
+
|
|
189
|
+
Create your config file with `transport: "stdio"`:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Linux
|
|
193
|
+
mkdir -p ~/.config/my-cool-proxy
|
|
194
|
+
# macOS
|
|
195
|
+
mkdir -p ~/Library/Preferences/my-cool-proxy
|
|
196
|
+
# Windows (PowerShell)
|
|
197
|
+
mkdir "$env:APPDATA\my-cool-proxy\Config"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Add your config (port and host are ignored in stdio mode):
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"transport": "stdio",
|
|
205
|
+
"mcpClients": {
|
|
206
|
+
"filesystem": {
|
|
207
|
+
"type": "stdio",
|
|
208
|
+
"command": "npx",
|
|
209
|
+
"args": ["-y", "@modelcontextprotocol/server-everything"]
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
> **Tip:** Run `node dist/index.js --config-path` to see exactly where your config should be located.
|
|
216
|
+
|
|
217
|
+
#### 2. Build
|
|
218
|
+
|
|
219
|
+
Stdio mode requires a compiled build:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pnpm install
|
|
223
|
+
pnpm build
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### 3. Connect from MCP Client
|
|
227
|
+
|
|
228
|
+
Add to your MCP client config (e.g., Claude Desktop's `claude_desktop_config.json`):
|
|
229
|
+
|
|
230
|
+
**macOS/Linux:**
|
|
231
|
+
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"mcpServers": {
|
|
235
|
+
"my-cool-proxy": {
|
|
236
|
+
"command": "node",
|
|
237
|
+
"args": ["/absolute/path/to/my-cool-proxy/dist/index.js"]
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
**Windows:**
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"mcpServers": {
|
|
248
|
+
"my-cool-proxy": {
|
|
249
|
+
"command": "node",
|
|
250
|
+
"args": ["C:\\Users\\yourname\\path\\to\\my-cool-proxy\\dist\\index.js"]
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
#### 4. Restart Your MCP Client
|
|
257
|
+
|
|
258
|
+
Restart Claude Desktop (or your MCP client) to pick up the new config. The gateway will start automatically when you begin a conversation.
|
|
259
|
+
|
|
260
|
+
#### Troubleshooting Stdio Mode
|
|
261
|
+
|
|
262
|
+
**Gateway not starting?**
|
|
263
|
+
|
|
264
|
+
- Check your MCP client's logs for error messages
|
|
265
|
+
- Verify the path to `dist/index.js` is correct and absolute
|
|
266
|
+
- Ensure you ran `pnpm build` after any code changes
|
|
267
|
+
|
|
268
|
+
**Config not found?**
|
|
269
|
+
|
|
270
|
+
- Run `node dist/index.js --config-path` from the project directory to see expected location
|
|
271
|
+
- Or set `CONFIG_PATH` environment variable to override:
|
|
272
|
+
|
|
273
|
+
```json
|
|
274
|
+
{
|
|
275
|
+
"mcpServers": {
|
|
276
|
+
"my-cool-proxy": {
|
|
277
|
+
"command": "node",
|
|
278
|
+
"args": ["path/to/my-cool-proxy/dist/index.js"],
|
|
279
|
+
"env": {
|
|
280
|
+
"CONFIG_PATH": "/path/to/your/config.json"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**Upstream servers failing to connect?**
|
|
288
|
+
|
|
289
|
+
- All configured MCP clients must connect successfully at startup in stdio mode
|
|
290
|
+
- Check that commands in your config are correct and dependencies are installed
|
|
291
|
+
- Try running the upstream servers individually first to verify they work
|
|
292
|
+
|
|
293
|
+
## MCP Client Transport Types
|
|
294
|
+
|
|
295
|
+
**HTTP** - Connect to remote MCP servers:
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"type": "http",
|
|
300
|
+
"url": "https://api.example.com/mcp",
|
|
301
|
+
"headers": {
|
|
302
|
+
"Authorization": "Bearer token"
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**Stdio** - Launch local MCP servers:
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
{
|
|
311
|
+
"type": "stdio",
|
|
312
|
+
"command": "npx",
|
|
313
|
+
"args": ["-y", "@modelcontextprotocol/server-everything"]
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Documentation
|
|
318
|
+
|
|
319
|
+
See [CONFIG.md](./CONFIG.md) for full configuration reference.
|
|
320
|
+
|
|
321
|
+
## Testing
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
pnpm test
|
|
325
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ILuaRuntime, IMCPClientManager, ILogger, ServerConfig, IShutdownHandler, ICapabilityStore, IServerInfoPreloader } from "../types/interfaces.js";
|
|
2
|
+
import type { MCPGatewayServer } from "../mcp/gateway-server.js";
|
|
3
|
+
import type { ToolDiscoveryService } from "../mcp/tool-discovery-service.js";
|
|
4
|
+
import type { ResourceAggregationService } from "../mcp/resource-aggregation-service.js";
|
|
5
|
+
import type { PromptAggregationService } from "../mcp/prompt-aggregation-service.js";
|
|
6
|
+
import type { MCPFormatterService } from "../mcp/mcp-formatter-service.js";
|
|
7
|
+
import type { ITool } from "../tools/base-tool.js";
|
|
8
|
+
import type { IToolRegistry } from "../tools/tool-registry.js";
|
|
9
|
+
export interface ContainerBindingMap {
|
|
10
|
+
ServerConfig: ServerConfig;
|
|
11
|
+
Logger: ILogger;
|
|
12
|
+
LuaRuntime: ILuaRuntime;
|
|
13
|
+
MCPClientManager: IMCPClientManager;
|
|
14
|
+
MCPFormatterService: MCPFormatterService;
|
|
15
|
+
ToolDiscoveryService: ToolDiscoveryService;
|
|
16
|
+
ResourceAggregationService: ResourceAggregationService;
|
|
17
|
+
PromptAggregationService: PromptAggregationService;
|
|
18
|
+
MCPGatewayServer: MCPGatewayServer;
|
|
19
|
+
ShutdownHandler: IShutdownHandler;
|
|
20
|
+
Tool: ITool;
|
|
21
|
+
ToolRegistry: IToolRegistry;
|
|
22
|
+
CapabilityStore: ICapabilityStore;
|
|
23
|
+
ServerInfoPreloader: IServerInfoPreloader;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=binding-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding-map.d.ts","sourceRoot":"","sources":["../../src/container/binding-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AACrF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,WAAW,CAAC;IACxB,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,0BAA0B,EAAE,0BAA0B,CAAC;IACvD,wBAAwB,EAAE,wBAAwB,CAAC;IACnD,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,eAAe,EAAE,gBAAgB,CAAC;IAClC,IAAI,EAAE,KAAK,CAAC;IACZ,YAAY,EAAE,aAAa,CAAC;IAC5B,eAAe,EAAE,gBAAgB,CAAC;IAClC,mBAAmB,EAAE,oBAAoB,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding-map.js","sourceRoot":"","sources":["../../src/container/binding-map.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TypedInject, TypedMultiInject } from "@inversifyjs/strongly-typed";
|
|
2
|
+
import type { ContainerBindingMap } from "./binding-map.js";
|
|
3
|
+
export declare const $inject: TypedInject<ContainerBindingMap>;
|
|
4
|
+
export declare const $multiInject: TypedMultiInject<ContainerBindingMap>;
|
|
5
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/container/decorators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAkB5D,eAAO,MAAM,OAAO,kCAA6C,CAAC;AAkBlE,eAAO,MAAM,YAAY,uCAC6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/container/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAuBhD,MAAM,CAAC,MAAM,OAAO,GAAG,MAA0C,CAAC;AAkBlE,MAAM,CAAC,MAAM,YAAY,GACvB,WAAoD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type { TypedContainer } from "@inversifyjs/strongly-typed";
|
|
3
|
+
import type { ContainerBindingMap } from "./binding-map.js";
|
|
4
|
+
import type { ServerConfig } from "../types/interfaces.js";
|
|
5
|
+
export declare function createContainer(config: ServerConfig): TypedContainer<ContainerBindingMap>;
|
|
6
|
+
//# sourceMappingURL=inversify.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inversify.config.d.ts","sourceRoot":"","sources":["../../src/container/inversify.config.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAIV,YAAY,EAIb,MAAM,wBAAwB,CAAC;AAsBhC,wBAAgB,eAAe,CAC7B,MAAM,EAAE,YAAY,GACnB,cAAc,CAAC,mBAAmB,CAAC,CAuFrC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Container } from "inversify";
|
|
3
|
+
import { TYPES } from "../types/index.js";
|
|
4
|
+
import { WasmoonRuntime } from "../lua/runtime.js";
|
|
5
|
+
import { MCPClientManager } from "../mcp/client-manager.js";
|
|
6
|
+
import { ConsoleLogger } from "../utils/logger.js";
|
|
7
|
+
import { MCPGatewayServer } from "../mcp/gateway-server.js";
|
|
8
|
+
import { ToolDiscoveryService } from "../mcp/tool-discovery-service.js";
|
|
9
|
+
import { ResourceAggregationService } from "../mcp/resource-aggregation-service.js";
|
|
10
|
+
import { PromptAggregationService } from "../mcp/prompt-aggregation-service.js";
|
|
11
|
+
import { MCPFormatterService } from "../mcp/mcp-formatter-service.js";
|
|
12
|
+
import { ShutdownHandler } from "../handlers/shutdown-handler.js";
|
|
13
|
+
import { CapabilityStore } from "../services/capability-store.js";
|
|
14
|
+
import { ServerInfoPreloader } from "../services/server-info-preloader.js";
|
|
15
|
+
import { ExecuteLuaTool } from "../tools/execute-lua-tool.js";
|
|
16
|
+
import { ListServersTool } from "../tools/list-servers-tool.js";
|
|
17
|
+
import { ListServerToolsTool } from "../tools/list-server-tools-tool.js";
|
|
18
|
+
import { ToolDetailsTool } from "../tools/tool-details-tool.js";
|
|
19
|
+
import { InspectToolResponseTool } from "../tools/inspect-tool-response-tool.js";
|
|
20
|
+
import { SummaryStatsTool } from "../tools/summary-stats-tool.js";
|
|
21
|
+
import { ToolRegistry } from "../tools/tool-registry.js";
|
|
22
|
+
export function createContainer(config) {
|
|
23
|
+
const container = new Container();
|
|
24
|
+
container.bind(TYPES.ServerConfig).toConstantValue(config);
|
|
25
|
+
container.bind(TYPES.Logger).to(ConsoleLogger).inSingletonScope();
|
|
26
|
+
container
|
|
27
|
+
.bind(TYPES.LuaRuntime)
|
|
28
|
+
.to(WasmoonRuntime)
|
|
29
|
+
.inSingletonScope();
|
|
30
|
+
container
|
|
31
|
+
.bind(TYPES.MCPClientManager)
|
|
32
|
+
.to(MCPClientManager)
|
|
33
|
+
.inSingletonScope();
|
|
34
|
+
container
|
|
35
|
+
.bind(TYPES.MCPFormatterService)
|
|
36
|
+
.to(MCPFormatterService)
|
|
37
|
+
.inSingletonScope();
|
|
38
|
+
container
|
|
39
|
+
.bind(TYPES.ToolDiscoveryService)
|
|
40
|
+
.to(ToolDiscoveryService)
|
|
41
|
+
.inSingletonScope();
|
|
42
|
+
container
|
|
43
|
+
.bind(TYPES.ResourceAggregationService)
|
|
44
|
+
.to(ResourceAggregationService)
|
|
45
|
+
.inSingletonScope();
|
|
46
|
+
container
|
|
47
|
+
.bind(TYPES.PromptAggregationService)
|
|
48
|
+
.to(PromptAggregationService)
|
|
49
|
+
.inSingletonScope();
|
|
50
|
+
container.bind(TYPES.Tool).to(ExecuteLuaTool);
|
|
51
|
+
container.bind(TYPES.Tool).to(ListServersTool);
|
|
52
|
+
container.bind(TYPES.Tool).to(ListServerToolsTool);
|
|
53
|
+
container.bind(TYPES.Tool).to(ToolDetailsTool);
|
|
54
|
+
container.bind(TYPES.Tool).to(InspectToolResponseTool);
|
|
55
|
+
container.bind(TYPES.Tool).to(SummaryStatsTool);
|
|
56
|
+
container
|
|
57
|
+
.bind(TYPES.ToolRegistry)
|
|
58
|
+
.toDynamicValue(() => {
|
|
59
|
+
const registry = new ToolRegistry();
|
|
60
|
+
const tools = container.getAll(TYPES.Tool);
|
|
61
|
+
for (const tool of tools) {
|
|
62
|
+
registry.register(tool);
|
|
63
|
+
}
|
|
64
|
+
return registry;
|
|
65
|
+
})
|
|
66
|
+
.inSingletonScope();
|
|
67
|
+
container
|
|
68
|
+
.bind(TYPES.MCPGatewayServer)
|
|
69
|
+
.to(MCPGatewayServer)
|
|
70
|
+
.inSingletonScope();
|
|
71
|
+
container
|
|
72
|
+
.bind(TYPES.ShutdownHandler)
|
|
73
|
+
.to(ShutdownHandler)
|
|
74
|
+
.inSingletonScope();
|
|
75
|
+
container
|
|
76
|
+
.bind(TYPES.CapabilityStore)
|
|
77
|
+
.to(CapabilityStore)
|
|
78
|
+
.inSingletonScope();
|
|
79
|
+
container
|
|
80
|
+
.bind(TYPES.ServerInfoPreloader)
|
|
81
|
+
.to(ServerInfoPreloader)
|
|
82
|
+
.inSingletonScope();
|
|
83
|
+
return container;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=inversify.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inversify.config.js","sourceRoot":"","sources":["../../src/container/inversify.config.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAW1C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,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ACjB,CAAC;SACD,gBAAgB,EAAE,CAAC;IAGtB,SAAS;SACN,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC;SAC5B,EAAE,CAAC,gBAAgB,CAAC;SACpB,gBAAgB,EAAE,CAAC;IAGtB,SAAS;SACN,IAAI,CAAmB,KAAK,CAAC,eAAe,CAAC;SAC7C,EAAE,CAAC,eAAe,CAAC;SACnB,gBAAgB,EAAE,CAAC;IAGtB,SAAS;SACN,IAAI,CAAmB,KAAK,CAAC,eAAe,CAAC;SAC7C,EAAE,CAAC,eAAe,CAAC;SACnB,gBAAgB,EAAE,CAAC;IAGtB,SAAS;SACN,IAAI,CAAuB,KAAK,CAAC,mBAAmB,CAAC;SACrD,EAAE,CAAC,mBAAmB,CAAC;SACvB,gBAAgB,EAAE,CAAC;IAEtB,OAAO,SAAS,CAAC;AAAA,CAClB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IMCPClientManager, ITransportManager, ILogger, ServerConfig, IMCPSessionController } from "../types/interfaces.js";
|
|
2
|
+
import type { IToolRegistry } from "../tools/tool-registry.js";
|
|
3
|
+
import type { ResourceAggregationService } from "../mcp/resource-aggregation-service.js";
|
|
4
|
+
import type { PromptAggregationService } from "../mcp/prompt-aggregation-service.js";
|
|
5
|
+
export declare class MCPSessionController implements IMCPSessionController {
|
|
6
|
+
private clientPool;
|
|
7
|
+
private transportManager;
|
|
8
|
+
private toolRegistry;
|
|
9
|
+
private resourceAggregation;
|
|
10
|
+
private promptAggregation;
|
|
11
|
+
private config;
|
|
12
|
+
private logger;
|
|
13
|
+
private connectingTransports;
|
|
14
|
+
private connectedTransports;
|
|
15
|
+
private gatewayServers;
|
|
16
|
+
constructor(clientPool: IMCPClientManager, transportManager: ITransportManager, toolRegistry: IToolRegistry, resourceAggregation: ResourceAggregationService, promptAggregation: PromptAggregationService, config: ServerConfig, logger: ILogger);
|
|
17
|
+
handleRequest(req: Request): Promise<Response>;
|
|
18
|
+
private initializeClientsForSession;
|
|
19
|
+
private connectGatewayServer;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=mcp-session-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-session-controller.d.ts","sourceRoot":"","sources":["../../src/controllers/mcp-session-controller.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,OAAO,EACP,YAAY,EACZ,qBAAqB,EACtB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAiBrF,qBACa,oBAAqB,YAAW,qBAAqB;IAc7B,OAAO,CAAC,UAAU;IAEnD,OAAO,CAAC,gBAAgB;IACK,OAAO,CAAC,YAAY;IAEjD,OAAO,CAAC,mBAAmB;IAE3B,OAAO,CAAC,iBAAiB;IACI,OAAO,CAAC,MAAM;IACpB,OAAO,CAAC,MAAM;IArBvC,OAAO,CAAC,oBAAoB,CAC0B;IAEtD,OAAO,CAAC,mBAAmB,CAC+B;IAE1D,OAAO,CAAC,cAAc,CAGlB;IAEJ,YAC2C,UAAU,EAAE,iBAAiB,EAE9D,gBAAgB,EAAE,iBAAiB,EACN,YAAY,EAAE,aAAa,EAExD,mBAAmB,EAAE,0BAA0B,EAE/C,iBAAiB,EAAE,wBAAwB,EACd,MAAM,EAAE,YAAY,EAC1B,MAAM,EAAE,OAAO,EAC5C;IAaE,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+CnD;YASa,2BAA2B;YAoC3B,oBAAoB;CAuBnC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { injectable } from "inversify";
|
|
14
|
+
import { $inject } from "../container/decorators.js";
|
|
15
|
+
import { TYPES } from "../types/index.js";
|
|
16
|
+
import { MCPGatewayServer } from "../mcp/gateway-server.js";
|
|
17
|
+
let MCPSessionController = class MCPSessionController {
|
|
18
|
+
clientPool;
|
|
19
|
+
transportManager;
|
|
20
|
+
toolRegistry;
|
|
21
|
+
resourceAggregation;
|
|
22
|
+
promptAggregation;
|
|
23
|
+
config;
|
|
24
|
+
logger;
|
|
25
|
+
connectingTransports = new Set();
|
|
26
|
+
connectedTransports = new WeakSet();
|
|
27
|
+
gatewayServers = new WeakMap();
|
|
28
|
+
constructor(clientPool, transportManager, toolRegistry, resourceAggregation, promptAggregation, config, logger) {
|
|
29
|
+
this.clientPool = clientPool;
|
|
30
|
+
this.transportManager = transportManager;
|
|
31
|
+
this.toolRegistry = toolRegistry;
|
|
32
|
+
this.resourceAggregation = resourceAggregation;
|
|
33
|
+
this.promptAggregation = promptAggregation;
|
|
34
|
+
this.config = config;
|
|
35
|
+
this.logger = logger;
|
|
36
|
+
}
|
|
37
|
+
async handleRequest(req) {
|
|
38
|
+
try {
|
|
39
|
+
const sessionId = req.headers.get("mcp-session-id") ?? undefined;
|
|
40
|
+
const transport = this.transportManager.getOrCreateForRequest(sessionId);
|
|
41
|
+
const clientSession = sessionId || "default";
|
|
42
|
+
await this.initializeClientsForSession(clientSession);
|
|
43
|
+
if (!this.connectedTransports.has(transport)) {
|
|
44
|
+
if (!this.connectingTransports.has(transport)) {
|
|
45
|
+
this.connectingTransports.add(transport);
|
|
46
|
+
try {
|
|
47
|
+
await this.connectGatewayServer(transport, clientSession);
|
|
48
|
+
this.connectedTransports.add(transport);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
this.connectingTransports.delete(transport);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
while (this.connectingTransports.has(transport)) {
|
|
56
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return await transport.handleRequest(req);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
this.logger.error(`Error handling MCP request: ${error}`, error);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async initializeClientsForSession(sessionId) {
|
|
68
|
+
for (const [name, clientConfig] of Object.entries(this.config.mcpClients)) {
|
|
69
|
+
if (clientConfig.type === "http") {
|
|
70
|
+
await this.clientPool.addHttpClient(name, clientConfig.url, sessionId, clientConfig.headers, clientConfig.allowedTools);
|
|
71
|
+
}
|
|
72
|
+
else if (clientConfig.type === "stdio") {
|
|
73
|
+
await this.clientPool.addStdioClient(name, clientConfig.command, sessionId, clientConfig.args, clientConfig.env, clientConfig.allowedTools);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const unknownConfig = clientConfig;
|
|
77
|
+
this.logger.error(`Unsupported client type '${unknownConfig.type}' for '${name}'`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async connectGatewayServer(transport, sessionId) {
|
|
82
|
+
this.logger.info(`Creating new gateway server instance for session ${sessionId}`);
|
|
83
|
+
const gatewayServer = new MCPGatewayServer(this.toolRegistry, this.clientPool, this.logger, this.resourceAggregation, this.promptAggregation);
|
|
84
|
+
this.gatewayServers.set(transport, gatewayServer);
|
|
85
|
+
await gatewayServer.getServer().connect(transport);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
MCPSessionController = __decorate([
|
|
89
|
+
injectable(),
|
|
90
|
+
__param(0, $inject(TYPES.MCPClientManager)),
|
|
91
|
+
__param(1, $inject(TYPES.TransportManager)),
|
|
92
|
+
__param(2, $inject(TYPES.ToolRegistry)),
|
|
93
|
+
__param(3, $inject(TYPES.ResourceAggregationService)),
|
|
94
|
+
__param(4, $inject(TYPES.PromptAggregationService)),
|
|
95
|
+
__param(5, $inject(TYPES.ServerConfig)),
|
|
96
|
+
__param(6, $inject(TYPES.Logger)),
|
|
97
|
+
__metadata("design:paramtypes", [Object, Object, Object, Function, Function, Object, Object])
|
|
98
|
+
], MCPSessionController);
|
|
99
|
+
export { MCPSessionController };
|
|
100
|
+
//# sourceMappingURL=mcp-session-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-session-controller.js","sourceRoot":"","sources":["../../src/controllers/mcp-session-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAQ1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAqBrD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAcY,UAAU;IAE3C,gBAAgB;IACa,YAAY;IAEzC,mBAAmB;IAEnB,iBAAiB;IACY,MAAM;IACZ,MAAM;IArB/B,oBAAoB,GAC1B,IAAI,GAAG,EAA4C,CAAC;IA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