Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(web-search): preserve XHTML self-closing content
Alfredo Lopez7e16ff43cb72
diff --git a/mcp-servers/web-search/README.md b/mcp-servers/web-search/README.mdindex a2337260e..f9e749986 100644--- a/mcp-servers/web-search/README.md+++ b/mcp-servers/web-search/README.md@@ -60,7 +60,8 @@ Errors expose a stable code without upstream details. Private destinations andoversized documents previously accepted are intentionally rejected. Text extractionignores comments and non-page prose in script, style, textarea and similarcontainers. It is a bounded lightweight scan, not a browser DOM; HTML entities-remain verbatim.+remain verbatim. Self-closing raw-text elements are recognized when the final+response declares XML/XHTML; in HTML syntax, a trailing slash does not close them.### Regression testsdiff --git a/mcp-servers/web-search/package-lock.json b/mcp-servers/web-search/package-lock.jsonindex e1bc4111d..e5020b22a 100644--- a/mcp-servers/web-search/package-lock.json+++ b/mcp-servers/web-search/package-lock.json@@ -1,12 +1,12 @@{"name": "@clerum/web-search-mcp",- "version": "1.0.16",+ "version": "1.0.17","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@clerum/web-search-mcp",- "version": "1.0.16",+ "version": "1.0.17","dependencies": {"@modelcontextprotocol/sdk": "^1.12.1","express": "^4.21.2"diff --git a/mcp-servers/web-search/package.json b/mcp-servers/web-search/package.jsonindex 294865816..398476ed8 100644--- a/mcp-servers/web-search/package.json+++ b/mcp-servers/web-search/package.json@@ -1,6 +1,6 @@{"name": "@clerum/web-search-mcp",- "version": "1.0.16",+ "version": "1.0.17","type": "module","main": "dist/index.js","scripts": {diff --git a/mcp-servers/web-search/src/fetchPage.ts b/mcp-servers/web-search/src/fetchPage.tsindex 150d9f83b..ebc8211a3 100644--- a/mcp-servers/web-search/src/fetchPage.ts+++ b/mcp-servers/web-search/src/fetchPage.ts@@ -56,7 +56,7 @@ function closingTag(html: string, lower: string, name: string, from: number) {const inertText = new Set(['script', 'style', 'textarea', 'xmp', 'iframe', 'noembed', 'noframes'])/** Extract visible page prose and the first real title in linear time. */-function scanPage(html: string): { title: string; content: string } {+function scanPage(html: string, xmlSyntax = false): { title: string; content: string } {const lower = asciiLower(html)const pieces: string[] = []let title = ''@@ -103,6 +103,11 @@ function scanPage(html: string): { title: string; content: string } {offset = end + 1if (!match || lower[start + 1] === '/') continueconst name = match[1]+ // Only XML media types honor '/>' for non-void elements. HTML does not.+ if (xmlSyntax && lower.slice(start, end).trimEnd().endsWith('/')) {+ if (name === 'title') foundTitle = true+ continue+ }if (name === 'plaintext') {pieces.push(html.slice(offset))break@@ -264,7 +269,12 @@ export async function fetchPage(throw new FetchPageError('upstream_failure')const html = await readBody(res, controller.signal)controller.signal.throwIfAborted()- const page = scanPage(html)+ const contentType = res.headers['content-type']+ const mediaType =+ typeof contentType === 'string' ? contentType.split(';', 1)[0].trim().toLowerCase() : ''+ const xmlSyntax =+ mediaType === 'application/xml' || mediaType === 'text/xml' || mediaType.endsWith('+xml')+ const page = scanPage(html, xmlSyntax)return {title: page.title.slice(0, maxChars),content: page.content.slice(0, maxChars),diff --git a/mcp-servers/web-search/test/fetchPage.test.mjs b/mcp-servers/web-search/test/fetchPage.test.mjsindex 059897cc4..41401d6f4 100644--- a/mcp-servers/web-search/test/fetchPage.test.mjs+++ b/mcp-servers/web-search/test/fetchPage.test.mjs@@ -275,3 +275,28 @@ test('plaintext keeps visible content without parsing its tag-like text', () =>test('bogus declarations end at their first greater-than', () => {assert.equal(pageText('<!x=">Visible'), 'Visible')})++for (const tag of ['script', 'style', 'textarea', 'xmp', 'iframe', 'noembed', 'noframes']) {+ test(`XML self-closing ${tag} does not consume following page content`, async t => {+ upstream(t, [+ {+ headers: { 'content-type': 'application/xhtml+xml; charset=utf-8' },+ body: `<${tag} data-value="x"/><title>Actual</title><p>Visible</p>`,+ },+ ])+ assert.deepEqual(await fetchPage('http://8.8.8.8', 100), {+ title: 'Actual',+ content: 'Actual Visible',+ })+ })+}++test('HTML trailing slash does not expose raw script content', async t => {+ upstream(t, [+ {+ headers: { 'content-type': 'text/html' },+ body: '<script src="app.js"/><title>Hidden</title><p>Also hidden</p>',+ },+ ])+ assert.deepEqual(await fetchPage('http://8.8.8.8', 100), { title: '', content: '' })+})diff --git a/mcp-servers/web-search/test/mcp.network.mjs b/mcp-servers/web-search/test/mcp.network.mjsindex 45a9a1d34..33ec6b7eb 100644--- a/mcp-servers/web-search/test/mcp.network.mjs+++ b/mcp-servers/web-search/test/mcp.network.mjs@@ -49,6 +49,11 @@ const upstream = http.createServer((req, res) => {)return}+ if (req.url === '/xhtml-self-close') {+ res.writeHead(200, { 'Content-Type': 'application/xhtml+xml; charset=utf-8' })+ res.end('<script src="app.js"/><title>Actual</title><p>Visible</p>')+ return+ }if (req.url === '/oversize') {res.writeHead(200)res.end('x'.repeat(1024 * 1024 + 1))@@ -152,6 +157,15 @@ test('real MCP extraction ignores inert HTML context', async () => {})})+test('real MCP retains XHTML content after a self-closing raw element', async () => {+ const result = await call('http://11.198.0.2:8080/xhtml-self-close')+ assert.notEqual(result.isError, true)+ assert.deepEqual(JSON.parse(result.content[0].text), {+ title: 'Actual',+ content: 'Actual Visible',+ })+})+test('direct and redirected private requests never touch the trap', async () => {assert.equal(errorCode(await call('http://127.0.0.1:8081/trap')), 'destination_blocked')assert.equal(errorCode(await call('http://11.198.0.2:8080/redirect')), 'destination_blocked')