Skip to content

Commit d2d7d7d

Browse files
committed
feat: Make server-tool name separator configurable SERVER_TOOLNAME_SEPERATOR
1 parent 5284c4d commit d2d7d7d

File tree

6 files changed

+311
-247
lines changed

6 files changed

+311
-247
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ Example `config/tool_config.json`:
174174
export TOOLS_FOLDER=/srv/mcp_tools
175175
```
176176
177+
- **`SERVER_TOOLNAME_SEPERATOR`**: (Optional) Defines the separator used to combine the server name and tool name when generating the unique key for tools (e.g., `server-key--tool-name`). This key is used internally and in the `tool_config.json` file.
178+
- Default: `--`.
179+
- Must be at least 2 characters long and contain only letters (a-z, A-Z), numbers (0-9), hyphens (`-`), and underscores (`_`).
180+
- If the provided value is invalid, the default (`--`) will be used, and a warning will be logged.
181+
```bash
182+
export SERVER_TOOLNAME_SEPERATOR="___" # Example: using triple underscore
183+
```
184+
177185
- **`LOGGING`**: (Optional) Controls the minimum log level output by the server.
178186
- Possible values (case-insensitive): `error`, `warn`, `info`, `debug`.
179187
- Logs at the specified level and all levels above it will be shown.

README_ZH.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@
175175
export TOOLS_FOLDER=/srv/mcp_tools
176176
```
177177

178+
- **`SERVER_TOOLNAME_SEPERATOR`**: (可选) 定义用于组合服务器名称和工具名称以生成工具唯一键的分隔符(例如 `server-key--tool-name`)。此键在内部和 `tool_config.json` 文件中使用。
179+
- 默认值:`--`
180+
- 必须至少包含 2 个字符,且只能包含字母(a-z, A-Z)、数字(0-9)、连字符(`-`)和下划线(`_`)。
181+
- 如果提供的值无效,将使用默认值(`--`)并记录警告。
182+
```bash
183+
export SERVER_TOOLNAME_SEPERATOR="___" # 示例:使用三个下划线
184+
```
185+
178186
- **`LOGGING`**: (可选) 控制服务器输出的最低日志级别。
179187
- 可能的值(不区分大小写):`error`, `warn`, `info`, `debug`
180188
- 将显示指定级别及以上的所有日志。

public/tools.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,37 @@ const saveToolConfigButton = document.getElementById('save-tool-config-button');
44
// const saveToolStatus = document.getElementById('save-tool-status'); // Removed: Declared in script.js
55
// Note: Assumes currentToolConfig and discoveredTools variables are globally accessible from script.js or passed.
66
// Note: Assumes triggerReload function is globally accessible from script.js or passed.
7+
let serverToolnameSeparator = '--'; // Default separator
78

89
// --- Tool Configuration Management ---
910
async function loadToolData() {
1011
if (!saveToolStatus || !toolListDiv) return; // Guard
1112
saveToolStatus.textContent = 'Loading tool data...';
1213
window.toolDataLoaded = false; // Reset flag during load attempt (use global flag)
1314
try {
14-
// Fetch both discovered tools and tool config concurrently
15-
const [toolsResponse, configResponse] = await Promise.all([
15+
// Fetch discovered tools, tool config, and environment info concurrently
16+
const [toolsResponse, configResponse, envResponse] = await Promise.all([
1617
fetch('/admin/tools/list'),
17-
fetch('/admin/tools/config')
18+
fetch('/admin/tools/config'),
19+
fetch('/admin/environment') // Fetch environment info
1820
]);
1921

2022
if (!toolsResponse.ok) throw new Error(`Failed to fetch discovered tools: ${toolsResponse.statusText}`);
2123
if (!configResponse.ok) throw new Error(`Failed to fetch tool config: ${configResponse.statusText}`);
24+
if (!envResponse.ok) throw new Error(`Failed to fetch environment info: ${envResponse.statusText}`); // Check env response
2225

2326
const toolsResult = await toolsResponse.json();
2427
window.discoveredTools = toolsResult.tools || []; // Expecting { tools: [...] } (use global var)
2528

2629
window.currentToolConfig = await configResponse.json(); // Use global var
2730
if (!window.currentToolConfig || typeof window.currentToolConfig !== 'object' || !window.currentToolConfig.tools) {
2831
console.warn("Received invalid tool configuration format, initializing empty.", window.currentToolConfig);
29-
window.currentToolConfig = { tools: {} }; // Initialize if invalid or empty
32+
window.currentToolConfig = { tools: {} }; // Initialize if invalid or empty
3033
}
3134

35+
const envResult = await envResponse.json(); // Parse environment info
36+
serverToolnameSeparator = envResult.serverToolnameSeparator || '--'; // Update separator
37+
console.log(`Using server toolname separator from backend: "${serverToolnameSeparator}"`);
3238

3339
renderTools(); // Render using both discovered and configured data
3440
window.toolDataLoaded = true; // Set global flag only after successful load and render
@@ -66,7 +72,7 @@ function renderTools() {
6672

6773
// Render discovered tools first, merging with config
6874
discoveredTools.forEach(tool => {
69-
const toolKey = `${tool.serverName}--${tool.name}`; // Unique key
75+
const toolKey = `${tool.serverName}${serverToolnameSeparator}${tool.name}`; // Use the fetched separator
7076
const config = currentToolConfig.tools[toolKey] || {}; // Get config or empty object
7177
// For discovered tools, their server is considered active by the proxy at connection time
7278
renderToolEntry(toolKey, tool, config, false, true); // isConfigOnly = false, isServerActive = true
@@ -76,7 +82,8 @@ function renderTools() {
7682
// Render any remaining configured tools that were not discovered
7783
configuredToolKeys.forEach(toolKey => {
7884
const config = currentToolConfig.tools[toolKey];
79-
const serverKeyForConfigOnlyTool = toolKey.split('--')[0];
85+
// Use the fetched separator for splitting
86+
const serverKeyForConfigOnlyTool = toolKey.split(serverToolnameSeparator)[0];
8087
let isServerActiveForConfigOnlyTool = true; // Default to true if server config not found or active flag is missing/true
8188

8289
if (window.currentServerConfig && window.currentServerConfig.mcpServers && window.currentServerConfig.mcpServers[serverKeyForConfigOnlyTool]) {

0 commit comments

Comments
 (0)