Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix build tools json
Sushmithamallesh committed
Nov 5, 2025 at 21:57 UTC
e5a7941317abaaad0bd1901a8f33426451834a75
1 file changed
+17
-48
fern/scripts/build-tools-json.ts
+17
-48
@@ -25,49 +25,33 @@ interface ToolsData {
25
[key: string]: string[] | ToolkitInfo;
26
}
27
28
-// Parse tool MDX files to extract toolkit information
28
function parseToolkitMdx(toolMdxPath: string): ToolkitInfo | null {
29
try {
30
const fullPath = path.join(TOOLKITS_DIR, toolMdxPath);
31
if (!fs.existsSync(fullPath)) {
33
- console.warn(`⚠️ Tool file not found: ${fullPath}`);
32
return null;
33
}
34
35
const content = fs.readFileSync(fullPath, 'utf8');
36
39
- // Extract frontmatter
37
const frontmatterMatch = content.match(/^---\s*\n([\s\S]*?)\n---/);
41
- if (!frontmatterMatch) {
42
- console.warn(`⚠️ No frontmatter found in: ${toolMdxPath}`);
43
- return null;
44
- }
38
+ if (!frontmatterMatch) return null;
39
40
const frontmatter = frontmatterMatch[1];
41
const titleMatch = frontmatter.match(/title:\s*["']?(.+?)["']?\s*$/m);
48
- if (!titleMatch) {
49
- console.warn(`⚠️ No title found in: ${toolMdxPath}`);
50
- return null;
51
- }
42
+ if (!titleMatch) return null;
43
53
- // Extract SLUG from content
44
const slugMatch = content.match(/\*\*SLUG\*\*:\s*`([^`]+)`/);
55
- if (!slugMatch) {
56
- // Not a toolkit page, skip
57
- return null;
58
- }
45
+ if (!slugMatch) return null;
46
60
- // Extract description
47
const descriptionMatch = content.match(/### Description\s*\n(.+?)(?:\n|$)/);
48
const description = descriptionMatch ? descriptionMatch[1].trim() : '';
63
-
64
- // Extract tool names from Accordion titles
49
+
50
const toolNames: string[] = [];
51
const accordionMatches = content.matchAll(/<Accordion title="([^"]+)">/g);
52
53
for (const match of accordionMatches) {
54
const toolName = match[1];
70
- // Only include tools that start with the toolkit prefix
55
if (toolName.startsWith(slugMatch[1] + '_')) {
56
toolNames.push(toolName);
57
}
@@ -79,72 +63,57 @@ function parseToolkitMdx(toolMdxPath: string): ToolkitInfo | null {
63
tools: toolNames,
64
};
65
} catch (error) {
82
- console.warn(`⚠️ Error parsing tool file ${toolMdxPath}:`, error);
66
+ console.warn(`Error parsing ${toolMdxPath}:`, error);
67
return null;
68
}
69
}
70
87
-// Scan toolkits directory and build tools data
71
function buildToolsData(): ToolsData {
72
const toolsData: ToolsData = { toolkitNames: [] };
73
74
if (!fs.existsSync(TOOLKITS_DIR)) {
92
- console.warn(`⚠️ Toolkits directory not found: ${TOOLKITS_DIR}`);
75
+ console.error(`Toolkits directory not found: ${TOOLKITS_DIR}`);
76
return toolsData;
77
}
78
96
- // Read all MDX files in toolkits directory
79
const files = fs.readdirSync(TOOLKITS_DIR);
80
const mdxFiles = files.filter(file => file.endsWith('.mdx'));
99
-
100
- console.log(`📂 Found ${mdxFiles.length} MDX files in toolkits directory`);
81
+ console.log(`Found ${mdxFiles.length} MDX files`);
82
83
for (const file of mdxFiles) {
84
const toolkitInfo = parseToolkitMdx(file);
85
if (toolkitInfo) {
86
toolsData.toolkitNames.push(toolkitInfo.slug);
87
toolsData[toolkitInfo.slug] = toolkitInfo;
107
- console.log(` ✓ ${toolkitInfo.slug}: ${toolkitInfo.tools.length} tools`);
88
+ console.log(` ${toolkitInfo.slug}: ${toolkitInfo.tools.length} tools`);
89
}
90
}
91
111
- // Sort toolkit names alphabetically
92
toolsData.toolkitNames.sort();
113
-
93
return toolsData;
94
}
95
117
-// Main function
118
-async function main(): Promise<void> {
119
- console.log('🔨 Building tools.json...');
120
-
96
+function main() {
97
+ console.log('Building tools.json...');
98
try {
122
- // Build tools data
99
const toolsData = buildToolsData();
100
125
- console.log(`\n📊 Summary:`);
126
- console.log(` - Total toolkits: ${toolsData.toolkitNames.length}`);
101
+ console.log(`\nSummary:`);
102
+ console.log(` Total toolkits: ${toolsData.toolkitNames.length}`);
103
104
let totalTools = 0;
105
for (const name of toolsData.toolkitNames) {
106
const toolkit = toolsData[name] as ToolkitInfo;
107
totalTools += toolkit.tools.length;
108
}
133
- console.log(` - Total tools: ${totalTools}`);
109
+ console.log(` Total tools: ${totalTools}`);
110
135
- // Write tools.json
136
- const toolsJsonContent = JSON.stringify(toolsData, null, 2);
137
- fs.writeFileSync(TOOLS_JSON_PATH, toolsJsonContent);
138
-
139
- console.log(`\n✅ Generated tools.json at ${TOOLS_JSON_PATH}`);
111
+ fs.writeFileSync(TOOLS_JSON_PATH, JSON.stringify(toolsData, null, 2));
112
+ console.log(`\nGenerated ${TOOLS_JSON_PATH}`);
113
} catch (error) {
141
- console.error('❌ Error building tools.json:', error);
114
+ console.error('Error:', error);
115
process.exit(1);
116
}
117
}
118
146
-// Run the script
147
-main().catch(error => {
148
- console.error('❌ Fatal error:', error);
149
- process.exit(1);
150
-});
\ No newline at end of file
119
+main();
\ No newline at end of file