@devries-cameron20 / composio Mirror · read-only / commits / 267200c0e
Fork 0

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, 10:45 UTC

docs: show nested parameter schemas on toolkit detail pages

Toolkit tool pages now display nested object and array parameter schemas using expandable TypeTables. When a user expands a tool, the full schema is lazily fetched from the single-tool API endpoint (with version pinning) to get complete nested property definitions that the list endpoint omits. - Add `properties`, `requiredFields`, `items` to ParameterSchema type - Fetch version-specific tools/triggers using toolkit version from changelog - Add `/api/tools/[slug]` proxy route for client-side detail fetches - Render nested object/array children as TypeTables inside parent descriptions - Show `array<type>` instead of just `array` for typed arrays - Increase tool/trigger fetch limit to 10,000 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Sushmithamallesh committed Feb 5, 2026 at 20:44 UTC 267200c0ef9a32e54ab62d2ee2f168463556e052
4 files changed +220 -80
docs/app/(home)/toolkits/[[...slug]]/page.tsx
+53 -61
@@ -12,9 +12,54 @@ import type { Toolkit, Tool, Trigger } from '@/types/toolkit';
12 const API_BASE = process.env.COMPOSIO_API_BASE || 'https://backend.composio.dev/api/v3';
13 const API_KEY = process.env.COMPOSIO_API_KEY;
14
15 +// Add required flag to each property based on the required array
16 +// Preserves nested properties/items for object and array types
17 +function processParams(props: any, requiredList: string[]): Record<string, any> | undefined {
18 + if (!props || typeof props !== 'object') return undefined;
19 + const result: Record<string, any> = {};
20 + for (const [key, value] of Object.entries(props)) {
21 + if (typeof value === 'object' && value !== null) {
22 + const param = value as any;
23 + result[key] = {
24 + type: param.type,
25 + description: param.description,
26 + default: param.default,
27 + example: param.example,
28 + enum: param.enum,
29 + required: requiredList.includes(key),
30 + ...(param.properties ? { properties: param.properties } : {}),
31 + ...(param.required ? { requiredFields: param.required } : {}),
32 + ...(param.items ? { items: param.items } : {}),
33 + };
34 + }
35 + }
36 + return Object.keys(result).length > 0 ? result : undefined;
37 +}
38 +
39 +function toolFromApi(tool: any): Tool {
40 + const inputSchema = tool.input_parameters || tool.parameters;
41 + const outputSchema = tool.output_parameters || tool.response;
42 +
43 + const inputProps = inputSchema?.properties || inputSchema;
44 + const inputRequired = inputSchema?.required || [];
45 + const outputProps = outputSchema?.properties || outputSchema;
46 + const outputRequired = outputSchema?.required || [];
47 +
48 + return {
49 + slug: tool.slug || '',
50 + name: tool.name || tool.display_name || tool.slug || '',
51 + description: tool.description || '',
52 + input_parameters: processParams(inputProps, inputRequired),
53 + output_parameters: processParams(outputProps, outputRequired),
54 + scopes: tool.scopes || undefined,
55 + tags: tool.tags || undefined,
56 + is_deprecated: tool.is_deprecated || false,
57 + };
58 +}
59 +
60 // Fetch detailed tool info from Composio API (server-side only)
61 // Returns null on failure, empty array if toolkit has no tools
17 -async function fetchDetailedTools(toolkitSlug: string): Promise<Tool[] | null> {
62 +async function fetchDetailedTools(toolkitSlug: string, version?: string | null): Promise<Tool[] | null> {
63 if (!API_KEY) {
64 console.warn('[Toolkits] COMPOSIO_API_KEY not set, skipping detailed tool fetch');
65 return null;
@@ -22,13 +67,13 @@ async function fetchDetailedTools(toolkitSlug: string): Promise<Tool[] | null> {
67
68 try {
69 const response = await fetch(
25 - `${API_BASE}/tools?toolkit_slug=${toolkitSlug.toUpperCase()}&limit=1000`,
70 + `${API_BASE}/tools?toolkit_slug=${toolkitSlug.toUpperCase()}&limit=10000${version ? `&version=${encodeURIComponent(version)}` : ''}`,
71 {
72 headers: {
73 'Content-Type': 'application/json',
74 'x-api-key': API_KEY,
75 },
31 - next: { revalidate: 3600 }, // Cache for 1 hour
76 + next: { revalidate: 3600 },
77 }
78 );
79
@@ -41,43 +86,7 @@ async function fetchDetailedTools(toolkitSlug: string): Promise<Tool[] | null> {
86 const rawItems = data.items || data;
87 const items = Array.isArray(rawItems) ? rawItems : [];
88
44 - return items.filter((tool: any) => tool && typeof tool === 'object').map((tool: any) => {
45 - // Extract parameters from JSON Schema format
46 - const inputSchema = tool.input_parameters || tool.parameters;
47 - const outputSchema = tool.output_parameters || tool.response;
48 -
49 - // Get properties and required array from JSON Schema
50 - const inputProps = inputSchema?.properties || inputSchema;
51 - const inputRequired = inputSchema?.required || [];
52 - const outputProps = outputSchema?.properties || outputSchema;
53 - const outputRequired = outputSchema?.required || [];
54 -
55 - // Add required flag to each property based on the required array
56 - const processParams = (props: any, requiredList: string[]) => {
57 - if (!props || typeof props !== 'object') return undefined;
58 - const result: Record<string, any> = {};
59 - for (const [key, value] of Object.entries(props)) {
60 - if (typeof value === 'object' && value !== null) {
61 - result[key] = {
62 - ...(value as object),
63 - required: requiredList.includes(key),
64 - };
65 - }
66 - }
67 - return Object.keys(result).length > 0 ? result : undefined;
68 - };
69 -
70 - return {
71 - slug: tool.slug || '',
72 - name: tool.name || tool.display_name || tool.slug || '',
73 - description: tool.description || '',
74 - input_parameters: processParams(inputProps, inputRequired),
75 - output_parameters: processParams(outputProps, outputRequired),
76 - scopes: tool.scopes || undefined,
77 - tags: tool.tags || undefined,
78 - is_deprecated: tool.is_deprecated || false,
79 - };
80 - });
89 + return items.filter((tool: any) => tool && typeof tool === 'object').map(toolFromApi);
90 } catch (error) {
91 console.error(`[Toolkits] Error fetching detailed tools for ${toolkitSlug}:`, error);
92 return null;
@@ -86,7 +95,7 @@ async function fetchDetailedTools(toolkitSlug: string): Promise<Tool[] | null> {
95
96 // Fetch detailed trigger info from Composio API (server-side only)
97 // Returns null on failure, empty array if toolkit has no triggers
89 -async function fetchDetailedTriggers(toolkitSlug: string): Promise<Trigger[] | null> {
98 +async function fetchDetailedTriggers(toolkitSlug: string, version?: string | null): Promise<Trigger[] | null> {
99 if (!API_KEY) {
100 console.warn('[Toolkits] COMPOSIO_API_KEY not set, skipping detailed trigger fetch');
101 return null;
@@ -94,7 +103,7 @@ async function fetchDetailedTriggers(toolkitSlug: string): Promise<Trigger[] | n
103
104 try {
105 const response = await fetch(
97 - `${API_BASE}/triggers_types?toolkit_slugs=${toolkitSlug.toUpperCase()}&limit=1000`,
106 + `${API_BASE}/triggers_types?toolkit_slugs=${toolkitSlug.toUpperCase()}&limit=10000${version ? `&version=${encodeURIComponent(version)}` : ''}`,
107 {
108 headers: {
109 'Content-Type': 'application/json',
@@ -114,31 +123,14 @@ async function fetchDetailedTriggers(toolkitSlug: string): Promise<Trigger[] | n
123 const items = Array.isArray(rawItems) ? rawItems : [];
124
125 return items.filter((trigger: any) => trigger && typeof trigger === 'object').map((trigger: any) => {
117 - // Extract config and payload schemas
126 const configSchema = trigger.config;
127 const payloadSchema = trigger.payload;
128
121 - // Get properties and required array from JSON Schema
129 const configProps = configSchema?.properties || configSchema;
130 const configRequired = configSchema?.required || [];
131 const payloadProps = payloadSchema?.properties || payloadSchema;
132 const payloadRequired = payloadSchema?.required || [];
133
127 - // Add required flag to each property based on the required array
128 - const processParams = (props: any, requiredList: string[]) => {
129 - if (!props || typeof props !== 'object') return undefined;
130 - const result: Record<string, any> = {};
131 - for (const [key, value] of Object.entries(props)) {
132 - if (typeof value === 'object' && value !== null) {
133 - result[key] = {
134 - ...(value as object),
135 - required: requiredList.includes(key),
136 - };
137 - }
138 - }
139 - return Object.keys(result).length > 0 ? result : undefined;
140 - };
141 -
134 return {
135 slug: trigger.slug || '',
136 name: trigger.name || trigger.display_name || trigger.slug || '',
@@ -277,8 +269,8 @@ export default async function ToolkitsPage({ params }: { params: Promise<{ slug?
269 if (toolkit) {
270 // Fetch detailed tool and trigger info from API (includes input/output params)
271 const [detailedTools, detailedTriggers] = await Promise.all([
280 - fetchDetailedTools(toolkitSlug),
281 - fetchDetailedTriggers(toolkitSlug),
272 + fetchDetailedTools(toolkitSlug, toolkit.version),
273 + fetchDetailedTriggers(toolkitSlug, toolkit.version),
274 ]);
275
276 // Use detailed data if fetch succeeded, otherwise fall back to static data
docs/app/api/tools/[slug]/route.ts new
+50
@@ -0,0 +1,50 @@
1 +import { NextRequest, NextResponse } from 'next/server';
2 +
3 +const API_BASE = process.env.COMPOSIO_API_BASE || 'https://backend.composio.dev/api/v3';
4 +const API_KEY = process.env.COMPOSIO_API_KEY;
5 +
6 +export async function GET(
7 + request: NextRequest,
8 + { params }: { params: Promise<{ slug: string }> }
9 +) {
10 + const { slug } = await params;
11 + const version = request.nextUrl.searchParams.get('version') || 'latest';
12 +
13 + if (!API_KEY) {
14 + return NextResponse.json({ error: 'API key not configured' }, { status: 500 });
15 + }
16 +
17 + if (!slug || !/^[A-Z0-9_]+$/i.test(slug)) {
18 + return NextResponse.json({ error: 'Invalid tool slug' }, { status: 400 });
19 + }
20 +
21 + try {
22 + const response = await fetch(
23 + `${API_BASE}/tools/${slug.toUpperCase()}?version=${encodeURIComponent(version)}`,
24 + {
25 + headers: {
26 + 'Content-Type': 'application/json',
27 + 'x-api-key': API_KEY,
28 + },
29 + next: { revalidate: 3600 },
30 + }
31 + );
32 +
33 + if (!response.ok) {
34 + return NextResponse.json({ error: 'Tool not found' }, { status: response.status });
35 + }
36 +
37 + const tool = await response.json();
38 +
39 + // Return just the schemas
40 + const inputSchema = tool.input_parameters || tool.parameters;
41 + const outputSchema = tool.output_parameters || tool.response;
42 +
43 + return NextResponse.json({
44 + input_parameters: inputSchema || null,
45 + output_parameters: outputSchema || null,
46 + });
47 + } catch {
48 + return NextResponse.json({ error: 'Failed to fetch tool' }, { status: 500 });
49 + }
50 +}
docs/components/toolkits/toolkit-detail.tsx
+111 -19
@@ -1,6 +1,6 @@
1 'use client';
2
3 -import { useState, useMemo } from 'react';
3 +import { useState, useMemo, useEffect, useCallback, type ReactNode } from 'react';
4 import Link from 'next/link';
5 import { ExternalLink, Search, Copy, Check, ChevronDown, ChevronRight, ArrowLeft } from 'lucide-react';
6 import { TypeTable } from 'fumadocs-ui/components/type-table';
@@ -40,6 +40,12 @@ function formatDefault(value: unknown): string | undefined {
40 function formatType(param: ParameterSchema): string {
41 let typeStr = param.type || 'string';
42
43 + // Show array item type
44 + if (typeStr === 'array' && param.items) {
45 + const itemType = param.items.type || 'unknown';
46 + typeStr = `array<${itemType}>`;
47 + }
48 +
49 // Include enum values in type display
50 if (param.enum && param.enum.length > 0) {
51 const enumValues = param.enum.map(v => `"${v}"`).join(' | ');
@@ -49,32 +55,83 @@ function formatType(param: ParameterSchema): string {
55 return typeStr;
56 }
57
52 -// Convert parameter schema to TypeTable format
58 +// Get children from a param (object properties or array item properties)
59 +function getChildren(param: ParameterSchema): Record<string, ParameterSchema> | null {
60 + const props = param.properties || param.items?.properties;
61 + if (!props || typeof props !== 'object') return null;
62 +
63 + const requiredList: string[] = param.requiredFields || param.items?.requiredFields || param.items?.required as string[] || [];
64 + const result: Record<string, ParameterSchema> = {};
65 + for (const [key, value] of Object.entries(props)) {
66 + if (typeof value === 'object' && value !== null) {
67 + result[key] = {
68 + ...(value as ParameterSchema),
69 + required: Array.isArray(requiredList) ? requiredList.includes(key) : false,
70 + };
71 + }
72 + }
73 + return Object.keys(result).length > 0 ? result : null;
74 +}
75 +
76 +// Build a ReactNode description that includes text + nested TypeTable for children
77 +function buildDescription(param: ParameterSchema): ReactNode {
78 + const children = getChildren(param);
79 + if (!children) return param.description || undefined;
80 +
81 + return (
82 + <div className="space-y-2">
83 + {param.description && <p>{param.description}</p>}
84 + <TypeTable type={paramsToTypeTable(children)} />
85 + </div>
86 + );
87 +}
88 +
89 +// Convert parameter schema to TypeTable format, recursively nesting child TypeTables in descriptions
90 function paramsToTypeTable(params: Record<string, ParameterSchema>): Record<string, {
91 type: string;
55 - description?: string;
92 + description?: ReactNode;
93 default?: string;
94 required?: boolean;
95 }> {
59 - const result: Record<string, {
60 - type: string;
61 - description?: string;
62 - default?: string;
63 - required?: boolean;
64 - }> = {};
65 -
96 + const result: Record<string, { type: string; description?: ReactNode; default?: string; required?: boolean }> = {};
97 for (const [name, param] of Object.entries(params)) {
98 result[name] = {
99 type: formatType(param),
69 - description: param.description || undefined,
100 + description: buildDescription(param),
101 default: formatDefault(param.default),
102 required: param.required,
103 };
104 }
74 -
105 return result;
106 }
107
108 +// Process raw API schema into ParameterSchema records
109 +function processApiSchema(schema: any): Record<string, ParameterSchema> | undefined {
110 + if (!schema) return undefined;
111 + const props = schema.properties || schema;
112 + const required = schema.required || [];
113 + if (!props || typeof props !== 'object') return undefined;
114 +
115 + const result: Record<string, ParameterSchema> = {};
116 + for (const [key, value] of Object.entries(props)) {
117 + if (typeof value === 'object' && value !== null) {
118 + const param = value as any;
119 + result[key] = {
120 + type: param.type,
121 + description: param.description,
122 + default: param.default,
123 + example: param.example,
124 + enum: param.enum,
125 + required: required.includes(key),
126 + ...(param.properties ? { properties: param.properties } : {}),
127 + ...(param.required ? { requiredFields: param.required } : {}),
128 + ...(param.items ? { items: param.items } : {}),
129 + };
130 + }
131 + }
132 + return Object.keys(result).length > 0 ? result : undefined;
133 +}
134 +
135 // Check if item is a Tool with parameters
136 function isTool(item: Tool | Trigger): item is Tool {
137 return 'input_parameters' in item || 'output_parameters' in item;
@@ -85,9 +142,14 @@ function isTrigger(item: Tool | Trigger): item is Trigger {
142 return 'config' in item || 'payload' in item || 'type' in item;
143 }
144
88 -function ToolItem({ item }: { item: Tool | Trigger }) {
145 +function ToolItem({ item, toolkitVersion }: { item: Tool | Trigger; toolkitVersion?: string | null }) {
146 const [expanded, setExpanded] = useState(false);
147 const [copied, setCopied] = useState(false);
148 + const [detailedParams, setDetailedParams] = useState<{
149 + input?: Record<string, ParameterSchema>;
150 + output?: Record<string, ParameterSchema>;
151 + } | null>(null);
152 + const [loading, setLoading] = useState(false);
153
154 const copySlug = (e: React.MouseEvent) => {
155 e.stopPropagation();
@@ -99,8 +161,38 @@ function ToolItem({ item }: { item: Tool | Trigger }) {
161 const tool = isTool(item) ? item : null;
162 const trigger = isTrigger(item) ? item : null;
163
102 - const hasInputParams = tool?.input_parameters && Object.keys(tool.input_parameters).length > 0;
103 - const hasOutputParams = tool?.output_parameters && Object.keys(tool.output_parameters).length > 0;
164 + // Fetch detailed schema when a tool is expanded
165 + const fetchDetailedSchema = useCallback(async () => {
166 + if (!tool || detailedParams || loading) return;
167 + setLoading(true);
168 + try {
169 + const versionParam = toolkitVersion ? `?version=${encodeURIComponent(toolkitVersion)}` : '';
170 + const res = await fetch(`/api/tools/${item.slug}${versionParam}`);
171 + if (res.ok) {
172 + const data = await res.json();
173 + setDetailedParams({
174 + input: processApiSchema(data.input_parameters),
175 + output: processApiSchema(data.output_parameters),
176 + });
177 + }
178 + } catch {
179 + // silently fall back to basic params
180 + } finally {
181 + setLoading(false);
182 + }
183 + }, [tool, item.slug, toolkitVersion, detailedParams, loading]);
184 +
185 + useEffect(() => {
186 + if (expanded && tool) {
187 + fetchDetailedSchema();
188 + }
189 + }, [expanded, tool, fetchDetailedSchema]);
190 +
191 + const inputParams = detailedParams?.input || tool?.input_parameters;
192 + const outputParams = detailedParams?.output || tool?.output_parameters;
193 +
194 + const hasInputParams = inputParams && Object.keys(inputParams).length > 0;
195 + const hasOutputParams = outputParams && Object.keys(outputParams).length > 0;
196 const hasConfig = trigger?.config && Object.keys(trigger.config).length > 0;
197 const hasPayload = trigger?.payload && Object.keys(trigger.payload).length > 0;
198
@@ -144,14 +236,14 @@ function ToolItem({ item }: { item: Tool | Trigger }) {
236 {hasInputParams && (
237 <div className="space-y-2">
238 <h4 className="text-xs font-semibold uppercase tracking-wide text-fd-muted-foreground">Input Parameters</h4>
147 - <TypeTable type={paramsToTypeTable(tool.input_parameters!)} />
239 + <TypeTable type={paramsToTypeTable(inputParams!)} />
240 </div>
241 )}
242
243 {hasOutputParams && (
244 <div className="space-y-2">
245 <h4 className="text-xs font-semibold uppercase tracking-wide text-fd-muted-foreground">Output</h4>
154 - <TypeTable type={paramsToTypeTable(tool.output_parameters!)} />
246 + <TypeTable type={paramsToTypeTable(outputParams!)} />
247 </div>
248 )}
249
@@ -341,7 +433,7 @@ export function ToolkitDetail({ toolkit, tools, triggers, path }: ToolkitDetailP
433 {activeTab === 'tools' && (
434 filteredTools.length > 0 ? (
435 filteredTools.map((tool) => (
344 - <ToolItem key={tool.slug} item={tool} />
436 + <ToolItem key={tool.slug} item={tool} toolkitVersion={toolkit.version} />
437 ))
438 ) : (
439 <p className="px-4 py-8 text-center text-sm text-fd-muted-foreground">
@@ -352,7 +444,7 @@ export function ToolkitDetail({ toolkit, tools, triggers, path }: ToolkitDetailP
444 {activeTab === 'triggers' && (
445 filteredTriggers.length > 0 ? (
446 filteredTriggers.map((trigger) => (
355 - <ToolItem key={trigger.slug} item={trigger} />
447 + <ToolItem key={trigger.slug} item={trigger} toolkitVersion={toolkit.version} />
448 ))
449 ) : (
450 <p className="px-4 py-8 text-center text-sm text-fd-muted-foreground">
docs/types/toolkit.ts
+6
@@ -6,6 +6,12 @@ export interface ParameterSchema {
6 default?: unknown;
7 example?: unknown;
8 enum?: string[];
9 + // Nested object properties (JSON Schema)
10 + properties?: Record<string, ParameterSchema>;
11 + // Required fields within this object
12 + requiredFields?: string[];
13 + // Array item schema
14 + items?: ParameterSchema;
15 }
16
17 export interface Tool {