Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): read a markdown link of any kind as its label alone
marcoteb12f086bc3dd4
diff --git a/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts b/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.tsindex 56400bda7..1bb7c60a5 100644--- a/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts+++ b/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts@@ -730,6 +730,26 @@ describe('generated internal artifact attachments', () => {})+ it.each([+ ['an anchor link', 'probe-[redaction](#notes)-value'],+ ['a relative link', 'probe-[redaction](notes.md)-value'],+ ['an angle-bracket destination', 'probe-[redaction](<notes page.md>)-value'],+ ['a reference link', 'probe-[redaction][r]-value\n\n[r]: https://a.example'],+ ['a bidi control', 'probe-red\u202aaction-value'],+ ])(+ 'does not attach markdown that splits a protected value with %s',+ async (_label, content) => {+ const result = await toolWith('clerum__generate_markdown', [+ 'probe-redaction-value',+ ]).execute({+ filename: 'split.md',+ content,+ })+ expect(result.is_error).toBe(false)+ expect(result.attachments ?? []).toHaveLength(0)+ }+ )+it('attaches a chart whose decimal label only runs the digits of a protected number together', async () => {const result = await toolWith('clerum__generate_chart', ['5432']).execute({filename: 'pct.png',diff --git a/mcp-host/src/workflow/toolText.ts b/mcp-host/src/workflow/toolText.tsindex 0e19ae9b7..96a1b4275 100644--- a/mcp-host/src/workflow/toolText.ts+++ b/mcp-host/src/workflow/toolText.ts@@ -65,8 +65,16 @@ export function cleanToolArgs<T>(value: T, depth = 0): T {return out as T}-/** Characters the document renderers draw as nothing. */-const INVISIBLE = /[--]/g+/** Characters the document renderers draw as nothing, bidi controls among them. */+const INVISIBLE = /[\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]/g++/**+ * Markdown link syntax a viewer does not print: a destination of any kind+ * ("](#notes)", "](notes.md)", "](<a b.md> \"title\")"), a reference ("][r]"),+ * a reference definition line and the brackets around a label.+ */+const LINK_SYNTAX =+ /\]\((?:<[^>\n]*>|[^\s()]*(?:\([^\s()]*\))*)(?:\s+"[^"\n]*")?\)|\]\[[^\]\n]*\]|^\s*\[[^\]\n]+\]:.*$|[[\]]/gm/** A backslash before ASCII punctuation, which markdown prints as that character. */const MARKDOWN_ESCAPE = /\\([!-/:-@[-`{-~])/g@@ -76,7 +84,8 @@ const MARKDOWN_ESCAPE = /\\([!-/:-@[-`{-~])/g* document generator may print it: as sent, cleaned as cleanToolArgs cleans* it, with HTML tags, character references, backslash escapes and invisible* characters taken out, with markdown markers taken out too, and read as- * inline markdown, where a link prints its label. Text split by any of these+ * inline markdown, where a link prints its label, and with the syntax of a+ * link of any kind taken out. Text split by any of these* prints whole, so a check for leaked secrets that reads every form sees it* whole. Keys count because a generator can print one, as an XLSX sheet prints* the keys of record rows as its header. Like cleanToolArgs, it reads no@@ -109,5 +118,7 @@ export function printedForms(args: unknown): string[] {.join('').replace(INVISIBLE, ''))- return [...sent, ...cleaned, ...printed, ...bare, ...spoken]+ // As a markdown viewer prints a link of any kind: its label only.+ const unlinked = bare.map(text => text.replace(LINK_SYNTAX, ''))+ return [...sent, ...cleaned, ...printed, ...bare, ...spoken, ...unlinked]}