get_subsidy_detail
Retrieve detailed information about a specific subsidy using its unique ID. Access comprehensive data for accurate insights and decision-making.
Instructions
Get detailed information about a specific subsidy. Use the subsidy ID, not the title.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subsidy_id | Yes | Subsidy ID |
Implementation Reference
- index.ts:159-259 (handler)Handler function for the 'get_subsidy_detail' tool. Parses input arguments using the schema, fetches detailed subsidy information from the API, processes attachment metadata (sizes without full base64 decoding), constructs a summary with attachment lists, and returns structured content.case "get_subsidy_detail": { const args = GetSubsidyDetailSchema.parse(request.params.arguments); try { const response = await fetch( `${API_BASE_URL}/subsidies/id/${args.subsidy_id}` ); if (!response.ok) { const errorBody = await response.text(); throw new Error(`API error: ${response.status} - ${errorBody}`); } const data = (await response.json()) as SubsidyDetailResponse; // Check result if (!data.result || data.result.length === 0) { return { content: [ { type: "text", text: `Subsidy with ID ${args.subsidy_id} was not found.`, }, ], }; } const subsidyInfo = data.result[0]; // 添付ファイルは軽量メタ情報(index, name, サイズ等)のみ返し、実データは download_attachment で取得 // Base64 文字列長から概算バイトサイズを計算(デコードコストを回避) const calculateBase64Size = (base64: string): number => { // 改行などの空白文字を除去(API が 76 文字ごとの改行付きで返すケースに対応) const cleanBase64 = base64.replace(/\s+/g, ""); const paddingCount = cleanBase64.endsWith("==") ? 2 : cleanBase64.endsWith("=") ? 1 : 0; return Math.floor((cleanBase64.length * 3) / 4) - paddingCount; }; // 添付配列から軽量メタ情報を生成する共通ヘルパー const buildAttachmentList = ( attachments?: Array<{ name: string; data: string }> ) => attachments?.map((attachment, index) => ({ index, name: attachment.name, sizeBytes: calculateBase64Size(attachment.data), })) ?? []; const applicationGuidelinesAttachments = buildAttachmentList( subsidyInfo.application_guidelines ); const outlineOfGrantAttachments = buildAttachmentList( subsidyInfo.outline_of_grant ); const applicationFormAttachments = buildAttachmentList( subsidyInfo.application_form ); const subsidySummary: SubsidyDetailSummary = { ...subsidyInfo, application_guidelines: { count: applicationGuidelinesAttachments.length, hasAttachments: applicationGuidelinesAttachments.length > 0, attachments: applicationGuidelinesAttachments, }, outline_of_grant: { count: outlineOfGrantAttachments.length, hasAttachments: outlineOfGrantAttachments.length > 0, attachments: outlineOfGrantAttachments, }, application_form: { count: applicationFormAttachments.length, hasAttachments: applicationFormAttachments.length > 0, attachments: applicationFormAttachments, }, }; return { content: [ { type: "text", text: JSON.stringify(subsidySummary, null, 2), }, ], structuredContent: subsidySummary, }; } catch (error) { return { content: [ { type: "text", text: `Error occurred: ${ error instanceof Error ? error.message : "Unknown error" }`, }, ], }; } }
- index.ts:23-25 (schema)Zod schema for validating input parameters of the 'get_subsidy_detail' tool, requiring a 'subsidy_id' string.const GetSubsidyDetailSchema = z.object({ subsidy_id: z.string(), });
- index.ts:69-83 (registration)Tool registration in the list_tools response, defining name, description, and input schema for 'get_subsidy_detail'.{ name: "get_subsidy_detail", description: "Get detailed information about a specific subsidy. Use the subsidy ID, not the title.", inputSchema: { type: "object", properties: { subsidy_id: { type: "string", description: "Subsidy ID", }, }, required: ["subsidy_id"], }, },