diff --git a/internal/awsdevops/export_test.go b/internal/awsdevops/export_test.go index 38904942..1bf7e317 100644 --- a/internal/awsdevops/export_test.go +++ b/internal/awsdevops/export_test.go @@ -21,3 +21,8 @@ func ConnectExisting(ctx context.Context, clients Clients, opts SetupOptions) (S return ConnectPlan(ctx, clients, opts, plan) } + +// MCPTools lists every tool in the allowlist, for tests. +func MCPTools() []string { + return append(append([]string{}, mcpReadOnlyTools...), mcpMutativeTools...) +} diff --git a/internal/awsdevops/lookup.go b/internal/awsdevops/lookup.go index 444d41e4..a8efbdae 100644 --- a/internal/awsdevops/lookup.go +++ b/internal/awsdevops/lookup.go @@ -197,10 +197,18 @@ func agentSpaceARN(region, accountID, spaceID string) string { return fmt.Sprintf("arn:aws:aidevops:%s:%s:agentspace/%s", region, accountID, spaceID) } +// mcpServerIDLength is the length to truncate the agent space ID to in the +// server name. +const mcpServerIDLength = 12 + // MCPServerNameFor is the name of the MCP server that setup registers for an // agent space. AWS needs a unique name of letters, digits, "_" and "-", and -// the ID ties the server to the space. +// the end of the ID ties the server to the space. func MCPServerNameFor(agentSpaceID string) string { + if len(agentSpaceID) > mcpServerIDLength { + agentSpaceID = agentSpaceID[len(agentSpaceID)-mcpServerIDLength:] + } + return MCPServerName + "-" + agentSpaceID } diff --git a/internal/awsdevops/runplan_test.go b/internal/awsdevops/runplan_test.go index f69ffbd6..1a7edc8f 100644 --- a/internal/awsdevops/runplan_test.go +++ b/internal/awsdevops/runplan_test.go @@ -1361,3 +1361,17 @@ func TestMCPServerNameForHasOnlyAllowedCharacters(t *testing.T) { assert.Regexp(t, `^[a-zA-Z0-9_-]{1,128}$`, name) } + +// The name keeps the last group of a UUID space ID. +func TestMCPServerNameForKeepsTheEndOfTheSpaceID(t *testing.T) { + assert.Equal(t, "LaunchDarkly-3f4e5d6c7b8a", awsdevops.MCPServerNameFor("0b9f6c3e-5d7a-4c1e-9a2b-3f4e5d6c7b8a")) +} + +// AWS caps the server name, "_" and a tool name at 64 characters. +func TestMCPServerNameForLeavesRoomForEveryTool(t *testing.T) { + name := awsdevops.MCPServerNameFor("0b9f6c3e-5d7a-4c1e-9a2b-3f4e5d6c7b8a") + + for _, tool := range awsdevops.MCPTools() { + assert.LessOrEqual(t, len(name+"_"+tool), 64, tool) + } +}