{"record":{"id":"3aec6c17621967ef","repo":"thedotmack/claude-mem","slug":"found-mcpservers-claude-mem-markers-but-could-not","errorCode":null,"errorMessage":"Found mcpServers/claude-mem markers but could not locate a replaceable claude-mem block","messagePattern":"Found mcpServers/claude-mem markers but could not locate a replaceable claude-mem block","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/integrations/McpIntegrations.ts","lineNumber":192,"sourceCode":"    mergeGooseYamlConfig(configPath, mcpServerPath);\n    return 0;\n  } catch (error) {\n    const message = error instanceof Error ? error.message : String(error);\n    console.error(`\\nInstallation failed: ${message}`);\n    return 1;\n  }\n}\n\nfunction mergeGooseYamlConfig(configPath: string, mcpServerPath: string): void {\n  if (existsSync(configPath)) {\n    let yamlContent = readFileSync(configPath, 'utf-8');\n\n    if (gooseConfigHasClaudeMemEntry(yamlContent)) {\n      const claudeMemPattern = /( {2}claude-mem:\\n(?:.*\\n)*?(?= {2}\\S|\\n\\n|^\\S|$))/m;\n      const newEntry = buildGooseClaudeMemEntryYaml(mcpServerPath) + '\\n';\n\n      if (!claudeMemPattern.test(yamlContent)) {\n        throw new Error('Found mcpServers/claude-mem markers but could not locate a replaceable claude-mem block');\n      }\n      yamlContent = yamlContent.replace(claudeMemPattern, newEntry);\n      writeFileSync(configPath, yamlContent);\n      console.log(`  Updated existing claude-mem entry in: ${configPath}`);\n    } else if (yamlContent.includes('mcpServers:')) {\n      const mcpServersIndex = yamlContent.indexOf('mcpServers:');\n      const insertionPoint = mcpServersIndex + 'mcpServers:'.length;\n      const newEntry = '\\n' + buildGooseClaudeMemEntryYaml(mcpServerPath);\n\n      yamlContent =\n        yamlContent.slice(0, insertionPoint) +\n        newEntry +\n        yamlContent.slice(insertionPoint);\n\n      writeFileSync(configPath, yamlContent);\n      console.log(`  Added claude-mem to existing mcpServers in: ${configPath}`);\n    } else {\n      const mcpBlock = '\\n' + buildGooseClaudeMemEntryYaml(mcpServerPath, true) + '\\n';","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/integrations/McpIntegrations.ts#L174-L210","documentation":"mergeGooseYamlConfig() updates an existing claude-mem MCP entry in a Goose YAML config. It detects that the file already mentions mcpServers/claude-mem, then tries to match the whole two-space-indented 'claude-mem:' block with a regex so it can replace it. If the file contains claude-mem markers but the regex cannot match a well-formed block (malformed or unusually formatted YAML), it throws rather than corrupting the config with a partial replacement.","triggerScenarios":"installGooseMcpIntegration() -> mergeGooseYamlConfig() runs against a ~/.config/goose/config.yaml where gooseConfigHasClaudeMemEntry() returns true (claude-mem/mcpServers markers present) but the regex /( {2}claude-mem:\\n(?:.*\\n)*?(?= {2}\\S|\\n\\n|^\\S|$))/m does not match — e.g. 'claude-mem:' is indented differently, nested deeper, or the block layout deviates from the expected two-space format.","commonSituations":"A hand-edited or tool-reformatted config.yaml with non-standard indentation (tabs, four spaces); claude-mem nested under a different parent key; comments or blank-line patterns between entries breaking the block matcher; a config written by a different Goose version with a different schema.","solutions":["Open the goose config.yaml and reformat the claude-mem entry to the standard two-space top-level layout under mcpServers:, then rerun the installer.","Back up and simplify: move the claude-mem block out (or reset the file to a minimal mcpServers: config) so the installer can insert a clean entry.","Let the installer rewrite the entry by removing the stale claude-mem markers manually and rerunning installGooseMcpIntegration."],"exampleFix":"// before: malformed indentation prevents block match\nmcpServers:\n    claude-mem:\n        command: old-command\n\n// after: standard two-space block the regex can replace\nmcpServers:\n  claude-mem:\n    command: bun\n    args:\n      - /path/to/mcp-server.cjs","handlingStrategy":"try-catch","validationCode":"import { readFileSync } from 'fs';\nconst yaml = readFileSync(gooseConfigPath, 'utf8');\nif (/claude-mem/.test(yaml) && !/( {2}claude-mem:\\n(?:.*\\n)*?(?= {2}\\S|\\n\\n|^\\S|$))/m.test(yaml)) {\n  console.error('Goose config has claude-mem markers but a non-standard block; reformat to two-space indentation first');\n}","typeGuard":null,"tryCatchPattern":"try {\n  installGooseMcpIntegration(configPath, mcpServerPath);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('could not locate a replaceable claude-mem block')) {\n    // back up config.yaml, reformat the claude-mem entry to standard two-space YAML, rerun\n  } else throw err;\n}","preventionTips":["Keep goose config.yaml in the standard two-space-indented schema; avoid hand edits with odd indentation.","Back up the config before running MCP integrations that rewrite it.","If the block is malformed, delete the stale claude-mem entry and let the installer insert a clean one.","Validate the YAML with a parser before running merge-based installers."],"tags":["yaml","config","mcp","goose","parse"],"backgroundTag":"yaml-block-not-found","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}