Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 14:45 UTC
fix(docs): complete generated string escaping
jkomyno committed
Aug 26, 2026 at 17:41 UTC
678ac7260a1976e373d167aea0b68b47e2a76cb7
7 files changed
+73
-9
docs/app/llms.mdx/[[...slug]]/route.ts
+2
-1
@@ -24,6 +24,7 @@ import { readFile } from 'fs/promises';
24
import { join } from 'path';
25
import { getAllToolkits, getToolkitBySlug } from '@/lib/toolkit-data';
26
import { getAllMetaTools, getMetaToolBySlug } from '@/lib/meta-tools-data';
27
+import { encodeMarkdownTableCell } from '@/lib/markdown-escaping';
28
import type { MetaTool, MetaToolParameter } from '@/lib/meta-tools-data';
29
import type { Toolkit, Tool, Trigger, ParameterSchema } from '@/types/toolkit';
30
import { apiToolListSchema, apiTriggerListSchema } from '@/lib/toolkit-schema';
@@ -819,7 +820,7 @@ function renderParamsMarkdown(params: Record<string, ParameterSchema>): string[]
820
for (const [name, param] of Object.entries(params)) {
821
const typeStr = formatParamType(param);
822
const required = param.required ? 'Yes' : 'No';
822
- const desc = (param.description || '').replace(/\|/g, '\\|').replace(/\n/g, ' ');
823
+ const desc = encodeMarkdownTableCell(param.description || '');
824
lines.push(`| \`${name}\` | ${typeStr} | ${required} | ${desc} |`);
825
}
826
docs/lib/markdown-escaping.ts
new
+7
@@ -0,0 +1,7 @@
1
+export function encodeMarkdownTableCell(value: string): string {
2
+ return value.replace(/\r\n?|\n/g, ' ').replace(/\|/g, '|');
3
+}
4
+
5
+export function encodeYamlString(value: string): string {
6
+ return JSON.stringify(value);
7
+}
docs/scripts/generate-meta-tools.ts
+7
-6
@@ -20,6 +20,7 @@ import { writeFile, mkdir, readdir, unlink } from 'fs/promises';
20
import { join } from 'path';
21
import { fetchWithRetry } from './fetch-with-retry';
22
import { META_TOOL_OVERRIDES } from '../lib/meta-tool-overrides';
23
+import { encodeMarkdownTableCell, encodeYamlString } from '../lib/markdown-escaping';
24
import { requireProductionApiV3Url, stripStagingHosts } from './production-api.mjs';
25
import { z } from 'zod';
26
@@ -177,13 +178,13 @@ function indexLine(tool: GeneratedMetaTool): string {
178
if (override) {
179
// First sentence of the hand-written summary keeps the table tight.
180
const firstSentence = override.summary.split(/\.(\s|$)/)[0].trim();
180
- return firstSentence.replace(/\|/g, '\\|');
181
+ return encodeMarkdownTableCell(firstSentence);
182
}
182
- return briefDescription(tool.description).replace(/\|/g, '\\|');
183
+ return encodeMarkdownTableCell(briefDescription(tool.description));
184
}
185
186
/** Generate the index.mdx overview page — Modal-voice intro plus a one-line-per-tool table */
186
-function generateIndexMdx(tools: GeneratedMetaTool[]): string {
187
+export function generateIndexMdx(tools: GeneratedMetaTool[]): string {
188
let content = `---
189
title: Meta Tools
190
description: The system tools every Composio session gives your agent to discover, authenticate, execute, and process tools at runtime.
@@ -218,12 +219,12 @@ These schemas are for reference only. We do not guarantee backward compatibility
219
}
220
221
/** Generate an individual tool MDX page */
221
-function generateToolMdx(tool: GeneratedMetaTool): string {
222
- const desc = briefDescription(tool.description).replace(/"/g, '\\"');
222
+export function generateToolMdx(tool: GeneratedMetaTool): string {
223
+ const desc = encodeYamlString(briefDescription(tool.description));
224
225
return `---
226
title: ${tool.displayName}
226
-description: "${desc}"
227
+description: ${desc}
228
keywords: [${tool.slug}, meta tool]
229
---
230
docs/tests/static/generate-toolkits.test.ts
+25
-1
@@ -23,7 +23,11 @@ import {
23
transformAuthConfigDetail,
24
transformToolkit,
25
} from "../../scripts/generate-toolkits";
26
-import { transformTool } from "../../scripts/generate-meta-tools";
26
+import {
27
+ generateIndexMdx,
28
+ generateToolMdx,
29
+ transformTool,
30
+} from "../../scripts/generate-meta-tools";
31
32
describe("transformToolkit", () => {
33
test("excludes the synthetic test_app catalog residue from public docs", () => {
@@ -342,6 +346,26 @@ describe("transformTool (generate-meta-tools.ts)", () => {
346
expect(tool.inputParameters).toEqual({});
347
expect(tool.responseSchema).toEqual({});
348
});
349
+
350
+ test("encodes table delimiters in generated index descriptions", () => {
351
+ const tool = transformTool({
352
+ slug: "COMPOSIO_X",
353
+ name: "composio_x",
354
+ description: String.raw`Compare \| and | values`,
355
+ });
356
+
357
+ expect(generateIndexMdx([tool])).toContain(String.raw`Compare \| and | values`);
358
+ });
359
+
360
+ test("serializes generated frontmatter descriptions as YAML strings", () => {
361
+ const tool = transformTool({
362
+ slug: "COMPOSIO_X",
363
+ name: "composio_x",
364
+ description: 'Use "quotes" at C:\\tools',
365
+ });
366
+
367
+ expect(generateToolMdx(tool)).toContain('description: "Use \\"quotes\\" at C:\\\\tools"');
368
+ });
369
});
370
371
describe("parseToolkitsPage", () => {
docs/tests/static/markdown-escaping.test.ts
new
+23
@@ -0,0 +1,23 @@
1
+import { describe, expect, test } from "bun:test";
2
+
3
+import { encodeMarkdownTableCell, encodeYamlString } from "../../lib/markdown-escaping";
4
+
5
+describe("Markdown and frontmatter escaping", () => {
6
+ test("encodes every table delimiter without consuming existing backslashes", () => {
7
+ expect(encodeMarkdownTableCell(String.raw`first \| second | third`)).toBe(
8
+ String.raw`first \| second | third`
9
+ );
10
+ });
11
+
12
+ test("collapses every line ending inside table cells", () => {
13
+ expect(encodeMarkdownTableCell("first\r\nsecond\rthird\nfourth")).toBe(
14
+ "first second third fourth"
15
+ );
16
+ });
17
+
18
+ test("serializes quotes, backslashes, and control characters as a YAML string", () => {
19
+ expect(encodeYamlString('Use "quotes" at C:\\tools\nnext')).toBe(
20
+ '"Use \\"quotes\\" at C:\\\\tools\\nnext"'
21
+ );
22
+ });
23
+});
ts/packages/core/scripts/generate-docs.ts
+2
-1
@@ -1004,8 +1004,9 @@ function toKebabCase(str: string): string {
1004
1005
// Escape text content for MDX (descriptions, etc. that appear outside backticks)
1006
// Handles both curly braces and angle brackets (which MDX interprets as JSX tags)
1007
-function escapeTextForMdx(str: string): string {
1007
+export function escapeTextForMdx(str: string): string {
1008
return str
1009
+ .replace(/\\/g, '\\\\')
1010
.replace(/\{/g, '\\{')
1011
.replace(/\}/g, '\\}')
1012
.replace(/</g, '<')
ts/packages/core/test/scripts/generate-docs.test.ts
+7
@@ -1,5 +1,6 @@
1
import { describe, expect, it } from 'vitest';
2
import {
3
+ escapeTextForMdx,
4
escapeTypeForMdx,
5
parseSourceSignatureTypesAtLine,
6
simplifyTypeForSignature,
@@ -37,6 +38,12 @@ describe('generate-docs type rendering', () => {
38
expect(escapeTypeForMdx(String.raw`{ pattern: '\|' }`)).toBe(String.raw`\{ pattern: '\\\|' \}`);
39
});
40
41
+ it('escapes existing backslashes before MDX text metacharacters', () => {
42
+ expect(escapeTextForMdx(String.raw`Use \{value\} or <literal>`)).toBe(
43
+ String.raw`Use \\\{value\\\} or <literal>`
44
+ );
45
+ });
46
+
47
it('reads named parameter and return types from source signatures', () => {
48
const source = `
49
class Example {