Skip to content

Commit a26c06c

Browse files
author
Evyatar Mitrani
committed
reverts and fixes
1 parent 5ab21ab commit a26c06c

File tree

3 files changed

+14
-114
lines changed

3 files changed

+14
-114
lines changed

src/core/prompts/tools/access-mcp-resource.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,14 @@
11
import { ToolArgs } from "./types"
2-
import { getModeBySlug, isServerAllowedForMode } from "../../../shared/modes"
32

43
export function getAccessMcpResourceDescription(args: ToolArgs): string | undefined {
54
if (!args.mcpHub) {
65
return undefined
76
}
8-
9-
let availableServers = args.mcpHub.getServers()
10-
11-
// Filter servers based on mode restrictions
12-
if (args.currentMode && args.customModes) {
13-
const mode = getModeBySlug(args.currentMode, args.customModes)
14-
const restrictions = mode?.mcpRestrictions || {} // Use empty object if no restrictions defined
15-
16-
// Always filter based on allowedInModesByDefault, even if no explicit restrictions
17-
availableServers = availableServers.filter((server) => {
18-
// Get server configuration to check allowedInModesByDefault setting
19-
const serverConfig = args.mcpHub?.getServerConfig(server.name)
20-
const allowedInModesByDefault = serverConfig?.allowedInModesByDefault ?? true // Default to true if not specified
21-
22-
return isServerAllowedForMode(server.name, restrictions, allowedInModesByDefault)
23-
})
24-
}
25-
26-
// Generate description with filtered servers and their available resources
27-
if (availableServers.length === 0) {
28-
return `## access_mcp_resource
29-
Description: Request to access a resource provided by a connected MCP server. Resources represent data sources that can be used as context, such as files, API responses, or system information.
30-
**Note: No MCP servers are available for the current mode.**
31-
32-
This tool allows you to access resources provided by Model Context Protocol (MCP) servers, but the current mode has restrictions that prevent access to all configured MCP servers.
33-
34-
Parameters:
35-
- server_name: (required) The name of the MCP server providing the resource
36-
- uri: (required) The URI identifying the specific resource to access`
37-
}
38-
39-
const serverDescriptions = availableServers
40-
.map((server) => {
41-
const resourceCount = (server.resources || []).length
42-
const resourceTemplateCount = (server.resourceTemplates || []).length
43-
const totalResources = resourceCount + resourceTemplateCount
44-
45-
return `**${server.name}**: ${totalResources} resource${totalResources !== 1 ? "s" : ""} available`
46-
})
47-
.join("\n")
48-
497
return `## access_mcp_resource
508
Description: Request to access a resource provided by a connected MCP server. Resources represent data sources that can be used as context, such as files, API responses, or system information.
51-
52-
**Available servers for current mode:**
53-
${serverDescriptions}
54-
559
Parameters:
5610
- server_name: (required) The name of the MCP server providing the resource
5711
- uri: (required) The URI identifying the specific resource to access
58-
5912
Usage:
6013
<access_mcp_resource>
6114
<server_name>server name here</server_name>

src/core/prompts/tools/use-mcp-tool.ts

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,15 @@
11
import { ToolArgs } from "./types"
2-
import { getModeBySlug, isServerAllowedForMode, isToolAllowedForModeAndServer } from "../../../shared/modes"
32

43
export function getUseMcpToolDescription(args: ToolArgs): string | undefined {
54
if (!args.mcpHub) {
65
return undefined
76
}
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-
697
return `## use_mcp_tool
708
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-
759
Parameters:
7610
- server_name: (required) The name of the MCP server providing the tool
7711
- tool_name: (required) The name of the tool to execute
7812
- arguments: (required) A JSON object containing the tool's input parameters, following the tool's input schema
79-
8013
Usage:
8114
<use_mcp_tool>
8215
<server_name>server name here</server_name>

src/core/tools/__tests__/useMcpToolTool.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ describe("useMcpToolTool", () => {
4040
deref: vi.fn().mockReturnValue({
4141
getMcpHub: vi.fn().mockReturnValue({
4242
callTool: vi.fn(),
43+
getServerConfig: vi.fn().mockReturnValue({
44+
allowedInModesByDefault: true,
45+
}),
4346
}),
4447
postMessageToWebview: vi.fn(),
48+
getState: vi.fn().mockReturnValue({
49+
mode: "code",
50+
customModes: [],
51+
}),
4552
}),
4653
}
4754

@@ -192,8 +199,15 @@ describe("useMcpToolTool", () => {
192199
mockProviderRef.deref.mockReturnValue({
193200
getMcpHub: () => ({
194201
callTool: vi.fn().mockResolvedValue(mockToolResult),
202+
getServerConfig: vi.fn().mockReturnValue({
203+
allowedInModesByDefault: true,
204+
}),
195205
}),
196206
postMessageToWebview: vi.fn(),
207+
getState: vi.fn().mockReturnValue({
208+
mode: "code",
209+
customModes: [],
210+
}),
197211
})
198212

199213
await useMcpToolTool(

0 commit comments

Comments
 (0)