Skip to main content
Glama

upload_caption

Upload SRT or WebVTT caption tracks to YouTube videos. Set language, track name, and format. Use draft mode to iterate without exposing captions to viewers.

Instructions

Upload a caption track (SRT or WebVTT) to a video. Creates a new track — use a distinct name per language/track, or is_draft=true while iterating.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_idYesVideo ID the caption belongs to.
languageYesBCP-47 language code, e.g. 'en', 'en-US', 'es', 'ja'. Must match a language the video supports.
nameNoCaption track name shown in the player's caption menu. Empty string for the default track.
caption_textYesCaption content as a string (SRT or WebVTT format). Source this from a file or the model's output.
formatNoContent type of caption_text: 'srt' (SubRip, application/x-subrip) or 'vtt' (WebVTT, text/vtt).srt
is_draftNoDraft captions aren't visible to viewers. Useful while reviewing auto-translations.

Implementation Reference

  • The 'upload_caption' tool handler: registers an MCP tool that accepts video_id, language, name, caption_text, format, and is_draft. It converts the caption text to a Uint8Array and calls client.insertCaption, then returns a result summary.
    server.tool(
      "upload_caption",
      "Upload a caption track (SRT or WebVTT) to a video. Creates a new track — use a distinct `name` per language/track, or `is_draft=true` while iterating.",
      uploadCaptionSchema,
      async (args) => {
        const contentType =
          args.format === "vtt" ? "text/vtt" : "application/x-subrip";
        const bytes = new Uint8Array(Buffer.from(args.caption_text, "utf-8"));
        const result = (await client.insertCaption({
          videoId: args.video_id,
          language: args.language,
          name: args.name,
          isDraft: args.is_draft,
          body: bytes,
          captionContentType: contentType,
        })) as {
          id?: string;
          snippet?: { status?: string };
        };
        return {
          content: [
            {
              type: "text" as const,
              text: [
                `Uploaded caption track: ${result.id ?? "(unknown id)"}`,
                `  video: ${args.video_id}`,
                `  language: ${args.language}`,
                `  name: "${args.name}"`,
                `  format: ${args.format}`,
                `  status: ${result.snippet?.status ?? "?"}`,
                args.is_draft ? "  (draft — not visible to viewers)" : "",
              ]
                .filter(Boolean)
                .join("\n"),
            },
          ],
        };
      },
    );
  • Zod schema for upload_caption parameters: video_id, language, name (default ''), caption_text (SRT/VTT string), format (srt|vtt, default srt), is_draft (boolean, default false).
    const uploadCaptionSchema = {
      video_id: z.string().describe("Video ID the caption belongs to."),
      language: z
        .string()
        .describe(
          "BCP-47 language code, e.g. 'en', 'en-US', 'es', 'ja'. Must match a language the video supports.",
        ),
      name: z
        .string()
        .default("")
        .describe(
          "Caption track name shown in the player's caption menu. Empty string for the default track.",
        ),
      caption_text: z
        .string()
        .describe(
          "Caption content as a string (SRT or WebVTT format). Source this from a file or the model's output.",
        ),
      format: z
        .enum(["srt", "vtt"])
        .default("srt")
        .describe(
          "Content type of caption_text: 'srt' (SubRip, application/x-subrip) or 'vtt' (WebVTT, text/vtt).",
        ),
      is_draft: z
        .boolean()
        .default(false)
        .describe(
          "Draft captions aren't visible to viewers. Useful while reviewing auto-translations.",
        ),
    };
  • src/server.ts:51-51 (registration)
    Registration of registerCaptionTools on the MCP server, which registers the 'upload_caption' tool (among others).
    registerCaptionTools(s, youtube);
  • The registerCaptionTools export function that registers 'upload_caption' (line 79-117), 'list_captions', and 'delete_caption' tools on the MCP server.
    export function registerCaptionTools(
      server: McpServer,
      client: YouTubeClient,
    ): void {
      server.tool(
        "list_captions",
        "List caption tracks on a video with their language, name, status, and whether they are drafts.",
        listCaptionsSchema,
        async (args) => {
          const res = await client.listCaptions(args.video_id);
          if (res.items.length === 0) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Video ${args.video_id} has no caption tracks.`,
                },
              ],
            };
          }
          const lines = [
            `Found ${res.items.length} caption track(s):`,
            ...res.items.map((c) => {
              const s = c.snippet ?? {};
              const draft = s.isDraft ? " [draft]" : "";
              const kind = s.trackKind ? ` (${s.trackKind})` : "";
              return `  ${c.id} — ${s.language ?? "?"} "${s.name ?? ""}"${kind} [${s.status ?? "?"}]${draft}`;
            }),
          ];
          return { content: [{ type: "text" as const, text: lines.join("\n") }] };
        },
      );
    
      server.tool(
        "upload_caption",
        "Upload a caption track (SRT or WebVTT) to a video. Creates a new track — use a distinct `name` per language/track, or `is_draft=true` while iterating.",
        uploadCaptionSchema,
        async (args) => {
          const contentType =
            args.format === "vtt" ? "text/vtt" : "application/x-subrip";
          const bytes = new Uint8Array(Buffer.from(args.caption_text, "utf-8"));
          const result = (await client.insertCaption({
            videoId: args.video_id,
            language: args.language,
            name: args.name,
            isDraft: args.is_draft,
            body: bytes,
            captionContentType: contentType,
          })) as {
            id?: string;
            snippet?: { status?: string };
          };
          return {
            content: [
              {
                type: "text" as const,
                text: [
                  `Uploaded caption track: ${result.id ?? "(unknown id)"}`,
                  `  video: ${args.video_id}`,
                  `  language: ${args.language}`,
                  `  name: "${args.name}"`,
                  `  format: ${args.format}`,
                  `  status: ${result.snippet?.status ?? "?"}`,
                  args.is_draft ? "  (draft — not visible to viewers)" : "",
                ]
                  .filter(Boolean)
                  .join("\n"),
              },
            ],
          };
        },
      );
    
      server.tool(
        "delete_caption",
        "Delete a caption track by ID. Use list_captions to find the track ID first.",
        deleteCaptionSchema,
        async (args) => {
          await client.deleteCaption(args.caption_id);
          return {
            content: [
              {
                type: "text" as const,
                text: `Deleted caption track ${args.caption_id}.`,
              },
            ],
          };
        },
      );
    }
  • YouTubeClient.insertCaption helper: builds a multipart/related request with JSON metadata and caption body bytes, POSTs to the YouTube API's captions endpoint.
    /** Upload a caption track for a video. Body is typically SRT or WebVTT text. */
    async insertCaption(params: {
      videoId: string;
      language: string;
      name: string;
      isDraft: boolean;
      body: Uint8Array;
      captionContentType: string;
    }): Promise<unknown> {
      const boundary = `youtube-mcp-${Date.now().toString(16)}`;
      const metadata = JSON.stringify({
        snippet: {
          videoId: params.videoId,
          language: params.language,
          name: params.name,
          isDraft: params.isDraft,
        },
      });
      const opening = Buffer.from(
        `--${boundary}\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n${metadata}\r\n--${boundary}\r\nContent-Type: ${params.captionContentType}\r\n\r\n`,
        "utf-8",
      );
      const closing = Buffer.from(`\r\n--${boundary}--\r\n`, "utf-8");
      const body = Buffer.concat([opening, Buffer.from(params.body), closing]);
    
      const url = new URL(`${UPLOAD_API}/captions`);
      url.searchParams.set("part", "snippet");
      url.searchParams.set("uploadType", "multipart");
      const token = await this.ensureAccessToken();
      const res = await fetch(url.toString(), {
        method: "POST",
        headers: {
          Authorization: `Bearer ${token}`,
          "Content-Type": `multipart/related; boundary=${boundary}`,
          "Content-Length": String(body.length),
        },
        body,
      });
      if (!res.ok) {
        throw new Error(
          `YouTube caption insert failed: ${res.status} ${await res.text()}`,
        );
      }
      return res.json();
    }
Behavior2/5

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

No annotations provided. Description only mentions creation but omits critical behavioral details such as error handling (e.g., duplicate tracks), authentication requirements, side effects, or return value. This leaves significant gaps for an agent.

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

Conciseness5/5

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

Two sentences with no wasted words. First sentence states action and formats; second provides actionable usage advice. Front-loaded and efficient.

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

Completeness3/5

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

Description covers core purpose, formats, and basic usage tips, but lacks information on success/error responses, validation of caption_text format, or prerequisites (e.g., video existence). For a mutation tool without output schema, more context would be beneficial.

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

Parameters4/5

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

Input schema has 100% coverage with descriptions for all 6 parameters. The description adds value by advising on distinct name usage and draft iteration, which goes beyond schema defaults. Some parameters like caption_text could benefit from format validation hints, but schema covers basics.

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?

Description clearly states 'Upload a caption track (SRT or WebVTT) to a video' with specific verb and resource. It differentiates from sibling tools like delete_caption by explicitly saying 'Creates a new track', making its purpose distinct.

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

Usage Guidelines3/5

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

Provides useful tips (e.g., distinct name per language/track, use is_draft while iterating) but does not explicitly contrast with alternatives like delete_caption or list_captions. Usage context is implied rather than stated.

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/miller-joe/youtube-mcp'

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