Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/awsdevops/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
10 changes: 9 additions & 1 deletion internal/awsdevops/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 14 additions & 0 deletions internal/awsdevops/runplan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading