DEV Community

Cover image for Building a Remote MCP Server to Handle Large Files (Audio/Video)
Leon
Leon

Posted on Edited on

Building a Remote MCP Server to Handle Large Files (Audio/Video)

The rise of AI agents (like Cursor and Claude Desktop) is incredible. But if you've ever tried to build a custom tool for them to process large files—like a 50MB audio track or a video—you already know the pain.

LLMs have strict token and payload limits. You can't just pass a local .mp3 file into a prompt.

In this post, I'll share the architectural pattern I used to build a Remote MCP (Model Context Protocol) Server that allows an AI agent to process heavy media files entirely hands-free.

The Core Problem: File Size & Context Switching

When you want an AI to process a file, the naive approach is to base64 encode it and send it. This blows up the context window instantly.

Alternatively, you can build a local MCP server that reads the file directly. But what if the processing requires heavy GPU compute that your local laptop doesn't have?

The Solution: The Async Upload Pattern

To solve this, I designed an MCP server that uses an asynchronous pipeline with presigned URLs.

Here is the exact flow the AI agent follows:

  1. get_upload_url: The agent calls this tool. The server returns a presigned URL (e.g., an S3/R2 URL).
  2. Local Upload: The agent (or a local script it triggers) uploads the file directly to cloud storage. No file data ever touches the LLM context window.
  3. submit_task: The agent tells the server, "Hey, process this uploaded file."
  4. check_task_status: The agent polls the server (or uses webhooks) to check when the GPU processing is done.
  5. get_download_url: Finally, the agent gets a URL to download the processed stems, MIDI, or denoised audio back to the local workspace.

Why This Rocks for Agentic Workflows

This pattern completely decouples the AI's reasoning from the heavy lifting.

Here is what a prompt looks like in Cursor:

"Extract the vocals from ./demo.mp3 and save the result locally."

The AI handles the file system, calls the tools, waits for the GPU, and drops the finished file right back into your project folder. It feels like magic.

Implementation Tips

  • Use Streamable HTTP: If you are building for remote clients like Claude or Cursor, stdio isn't enough. Host your server and expose it via HTTP.
  • Handle Polling Gracefully: LLMs can get stuck in loops if a task fails. Make sure your check_task_status returns clear error states, not just "pending".
  • Authentication: Protect your server with OAuth. Exposing a GPU-backed API without auth is a quick way to get a massive bill.

Open Source Example

I built this entire architecture for Sonicaura MCP (an audio processing engine). It's completely open-source and published in the official MCP Registry if you want to dig into the code or try it out.

If you are building agents, I'd love to know: How are you handling large file processing in your MCP servers? Let me know in the comments!

Top comments (3)

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Keeping the file out of the context window with a presigned URL, then having check_task_status return a clear error instead of pending, is the part that would save a lot of stuck loops.

Collapse
 
paul_irolla_6b5ae261d0224 profile image
Paul Irolla •

Return the transcript, not the file. The model reads text, and a long transcript keeps replaying turn after turn, so cut it to the segments the next step needs.

Collapse
 
warmcoding profile image
Leon •

Thanks for reading! If you're building MCP servers, let me know what architecture you're using for large files. Happy to answer any questions about the async upload pattern.