Skip to main content
Glama
tachibanayu24

jgrants-mcp

download_attachment

Download subsidy attachment documents from Japan's Digital Agency grants API. Retrieve files like application guidelines, grant outlines, and forms using subsidy ID, category, and index parameters.

Instructions

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.

Input Schema

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

Implementation Reference

  • The handler function for the 'download_attachment' tool. It fetches the subsidy details from the API, validates the category and index, extracts the specific attachment's base64-encoded data, computes its size, and returns the file metadata along with the data in a structured response.
    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 used for input validation in the download_attachment tool handler.
    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 ListTools response, including its name, description, and input 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"],
      },
    },

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other 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