Skip to main content

A Docker-based environment for creating mathematical animations with Manim, featuring MCP support

Project description

Manim MCP

License: Apache 2.0 Docker Manim API

A Docker-based environment for creating mathematical animations with Manim, featuring both a CLI interface and a web API with Model Context Protocol (MCP) support for AI assistants.

📑 Overview

This project provides:

  1. Containerized Manim Environment: Run Manim in an isolated, reproducible Docker environment
  2. Web API: Create and manage Manim animations via HTTP requests
  3. MCP Integration: Direct interaction with AI assistants like Claude
  4. File Management: Upload scripts and download generated animations

🚀 Quick Start

Prerequisites

  • Docker and Docker Compose installed on your system

Installation

Option 1: Use the Prebuilt Image (Recommended)

Simply pull the prebuilt image from Docker Hub:

docker pull wstcpyt/manim-docker-mcp:latest

Then run it with docker-compose:

docker compose up -d

Option 2: Build Locally

  1. Clone the repository:

    git clone https://github.com/YOUR_USERNAME/manim-docker-mcp.git
    cd manim-docker-mcp
    
  2. Build the Docker images:

    docker compose build
    

Usage

CLI Mode

Create a Python file in the animations directory (see example below), then run:

docker compose run manim -pql animations/example.py ExampleScene

API Mode

Start the API server:

docker compose up -d manim-api

Access the API documentation at http://localhost:8000/docs

🎬 Creating Animations

Basic Example

Create a file animations/example.py:

from manim import *

class CircleToSquare(Scene):
    def construct(self):
        circle = Circle()
        circle.set_fill(BLUE, opacity=0.5)

        square = Square()
        square.set_fill(RED, opacity=0.5)

        self.play(Create(circle))
        self.wait()
        self.play(Transform(circle, square))
        self.wait()

Running the Animation

# CLI mode with preview (-p), low quality (-ql)
docker compose run manim -pql animations/example.py CircleToSquare

# API mode
curl -X POST "http://localhost:8000/run-manim?filepath=/manim/temp/circle_example.py&scene_name=CircleToSquare&quality=low_quality"

📂 Project Structure

manim-docker-mcp/
├── animations/           # Manim animation scripts
├── app/                  # FastAPI application
├── media/                # Generated animations (CLI mode)
├── output/               # Generated animations (API mode)
├── temp/                 # Temporary files
├── uploads/              # Uploaded animation scripts
├── Dockerfile            # Docker image definition
├── docker-compose.yml    # Docker Compose configuration
└── README.md             # This file

🔧 Configuration

Quality Settings

Flag Resolution Frame Rate Best For
-ql 480p 15fps Quick previews
-qm 720p 30fps General use
-qh 1080p 60fps Presentations
-qk 1440p 60fps Production videos

Other Useful Flags

  • -p: Preview the output file
  • -t: Transparent background
  • --save_last_frame: Render only the last frame
  • -c COLOR: Set background color

🌐 API Documentation

Core Endpoints

List Files

GET /list-files?directory=/manim

Write File

POST /write-file?filepath=/manim/temp/example.py

Run Animation

POST /run-manim?filepath=/manim/temp/example.py&scene_name=CircleToSquare

Download Animation

GET /download-file?filepath=/media/videos/example/480p15/CircleToSquare.mp4

Full API documentation is available at the /docs endpoint.

🤖 AI Assistant Integration (MCP)

This project supports the Model Context Protocol (MCP), enabling AI assistants to:

  1. Create Manim scripts based on natural language descriptions
  2. Run animations and provide download links
  3. Browse and manage generated media files

Example MCP session:

User: Create an animation showing a circle morphing into a square
AI: I'll create that for you...

🔍 Advanced Usage

Custom LaTeX

The container includes a minimal LaTeX installation. Custom LaTeX can be used in animations:

formula = MathTex(r"\int_{a}^{b} f(x) \, dx = F(b) - F(a)")
self.play(Write(formula))

Mounting Custom Directories

Modify the docker-compose.yml file to mount additional directories:

volumes:
  - ./my_custom_dir:/manim/custom

🛠️ Troubleshooting

Common Issues

  • Docker not running: Make sure Docker daemon is running
  • Permission errors: The container needs write access to mounted volumes
  • Missing media: Check the correct output directory (media/ for CLI, output/ for API)

Getting Help

If you encounter issues:

  1. Check the Manim documentation
  2. Search existing GitHub issues
  3. Create a new issue with details about your problem

📜 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🙏 Acknowledgements

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_wstcpyt_manim_mcp-0.1.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iflow_mcp_wstcpyt_manim_mcp-0.1.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file iflow_mcp_wstcpyt_manim_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: iflow_mcp_wstcpyt_manim_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_wstcpyt_manim_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 41ac15bb04884a83c1ba8a380a683e1cd8d749a44bf79713280e68558311438a
MD5 fd438e2a136ba25f9c552a0e64caf63d
BLAKE2b-256 1b734a830f7672c178b40ed26af25bb943b95ea18dd9981d539e517785a440a3

See more details on using hashes here.

File details

Details for the file iflow_mcp_wstcpyt_manim_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_wstcpyt_manim_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_wstcpyt_manim_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f51a80aa918c1badd7bebd3e44896d0c969be0645ec7c04b862a831b746a70de
MD5 3c8079d889450010c9c47fea45af14c5
BLAKE2b-256 73a0aad97a0fc10a9cde371e5bd69e2943af422b92ab5921cb879b48ecc02711

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page