MCP Apps
    Preparing search index...

    Function getToolFileArgument

    • Find the argument through which a tool takes a file when it is opened from a "file" entrypoint: its one top-level property marked with x-mcp-file (File Uploads extension, io.modelcontextprotocol/files).

      Returns undefined when the input schema marks no top-level property or several, or requires another property: the host cannot open such a tool with a file alone.

      Parameters

      • tool: Partial<Tool>

        A tool object with an inputSchema

      Returns string | undefined

      The name of the file argument, if the tool can be opened with a file alone

      const argument = getToolFileArgument(tool);
      if (argument === undefined) {
      throw new Error(`${tool.name} cannot be opened with a file alone`);
      }

      // The file is the only argument
      const result = await client.callTool({
      name: tool.name,
      arguments: { [argument]: fileInput },
      });