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 22, 12:00 UTC
feat(docs): Add detailed tool/trigger types to LLM markdown
- Fetch detailed tool and trigger data from Composio API for markdown generation - Include input/output parameter tables with types, required flags, and descriptions - Add trigger type (webhook/poll), config and payload parameters - Display enum values in type strings - Add slug and version to toolkit metadata Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sushmithamallesh committed
Jan 28, 2026 at 14:07 UTC
b7a983a477866efc2b86aed5386dbed1c5e6c7f5
1 file changed
+237
-14
docs/app/llms.mdx/[[...slug]]/route.ts
+237
-14
@@ -9,10 +9,148 @@ import { openapi } from '@/lib/openapi';
9
import { notFound } from 'next/navigation';
10
import { readFile } from 'fs/promises';
11
import { join } from 'path';
12
-import type { Toolkit } from '@/types/toolkit';
12
+import type { Toolkit, Tool, Trigger, ParameterSchema } from '@/types/toolkit';
13
14
export const revalidate = false;
15
16
+const API_BASE = process.env.COMPOSIO_API_BASE || 'https://backend.composio.dev/api/v3';
17
+const API_KEY = process.env.COMPOSIO_API_KEY;
18
+
19
+// Fetch detailed tool info from Composio API
20
+async function fetchDetailedTools(toolkitSlug: string): Promise<Tool[] | null> {
21
+ if (!API_KEY) {
22
+ return null;
23
+ }
24
+
25
+ try {
26
+ const response = await fetch(
27
+ `${API_BASE}/tools?toolkit_slug=${toolkitSlug.toUpperCase()}&limit=1000`,
28
+ {
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ 'x-api-key': API_KEY,
32
+ },
33
+ next: { revalidate: 3600 },
34
+ }
35
+ );
36
+
37
+ if (!response.ok) {
38
+ return null;
39
+ }
40
+
41
+ const data = await response.json();
42
+ const rawItems = data.items || data;
43
+ const items = Array.isArray(rawItems) ? rawItems : [];
44
+
45
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
+ return items.filter((tool: any) => tool && typeof tool === 'object').map((tool: any) => {
47
+ const inputSchema = tool.input_parameters || tool.parameters;
48
+ const outputSchema = tool.output_parameters || tool.response;
49
+
50
+ const inputProps = inputSchema?.properties || inputSchema;
51
+ const inputRequired = inputSchema?.required || [];
52
+ const outputProps = outputSchema?.properties || outputSchema;
53
+ const outputRequired = outputSchema?.required || [];
54
+
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ const processParams = (props: any, requiredList: string[]) => {
57
+ if (!props || typeof props !== 'object') return undefined;
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ const result: Record<string, any> = {};
60
+ for (const [key, value] of Object.entries(props)) {
61
+ if (typeof value === 'object' && value !== null) {
62
+ result[key] = {
63
+ ...(value as object),
64
+ required: requiredList.includes(key),
65
+ };
66
+ }
67
+ }
68
+ return Object.keys(result).length > 0 ? result : undefined;
69
+ };
70
+
71
+ return {
72
+ slug: tool.slug || '',
73
+ name: tool.name || tool.display_name || tool.slug || '',
74
+ description: tool.description || '',
75
+ input_parameters: processParams(inputProps, inputRequired),
76
+ output_parameters: processParams(outputProps, outputRequired),
77
+ scopes: tool.scopes || undefined,
78
+ tags: tool.tags || undefined,
79
+ is_deprecated: tool.is_deprecated || false,
80
+ };
81
+ });
82
+ } catch {
83
+ return null;
84
+ }
85
+}
86
+
87
+// Fetch detailed trigger info from Composio API
88
+async function fetchDetailedTriggers(toolkitSlug: string): Promise<Trigger[] | null> {
89
+ if (!API_KEY) {
90
+ return null;
91
+ }
92
+
93
+ try {
94
+ const response = await fetch(
95
+ `${API_BASE}/triggers_types?toolkit_slugs=${toolkitSlug.toUpperCase()}&limit=1000`,
96
+ {
97
+ headers: {
98
+ 'Content-Type': 'application/json',
99
+ 'x-api-key': API_KEY,
100
+ },
101
+ next: { revalidate: 3600 },
102
+ }
103
+ );
104
+
105
+ if (!response.ok) {
106
+ return null;
107
+ }
108
+
109
+ const data = await response.json();
110
+ const rawItems = data.items || data;
111
+ const items = Array.isArray(rawItems) ? rawItems : [];
112
+
113
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
+ return items.filter((trigger: any) => trigger && typeof trigger === 'object').map((trigger: any) => {
115
+ const configSchema = trigger.config;
116
+ const payloadSchema = trigger.payload;
117
+
118
+ const configProps = configSchema?.properties || configSchema;
119
+ const configRequired = configSchema?.required || [];
120
+ const payloadProps = payloadSchema?.properties || payloadSchema;
121
+ const payloadRequired = payloadSchema?.required || [];
122
+
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
+ const processParams = (props: any, requiredList: string[]) => {
125
+ if (!props || typeof props !== 'object') return undefined;
126
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127
+ const result: Record<string, any> = {};
128
+ for (const [key, value] of Object.entries(props)) {
129
+ if (typeof value === 'object' && value !== null) {
130
+ result[key] = {
131
+ ...(value as object),
132
+ required: requiredList.includes(key),
133
+ };
134
+ }
135
+ }
136
+ return Object.keys(result).length > 0 ? result : undefined;
137
+ };
138
+
139
+ return {
140
+ slug: trigger.slug || '',
141
+ name: trigger.name || trigger.display_name || trigger.slug || '',
142
+ description: trigger.description || '',
143
+ type: trigger.type || undefined,
144
+ config: processParams(configProps, configRequired),
145
+ payload: processParams(payloadProps, payloadRequired),
146
+ instructions: trigger.instructions || undefined,
147
+ };
148
+ });
149
+ } catch {
150
+ return null;
151
+ }
152
+}
153
+
154
// Types for OpenAPI structures (from dereferenced document)
155
interface OpenAPISchema {
156
type?: string;
@@ -381,8 +519,37 @@ const sources = [
519
{ prefix: 'toolkits', source: toolkitsSource },
520
];
521
384
-// Generate markdown from toolkit JSON data
385
-function toolkitToMarkdown(toolkit: Toolkit): string {
522
+// Format parameter type with enum values if available
523
+function formatParamType(param: ParameterSchema): string {
524
+ let typeStr = param.type || 'string';
525
+ if (param.enum && param.enum.length > 0) {
526
+ const enumValues = param.enum.map(v => `"${v}"`).join(' | ');
527
+ typeStr = `${typeStr} (${enumValues})`;
528
+ }
529
+ return typeStr;
530
+}
531
+
532
+// Render parameters as markdown table
533
+function renderParamsMarkdown(params: Record<string, ParameterSchema>): string[] {
534
+ const lines: string[] = [];
535
+ lines.push('| Parameter | Type | Required | Description |');
536
+ lines.push('|-----------|------|----------|-------------|');
537
+
538
+ for (const [name, param] of Object.entries(params)) {
539
+ const typeStr = formatParamType(param);
540
+ const required = param.required ? 'Yes' : 'No';
541
+ const desc = (param.description || '').replace(/\|/g, '\\|').replace(/\n/g, ' ');
542
+ lines.push(`| \`${name}\` | ${typeStr} | ${required} | ${desc} |`);
543
+ }
544
+
545
+ return lines;
546
+}
547
+
548
+// Generate markdown from toolkit with detailed tools and triggers
549
+function toolkitToMarkdown(toolkit: Toolkit, detailedTools?: Tool[], detailedTriggers?: Trigger[]): string {
550
+ const tools = detailedTools || toolkit.tools;
551
+ const triggers = detailedTriggers || toolkit.triggers;
552
+
553
const lines: string[] = [
554
`# ${toolkit.name.trim()}`,
555
'',
@@ -392,19 +559,62 @@ function toolkitToMarkdown(toolkit: Toolkit): string {
559
`- **Auth:** ${toolkit.authSchemes.join(', ') || 'None'}`,
560
`- **Tools:** ${toolkit.toolCount}`,
561
`- **Triggers:** ${toolkit.triggerCount}`,
562
+ `- **Slug:** \`${toolkit.slug.toUpperCase()}\``,
563
];
564
397
- if (toolkit.tools.length > 0) {
565
+ if (toolkit.version) {
566
+ lines.push(`- **Version:** ${toolkit.version}`);
567
+ }
568
+
569
+ if (tools.length > 0) {
570
lines.push('', '## Tools', '');
399
- for (const tool of toolkit.tools) {
400
- lines.push(`### ${tool.name}`, '', tool.description, '');
571
+ for (const tool of tools) {
572
+ lines.push(`### ${tool.name}`, '');
573
+ lines.push(`**Slug:** \`${tool.slug}\``, '');
574
+ lines.push(tool.description, '');
575
+
576
+ // Input parameters
577
+ if (tool.input_parameters && Object.keys(tool.input_parameters).length > 0) {
578
+ lines.push('#### Input Parameters', '');
579
+ lines.push(...renderParamsMarkdown(tool.input_parameters));
580
+ lines.push('');
581
+ }
582
+
583
+ // Output parameters
584
+ if (tool.output_parameters && Object.keys(tool.output_parameters).length > 0) {
585
+ lines.push('#### Output', '');
586
+ lines.push(...renderParamsMarkdown(tool.output_parameters));
587
+ lines.push('');
588
+ }
589
}
590
}
591
404
- if (toolkit.triggers.length > 0) {
592
+ if (triggers.length > 0) {
593
lines.push('', '## Triggers', '');
406
- for (const trigger of toolkit.triggers) {
407
- lines.push(`### ${trigger.name}`, '', trigger.description, '');
594
+ for (const trigger of triggers) {
595
+ lines.push(`### ${trigger.name}`, '');
596
+ lines.push(`**Slug:** \`${trigger.slug}\``, '');
597
+
598
+ // Trigger type (webhook/poll)
599
+ if (trigger.type) {
600
+ lines.push(`**Type:** ${trigger.type}`, '');
601
+ }
602
+
603
+ lines.push(trigger.description, '');
604
+
605
+ // Config parameters
606
+ if (trigger.config && Object.keys(trigger.config).length > 0) {
607
+ lines.push('#### Configuration', '');
608
+ lines.push(...renderParamsMarkdown(trigger.config));
609
+ lines.push('');
610
+ }
611
+
612
+ // Payload parameters
613
+ if (trigger.payload && Object.keys(trigger.payload).length > 0) {
614
+ lines.push('#### Payload', '');
615
+ lines.push(...renderParamsMarkdown(trigger.payload));
616
+ lines.push('');
617
+ }
618
}
619
}
620
@@ -565,11 +775,24 @@ export async function GET(
775
if (prefix === 'toolkits' && rest.length === 1) {
776
const toolkit = await getToolkit(rest[0]);
777
if (toolkit) {
568
- return new Response(toolkitToMarkdown(toolkit), {
569
- headers: {
570
- 'Content-Type': 'text/markdown; charset=utf-8',
571
- },
572
- });
778
+ // Fetch detailed tool and trigger info from API
779
+ const [detailedTools, detailedTriggers] = await Promise.all([
780
+ fetchDetailedTools(rest[0]),
781
+ fetchDetailedTriggers(rest[0]),
782
+ ]);
783
+
784
+ return new Response(
785
+ toolkitToMarkdown(
786
+ toolkit,
787
+ detailedTools !== null ? detailedTools : undefined,
788
+ detailedTriggers !== null ? detailedTriggers : undefined
789
+ ),
790
+ {
791
+ headers: {
792
+ 'Content-Type': 'text/markdown; charset=utf-8',
793
+ },
794
+ }
795
+ );
796
}
797
}
798