list_apps_and_forms
Retrieve all applications and their forms accessible by the current API key on JianDaoYun MCP Server. Optionally filter results by specifying an app ID to focus on specific data.
Instructions
List all available applications and their forms that the current API key can access
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appId | No | Optional: specific app ID to get forms for. If not provided, lists all apps. | |
| appKey | No | The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided) |
Input Schema (JSON Schema)
{
"properties": {
"appId": {
"description": "Optional: specific app ID to get forms for. If not provided, lists all apps.",
"type": "string"
},
"appKey": {
"description": "The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided)",
"type": "string"
}
},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:950-1028 (handler)Main execution handler for the 'list_apps_and_forms' tool. Lists all accessible applications if no specific appId is provided, or lists forms within a specific application if appId is given. Uses caching via getAppList helper.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 (registration)Registration of the 'list_apps_and_forms' tool in the ListTools response, including name, description, and input schema definition.{ 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:491-504 (schema)Input schema definition for the 'list_apps_and_forms' tool, specifying optional appKey and appId parameters.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:43-70 (helper)Helper function to fetch and cache the list of applications accessible via the API key. Used when no specific appId is provided.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 []; } }
- src/index.ts:513-519 (helper)Utility function to extract and provide default values for common parameters like appId, appKey, and baseUrl from tool arguments and environment variables.function getDefaultParams(args: any) { return { appId: args.appId, appKey: args.appKey || process.env.JIANDAOYUN_APP_KEY, baseUrl: process.env.JIANDAOYUN_BASE_URL }; }