list_apps_and_forms
Retrieve accessible applications and their forms using an API key to manage JianDaoYun form data.
Instructions
List all available applications and their forms that the current API key can access
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appKey | No | The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided) | |
| appId | No | Optional: specific app ID to get forms for. If not provided, lists all apps. |
Implementation Reference
- src/index.ts:950-1028 (handler)Main execution handler for the 'list_apps_and_forms' tool. Handles listing all applications or forms under a specific app using the provided appKey. Returns structured JSON with apps or forms details.case 'list_apps_and_forms': { const { appId: specificAppId } = args as { appId?: string }; const { appId, appKey, baseUrl } = getDefaultParams(args); // 验证必需参数 if (!appKey) { throw new Error('appKey is required. Please set JIANDAOYUN_APP_KEY in MCP server configuration.'); } try { const targetAppId = specificAppId || appId; if (targetAppId) { // 获取特定应用的表单列表 const jdyClient = new JianDaoYunClient({ appId: targetAppId, appKey, baseUrl }); try { const response = await axios.post( `${baseUrl}/api/v1/app/${targetAppId}/entry/list`, {}, { headers: { 'Authorization': `Bearer ${appKey}`, 'Content-Type': 'application/json' } } ); const forms = response.data || []; return { content: [ { type: 'text', text: JSON.stringify({ appId: targetAppId, forms: forms.map((form: any) => ({ id: form.entry_id || form._id, name: form.name || '未命名表单', description: form.description || '', created_time: form.created_time, updated_time: form.updated_time })), total: forms.length }, null, 2), }, ], }; } catch (error) { throw new Error(`无法获取应用 "${targetAppId}" 下的表单列表: ${error instanceof Error ? error.message : '未知错误'}`); } } else { // 获取所有应用列表 const apps = await getAppList(appKey); return { content: [ { type: 'text', text: JSON.stringify({ apps: apps.map(app => ({ id: app.app_id, name: app.name, description: app.description || '', created_time: app.created_time, updated_time: app.updated_time })), total: apps.length, message: '使用 list_apps_and_forms 工具并提供 appId 参数可以查看特定应用下的表单列表' }, null, 2), }, ], }; } } catch (error) { throw createEnhancedError(error, '获取应用和表单列表'); } }
- src/index.ts:488-505 (schema)Input schema definition for the 'list_apps_and_forms' tool, specifying optional appKey and appId parameters.{ name: 'list_apps_and_forms', description: 'List all available applications and their forms that the current API key can access', inputSchema: { type: 'object', properties: { appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)', }, appId: { type: 'string', description: 'Optional: specific app ID to get forms for. If not provided, lists all apps.', }, }, required: [], }, },
- src/index.ts:244-508 (registration)Registration of all tools including 'list_apps_and_forms' in the MCP server's ListToolsRequestSchema handler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'get_form_fields', description: 'Get field definitions for a JianDaoYun form', inputSchema: { type: 'object', properties: { appId: { type: 'string', description: 'The JianDaoYun application ID', }, appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (can be provided via JIANDAOYUN_APP_KEY environment variable)', }, formId: { type: 'string', description: 'The form ID to query fields for (can be form ID or app ID)', }, }, required: ['appId', 'formId'], }, }, { name: 'submit_form_data', description: 'Submit data to a JianDaoYun form with automatic field type matching', inputSchema: { type: 'object', properties: { appId: { type: 'string', description: 'The JianDaoYun application ID', }, appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)', }, formId: { type: 'string', description: 'The form ID to submit data to (can be form ID or app ID)', }, data: { type: ['object', 'array'], description: 'The data to submit (single object or array for batch)', }, autoMatch: { type: 'boolean', description: 'Whether to automatically match field types (default: true)', default: true, }, transactionId: { type: 'string', description: 'Optional transaction ID for idempotent submissions', }, }, required: ['appId', 'formId', 'data'], }, }, { name: 'get_form_data', description: 'Get a specific data entry from a JianDaoYun form', inputSchema: { type: 'object', properties: { appId: { type: 'string', description: 'The JianDaoYun application ID', }, appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)', }, formId: { type: 'string', description: 'The form ID (can be form ID or app ID)', }, dataId: { type: 'string', description: 'The data entry ID', }, }, required: ['appId', 'formId', 'dataId'], }, }, { name: 'query_form_data', description: 'Query multiple form data entries with filtering support', inputSchema: { type: 'object', properties: { appId: { type: 'string', description: 'The JianDaoYun application ID', }, appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)', }, formId: { type: 'string', description: 'The form ID (can be form ID or app ID)', }, dataId: { type: 'string', description: 'Last data ID for pagination', }, fields: { type: 'array', items: { type: 'string' }, description: 'Fields to return (widget IDs)', }, filter: { type: 'object', description: 'Data filter conditions', properties: { rel: { type: 'string', enum: ['and', 'or'], description: 'Relation between conditions', }, cond: { type: 'array', description: 'Filter conditions', items: { type: 'object', properties: { field: { type: 'string' }, type: { type: 'string' }, method: { type: 'string' }, value: {}, }, required: ['field', 'method'], }, }, }, required: ['rel', 'cond'], }, limit: { type: 'number', description: 'Number of records to return (1-100, default: 10)', minimum: 1, maximum: 100, }, }, required: ['appId', 'formId'], }, }, { name: 'update_form_data', description: 'Update an existing form data entry', inputSchema: { type: 'object', properties: { appId: { type: 'string', description: 'The JianDaoYun application ID', }, appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)', }, formId: { type: 'string', description: 'The form ID (can be form ID or app ID)', }, dataId: { type: 'string', description: 'The data entry ID to update', }, data: { type: 'object', description: 'The data to update', }, transactionId: { type: 'string', description: 'Optional transaction ID', }, isStartTrigger: { type: 'boolean', description: 'Whether to trigger automation', }, }, required: ['appId', 'formId', 'dataId', 'data'], }, }, { name: 'delete_form_data', description: 'Delete one or more form data entries', inputSchema: { type: 'object', properties: { appId: { type: 'string', description: 'The JianDaoYun application ID', }, appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)', }, formId: { type: 'string', description: 'The form ID (can be form ID or app ID)', }, dataIds: { type: ['string', 'array'], description: 'Data ID(s) to delete', items: { type: 'string' }, }, isStartTrigger: { type: 'boolean', description: 'Whether to trigger automation', }, }, required: ['appId', 'formId', 'dataIds'], }, }, { name: 'get_upload_token', description: 'Get file upload tokens for file/image fields', inputSchema: { type: 'object', properties: { appId: { type: 'string', description: 'The JianDaoYun application ID', }, appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)', }, formId: { type: 'string', description: 'The form ID (can be form ID or app ID)', }, transactionId: { type: 'string', description: 'Transaction ID to bind uploads to', }, }, required: ['appId', 'formId', 'transactionId'], }, }, { name: 'list_apps_and_forms', description: 'List all available applications and their forms that the current API key can access', inputSchema: { type: 'object', properties: { appKey: { type: 'string', description: 'The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)', }, appId: { type: 'string', description: 'Optional: specific app ID to get forms for. If not provided, lists all apps.', }, }, required: [], }, }, ], }; });
- src/index.ts:42-70 (helper)Helper function getAppList used by the tool to fetch and cache the list of applications accessible by the appKey.*/ async function getAppList(appKey: string): Promise<any[]> { const now = Date.now(); if (appListCache && (now - appListCacheTime) < CACHE_DURATION) { return appListCache; } try { const response = await axios.post( `${process.env.JIANDAOYUN_BASE_URL || 'https://api.jiandaoyun.com'}/api/v5/app/list`, {}, { headers: { 'Authorization': `Bearer ${appKey}`, 'Content-Type': 'application/json' } } ); // 简道云API返回格式通常是 { code: 0, data: [...] } const apps = response.data?.data || response.data || []; appListCache = Array.isArray(apps) ? apps : []; appListCacheTime = now; return appListCache; } catch (error) { console.error('Failed to fetch app list:', error); return []; } }