diff options
| author | sigoden <sigoden@gmail.com> | 2024-12-13 06:01:53 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-13 06:01:53 +0800 |
| commit | 8e8b2f736b8e635396e713e219c8fe8575a6f491 (patch) | |
| tree | 287177124e95506d0442e9916b052f905ae100d3 | |
| parent | 33ef4f9178dc0d9c70f3e370a596c01780cc5b27 (diff) | |
| download | llm-functions-docker-8e8b2f736b8e635396e713e219c8fe8575a6f491.tar.gz | |
feat(mcp): add `prefix` filed to bridge server configuraiton (#148)
| -rw-r--r-- | mcp/bridge/README.md | 17 | ||||
| -rw-r--r-- | mcp/bridge/index.js | 8 |
2 files changed, 19 insertions, 6 deletions
diff --git a/mcp/bridge/README.md b/mcp/bridge/README.md index aec3703..46cf2de 100644 --- a/mcp/bridge/README.md +++ b/mcp/bridge/README.md @@ -4,7 +4,7 @@ Let external MCP tools be used by LLM-Functions. ## Get Started -1. Create a `mpc.json` at `<llm-functions-dir>`. +### 1. Create a `mpc.json` at `<llm-functions-dir>`. ```json { @@ -17,6 +17,15 @@ Let external MCP tools be used by LLM-Functions. "/tmp/foo.db" ] }, + "git": { + "command": "uvx", + "args": [ + "mcp-server-git", + "--repository", + "path/to/git/repo" + ], + "prefix": false + }, "github": { "command": "npx", "args": [ @@ -31,9 +40,11 @@ Let external MCP tools be used by LLM-Functions. } ``` -> MCP-Bridge will launch the server and register all the tools listed by the server. The tool identifier will be `server_toolname` to avoid clashes. +> MCP-Bridge will launch the server and register all the tools listed by the server. + +> To avoid name clashes, The server automatically prefix tool names with `<server>_`. You can disable this behavior by add `prefix: false` to server configuration. -2. Run the bridge server, build mcp tool binaries, update functions.json, all with: +### 2. Run the bridge server, build mcp tool binaries, update functions.json, all with: ``` argc mcp start diff --git a/mcp/bridge/index.js b/mcp/bridge/index.js index c978737..59896e3 100644 --- a/mcp/bridge/index.js +++ b/mcp/bridge/index.js @@ -29,8 +29,9 @@ try { async function startMcpServer(id, serverConfig) { console.log(`Starting ${id} server...`); const capabilities = { tools: {} }; + const { prefix = true, ...rest } = serverConfig; const transport = new StdioClientTransport({ - ...serverConfig, + ...rest, }); const client = new Client( { name: id, version: "1.0.0" }, @@ -42,7 +43,7 @@ async function startMcpServer(id, serverConfig) { ({ name, description, inputSchema }) => ({ spec: { - name: `${normalizeToolName(`${id}_${name}`)}`, + name: `${formatToolName(id, name, prefix)}`, description, parameters: inputSchema, }, @@ -181,7 +182,8 @@ function arrayify(a) { return r } -function normalizeToolName(name) { +function formatToolName(serverName, toolName, prefix) { + const name = prefix ? `${serverName}_${toolName}` : toolName; return name.toLowerCase().replace(/-/g, "_"); } |
