Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f88fd74

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular/cli): use main element extraction for MCP doc search
The angular.dev documenation now uses `main` elements within each page to indicate the actual content. To reduce the amount of HTML passed back in the MCP `search_documentation` tool, only the `main` element is now used instead of the entire `body` element.
1 parent aae5374 commit f88fd74

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

‎packages/angular/cli/src/commands/mcp/tools/doc-search.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function createDocSearchHandler() {
101101
const response = await fetch(url);
102102
if (response.ok) {
103103
const html = await response.text();
104-
const mainContent = extractBodyContent(html);
104+
const mainContent = extractMainContent(html);
105105
if (mainContent) {
106106
topText += `\n\n--- DOCUMENTATION CONTENT ---\n${mainContent}`;
107107
}
@@ -129,24 +129,23 @@ function createDocSearchHandler() {
129129
}
130130

131131
/**
132-
* Extracts the content of the `<body>` element from an HTML string.
132+
* Extracts the content of the `<main>` element from an HTML string.
133133
*
134134
* @param html The HTML content of a page.
135-
* @returns The content of the `<body>` element, or `undefined` if not found.
135+
* @returns The content of the `<main>` element, or `undefined` if not found.
136136
*/
137-
function extractBodyContent(html: string): string | undefined {
138-
// TODO: Use '<main>' element instead of '<body>' when available in angular.dev HTML.
139-
const mainTagStart = html.indexOf('<body');
137+
function extractMainContent(html: string): string | undefined {
138+
const mainTagStart = html.indexOf('<main');
140139
if (mainTagStart === -1) {
141140
return undefined;
142141
}
143142

144-
const mainTagEnd = html.lastIndexOf('</body>');
143+
const mainTagEnd = html.lastIndexOf('</main>');
145144
if (mainTagEnd <= mainTagStart) {
146145
return undefined;
147146
}
148147

149-
// Add 7 to include '</body>'
148+
// Add 7 to include '</main>'
150149
return html.substring(mainTagStart, mainTagEnd + 7);
151150
}
152151

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /