Skip to main content
Glama

download_attachment

Retrieve the download URL for subsidy-related attachment documents by specifying subsidy ID, category, and index. Simplify access to essential grant materials.

Instructions

Get the download URL for a subsidy's attachment document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesAttachment category
indexYesAttachment index (starts from 0)
subsidy_idYesSubsidy ID

Implementation Reference

  • The main handler for the 'download_attachment' tool. Fetches subsidy details from the API, validates category and index, retrieves the specific attachment's base64 data, calculates its byte size, and returns metadata and data in structured format.
    case "download_attachment": { const args = DownloadAttachmentSchema.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; 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]; if ( !subsidyInfo[args.category] || !Array.isArray(subsidyInfo[args.category]) ) { return { content: [ { type: "text", text: `Attachment category '${args.category}' does not exist.`, }, ], }; } const attachments = subsidyInfo[args.category]!; if (args.index < 0 || args.index >= attachments.length) { return { content: [ { type: "text", text: `Attachment index ${args.index} is invalid.`, }, ], }; } const attachment = attachments[args.index]; const actualByteSize = Buffer.from(attachment.data, "base64").length; const output = { subsidy_id: subsidyInfo.id, subsidy_name: subsidyInfo.name, category: args.category, index: args.index, file_name: attachment.name, data: attachment.data, data_size_bytes: actualByteSize, encoding: "base64" as const, }; return { content: [ { type: "text", text: JSON.stringify( { ...output, data: `[Base64 data: ${actualByteSize} bytes]`, }, null, 2 ), }, ], structuredContent: output, }; } catch (error) { return { content: [ { type: "text", text: `Error occurred: ${ error instanceof Error ? error.message : "Unknown error" }`, }, ], }; } }
  • Zod schema defining the input parameters for the 'download_attachment' tool: subsidy_id (string), category (enum), index (non-negative integer).
    const DownloadAttachmentSchema = z.object({ subsidy_id: z.string(), category: z.enum([ "application_guidelines", "outline_of_grant", "application_form", ]), index: z.number().int().min(0), });
  • index.ts:84-112 (registration)
    Registration of the 'download_attachment' tool in the list_tools handler, providing name, description, and input schema matching the Zod schema.
    { name: "download_attachment", description: "Download a subsidy's attachment document. Returns the file data in base64 encoding along with metadata. First call get_subsidy_detail to see the attachments array for each category (application_guidelines, outline_of_grant, application_form), then use the 'index' from attachments[n].index to download the specific file.", inputSchema: { type: "object", properties: { subsidy_id: { type: "string", description: "Subsidy ID", }, category: { type: "string", enum: [ "application_guidelines", "outline_of_grant", "application_form", ], description: "Attachment category", }, index: { type: "integer", description: "Attachment index (starts from 0)", minimum: 0, }, }, required: ["subsidy_id", "category", "index"], }, },

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tachibanayu24/jgrants-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server