├── .gitignore ├── Demo-manim-mcp.gif ├── LICENSE.txt ├── README.md └── src └── manim_server.py /.gitignore: -------------------------------------------------------------------------------- 1 | *_pycache_/ -------------------------------------------------------------------------------- /Demo-manim-mcp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiemj/manim-mcp-server/da23214426a56ce3ba4da39b0718d64cf97cd23c/Demo-manim-mcp.gif -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Hannes Rudolph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Manim MCP Server 2 | 3 | ![Manim MCP Demo](Demo-manim-mcp.gif) 4 | 5 | 6 | ## Overview 7 | 8 | This is an MCP (Model Context Protocol) server that executes Manim animation code and returns the generated video. It allows users to send Manim scripts and receive the rendered animation. 9 | 10 | ## Features 11 | 12 | - Executes Manim Python scripts. 13 | - Saves animation output in a visible media folder. 14 | - Allows users to clean up temporary files after execution. 15 | - Portable and configurable via environment variables. 16 | 17 | ## Installation 18 | 19 | ### Prerequisites 20 | 21 | Ensure you have the following installed: 22 | 23 | - Python 3.8+ 24 | - Manim (Community Version) 25 | - MCP 26 | 27 | ### Install Manim 28 | 29 | ```sh 30 | pip install manim 31 | ``` 32 | 33 | ### Install MCP 34 | 35 | ```sh 36 | pip install mcp 37 | ``` 38 | 39 | ### Clone the Repository 40 | 41 | ```sh 42 | git clone https://github.com/abhiemj/manim-mcp-server.git 43 | cd manim-mcp-server 44 | ``` 45 | 46 | ## Integration with Claude 47 | 48 | To integrate the Manim MCP server with Claude, add the following to your `claude_desktop_config.json` file: 49 | 50 | ```json 51 | { 52 | "mcpServers": { 53 | "manim-server": { 54 | "command": "/absolute/path/to/python", 55 | "args": [ 56 | "/absolute/path/to/manim-mcp-server/src/manim_server.py" 57 | ], 58 | "env": { 59 | "MANIM_EXECUTABLE": "/Users/[Your_username]/anaconda3/envs/manim2/Scripts/manim.exe" 60 | } 61 | } 62 | } 63 | } 64 | ``` 65 | 66 | ### Finding Your Python Path 67 | 68 | To find your Python executable path, use the following command: 69 | 70 | #### Windows (PowerShell): 71 | ```sh 72 | (Get-Command python).Source 73 | ``` 74 | 75 | #### Windows (Command Prompt/Terminal): 76 | ```sh 77 | where python 78 | ``` 79 | 80 | #### Linux/macOS (Terminal): 81 | ```sh 82 | which python 83 | ``` 84 | 85 | This ensures that Claude can communicate with the Manim MCP server to generate animations dynamically. 86 | 87 | ## Contributing 88 | 89 | 1. Fork the repository. 90 | 2. Create a new branch: 91 | ```sh 92 | git checkout -b add-feature 93 | ``` 94 | 3. Make changes and commit: 95 | ```sh 96 | git commit -m "Added a new feature" 97 | ``` 98 | 4. Push to your fork: 99 | ```sh 100 | git push origin add-feature 101 | ``` 102 | 5. Open a pull request. 103 | 104 | ## License 105 | 106 | This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository. 107 | 108 | ## Author 109 | 110 | Created by **[abhiemj](https://github.com/abhiemj)**. Contributions welcome! 🚀 111 | 112 | ### **Listed in Awesome MCP Servers** 113 | This repository is featured in the [Awesome MCP Servers](https://github.com/punkpeye/awesome-mcp-servers) repository under the **Animation & Video** category. Check it out along with other great MCP server implementations! 114 | 115 | 116 | ## **Acknowledgments** 117 | - Thanks to the [Manim Community](https://www.manim.community/) for their amazing animation library. 118 | - Inspired by the open-source MCP ecosystem. 119 | 120 | ## Find me at 121 | aiburner_official 122 | @aiburner_official 123 | -------------------------------------------------------------------------------- /src/manim_server.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import tempfile 3 | import os 4 | import shutil 5 | from mcp.server.fastmcp import FastMCP 6 | 7 | mcp = FastMCP() 8 | 9 | # Get Manim executable path from environment variables or assume it's in the system PATH 10 | MANIM_EXECUTABLE = os.getenv("MANIM_EXECUTABLE", "manim") #MANIM_PATH "/Users/[Your_username]/anaconda3/envs/manim2/Scripts/manim.exe" 11 | 12 | TEMP_DIRS = {} 13 | BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "media") 14 | os.makedirs(BASE_DIR, exist_ok=True) # Ensure the media folder exists 15 | 16 | @mcp.tool() 17 | def execute_manim_code(manim_code: str) -> str: 18 | """Execute the Manim code""" 19 | # tmpdir = tempfile.mkdtemp() # Creates a temp directory that won't be deleted immediately 20 | tmpdir = os.path.join(BASE_DIR, "manim_tmp") 21 | os.makedirs(tmpdir, exist_ok=True) # Ensure the temp folder exists 22 | script_path = os.path.join(tmpdir, "scene.py") 23 | 24 | try: 25 | # Write the Manim script to the temp directory 26 | with open(script_path, "w") as script_file: 27 | script_file.write(manim_code) 28 | 29 | # Execute Manim with the correct path 30 | result = subprocess.run( 31 | [MANIM_EXECUTABLE, "-p", script_path], #MANIM_PATH "/Users/[Your_username]/anaconda3/envs/manim2/Scripts/manim.exe" 32 | capture_output=True, 33 | text=True, 34 | cwd=tmpdir 35 | ) 36 | 37 | if result.returncode == 0: 38 | TEMP_DIRS[tmpdir] = True 39 | print(f"Check the generated video at: {tmpdir}") 40 | 41 | return "Execution successful. Video generated." 42 | else: 43 | return f"Execution failed: {result.stderr}" 44 | 45 | except Exception as e: 46 | return f"Error during execution: {str(e)}" 47 | 48 | 49 | 50 | @mcp.tool() 51 | def cleanup_manim_temp_dir(directory: str) -> str: 52 | """Clean up the specified Manim temporary directory after execution.""" 53 | try: 54 | if os.path.exists(directory): 55 | shutil.rmtree(directory) 56 | return f"Cleanup successful for directory: {directory}" 57 | else: 58 | return f"Directory not found: {directory}" 59 | except Exception as e: 60 | return f"Failed to clean up directory: {directory}. Error: {str(e)}" 61 | 62 | 63 | if __name__ == "__main__": 64 | mcp.run(transport="stdio") 65 | 66 | 67 | 68 | 69 | --------------------------------------------------------------------------------