From e8ffb414c424a59523f94db5e8aba86b723b5b7e Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 12 Dec 2024 12:42:23 +0800 Subject: feat(mcp-server): support env var `AGENT_TOOLS_ONLY` (#145) --- mcp/server/README.md | 14 +++++++++----- mcp/server/index.js | 13 ++++++++++++- mcp/server/package.json | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/mcp/server/README.md b/mcp/server/README.md index f2bda68..3881ca2 100644 --- a/mcp/server/README.md +++ b/mcp/server/README.md @@ -8,10 +8,10 @@ Let LLM-functions tools/agents be used through the Model Context Protocol. { "mcpServers": { "tools": { - "command": "node", + "command": "npx", "args": [ - "/mcp/server/index.js", - "" + "mcp-llm-functions", + "" ] } } @@ -26,11 +26,15 @@ Let LLM-functions tools/agents be used through the Model Context Protocol. "": { "command": "node", "args": [ - "/mcp/server/index.js", - "", + "mcp-llm-functions", + "" "", ] } } } ``` + +## Environment Variables + +- `AGENT_TOOLS_ONLY`: Set to `true` or `1` to ignore shared tools and display only agent tools. \ No newline at end of file diff --git a/mcp/server/index.js b/mcp/server/index.js index d725568..3f4c5b6 100755 --- a/mcp/server/index.js +++ b/mcp/server/index.js @@ -33,6 +33,18 @@ try { console.error(`Failed to read functions at '${functionsJsonPath}'`); process.exit(1); } +const agentToolsOnly = process.env["AGENT_TOOLS_ONLY"] === "true" || process.env["AGENT_TOOLS_ONLY"] === "1"; +functions = functions.filter(f => { + if (f.mcp) { + return false; + } + if (agentToolsOnly) { + return f.agent; + } else { + return true; + } +}); + const env = Object.assign({}, process.env, { PATH: `${path.join(rootDir, "bin")}:${process.env.PATH}` }); @@ -114,7 +126,6 @@ function runCommand(command, args, env) { async function runServer() { const transport = new StdioServerTransport(); await server.connect(transport); - console.error("LLM-Functions MCP Server running on stdio"); } runServer().catch(console.error); \ No newline at end of file diff --git a/mcp/server/package.json b/mcp/server/package.json index 69bbcc2..22fcd01 100644 --- a/mcp/server/package.json +++ b/mcp/server/package.json @@ -1,6 +1,6 @@ { "name": "mcp-llm-functions", - "version": "1.0.0", + "version": "1.1.0", "description": "Let LLM-functions tools/agents be used through the Model Context Protocol", "license": "MIT", "author": "sigoden ", -- cgit v1.2.3