Skip to content

Commit 8e42547

Browse files
committed
fix: remove dots and colons from MCP tool names for Bedrock compatibility
AWS Bedrock requires tool names to match [a-zA-Z0-9_-]+ pattern. Previously, dots and colons were allowed, causing validation errors for MCP servers with names like 'awslabs.aws-documentation-mcp-server'.
1 parent 2863b1c commit 8e42547

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/utils/__tests__/mcp-name.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,24 @@ describe("mcp-name utilities", () => {
2323
expect(sanitizeMcpName("test#$%^&*()")).toBe("test")
2424
})
2525

26-
it("should keep valid characters (alphanumeric, underscore, dot, colon, dash)", () => {
26+
it("should keep valid characters (alphanumeric, underscore, dash)", () => {
2727
expect(sanitizeMcpName("server_name")).toBe("server_name")
28-
expect(sanitizeMcpName("server.name")).toBe("server.name")
29-
expect(sanitizeMcpName("server:name")).toBe("server:name")
3028
expect(sanitizeMcpName("server-name")).toBe("server-name")
3129
expect(sanitizeMcpName("Server123")).toBe("Server123")
3230
})
3331

32+
it("should remove dots and colons for AWS Bedrock compatibility", () => {
33+
// Dots and colons are NOT allowed due to AWS Bedrock restrictions
34+
expect(sanitizeMcpName("server.name")).toBe("servername")
35+
expect(sanitizeMcpName("server:name")).toBe("servername")
36+
expect(sanitizeMcpName("awslabs.aws-documentation-mcp-server")).toBe("awslabsaws-documentation-mcp-server")
37+
})
38+
3439
it("should prepend underscore if name starts with non-letter/underscore", () => {
3540
expect(sanitizeMcpName("123server")).toBe("_123server")
3641
expect(sanitizeMcpName("-server")).toBe("_-server")
37-
expect(sanitizeMcpName(".server")).toBe("_.server")
42+
// Dots are removed, so ".server" becomes "server" which starts with a letter
43+
expect(sanitizeMcpName(".server")).toBe("server")
3844
})
3945

4046
it("should not modify names that start with letter or underscore", () => {

src/utils/mcp-name.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/**
22
* Utilities for sanitizing MCP server and tool names to conform to
3-
* API function name requirements (e.g., Gemini's restrictions).
4-
*
5-
* Gemini function name requirements:
6-
* - Must start with a letter or an underscore
7-
* - Must be alphanumeric (a-z, A-Z, 0-9), underscores (_), dots (.), colons (:), or dashes (-)
8-
* - Maximum length of 64 characters
3+
* API function name requirements across all providers.
94
*/
105

116
/**
127
* Separator used between MCP prefix, server name, and tool name.
138
* We use "--" (double hyphen) because:
14-
* 1. It's allowed by Gemini (dashes are permitted in function names)
9+
* 1. It's allowed by all providers (dashes are permitted in function names)
1510
* 2. It won't conflict with underscores in sanitized server/tool names
1611
* 3. It's unique enough to be a reliable delimiter for parsing
1712
*/
@@ -40,8 +35,8 @@ export function sanitizeMcpName(name: string): string {
4035
// Replace spaces with underscores first
4136
let sanitized = name.replace(/\s+/g, "_")
4237

43-
// Remove any characters that are not alphanumeric, underscores, dots, colons, or dashes
44-
sanitized = sanitized.replace(/[^a-zA-Z0-9_.\-:]/g, "")
38+
// Only allow alphanumeric, underscores, and dashes
39+
sanitized = sanitized.replace(/[^a-zA-Z0-9_\-]/g, "")
4540

4641
// Replace any double-hyphen sequences with single hyphen to avoid separator conflicts
4742
sanitized = sanitized.replace(/--+/g, "-")

0 commit comments

Comments
 (0)