Skip to main content
Glama

youtube-to-markdown

Convert YouTube videos to markdown format with transcripts for easy documentation and content creation.

Instructions

Convert a YouTube video to markdown, including transcript if available

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL of the YouTube video

Implementation Reference

  • Handler switch case for youtube-to-markdown (shared with webpage tools): validates URL, security checks, calls Markdownify.toMarkdown with URL
    case tools.YouTubeToMarkdownTool.name:
    case tools.BingSearchResultToMarkdownTool.name:
    case tools.WebpageToMarkdownTool.name:
      if (!validatedArgs.url) {
        throw new Error("URL is required for this tool");
      }     
      
      const parsedUrl = new URL(validatedArgs.url);
      if (!["http:", "https:"].includes(parsedUrl.protocol)) {
        throw new Error("Only http: and https: schemes are allowed.");
      }
      
      if (is_ip_private(parsedUrl.hostname)) {
        throw new Error(`Fetching ${validatedArgs.url} is potentially dangerous, aborting.`);
      }
    
      result = await Markdownify.toMarkdown({
        url: validatedArgs.url,
        projectRoot: validatedArgs.projectRoot,
        uvPath: validatedArgs.uvPath || process.env.UV_PATH,
      });
      break;
  • Tool schema definition including name, description, and input schema requiring 'url'
    export const YouTubeToMarkdownTool = ToolSchema.parse({
      name: "youtube-to-markdown",
      description:
        "Convert a YouTube video to markdown, including transcript if available",
      inputSchema: {
        type: "object",
        properties: {
          url: {
            type: "string",
            description: "URL of the YouTube video",
          },
        },
        required: ["url"],
      },
    });
  • src/server.ts:33-37 (registration)
    Tool registration via ListTools handler returning all exported tool schemas from tools.ts
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: Object.values(tools),
      };
    });
  • Core conversion helper: for URL input (used by youtube-to-markdown), fetches content, saves to temp file, runs markitdown via uv, saves output markdown
    static async toMarkdown({
      filePath,
      url,
      projectRoot = path.resolve(__dirname, ".."),
      uvPath = "~/.local/bin/uv",
    }: {
      filePath?: string;
      url?: string;
      projectRoot?: string;
      uvPath?: string;
    }): Promise<MarkdownResult> {
      try {
        let inputPath: string;
        let isTemporary = false;
    
        if (url) {
          const response = await fetch(url);
    
          let extension = null;
    
          if (url.endsWith(".pdf")) {
            extension = "pdf";
          }
    
          const arrayBuffer = await response.arrayBuffer();
          const content = Buffer.from(arrayBuffer);
    
          inputPath = await this.saveToTempFile(content, extension);
          isTemporary = true;
        } else if (filePath) {
          inputPath = filePath;
        } else {
          throw new Error("Either filePath or url must be provided");
        }
    
        const text = await this._markitdown(inputPath, projectRoot, uvPath);
        const outputPath = await this.saveToTempFile(text);
    
        if (isTemporary) {
          fs.unlinkSync(inputPath);
        }
    
        return { path: outputPath, text };
      } catch (e: unknown) {
        if (e instanceof Error) {
          throw new Error(`Error processing to Markdown: ${e.message}`);
        } else {
          throw new Error("Error processing to Markdown: Unknown error occurred");
        }
      }
    }
  • Helper that executes the external 'markitdown' tool (which handles YouTube conversion) via uv run on the input file path
    private static async _markitdown(
      filePath: string,
      projectRoot: string,
      uvPath: string,
    ): Promise<string> {
      const venvPath = path.join(projectRoot, ".venv");
      const markitdownPath = path.join(
        venvPath,
        process.platform === "win32" ? "Scripts" : "bin",
        `markitdown${process.platform === "win32" ? ".exe" : ""}`,
      );
    
      if (!fs.existsSync(markitdownPath)) {
        throw new Error("markitdown executable not found");
      }
    
      // Expand tilde in uvPath if present
      const expandedUvPath = expandHome(uvPath);
    
      // Use execFile to prevent command injection
      const { stdout, stderr } = await execFileAsync(expandedUvPath, [
        "run",
        markitdownPath,
        filePath,
      ]);
    
      if (stderr) {
        throw new Error(`Error executing command: ${stderr}`);
      }
    
      return stdout;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions including a transcript 'if available', which hints at conditional behavior, but doesn't explain what happens when a transcript isn't available (e.g., error, fallback, or partial output). It also omits details like rate limits, authentication needs, or output format specifics, leaving gaps for a tool that performs conversion.

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?

The description is a single, efficient sentence that front-loads the core functionality ('Convert a YouTube video to markdown') and adds a key detail ('including transcript if available'). There is no wasted text, and it's appropriately sized for a tool with one parameter and no complex annotations.

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?

Given the tool's moderate complexity (conversion with conditional transcript inclusion), lack of annotations, and no output schema, the description is minimally adequate. It states what the tool does but lacks details on behavioral traits, error handling, or output structure. It meets the basic requirement but leaves significant gaps that could hinder effective use by an AI agent.

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?

The input schema has 100% coverage with a single parameter 'url' clearly described. The description doesn't add any parameter-specific information beyond what the schema provides, such as URL format requirements or validation rules. With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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

Purpose4/5

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

The description clearly states the tool's purpose: converting a YouTube video to markdown, including transcript if available. It specifies the verb 'convert' and resource 'YouTube video', making the action clear. However, it doesn't explicitly distinguish this tool from sibling tools like 'audio-to-markdown' or 'webpage-to-markdown', which handle different input types but share the same output format.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'audio-to-markdown' (which might handle audio from YouTube) or 'webpage-to-markdown' (which could process YouTube pages), nor does it specify prerequisites such as video accessibility or transcript availability. Usage is implied by the tool name and description alone.

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/zcaceres/markdownify-mcp'

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