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"],
      },
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the return format ('Returns the file data in base64 encoding along with metadata'), which is useful. However, it lacks details on error handling, rate limits, authentication needs, or file size constraints, leaving gaps for a download operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core purpose. The second sentence adds necessary context about the return format, and the third provides crucial usage guidance. While efficient, it could be slightly more concise by integrating the return format into the first sentence without losing clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (download operation with three parameters) and no output schema, the description is mostly complete: it explains the purpose, return format, and usage workflow. However, it lacks details on error cases or behavioral traits like rate limits, which would enhance completeness for a tool with no annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all three parameters (subsidy_id, category, index) with descriptions and constraints. The description adds minimal value beyond the schema by mentioning the index comes from 'attachments[n].index' and the categories, but it doesn't provide additional syntax or format details. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Download a subsidy's attachment document') and resource ('subsidy's attachment'), distinguishing it from siblings like get_subsidy_detail (which retrieves subsidy details) and list_subsidies (which lists subsidies). It explicitly mentions the verb 'download' and the target resource, avoiding tautology.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool: 'First call get_subsidy_detail to see the attachments array for each category... then use the 'index' from attachments[n].index to download the specific file.' It names the alternative tool (get_subsidy_detail) and specifies the prerequisite step, clearly outlining the workflow.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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