Compare commits

...

11 Commits

Author SHA1 Message Date
ahujasid
a6ca7509d1
Merge pull request #126 from cageyv/main
add environment variables configuration for Blender connection host and port
2025-08-21 12:43:16 -07:00
ahujasid
a35a1e10a7
Merge pull request #145 from satishgoda/vscode_button
Add Visual Studio Code integration section to README
2025-08-21 12:40:52 -07:00
ahujasid
75787a81cb
Merge pull request #147 from gregzaal/main
Add UserAgent header as required by Poly Haven's API terms
2025-08-21 12:40:24 -07:00
ahujasid
cc0be00c7c
Update README.md 2025-08-18 11:23:09 -07:00
Greg Zaal
5a7765c2a8 Add UserAgent header as required by Poly Haven's API terms 2025-08-12 10:48:59 +02:00
Satish Goda
e85ea6390f docs: enhance Visual Studio Code integration section in README 2025-08-04 16:18:23 -07:00
Satish Goda
60b1b41e63 docs: add Visual Studio Code integration section to README
https://vscodemcp.com/
2025-08-04 14:15:37 -07:00
ahujasid
9b9a14f7c7
Update README.md 2025-08-02 18:31:52 -07:00
ahujasid
0bc765544e Revert "removed description from server"
This reverts commit a2a28b949c.
2025-08-02 18:09:25 -07:00
ahujasid
a2a28b949c removed description from server 2025-08-02 18:06:35 -07:00
Vladimir Samoylov
7c294217ff
add environment variables configuration for Blender connection host and port 2025-06-16 00:02:46 +07:00
3 changed files with 306 additions and 274 deletions

View File

@ -4,6 +4,8 @@
BlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
**We have no official website. Any website you see online is unofficial and has no affiliation with this project. Use them at your own risk.**
[Full tutorial](https://www.youtube.com/watch?v=lCyQ717DuzQ)
### Join the Community
@ -30,6 +32,8 @@ Give feedback, get inspired, and build on top of the MCP: [Discord](https://disc
[CodeRabbit](https://www.coderabbit.ai/)
[Satish Goda](https://github.com/satishgoda)
**All supporters:**
[Support this project](https://github.com/sponsors/ahujasid)
@ -87,6 +91,18 @@ Otherwise installation instructions are on their website: [Install uv](https://d
**⚠️ Do not proceed before installing UV**
### Environment Variables
The following environment variables can be used to configure the Blender connection:
- `BLENDER_HOST`: Host address for Blender socket server (default: "localhost")
- `BLENDER_PORT`: Port number for Blender socket server (default: 9876)
Example:
```bash
export BLENDER_HOST='host.docker.internal'
export BLENDER_PORT=9876
```
### Claude for Desktop Integration
@ -151,6 +167,12 @@ For Windows users, go to Settings > MCP > Add Server, add a new server with the
**⚠️ Only run one instance of the MCP server (either on Cursor or Claude Desktop), not both**
### Visual Studio Code Integration
_Prerequisites_: Make sure you have [Visual Studio Code](https://code.visualstudio.com/) installed before proceeding.
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_blender--mcp_server-0098FF?style=flat-square&logo=visualstudiocode&logoColor=ffffff)](vscode:mcp/install?%7B%22name%22%3A%22blender-mcp%22%2C%22type%22%3A%22stdio%22%2C%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22blender-mcp%22%5D%7D)
### Installing the Blender Addon
1. Download the `addon.py` file from this repo

View File

@ -28,6 +28,10 @@ bl_info = {
RODIN_FREE_TRIAL_KEY = "k9TcfFoEhNd9cCPP2guHAHHHkctZHIRhZDywZ1euGUXwihbYLpOjQhofby80NJez"
# Add User-Agent as required by Poly Haven API
REQ_HEADERS = requests.utils.default_headers()
REQ_HEADERS.update({"User-Agent": "blender-mcp"})
class BlenderMCPServer:
def __init__(self, host='localhost', port=9876):
self.host = host
@ -423,7 +427,7 @@ class BlenderMCPServer:
if asset_type not in ["hdris", "textures", "models", "all"]:
return {"error": f"Invalid asset type: {asset_type}. Must be one of: hdris, textures, models, all"}
response = requests.get(f"https://api.polyhaven.com/categories/{asset_type}")
response = requests.get(f"https://api.polyhaven.com/categories/{asset_type}", headers=REQ_HEADERS)
if response.status_code == 200:
return {"categories": response.json()}
else:
@ -445,7 +449,7 @@ class BlenderMCPServer:
if categories:
params["categories"] = categories
response = requests.get(url, params=params)
response = requests.get(url, params=params, headers=REQ_HEADERS)
if response.status_code == 200:
# Limit the response size to avoid overwhelming Blender
assets = response.json()
@ -465,7 +469,7 @@ class BlenderMCPServer:
def download_polyhaven_asset(self, asset_id, asset_type, resolution="1k", file_format=None):
try:
# First get the files information
files_response = requests.get(f"https://api.polyhaven.com/files/{asset_id}")
files_response = requests.get(f"https://api.polyhaven.com/files/{asset_id}", headers=REQ_HEADERS)
if files_response.status_code != 200:
return {"error": f"Failed to get asset files: {files_response.status_code}"}
@ -485,7 +489,7 @@ class BlenderMCPServer:
# since Blender can't properly load HDR data directly from memory
with tempfile.NamedTemporaryFile(suffix=f".{file_format}", delete=False) as tmp_file:
# Download the file
response = requests.get(file_url)
response = requests.get(file_url, headers=REQ_HEADERS)
if response.status_code != 200:
return {"error": f"Failed to download HDRI: {response.status_code}"}
@ -581,7 +585,7 @@ class BlenderMCPServer:
# Use NamedTemporaryFile like we do for HDRIs
with tempfile.NamedTemporaryFile(suffix=f".{file_format}", delete=False) as tmp_file:
# Download the file
response = requests.get(file_url)
response = requests.get(file_url, headers=REQ_HEADERS)
if response.status_code == 200:
tmp_file.write(response.content)
tmp_path = tmp_file.name
@ -718,7 +722,7 @@ class BlenderMCPServer:
main_file_name = file_url.split("/")[-1]
main_file_path = os.path.join(temp_dir, main_file_name)
response = requests.get(file_url)
response = requests.get(file_url, headers=REQ_HEADERS)
if response.status_code != 200:
return {"error": f"Failed to download model: {response.status_code}"}
@ -736,7 +740,7 @@ class BlenderMCPServer:
os.makedirs(os.path.dirname(include_file_path), exist_ok=True)
# Download the included file
include_response = requests.get(include_url)
include_response = requests.get(include_url, headers=REQ_HEADERS)
if include_response.status_code == 200:
with open(include_file_path, "wb") as f:
f.write(include_response.content)

View File

@ -18,6 +18,10 @@ logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger("BlenderMCPServer")
# Default configuration
DEFAULT_HOST = "localhost"
DEFAULT_PORT = 9876
@dataclass
class BlenderConnection:
host: str
@ -225,7 +229,9 @@ def get_blender_connection():
# Create a new connection if needed
if _blender_connection is None:
_blender_connection = BlenderConnection(host="localhost", port=9876)
host = os.getenv("BLENDER_HOST", DEFAULT_HOST)
port = int(os.getenv("BLENDER_PORT", DEFAULT_PORT))
_blender_connection = BlenderConnection(host=host, port=port)
if not _blender_connection.connect():
logger.error("Failed to connect to Blender")
_blender_connection = None