get_upload_token
Generate file upload tokens for file/image fields in JianDaoYun forms, enabling secure and traceable uploads by specifying app ID, form ID, and transaction ID.
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:906-948 (handler)MCP tool handler for 'get_upload_token': validates parameters, resolves form ID, instantiates client, calls getUploadToken, formats and returns 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/index.ts:462-487 (schema)Schema definition and registration entry for the 'get_upload_token' tool in the MCP tools array.{ 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/client.ts:331-350 (helper)Core implementation of getUploadToken in JianDaoYunClient: POST request to JianDaoYun API 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; } }