Skip to content

Commit 122a8c0

Browse files
committed
fix(@angular/cli): correct frontmatter parsing in MCP examples tool
This commit fixes a bug in the YAML frontmatter parsing logic that caused string values in arrays to be double-quoted. The issue was present in both the `find_examples` MCP tool's runtime parser and the `example_db_generator.js` script. The `parseFrontmatter` function in both files has been updated to correctly unquote string values, ensuring that the structured data in the examples database is clean and the tool's output is formatted correctly.
1 parent 4311065 commit 122a8c0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/angular/cli/src/commands/mcp/tools/examples.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,15 @@ function parseFrontmatter(content: string): Record<string, unknown> {
546546
} else {
547547
const arrayItemMatch = line.match(/^\s*-\s*(.*)/);
548548
if (arrayItemMatch && currentKey && isArray) {
549-
arrayValues.push(arrayItemMatch[1].trim());
549+
let value = arrayItemMatch[1].trim();
550+
// Unquote if the value is quoted.
551+
if (
552+
(value.startsWith("'") && value.endsWith("'")) ||
553+
(value.startsWith('"') && value.endsWith('"'))
554+
) {
555+
value = value.slice(1, -1);
556+
}
557+
arrayValues.push(value);
550558
}
551559
}
552560
}

tools/example_db_generator.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ function parseFrontmatter(content) {
6060
} else {
6161
const arrayItemMatch = line.match(/^\s*-\s*(.*)/);
6262
if (arrayItemMatch && currentKey && isArray) {
63-
arrayValues.push(arrayItemMatch[1].trim());
63+
let value = arrayItemMatch[1].trim();
64+
// Unquote if the value is quoted.
65+
if (
66+
(value.startsWith("'") && value.endsWith("'")) ||
67+
(value.startsWith('"') && value.endsWith('"'))
68+
) {
69+
value = value.slice(1, -1);
70+
}
71+
arrayValues.push(value);
6472
}
6573
}
6674
}

0 commit comments

Comments
 (0)