removeFieldFromMCPServer removes a field from a specific MCP server configuration
(lines []string, serverName string, fieldName string)
| 150 | |
| 151 | // removeFieldFromMCPServer removes a field from a specific MCP server configuration |
| 152 | func removeFieldFromMCPServer(lines []string, serverName string, fieldName string) ([]string, bool) { |
| 153 | var result []string |
| 154 | var modified bool |
| 155 | var inMCPServers bool |
| 156 | var mcpServersIndent string |
| 157 | var inServerBlock bool |
| 158 | var serverIndent string |
| 159 | var inFieldBlock bool |
| 160 | var fieldIndent string |
| 161 | |
| 162 | for i, line := range lines { |
| 163 | trimmedLine := strings.TrimSpace(line) |
| 164 | |
| 165 | // Track if we're in mcp-servers block |
| 166 | if strings.HasPrefix(trimmedLine, "mcp-servers:") { |
| 167 | inMCPServers = true |
| 168 | mcpServersIndent = getIndentation(line) |
| 169 | result = append(result, line) |
| 170 | continue |
| 171 | } |
| 172 | |
| 173 | // Check if we've left mcp-servers block |
| 174 | if inMCPServers && len(trimmedLine) > 0 && !strings.HasPrefix(trimmedLine, "#") { |
| 175 | if hasExitedBlock(line, mcpServersIndent) { |
| 176 | inMCPServers = false |
| 177 | inServerBlock = false |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Track if we're in the specific server block |
| 182 | if inMCPServers && strings.HasPrefix(trimmedLine, serverName+":") { |
| 183 | inServerBlock = true |
| 184 | serverIndent = getIndentation(line) |
| 185 | result = append(result, line) |
| 186 | continue |
| 187 | } |
| 188 | |
| 189 | // Check if we've left the server block |
| 190 | if inServerBlock && len(trimmedLine) > 0 && !strings.HasPrefix(trimmedLine, "#") { |
| 191 | currentIndent := getIndentation(line) |
| 192 | // Exit if we're back at mcp-servers level or less |
| 193 | if len(currentIndent) <= len(serverIndent) && strings.Contains(line, ":") { |
| 194 | inServerBlock = false |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // Remove field line if in server block |
| 199 | if inServerBlock && strings.HasPrefix(trimmedLine, fieldName+":") { |
| 200 | modified = true |
| 201 | inFieldBlock = true |
| 202 | fieldIndent = getIndentation(line) |
| 203 | mcpNetworkCodemodLog.Printf("Removed %s from mcp-server '%s' on line %d", fieldName, serverName, i+1) |
| 204 | continue |
| 205 | } |
| 206 | |
| 207 | // Skip nested properties under the field |
| 208 | if inFieldBlock { |
| 209 | // Empty lines within the field block should be removed |
no test coverage detected