@loop_ouroboros/mcp-hub-lite 1.1.1 → 1.2.1

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 (37) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/README.md +73 -115
  3. package/dist/server/src/cli/commands/mcp-tool-use.d.ts +62 -0
  4. package/dist/server/src/cli/commands/mcp-tool-use.d.ts.map +1 -0
  5. package/dist/server/src/cli/commands/mcp-tool-use.js +174 -0
  6. package/dist/server/src/cli/commands/tool-use.d.ts +95 -0
  7. package/dist/server/src/cli/commands/tool-use.d.ts.map +1 -0
  8. package/dist/server/src/cli/commands/tool-use.js +255 -0
  9. package/dist/server/src/cli/index.d.ts +4 -2
  10. package/dist/server/src/cli/index.d.ts.map +1 -1
  11. package/dist/server/src/cli/index.js +35 -3
  12. package/dist/server/src/config/config-loader.js +1 -1
  13. package/dist/server/src/config/config-manager.js +1 -1
  14. package/dist/server/src/models/system-tools.constants.d.ts +2 -2
  15. package/dist/server/src/models/system-tools.constants.d.ts.map +1 -1
  16. package/dist/server/src/models/system-tools.constants.js +2 -2
  17. package/dist/server/src/services/connection/tool-cache.d.ts.map +1 -1
  18. package/dist/server/src/services/connection/tool-cache.js +3 -1
  19. package/dist/server/src/services/gateway/request-handlers/system-tools-handler.js +2 -2
  20. package/dist/server/src/services/hub-tools/system-tool-definitions.d.ts +1 -0
  21. package/dist/server/src/services/hub-tools/system-tool-definitions.d.ts.map +1 -1
  22. package/dist/server/src/services/hub-tools/system-tool-definitions.js +4 -3
  23. package/dist/server/src/services/hub-tools.service.d.ts +3 -2
  24. package/dist/server/src/services/hub-tools.service.d.ts.map +1 -1
  25. package/dist/server/src/services/hub-tools.service.js +36 -19
  26. package/dist/server/src/services/system-tool-handler.js +2 -2
  27. package/dist/server/src/utils/index.d.ts +1 -0
  28. package/dist/server/src/utils/index.d.ts.map +1 -1
  29. package/dist/server/src/utils/index.js +1 -0
  30. package/dist/server/src/utils/name-converter.d.ts +17 -0
  31. package/dist/server/src/utils/name-converter.d.ts.map +1 -0
  32. package/dist/server/src/utils/name-converter.js +27 -0
  33. package/dist/server/tests/unit/services/hub-tools.service.test.js +1 -1
  34. package/dist/server/tests/unit/utils/name-converter.test.d.ts +2 -0
  35. package/dist/server/tests/unit/utils/name-converter.test.d.ts.map +1 -0
  36. package/dist/server/tests/unit/utils/name-converter.test.js +69 -0
  37. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,145 @@
1
1
  # Changelog
2
2
 
3
+ ## 2026-04-14
4
+
5
+ - **Lint Fix**: Remove unnecessary escape character in CLI entry detection
6
+ - **Docs**: Format README files for release
7
+ - **Version**: Bump version to 1.2.1
8
+ - **CLI Fix**: Fix CLI entry detection for Windows/npm symlink environments
9
+ - **CLI Refactor**: Fix command count and rename mcpToolUseCommand to toolUseCommand
10
+ - **Config Refactor**: Change config loading logs from info to debug level
11
+ - **Core Feature**: Add normalizeToolName for cross-format tool name matching
12
+ - **CLI Feature**: Add tool-use command for MCP server tool operations
13
+ - **Gateway Feature**: Implement per-request transport mode to fix connection errors
14
+
15
+ ## 2026-04-13
16
+
17
+ - **Deps**: Add undici dependency for HTTP transport
18
+ - **Frontend Fix**: Prevent runtime error when tool is undefined in groupedTools
19
+ - **Version**: Bump version to 1.1.0
20
+ - **Core Refactor**: Use composite key serverName-serverIndex instead of serverId
21
+ - **Resource Feature**: Implement MCP native resource forwarding
22
+ - **Docs**: Update search functionality description in CLAUDE.md
23
+ - **Hub Tools Refactor**: Add non-strict mode to selectBestInstance
24
+ - **Search Refactor**: Remove complex search module, simplify to string matching
25
+ - **Test Refactor**: Remove evaluation tests not compliant with MCP spec
26
+
27
+ ## 2026-04-12
28
+
29
+ - **Config Refactor**: Move instance selection strategy to template
30
+ - **Frontend Refactor**: Improve type declarations and test type safety
31
+ - **Frontend Refactor**: Compute instance counts from server.instances directly
32
+ - **Gateway Feature**: Restrict call_tool from invoking system tools
33
+ - **Docs**: Compress use-guide from 13 to 7 sections
34
+ - **Gateway Fix**: Return 400 for missing Accept header
35
+
36
+ ## 2026-04-10
37
+
38
+ - **Transport Refactor**: Use official SDK StdioClientTransport
39
+ - **Stdio Transport Refactor**: Log non-JSON-RPC stdout and unify stderr log level
40
+ - **Frontend Fix**: Fix tools and resources not displaying in server detail
41
+ - **Frontend Fix**: Add description field to ConfigTemplateForm
42
+ - **Tools Fix**: Handle nested toolArgs in updateServerDescription
43
+
44
+ ## 2026-04-09
45
+
46
+ - **Security Feature**: Mask sensitive values in config change logs
47
+ - **Frontend Fix**: Improve instance status reactivity and management
48
+ - **i18n Fix**: Improve noToolsFound message to reflect tool aggregation
49
+ - **Frontend Fix**: Add bottom padding to prevent save button cutoff on scroll
50
+ - **Gateway Refactor**: Extract version and protocol version to shared utility
51
+ - **Config Refactor**: Unify instance ID generation with content hash
52
+
53
+ ## 2026-04-08
54
+
55
+ - **MCP Status Fix**: Prevent automatic enabled field updates on connect/disconnect
56
+ - **Chore**: Update .gitignore to ignore .full-review directory
57
+
58
+ ## 2026-04-07
59
+
60
+ - **Frontend Fix**: Fix TypeScript type errors in component event handlers
61
+
62
+ ## 2026-04-04
63
+
64
+ - **Test Refactor**: Simplify ServerStatusTags tests with mocks
65
+ - **Config Feature**: Sort env and headers keys on config save
66
+ - **Proxy Feature**: Add proxy configuration support for SSE and Streamable HTTP transports
67
+
68
+ ## 2026-04-03
69
+
70
+ - **Config Feature**: Sort env and headers keys on config save
71
+ - **Config Refactor**: Optimize updateServerInstance logging
72
+ - **Connection Refactor**: Improve serverId handling and protocol version support
73
+
74
+ ## 2026-04-02
75
+
76
+ - **Docs**: Update CLAUDE.md documentation for logging and composables
77
+ - **Logging Refactor**: Enhance transport logging with serverId context
78
+ - **Transports Feature**: Add LineBuffer for proper stderr line buffering
79
+ - **Logging Refactor**: Enhance logging module and configuration change tracking
80
+ - **Docs**: Update CLAUDE.md documentation for v1.1 config refactor
81
+
82
+ ## 2026-04-01
83
+
84
+ - **Config Refactor**: Complete v1.1 multi-instance configuration refactoring
85
+ - **Docs**: Update CLAUDE.md files to reflect session removal
86
+ - **Session Refactor**: Remove session persistence mechanism and use SDK native stateless mode
87
+ - **Session Refactor**: Remove session persistence mechanism
88
+
89
+ ## 2026-03-31
90
+
91
+ - **UI Fix**: Ensure log viewer area fills available container height
92
+ - **Frontend Feature**: Add instance tab routing synchronization
93
+
94
+ ## 2026-03-29
95
+
96
+ - **i18n Fix**: Correct missing translation key in InstanceConfig component
97
+
98
+ ## 2026-03-28
99
+
100
+ - **Hub Tools Feature**: Implement instance selection strategies
101
+
102
+ ## 2026-03-27
103
+
104
+ - **Docs**: Update CLAUDE.md files across project modules
105
+ - **Session Feature**: Remove cwd and project fields from session management
106
+ - **UI Fix**: Optimize instance list display in English and hide redundant Running tag
107
+ - **Config Fix**: Ensure server instance indexes from config load and migration
108
+
109
+ ## 2026-03-26
110
+
111
+ - **Config Feature**: Implement v1.1 instance configuration system
112
+
113
+ ## 2026-03-25
114
+
115
+ - **Config Fix**: Support string index type for server instance operations
116
+ - **Docs**: Update CLAUDE.md files to reflect recent v1.1 config changes
117
+ - **Config Feature**: Enhance instance management with display name and route selection
118
+
119
+ ## 2026-03-24
120
+
121
+ - **Config Refactor**: Activate v1.1 config format with instance support
122
+ - **Gateway Fix**: Only include tools from servers with allowedTools configured
123
+ - **Hub Tools Fix**: Support both toolArgs and arguments for backward compatibility
124
+
125
+ ## 2026-03-23
126
+
127
+ - **Config Refactor**: Activate v1.1 config format, remove v1.0 compatibility code
128
+ - **Config Feature**: Add empty value cleaning when saving config
129
+
130
+ ## 2026-03-20
131
+
132
+ - **UI Fix**: Correct dark mode background color and refine instance UI
133
+ - **UI Feature**: Add server instance management UI components
134
+ - **Config Feature**: Add index and displayName to ServerInstanceConfig with reassignment API
135
+ - **UI Feature**: Add tag management UI with TagManager component
136
+ - **Config Feature**: Add v1.1 config schema with auto-migration support
137
+
138
+ ## 2026-03-19
139
+
140
+ - **i18n Fix**: Fix headers label and add button text in server config
141
+ - **UI Feature**: Add description field support in AddServerModal
142
+
3
143
  ## 2026-03-17
4
144
 
5
145
  - **UI Enhancement**: Update resource detail and list views with hub tools integration
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # MCP-HUB-LITE
2
2
 
3
- [![License][license-src]][license-href]
4
- [![Node.js][node-src]][node-href]
5
- [![TypeScript][typescript-src]][typescript-href]
6
- [![Vitest][vitest-src]][vitest-href]
7
- [![Fastify][fastify-src]][fastify-href]
8
- [![Vue.js][vue-src]][vue-href]
9
- [![Claude Code][claude-code-src]][claude-code-href]
3
+ [![License](https://img.shields.io/badge/license-MIT-080f12?style=flat&colorA=080f12&colorB=1fa669)](./LICENSE)
4
+ [![Node.js](https://img.shields.io/badge/Node.js-22.x-080f12?style=flat&logo=nodedotjs&logoColor=white&colorA=080f12&colorB=339933)](https://nodejs.org/)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-080f12?style=flat&logo=typescript&logoColor=white&colorA=080f12&colorB=3178C6)](https://www.typescriptlang.org/)
6
+ [![Vitest](https://img.shields.io/badge/Vitest-Testing-080f12?style=flat&logo=vitest&logoColor=white&colorA=080f12&colorB=6E9F18)](https://vitest.dev/)
7
+ [![Fastify](https://img.shields.io/badge/Fastify-Web-080f12?style=flat&logo=fastify&logoColor=white&colorA=080f12&colorB=000000)](https://fastify.io/)
8
+ [![Vue.js](https://img.shields.io/badge/Vue.js-3-080f12?style=flat&logo=vuedotjs&logoColor=white&colorA=080f12&colorB=4FC08D)](https://vuejs.org/)
9
+ [![Claude Code](https://img.shields.io/badge/Claude-Code-1fa669?style=flat&colorA=080f12&colorB=1fa669)](https://claude.ai/code)
10
10
 
11
11
  ---
12
12
 
@@ -18,32 +18,22 @@ A lightweight MCP management platform designed for independent developers, provi
18
18
 
19
19
  MCP-HUB-LITE is an MCP server gateway designed specifically for independent developers. It acts as a proxy between your frontend and multiple backend MCP servers, providing a unified access interface with support for the MCP JSON-RPC 2.0 protocol.
20
20
 
21
- ### Dashboard
22
-
23
- ![Dashboard](./docs/screenshot/en/dashboard.png)
24
-
25
21
  ### Core Features
26
22
 
27
23
  - **MCP Gateway Service**: Unified proxy interface for multiple backend MCP servers
24
+ - **MCP CLI Tool**: Command-line tool for listing and calling MCP tools across servers
28
25
  - **Server Management**: Manage multiple MCP servers through a web interface
29
- - **Tool Search**: Fuzzy search and tool discovery across all servers
26
+ - **Tool Search**: Search and tool discovery across all servers with aggregation
30
27
  - **Process Management**: Launch and manage MCP server processes via npx/uvx
31
- - **Session Management**: Session state management with persistence and recovery
28
+ - **Session Management**: Native stateless session management via MCP SDK
29
+ - **Multi-Instance Support**: Run multiple instances of the same MCP server with load balancing
30
+ - **Instance Selection Strategies**: Support random, round-robin, and unique-by-tag selection
32
31
  - **Tag System**: Organize multiple MCP servers by environment, category, function, etc.
33
32
  - **Fault Tolerance**: System continues to operate when individual servers fail
34
33
  - **Bilingual Interface**: Support for Chinese/English interface switching
35
34
  - **Configuration Management**: Support for hot-reloading and maintenance of `.mcp-hub.json`
36
-
37
- ## Tech Stack
38
-
39
- - **TypeScript 5.x** + Node.js 22.x
40
- - **Fastify**: High-performance HTTP server
41
- - **MCP SDK**: Official MCP protocol support (@modelcontextprotocol/sdk)
42
- - **Vitest**: Unit testing framework
43
- - **Zod**: Data validation
44
- - **Vue 3**: Frontend UI framework
45
- - **Pinia**: Frontend state management
46
- - **Element Plus**: UI component library
35
+ - **MCP Native Resources**: Forward resource calls to backend MCP servers
36
+ - **Security**: Mask sensitive values in config change logs
47
37
 
48
38
  ## Quick Start
49
39
 
@@ -93,7 +83,7 @@ npm run status
93
83
  npm run ui
94
84
  ```
95
85
 
96
- The server will start at http://localhost:7788.
86
+ The server will start at <http://localhost:7788>.
97
87
 
98
88
  ## Server Management
99
89
 
@@ -115,32 +105,17 @@ Discover and call tools from all connected MCP servers through the unified gatew
115
105
 
116
106
  Browse and manage MCP resources from all connected servers.
117
107
 
118
- ## Sessions
119
-
120
- ![Sessions](./docs/screenshot/en/sessions.png)
121
-
122
- Session management with persistence support. Sessions are automatically saved to disk and can be restored after service restart.
123
-
124
- ## Settings
125
-
126
- ![Settings](./docs/screenshot/en/settings.png)
127
-
128
- Configure language, logging, and other settings through the settings page.
129
-
130
108
  ### Testing
131
109
 
132
110
  ```bash
133
111
  # Run all tests
134
112
  npm test
135
113
 
136
- # Unit tests
137
- npm run test:unit
138
-
139
- # Integration tests
140
- npm run test:integration
114
+ # Backend tests
115
+ npm run test:backend
141
116
 
142
- # Contract tests
143
- npm run test:contract
117
+ # Frontend tests
118
+ npm run test:frontend
144
119
  ```
145
120
 
146
121
  ## CLI Commands
@@ -166,6 +141,32 @@ node dist/index.js ui
166
141
  node dist/index.js --help
167
142
  ```
168
143
 
144
+ ### Tool Use Command
145
+
146
+ The `tool-use` command provides MCP server tool operations:
147
+
148
+ ```bash
149
+ # List system tools (default server: mcp-hub-lite)
150
+ npm run tool-use -- list-tools
151
+ mcp-hub-lite tool-use list-tools
152
+
153
+ # List tools from a specific server
154
+ npm run tool-use -- list-tools --server baidu-search
155
+ mcp-hub-lite tool-use list-tools --server baidu-search
156
+
157
+ # Get tool schema
158
+ npm run tool-use -- get-tool --tool list_tools
159
+ mcp-hub-lite tool-use get-tool --tool list_tools
160
+
161
+ # Call a system tool
162
+ npm run tool-use -- call-tool --tool list_tools --args '{}'
163
+ mcp-hub-lite tool-use call-tool --tool list_tools --args '{}'
164
+
165
+ # Call a server tool
166
+ npm run tool-use -- call-tool --server baidu-search --tool search --args '{"query":"hello"}'
167
+ mcp-hub-lite tool-use call-tool --server baidu-search --tool search --args '{"query":"hello"}'
168
+ ```
169
+
169
170
  ## Configuration
170
171
 
171
172
  MCP-HUB-LITE uses a `.mcp-hub.json` file for configuration. Configuration lookup priority:
@@ -177,24 +178,33 @@ MCP-HUB-LITE uses a `.mcp-hub.json` file for configuration. Configuration lookup
177
178
 
178
179
  ```json
179
180
  {
180
- "version": "1.0.0",
181
+ "version": "1.1.0",
181
182
  "servers": [
182
183
  {
183
184
  "id": "server-1",
184
185
  "name": "My MCP Server",
185
186
  "description": "Example server",
187
+ "transport": "streamable-http",
186
188
  "endpoint": "http://localhost:8080",
187
- "transport": "http-stream",
188
189
  "tags": {
189
190
  "env": "development",
190
191
  "category": "api-server",
191
192
  "function": "http-api",
192
193
  "priority": "medium"
193
194
  },
195
+ "allowedTools": [],
196
+ "instances": [
197
+ {
198
+ "index": 0,
199
+ "displayName": "Instance 1",
200
+ "enabled": true,
201
+ "env": {}
202
+ }
203
+ ],
194
204
  "managedProcess": {
195
205
  "command": "npx my-mcp-server",
196
206
  "managedMode": "npx",
197
- "processType": "http-stream"
207
+ "processType": "streamable-http"
198
208
  }
199
209
  }
200
210
  ],
@@ -225,50 +235,11 @@ MCP-HUB-LITE uses a `.mcp-hub.json` file for configuration. Configuration lookup
225
235
 
226
236
  Through the web interface:
227
237
 
228
- 1. Open http://localhost:7788
238
+ 1. Open <http://localhost:7788>
229
239
  2. Navigate to the "Servers" page
230
240
  3. Click "Add Server"
231
241
  4. Fill in server details and save
232
242
 
233
- ### MCP Protocol Usage
234
-
235
- MCP-HUB-LITE exposes the MCP protocol interface on the same port:
236
-
237
- #### List All Tools
238
-
239
- ```json
240
- {
241
- "jsonrpc": "2.0",
242
- "method": "tools/list",
243
- "params": {}
244
- }
245
- ```
246
-
247
- #### Call a Tool
248
-
249
- ```json
250
- {
251
- "jsonrpc": "2.0",
252
- "method": "tool/call",
253
- "params": {
254
- "toolId": "server1:example-tool",
255
- "arguments": {}
256
- }
257
- }
258
- ```
259
-
260
- #### Get Server Status
261
-
262
- ```json
263
- {
264
- "jsonrpc": "2.0",
265
- "method": "server/status",
266
- "params": {
267
- "serverId": "server-1"
268
- }
269
- }
270
- ```
271
-
272
243
  ## Process Management
273
244
 
274
245
  MCP-HUB-LITE supports launching and managing MCP servers using your local environment:
@@ -297,9 +268,15 @@ src/
297
268
  │ └── web-api/ # Web API routes
298
269
  ├── models/ # Data models
299
270
  ├── services/ # Core business logic
271
+ │ ├── gateway/ # MCP gateway service
272
+ │ ├── connection/ # Connection management
273
+ │ └── hub-tools/ # Hub tools service
300
274
  ├── utils/ # Utility functions
275
+ │ ├── logger/ # Logging utilities
276
+ │ └── transports/ # MCP transport implementations
301
277
  ├── config/ # Configuration
302
278
  ├── cli/ # CLI commands
279
+ │ └── commands/ # CLI command implementations
303
280
  ├── pid/ # Process ID management
304
281
  └── server/ # Server runtime
305
282
 
@@ -308,17 +285,21 @@ frontend/
308
285
  │ ├── components/ # Reusable UI components
309
286
  │ ├── views/ # Page view components
310
287
  │ ├── stores/ # Pinia state management
288
+ │ ├── composables/ # Vue composables
311
289
  │ ├── router/ # Vue Router configuration
312
- └── i18n/ # Internationalization
290
+ ├── i18n/ # Internationalization
291
+ │ └── types/ # Frontend type definitions
313
292
 
314
293
  shared/
315
294
  ├── models/ # Shared models
316
- └── types/ # Shared types
295
+ └── types/ # Shared types
317
296
 
318
297
  tests/
319
- ├── unit/ # Unit tests
320
- ├── integration/ # Integration tests
321
- └── contract/ # Contract tests
298
+ ├── unit/ # Unit tests
299
+ ├── integration/ # Integration tests
300
+ ├── contract/ # Contract tests
301
+ ├── helpers/ # Test helpers
302
+ └── types/ # Test types
322
303
  ```
323
304
 
324
305
  ### Adding New Features
@@ -329,14 +310,6 @@ tests/
329
310
  4. Write tests (tests/)
330
311
  5. Update configuration files
331
312
 
332
- ## Constraints and Limits
333
-
334
- - Maximum servers: 50
335
- - Maximum memory usage: 4GB
336
- - CPU usage threshold: 80%
337
- - Search response time: <500ms (90%)
338
- - Gateway latency: <100ms
339
-
340
313
  ## Detailed Technical Documentation
341
314
 
342
315
  Complete project architecture, constraints, and design decisions can be found in:
@@ -352,18 +325,3 @@ MIT
352
325
  Pull Requests and Issues are welcome!
353
326
 
354
327
  <!-- Badges -->
355
-
356
- [license-src]: https://img.shields.io/badge/license-MIT-080f12?style=flat&colorA=080f12&colorB=1fa669
357
- [license-href]: ./LICENSE
358
- [node-src]: https://img.shields.io/badge/Node.js-22.x-080f12?style=flat&logo=nodedotjs&logoColor=white&colorA=080f12&colorB=339933
359
- [node-href]: https://nodejs.org/
360
- [typescript-src]: https://img.shields.io/badge/TypeScript-5.x-080f12?style=flat&logo=typescript&logoColor=white&colorA=080f12&colorB=3178C6
361
- [typescript-href]: https://www.typescriptlang.org/
362
- [vitest-src]: https://img.shields.io/badge/Vitest-Testing-080f12?style=flat&logo=vitest&logoColor=white&colorA=080f12&colorB=6E9F18
363
- [vitest-href]: https://vitest.dev/
364
- [fastify-src]: https://img.shields.io/badge/Fastify-Web-080f12?style=flat&logo=fastify&logoColor=white&colorA=080f12&colorB=000000
365
- [fastify-href]: https://fastify.io/
366
- [vue-src]: https://img.shields.io/badge/Vue.js-3-080f12?style=flat&logo=vuedotjs&logoColor=white&colorA=080f12&colorB=4FC08D
367
- [vue-href]: https://vuejs.org/
368
- [claude-code-src]: https://img.shields.io/badge/Claude-Code-1fa669?style=flat&colorA=080f12&colorB=1fa669
369
- [claude-code-href]: https://claude.ai/code
@@ -0,0 +1,62 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * CLI command for dynamic MCP server tool operations via API.
4
+ *
5
+ * This command provides a simplified CLI interface for interacting with MCP server tools,
6
+ * supporting four actions: list-servers, list-tools, get-tool, and call-tool. It wraps
7
+ * the HTTP API endpoints and requires the MCP Hub Lite server to be running.
8
+ *
9
+ * ## Command Format
10
+ *
11
+ * ```
12
+ * mcp-tool-use <serverName> <action> [toolName] [--args <json>] [--tags <json>]
13
+ * ```
14
+ *
15
+ * Or via npm:
16
+ * ```
17
+ * npm run tool-use <serverName> <action> [toolName] [--args <json>] [--tags <json>]
18
+ * ```
19
+ *
20
+ * ## Supported Actions
21
+ *
22
+ * - `list-servers` - List all connected MCP servers
23
+ * - `list-tools` - List all tools from the specified server
24
+ * - `get-tool <toolName>` - Get complete schema for a specific tool
25
+ * - `call-tool <toolName>` - Call a tool on the specified server
26
+ *
27
+ * ## Options
28
+ *
29
+ * - `--args <json>` - JSON string of tool arguments (for call-tool action)
30
+ * - `--tags <json>` - JSON object of instance selection tags (call-tool only, for multi-instance servers)
31
+ *
32
+ * ## Usage Examples
33
+ *
34
+ * ```bash
35
+ * # List all connected servers
36
+ * mcp-hub-lite mcp-tool-use mcp-hub-lite list-servers
37
+ *
38
+ * # List all tools from a specific server
39
+ * mcp-hub-lite mcp-tool-use mcp-hub-lite list-tools
40
+ *
41
+ * # Get tool schema
42
+ * mcp-hub-lite mcp-tool-use mcp-hub-lite get-tool list_tools
43
+ *
44
+ * # Call a tool with arguments
45
+ * mcp-hub-lite mcp-tool-use mcp-hub-lite call-tool list_tools --args '{"serverName":"mcp-hub-lite"}'
46
+ *
47
+ * # Call a tool with tags for multi-instance selection
48
+ * mcp-hub-lite mcp-tool-use baidu-search call-tool search --args '{"query":"天气"}' --tags '{"env":"prod"}'
49
+ * ```
50
+ *
51
+ * ## Error Handling
52
+ *
53
+ * - Exits with code 1 if the server is not running
54
+ * - Exits with code 1 if action is unknown
55
+ * - Exits with code 1 if toolName is required but not provided
56
+ * - Exits with code 1 if JSON parsing fails for --args or --tags
57
+ * - Exits with code 1 if the underlying API call fails
58
+ *
59
+ * @returns {Command} The configured mcp-tool-use command instance for registration with Commander.js
60
+ */
61
+ export declare const mcpToolUseCommand: Command;
62
+ //# sourceMappingURL=mcp-tool-use.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-tool-use.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/mcp-tool-use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,eAAO,MAAM,iBAAiB,SAkI1B,CAAC"}
@@ -0,0 +1,174 @@
1
+ import { Command } from 'commander';
2
+ import { getServerStatus } from '../server.js';
3
+ /**
4
+ * CLI command for dynamic MCP server tool operations via API.
5
+ *
6
+ * This command provides a simplified CLI interface for interacting with MCP server tools,
7
+ * supporting four actions: list-servers, list-tools, get-tool, and call-tool. It wraps
8
+ * the HTTP API endpoints and requires the MCP Hub Lite server to be running.
9
+ *
10
+ * ## Command Format
11
+ *
12
+ * ```
13
+ * mcp-tool-use <serverName> <action> [toolName] [--args <json>] [--tags <json>]
14
+ * ```
15
+ *
16
+ * Or via npm:
17
+ * ```
18
+ * npm run tool-use <serverName> <action> [toolName] [--args <json>] [--tags <json>]
19
+ * ```
20
+ *
21
+ * ## Supported Actions
22
+ *
23
+ * - `list-servers` - List all connected MCP servers
24
+ * - `list-tools` - List all tools from the specified server
25
+ * - `get-tool <toolName>` - Get complete schema for a specific tool
26
+ * - `call-tool <toolName>` - Call a tool on the specified server
27
+ *
28
+ * ## Options
29
+ *
30
+ * - `--args <json>` - JSON string of tool arguments (for call-tool action)
31
+ * - `--tags <json>` - JSON object of instance selection tags (call-tool only, for multi-instance servers)
32
+ *
33
+ * ## Usage Examples
34
+ *
35
+ * ```bash
36
+ * # List all connected servers
37
+ * mcp-hub-lite mcp-tool-use mcp-hub-lite list-servers
38
+ *
39
+ * # List all tools from a specific server
40
+ * mcp-hub-lite mcp-tool-use mcp-hub-lite list-tools
41
+ *
42
+ * # Get tool schema
43
+ * mcp-hub-lite mcp-tool-use mcp-hub-lite get-tool list_tools
44
+ *
45
+ * # Call a tool with arguments
46
+ * mcp-hub-lite mcp-tool-use mcp-hub-lite call-tool list_tools --args '{"serverName":"mcp-hub-lite"}'
47
+ *
48
+ * # Call a tool with tags for multi-instance selection
49
+ * mcp-hub-lite mcp-tool-use baidu-search call-tool search --args '{"query":"天气"}' --tags '{"env":"prod"}'
50
+ * ```
51
+ *
52
+ * ## Error Handling
53
+ *
54
+ * - Exits with code 1 if the server is not running
55
+ * - Exits with code 1 if action is unknown
56
+ * - Exits with code 1 if toolName is required but not provided
57
+ * - Exits with code 1 if JSON parsing fails for --args or --tags
58
+ * - Exits with code 1 if the underlying API call fails
59
+ *
60
+ * @returns {Command} The configured mcp-tool-use command instance for registration with Commander.js
61
+ */
62
+ export const mcpToolUseCommand = new Command('tool-use')
63
+ .description('Manage MCP server tools via API (list-servers, list-tools, get-tool, call-tool)')
64
+ .argument('<serverName>', 'Server name to target (use "mcp-hub-lite" for system tools)')
65
+ .argument('<action>', 'Action: list-servers, list-tools, get-tool, call-tool')
66
+ .argument('[toolName]', 'Tool name (required for get-tool and call-tool actions)')
67
+ .option('--args <json>', 'JSON string of tool arguments (call-tool only)')
68
+ .option('--tags <json>', 'JSON object of instance selection tags (call-tool only, for multi-instance servers)')
69
+ .action(async (serverName, action, toolName, options) => {
70
+ try {
71
+ // Check if server is running and get connection info
72
+ const status = await getServerStatus();
73
+ if (!status.running) {
74
+ console.error('Error: MCP Hub Lite server is not running.');
75
+ console.error('Start the server with: mcp-hub-lite start');
76
+ process.exit(1);
77
+ }
78
+ const baseUrl = `http://${status.host}:${status.port}`;
79
+ switch (action) {
80
+ case 'list-servers': {
81
+ const response = await fetch(`${baseUrl}/web/hub-tools/servers`, {
82
+ headers: { Accept: 'application/json' }
83
+ });
84
+ if (!response.ok) {
85
+ throw new Error(`API error: ${response.status} ${response.statusText}`);
86
+ }
87
+ const result = await response.json();
88
+ console.log(JSON.stringify(result, null, 2));
89
+ break;
90
+ }
91
+ case 'list-tools': {
92
+ const tagsParam = options.tags ? `?tags=${encodeURIComponent(options.tags)}` : '';
93
+ const response = await fetch(`${baseUrl}/web/hub-tools/servers/${serverName}/tools${tagsParam}`, {
94
+ headers: { Accept: 'application/json' }
95
+ });
96
+ if (!response.ok) {
97
+ const error = await response.json().catch(() => ({ message: response.statusText }));
98
+ throw new Error(error.message || `API error: ${response.status}`);
99
+ }
100
+ const result = await response.json();
101
+ console.log(JSON.stringify(result, null, 2));
102
+ break;
103
+ }
104
+ case 'get-tool': {
105
+ if (!toolName) {
106
+ console.error('Error: toolName is required for get-tool action');
107
+ process.exit(1);
108
+ }
109
+ const tagsParam = options.tags ? `?tags=${encodeURIComponent(options.tags)}` : '';
110
+ const response = await fetch(`${baseUrl}/web/hub-tools/servers/${serverName}/tools/${toolName}${tagsParam}`, { headers: { Accept: 'application/json' } });
111
+ if (!response.ok) {
112
+ const error = await response.json().catch(() => ({ message: response.statusText }));
113
+ throw new Error(error.message || `API error: ${response.status}`);
114
+ }
115
+ const result = await response.json();
116
+ console.log(JSON.stringify(result, null, 2));
117
+ break;
118
+ }
119
+ case 'call-tool': {
120
+ if (!toolName) {
121
+ console.error('Error: toolName is required for call-tool action');
122
+ process.exit(1);
123
+ }
124
+ // Parse tool arguments
125
+ let toolArgs = {};
126
+ if (options.args) {
127
+ try {
128
+ toolArgs = JSON.parse(options.args);
129
+ }
130
+ catch {
131
+ console.error('Error: Invalid JSON in --args option');
132
+ process.exit(1);
133
+ }
134
+ }
135
+ // Parse tags for instance selection (call-tool only)
136
+ let requestOptions;
137
+ if (options.tags) {
138
+ try {
139
+ requestOptions = { tags: JSON.parse(options.tags) };
140
+ }
141
+ catch {
142
+ console.error('Error: Invalid JSON in --tags option');
143
+ process.exit(1);
144
+ }
145
+ }
146
+ const response = await fetch(`${baseUrl}/web/hub-tools/servers/${serverName}/tools/${toolName}/call`, {
147
+ method: 'POST',
148
+ headers: {
149
+ 'Content-Type': 'application/json',
150
+ Accept: 'application/json'
151
+ },
152
+ body: JSON.stringify({ toolArgs, requestOptions })
153
+ });
154
+ if (!response.ok) {
155
+ const error = await response.json().catch(() => ({ message: response.statusText }));
156
+ throw new Error(error.message || `API error: ${response.status}`);
157
+ }
158
+ const result = await response.json();
159
+ console.log(JSON.stringify(result, null, 2));
160
+ break;
161
+ }
162
+ default: {
163
+ console.error(`Unknown action: ${action}`);
164
+ console.error('Valid actions: list-servers, list-tools, get-tool, call-tool');
165
+ process.exit(1);
166
+ }
167
+ }
168
+ process.exit(0);
169
+ }
170
+ catch (error) {
171
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
172
+ process.exit(1);
173
+ }
174
+ });