Skip to content

Commit fc8cc10

Browse files
authored
fix: remove hardcoding of builtIn and builtInWrite tools (#1774)
1 parent 788d8ed commit fc8cc10

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ describe('AgenticChatController', () => {
241241
),
242242
addTool: sinon.stub().resolves(),
243243
removeTool: sinon.stub().resolves(),
244-
getBuiltInToolNames: sinon.stub().resolves(),
245-
getBuiltInWriteToolNames: sinon.stub().resolves(),
244+
getBuiltInToolNames: sinon.stub().returns(['fsRead']),
245+
getBuiltInWriteToolNames: sinon.stub().returns(['fsWrite']),
246246
} as any // Using 'as any' to prevent type errors when the Agent interface is updated with new methods
247247

248248
additionalContextProviderStub = sinon.stub(AdditionalContextProvider.prototype, 'getAdditionalContext')

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,10 +1919,7 @@ export class AgenticChatController implements ChatHandlers {
19191919
}
19201920

19211921
// Determine if this is a built-in tool or MCP tool
1922-
// TODO: add agent.getBuiltInTools to avoid hardcoding the list here
1923-
const isStandardTool =
1924-
toolName !== undefined &&
1925-
['executeBash', 'fsWrite', 'fsRead', 'listDirectory', 'fsReplace', 'fileSearch'].includes(toolName)
1922+
const isStandardTool = toolName !== undefined && this.#features.agent.getBuiltInToolNames().includes(toolName)
19261923

19271924
if (isStandardTool) {
19281925
return {
@@ -3368,13 +3365,11 @@ export class AgenticChatController implements ChatHandlers {
33683365
}
33693366

33703367
#getTools(session: ChatSessionService) {
3368+
const builtInWriteTools = new Set(this.#features.agent.getBuiltInWriteToolNames())
33713369
const allTools = this.#features.agent.getTools({ format: 'bedrock' })
33723370
if (!enabledMCP(this.#features.lsp.getClientInitializeParams())) {
33733371
if (!session.pairProgrammingMode) {
3374-
return allTools.filter(
3375-
// TODO: add agent.getBuiltInReadOnlyTools or agent.getBuiltInWriteTools to avoid hardcoding
3376-
tool => !['fsWrite', 'fsReplace', 'executeBash'].includes(tool.toolSpecification?.name || '')
3377-
)
3372+
return allTools.filter(tool => !builtInWriteTools.has(tool.toolSpecification?.name || ''))
33783373
}
33793374
return allTools
33803375
}
@@ -3395,8 +3390,7 @@ export class AgenticChatController implements ChatHandlers {
33953390
)
33963391

33973392
McpManager.instance.setToolNameMapping(tempMapping)
3398-
const writeToolNames = new Set(['fsWrite', 'fsReplace', 'executeBash'])
3399-
const restrictedToolNames = new Set([...mcpToolSpecNames, ...writeToolNames])
3393+
const restrictedToolNames = new Set([...mcpToolSpecNames, ...builtInWriteTools])
34003394

34013395
const readOnlyTools = allTools.filter(tool => {
34023396
const toolName = tool.toolSpecification.name

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/toolServer.ts

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { CancellationToken, Server } from '@aws/language-server-runtimes/server-interface'
1+
import { CancellationToken, Server, ToolClassification } from '@aws/language-server-runtimes/server-interface'
22
import { FsRead, FsReadParams } from './fsRead'
33
import { FsWrite, FsWriteParams } from './fsWrite'
44
import { ListDirectory, ListDirectoryParams } from './listDirectory'
55
import { ExecuteBash, ExecuteBashParams } from './executeBash'
66
import { LspGetDocuments, LspGetDocumentsParams } from './lspGetDocuments'
77
import { LspReadDocumentContents, LspReadDocumentContentsParams } from './lspReadDocumentContents'
8-
import { LspApplyWorkspaceEdit, LspApplyWorkspaceEditParams } from './lspApplyWorkspaceEdit'
8+
import { LspApplyWorkspaceEdit } from './lspApplyWorkspaceEdit'
99
import { AGENT_TOOLS_CHANGED, McpManager } from './mcp/mcpManager'
1010
import { McpTool } from './mcp/mcpTool'
1111
import { FileSearch, FileSearchParams } from './fileSearch'
@@ -30,36 +30,56 @@ export const FsToolsServer: Server = ({ workspace, logging, agent, lsp }) => {
3030
const grepSearchTool = new GrepSearch({ workspace, logging, lsp })
3131
const fsReplaceTool = new FsReplace({ workspace, lsp, logging })
3232

33-
agent.addTool(fsReadTool.getSpec(), async (input: FsReadParams) => {
34-
await fsReadTool.validate(input)
35-
return await fsReadTool.invoke(input)
36-
})
33+
agent.addTool(
34+
fsReadTool.getSpec(),
35+
async (input: FsReadParams) => {
36+
await fsReadTool.validate(input)
37+
return await fsReadTool.invoke(input)
38+
},
39+
ToolClassification.BuiltIn
40+
)
3741

38-
agent.addTool(fsWriteTool.getSpec(), async (input: FsWriteParams) => {
39-
await fsWriteTool.validate(input)
40-
return await fsWriteTool.invoke(input)
41-
})
42+
agent.addTool(
43+
fsWriteTool.getSpec(),
44+
async (input: FsWriteParams) => {
45+
await fsWriteTool.validate(input)
46+
return await fsWriteTool.invoke(input)
47+
},
48+
ToolClassification.BuiltInCanWrite
49+
)
4250

43-
agent.addTool(fsReplaceTool.getSpec(), async (input: FsReplaceParams) => {
44-
await fsReplaceTool.validate(input)
45-
return await fsReplaceTool.invoke(input)
46-
})
51+
agent.addTool(
52+
fsReplaceTool.getSpec(),
53+
async (input: FsReplaceParams) => {
54+
await fsReplaceTool.validate(input)
55+
return await fsReplaceTool.invoke(input)
56+
},
57+
ToolClassification.BuiltInCanWrite
58+
)
4759

48-
agent.addTool(listDirectoryTool.getSpec(), async (input: ListDirectoryParams, token?: CancellationToken) => {
49-
await listDirectoryTool.validate(input)
50-
return await listDirectoryTool.invoke(input, token)
51-
})
60+
agent.addTool(
61+
listDirectoryTool.getSpec(),
62+
async (input: ListDirectoryParams, token?: CancellationToken) => {
63+
await listDirectoryTool.validate(input)
64+
return await listDirectoryTool.invoke(input, token)
65+
},
66+
ToolClassification.BuiltIn
67+
)
5268

53-
agent.addTool(fileSearchTool.getSpec(), async (input: FileSearchParams, token?: CancellationToken) => {
54-
await fileSearchTool.validate(input)
55-
return await fileSearchTool.invoke(input, token)
56-
})
69+
agent.addTool(
70+
fileSearchTool.getSpec(),
71+
async (input: FileSearchParams, token?: CancellationToken) => {
72+
await fileSearchTool.validate(input)
73+
return await fileSearchTool.invoke(input, token)
74+
},
75+
ToolClassification.BuiltIn
76+
)
5777

5878
// Temporarily disable grep search
5979
// agent.addTool(grepSearchTool.getSpec(), async (input: GrepSearchParams, token?: CancellationToken) => {
6080
// await grepSearchTool.validate(input)
6181
// return await grepSearchTool.invoke(input, token)
62-
// })
82+
// }, ToolClassification.BuiltIn)
6383

6484
return () => {}
6585
}
@@ -71,7 +91,8 @@ export const BashToolsServer: Server = ({ logging, workspace, agent, lsp }) => {
7191
async (input: ExecuteBashParams, token?: CancellationToken, updates?: WritableStream) => {
7292
await bashTool.validate(input)
7393
return await bashTool.invoke(input, token, updates)
74-
}
94+
},
95+
ToolClassification.BuiltInCanWrite
7596
)
7697
return () => {}
7798
}
@@ -136,7 +157,8 @@ export const McpToolsServer: Server = ({ credentialsProvider, workspace, logging
136157
description: def.description?.trim() || 'undefined',
137158
inputSchema: inputSchemaWithExplanation,
138159
},
139-
input => tool.invoke(input)
160+
input => tool.invoke(input),
161+
ToolClassification.MCP
140162
)
141163
registered[server].push(namespaced)
142164
logging.info(`MCP: registered tool ${namespaced} (original: ${def.toolName})`)

0 commit comments

Comments
 (0)