get_upload_token
Obtain secure upload tokens for file and image fields in JianDaoYun forms to enable file attachments in form submissions.
Instructions
Get file upload tokens for file/image fields
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appId | Yes | The JianDaoYun application ID | |
| appKey | No | The JianDaoYun application key (API key) (optional, will use JIANDAOYUN_APP_KEY from environment if not provided) | |
| formId | Yes | The form ID (can be form ID or app ID) | |
| transactionId | Yes | Transaction ID to bind uploads to |
Implementation Reference
- src/index.ts:462-487 (registration)Registration of the 'get_upload_token' tool in the MCP server, including name, description, and input schema.{ 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'], }, },
- src/index.ts:906-948 (handler)MCP server handler for 'get_upload_token' tool: validates params, resolves formId, creates client, calls getUploadToken, and formats response.case 'get_upload_token': { const { formId, transactionId } = args as { formId: string; transactionId: string; }; const { appId, appKey, baseUrl } = getDefaultParams(args); // 验证必需参数 if (!appKey) { throw new Error('appKey is required. Please set JIANDAOYUN_APP_KEY in MCP server configuration.'); } if (!appId) { throw new Error('appId is required. Please provide it as parameter.'); } try { // 创建客户端实例 const jdyClient = new JianDaoYunClient({ appId, appKey, baseUrl }); const resolved = await resolveFormId(formId, appKey); const result = await jdyClient.getUploadToken(resolved.formId, transactionId); return { content: [ { type: 'text', text: JSON.stringify({ success: true, result, formUsed: resolved.formId, appId: resolved.appId || appId }, null, 2), }, ], }; } catch (error) { throw createEnhancedError(error, '获取上传令牌'); } }
- src/client.ts:331-350 (handler)Core implementation of getUploadToken: makes API POST request to JianDaoYun endpoint '/v5/app/entry/file/get_upload_token' to retrieve upload token.async getUploadToken(formId: string, transactionId: string): Promise<any> { try { const response = await this.axios.post<ApiResponse>('/v5/app/entry/file/get_upload_token', { app_id: this.config.appId, entry_id: formId, transaction_id: transactionId }); if (response.data.code !== 0) { throw new Error(`Failed to get upload token: ${response.data.msg}`); } return response.data.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`API request failed: ${error.response?.data?.msg || error.message}`); } throw error; } }