get_defect_link
Retrieve a direct link to a specific defect in Feishu by providing its ID, enabling quick access to issue details for development teams.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ID | Yes |
Implementation Reference
- src/services/mcpServer.ts:43-51 (handler)The handler function that executes the 'get_defect_link' tool logic. It receives the ID, queries the feishuService for the corresponding defect record link (token), and returns it formatted as JSON text in the MCP response structure.async ({ ID }) => { const token = await feishuService.getRecord('ID', ID); return { content: [{ type: "text", text: JSON.stringify({ token }, null, 2) }] }; }
- src/services/mcpServer.ts:40-42 (schema)Input schema for the 'get_defect_link' tool using Zod, validating the 'ID' parameter as a string.{ ID: z.string(), },
- src/services/mcpServer.ts:38-52 (registration)Registration of the 'get_defect_link' tool on the McpServer instance, specifying name, input schema, and handler function.this.server.tool( "get_defect_link", { ID: z.string(), }, async ({ ID }) => { const token = await feishuService.getRecord('ID', ID); return { content: [{ type: "text", text: JSON.stringify({ token }, null, 2) }] }; } );
- src/services/feishuService.ts:51-80 (helper)Helper method that retrieves the shared link (defect link) for a record by filtering on a specified field name and value (used with field 'ID'). It fetches records, extracts record ID, and obtains the shared URL.async getRecord(fieldName: string, fieldValue: string): Promise<string | null> { const tenantAccessToken = await this.getTenantAccessToken(); // 调用列出记录 API const { data } = await axios.get( `https://open.feishu.cn/open-apis/bitable/v1/apps/${this.APP_TOKEN}/tables/${this.TABLE_ID}/records`, { headers: { Authorization: `Bearer ${tenantAccessToken}`, }, params: { filter: `CurrentValue.[${fieldName}] = "${fieldValue}"`, // 修改过滤条件的格式 }, } ); if (data.code !== 0) { throw new Error(`Failed to get records: ${data.msg}`); } // 获取记录 ID const records = data.data.items; if (records.length === 0) { return null; // 没有找到匹配的记录 } const recordId = records[0].record_id; // 构造记录链接 let sharedLink = '查找不到此记录' if (recordId) { sharedLink = (await this.getSharedLink(recordId)) || sharedLink; } return sharedLink; }
- src/services/feishuService.ts:87-111 (helper)Supporting helper that fetches the shared URL for a given record ID, called by getRecord to obtain the defect link.async getSharedLink(recordId: string): Promise<string | null> { const tenantAccessToken = await this.getTenantAccessToken(); // 调用批量获取记录 API const { data } = await axios.post( `https://open.feishu.cn/open-apis/bitable/v1/apps/${this.APP_TOKEN}/tables/${this.TABLE_ID}/records/batch_get`, { record_ids: [recordId], with_shared_url: true, // 请求返回分享链接 }, { headers: { Authorization: `Bearer ${tenantAccessToken}`, "Content-Type": "application/json", }, } ); if (data.code !== 0) { throw new Error(`Failed to get shared link: ${data.msg}`); } const records = data.data.records; if (records.length === 0 || !records[0].shared_url) { return null; // 没有找到分享链接 } return records[0].shared_url; // 返回分享链接 }