Skip to content

Commit 6663f87

Browse files
authored
fix: enforce MAX_TOOL_NAME_LENGTH check in createNamespacedToolName (#2447)
1 parent 82e2340 commit 6663f87

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpUtils.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,17 @@ describe('createNamespacedToolName', () => {
543543
toolName: longTool,
544544
})
545545
})
546+
547+
it('truncates tool name and adds suffix when it exceeds MAX_TOOL_NAME_LENGTH', () => {
548+
const longTool = 'Smartanalyzerthatreadssummariescreatesmappingrulesandupdatespayloads'
549+
const result = createNamespacedToolName('ConnectiveRx', longTool, tools, toolNameMapping)
550+
expect(result.length).to.equal(MAX_TOOL_NAME_LENGTH)
551+
expect(tools.has(result)).to.be.true
552+
expect(toolNameMapping.get(result)).to.deep.equal({
553+
serverName: 'ConnectiveRx',
554+
toolName: longTool,
555+
})
556+
})
546557
})
547558

548559
describe('normalizePathFromUri', () => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,8 @@ export function createNamespacedToolName(
11681168
// Sanitize the tool name
11691169
const sanitizedToolName = sanitizeName(toolName)
11701170

1171-
// First try to use just the tool name if it's not already in use
1172-
if (!allNamespacedTools.has(sanitizedToolName)) {
1171+
// First try to use just the tool name if it's not already in use and fits within length limit
1172+
if (sanitizedToolName.length <= MAX_TOOL_NAME_LENGTH && !allNamespacedTools.has(sanitizedToolName)) {
11731173
allNamespacedTools.add(sanitizedToolName)
11741174
toolNameMapping.set(sanitizedToolName, { serverName, toolName })
11751175
return sanitizedToolName

0 commit comments

Comments
 (0)