|
1 | 1 | import { ToolArgs } from "./types" |
2 | | -import { getModeBySlug, isServerAllowedForMode, isToolAllowedForModeAndServer } from "../../../shared/modes" |
3 | 2 |
|
4 | 3 | export function getUseMcpToolDescription(args: ToolArgs): string | undefined { |
5 | 4 | if (!args.mcpHub) { |
6 | 5 | return undefined |
7 | 6 | } |
8 | | - |
9 | | - let availableServers = args.mcpHub.getServers() |
10 | | - |
11 | | - if (args.currentMode && args.customModes) { |
12 | | - const mode = getModeBySlug(args.currentMode, args.customModes) |
13 | | - const restrictions = mode?.mcpRestrictions || {} // Use empty object if no restrictions defined |
14 | | - |
15 | | - // Always filter based on allowedInModesByDefault, even if no explicit restrictions |
16 | | - availableServers = availableServers.filter((server) => { |
17 | | - // Get server configuration to check allowedInModesByDefault setting |
18 | | - const serverConfig = args.mcpHub?.getServerConfig(server.name) |
19 | | - const allowedInModesByDefault = serverConfig?.allowedInModesByDefault ?? true // Default to true if not specified |
20 | | - |
21 | | - return isServerAllowedForMode(server.name, restrictions, allowedInModesByDefault) |
22 | | - }) |
23 | | - } |
24 | | - |
25 | | - // Generate description with filtered servers and their available tools |
26 | | - if (availableServers.length === 0) { |
27 | | - return `## use_mcp_tool |
28 | | -Description: Request to use a tool provided by a connected MCP server. |
29 | | -**Note: No MCP servers are available for the current mode.** |
30 | | -
|
31 | | -This tool allows you to execute tools provided by Model Context Protocol (MCP) servers, but the current mode has restrictions that prevent access to all configured MCP servers. |
32 | | -
|
33 | | -Parameters: |
34 | | -- server_name: (required) The name of the MCP server providing the tool |
35 | | -- tool_name: (required) The name of the tool to execute |
36 | | -- arguments: (required) A JSON object containing the tool's input parameters` |
37 | | - } |
38 | | - |
39 | | - const serverDescriptions = availableServers |
40 | | - .map((server) => { |
41 | | - let availableTools = server.tools || [] |
42 | | - |
43 | | - // Filter tools based on mode restrictions (only if explicit restrictions exist) |
44 | | - if (args.currentMode && args.customModes) { |
45 | | - const mode = getModeBySlug(args.currentMode, args.customModes) |
46 | | - const restrictions = mode?.mcpRestrictions |
47 | | - |
48 | | - if (restrictions) { |
49 | | - availableTools = availableTools.filter((tool) => |
50 | | - isToolAllowedForModeAndServer(server.name, tool.name, restrictions), |
51 | | - ) |
52 | | - } |
53 | | - } |
54 | | - |
55 | | - const toolList = |
56 | | - availableTools.length > 0 |
57 | | - ? availableTools |
58 | | - .map((tool) => { |
59 | | - const desc = tool.description ? ` - ${tool.description}` : "" |
60 | | - return ` • ${tool.name}${desc}` |
61 | | - }) |
62 | | - .join("\n") |
63 | | - : " (No tools available for current mode)" |
64 | | - |
65 | | - return `**${server.name}**:\n${toolList}` |
66 | | - }) |
67 | | - .join("\n\n") |
68 | | - |
69 | 7 | return `## use_mcp_tool |
70 | 8 | Description: Request to use a tool provided by a connected MCP server. Each MCP server can provide multiple tools with different capabilities. Tools have defined input schemas that specify required and optional parameters. |
71 | | -
|
72 | | -**Available servers and tools for current mode:** |
73 | | -${serverDescriptions} |
74 | | -
|
75 | 9 | Parameters: |
76 | 10 | - server_name: (required) The name of the MCP server providing the tool |
77 | 11 | - tool_name: (required) The name of the tool to execute |
78 | 12 | - arguments: (required) A JSON object containing the tool's input parameters, following the tool's input schema |
79 | | -
|
80 | 13 | Usage: |
81 | 14 | <use_mcp_tool> |
82 | 15 | <server_name>server name here</server_name> |
|
0 commit comments