blender

MoonBit SDK for the Blender MCP server

moon add gmlewis/blender@0.2.0
Download zip
Author
Version
0.2.0
License
Apache-2.0
Last updated
last month
Downloads
12

Dependencies

README

#blender — MoonBit SDK for the Blender MCP Server

blender is an auto-generated MoonBit SDK for the Blender MCP server. It provides a fully typed, idiomatic MoonBit interface to all 26 Blender MCP tools — from executing Python code to querying scene objects, capturing screenshots, rendering, and inspecting blend files.

All tool methods are async and use moonbitlang/async for subprocess management. They must be called within an async fn main block.

#Quick Start

moon add gmlewis/blender

///|
async fn main {
let client = @blender.new_client("")

// Execute Python code in Blender
let res = client.execute_blender_code("import bpy; result = {'count': len(bpy.data.objects)}")
println(res)

// Get scene objects summary
let summary = client.get_objects_summary()
println(summary)

// Search the Blender Python API docs
let docs = client.search_api_docs("how to bake")
println(docs)

client.close()
}

#API Overview

The SDK exposes all 26 Blender MCP tools via typed methods:

CategoryTools
API Docsget_python_api_docs, search_api_docs
Blend Fileget_blendfile_summary_datablocks, get_blendfile_summary_datablocks_for_cli, get_blendfile_summary_missing_files, get_blendfile_summary_missing_files_for_cli, get_blendfile_summary_of_linked_libraries, get_blendfile_summary_of_linked_libraries_for_cli, get_blendfile_summary_path_info, get_blendfile_summary_path_info_for_cli, get_blendfile_summary_usage_guess, get_blendfile_summary_usage_guess_for_cli
Executeexecute_blender_code, execute_blender_code_for_cli
Manual Docssearch_manual_docs
Objectsget_object_detail_summary, get_objects_summary
Renderrender_thumbnail_to_path, render_viewport_to_path
Screenshotget_screenshot_of_area_as_image, get_screenshot_of_window_as_image, get_screenshot_of_window_as_json
Viewportjump_to_view3d_object_by_name, jump_to_view3d_object_data_by_name
Workspacejump_to_tab_by_name, jump_to_tab_by_space_type

Each tool has:
  • A Client::method_name(...) method with typed parameters (snake_case)
  • Optional parameters are Option[T] (use Some(value) or None)
  • Returns String (the tool's text response) or raises Failure on error
  • Full doc comments

#Architecture

The SDK launches the Blender MCP server as a subprocess and communicates via JSON-RPC over stdio. The Blender MCP server must be installed separately, and Blender must be running with the MCP addon enabled.

#Auto-Generation

This SDK is auto-generated from the Blender MCP server tool definitions by scripts/generate-mbt-blender-sdk.py. To regenerate:

./scripts/generate-mbt-blender-sdk.py --verbose

DO NOT EDIT the generated files — changes will be overwritten.

#
Client

Client manages a connection to the Blender MCP server. It launches the server as a subprocess and communicates via JSON-RPC over stdio. All tool methods are async and must be called within an async fn main block.

Usage: async fn main { let client = @blender.new_client("") let res = client.execute_blender_code("import bpy; result = {'count': len(bpy.data.objects)}") println(res) client.close() }

#
Client::call_tool

async fn Client::call_tool(self : Client, tool_name : String, args : Map[String, Json]) -> String

call_tool invokes an MCP tool by name and returns the text response.

#
Client::close

fn Client::close(self : Client) -> Unit

close shuts down the MCP server process.

#
Client::execute_blender_code

async fn Client::execute_blender_code(self : Client, code : String) -> String

execute_blender_code — execute_blender_code Execute Python code in the connected Blender instance. The code runs in Blender's Python environment with full access to bpy. To return data, assign a JSON-serialisable dict to a variable named result. Deferred completion via check_is_finished is only supported by the interactive addon server, and is rejected in background mode.

#
Client::execute_blender_code_for_cli

async fn Client::execute_blender_code_for_cli(self : Client, blendFile : String, code : String) -> String

execute_blender_code_for_cli — execute_blender_code_for_cli Execute Python code in a background Blender process. Opens blend_file with blender --background and runs code. Assign a dict to result to return data.

#
Client::get_blendfile_summary_datablocks

async fn Client::get_blendfile_summary_datablocks(self : Client) -> String

get_blendfile_summary_datablocks — get_blendfile_summary_datablocks Return a summary of the blend file: data-block counts, active workspace, and render engine.

#
Client::get_blendfile_summary_datablocks_for_cli

async fn Client::get_blendfile_summary_datablocks_for_cli(self : Client, blendFile : String) -> String

get_blendfile_summary_datablocks_for_cli — get_blendfile_summary_datablocks_for_cli Return a data-block summary by opening blend_file in background Blender.

#
Client::get_blendfile_summary_missing_files

async fn Client::get_blendfile_summary_missing_files(self : Client) -> String

get_blendfile_summary_missing_files — get_blendfile_summary_missing_files Report external file references that are missing from disk (images, libraries, fonts, sounds, movie clips, caches, sequences).

#
Client::get_blendfile_summary_missing_files_for_cli

async fn Client::get_blendfile_summary_missing_files_for_cli(self : Client, blendFile : String) -> String

get_blendfile_summary_missing_files_for_cli — get_blendfile_summary_missing_files_for_cli Report missing file references by opening blend_file in background Blender.

#
Client::get_blendfile_summary_of_linked_libraries

async fn Client::get_blendfile_summary_of_linked_libraries(self : Client) -> String

get_blendfile_summary_of_linked_libraries — get_blendfile_summary_of_linked_libraries Return a tree of directly and indirectly linked library files.

#
Client::get_blendfile_summary_of_linked_libraries_for_cli

async fn Client::get_blendfile_summary_of_linked_libraries_for_cli(self : Client, blendFile : String) -> String

get_blendfile_summary_of_linked_libraries_for_cli — get_blendfile_summary_of_linked_libraries_for_cli Return linked-library info by opening blend_file in background Blender.

#
Client::get_blendfile_summary_path_info

async fn Client::get_blendfile_summary_path_info(self : Client) -> String

get_blendfile_summary_path_info — get_blendfile_summary_path_info Simple/fast access to the blend file's path, save status, age, and backups.

#
Client::get_blendfile_summary_path_info_for_cli

async fn Client::get_blendfile_summary_path_info_for_cli(self : Client, blendFile : String) -> String

get_blendfile_summary_path_info_for_cli — get_blendfile_summary_path_info_for_cli Return path info by opening blend_file in background Blender.

#
Client::get_blendfile_summary_usage_guess

async fn Client::get_blendfile_summary_usage_guess(self : Client) -> String

get_blendfile_summary_usage_guess — get_blendfile_summary_usage_guess Guess the primary use-cases of the current blend file (scored 0-100 with certainty).

#
Client::get_blendfile_summary_usage_guess_for_cli

async fn Client::get_blendfile_summary_usage_guess_for_cli(self : Client, blendFile : String) -> String

get_blendfile_summary_usage_guess_for_cli — get_blendfile_summary_usage_guess_for_cli Guess use-cases by opening blend_file in background Blender.

#
Client::get_object_detail_summary

async fn Client::get_object_detail_summary(self : Client, name : String) -> String

get_object_detail_summary — get_object_detail_summary Return a structured summary of the object identified by name. Includes type, transforms, parent, children, modifiers, constraints, materials, visibility, data-block name, and collections.

#
Client::get_objects_summary

async fn Client::get_objects_summary(self : Client) -> String

get_objects_summary — get_objects_summary Return the scene's collection hierarchy and their objects. Each collection lists its objects (name, type, parent, data name, selection, visibility) and nested child collections.

#
Client::get_python_api_docs

async fn Client::get_python_api_docs(self : Client, identifier : String) -> String

get_python_api_docs — get_python_api_docs Return the Blender Python API docs for identifier, or list modules matching a trailing-* discovery pattern. identifier should be a fully-qualified Python name (e.g. bpy.app or bpy.types.Scene.frame_current). The trailing-* forms are supported as discovery entry-points: - * enumerates the top-level modules (bpy, bmesh, mathutils, gpu, ...). - X.* enumerates the direct-child identifiers under the X namespace (bpy.* -> bpy.app, bpy.context, ...). Both return a namespace response even when X.rst would otherwise resolve to exact; the .* form lets an agent force the child listing. The response always carries kind, found, and identifier. The remaining keys depend on kind: - "exact" (found=True): <identifier>.rst was read. Extra keys: content (RST text), examples. When the file exceeds 32 KB, content is replaced with a dot-point summary of the file's top-level definitions (prefixed by a header noting the truncation) and examples is empty - re-query individual members for their rendered blocks. - "namespace" (found=True): no <identifier>.rst but <identifier>.<child>.rst siblings exist. Extra key: submodules (list of child identifiers). - "definition" (found=True): identifier is defined inside a parent RST (e.g. bpy.props.IntProperty lives in bpy.props.rst). Extra keys: content (rendered block), examples. - "partial" (found=False): the parent RST was located but the trailing component isn't defined in it. Extra keys: - parent the identifier whose RST was loaded. - available top-level definitions in that RST. - submodules sibling identifiers <parent>.<child> with their own RSTs, filtered to those whose last component contains every character of the missing tail. For a toctree landing page like bpy.types available is empty and submodules is the near-miss list; for a self-contained module like bpy.props it's the reverse. - "suggestions" (found=False): no direct match, but identifier appears as a component of other files. Extra key: suggestions (list of full identifiers). - "missing" (found=False): nothing matched. examples (present on the exact and definition kinds) is a list of {path, content} entries referenced from this documentation.

#
Client::get_screenshot_of_area_as_image

async fn Client::get_screenshot_of_area_as_image(self : Client, areaUiType : String, sizeLimitInBytes : Int?) -> String

get_screenshot_of_area_as_image — get_screenshot_of_area_as_image Take a screenshot of a single Blender area and return it as a PNG image. area_ui_type matches the area's ui_type. size_limit_in_bytes caps the image size in bytes. Zero (the default) uses the MCP message size limit.

#
Client::get_screenshot_of_window_as_image

async fn Client::get_screenshot_of_window_as_image(self : Client, sizeLimitInBytes : Int?) -> String

get_screenshot_of_window_as_image — get_screenshot_of_window_as_image Take a screenshot of the entire Blender window and return it as a PNG image. size_limit_in_bytes caps the image size in bytes. Zero (the default) uses the MCP message size limit.

#
Client::get_screenshot_of_window_as_json

async fn Client::get_screenshot_of_window_as_json(self : Client) -> String

get_screenshot_of_window_as_json — get_screenshot_of_window_as_json Return a JSON description of the Blender window layout, areas, active object, and selection.

#
Client::jump_to_tab_by_name

async fn Client::jump_to_tab_by_name(self : Client, name : String) -> String

jump_to_tab_by_name — jump_to_tab_by_name Switch the active workspace tab to name.

#
Client::jump_to_tab_by_space_type

async fn Client::jump_to_tab_by_space_type(self : Client, spaceType : String, allowEdits : Bool?) -> String

jump_to_tab_by_space_type — jump_to_tab_by_space_type Switch to a workspace whose main area matches space_type. If allow_edits is True and no matching workspace exists, a new one is created by duplicating the current workspace.

#
Client::jump_to_view3d_object_by_name

async fn Client::jump_to_view3d_object_by_name(self : Client, name : String, allowEdits : Bool?) -> String

jump_to_view3d_object_by_name — jump_to_view3d_object_by_name Move the 3D viewport to focus on an object by name. If allow_edits is True the object may be un-hidden and its collections enabled to make it visible.

#
Client::jump_to_view3d_object_data_by_name

async fn Client::jump_to_view3d_object_data_by_name(self : Client, name : String, allowEdits : Bool?) -> String

jump_to_view3d_object_data_by_name — jump_to_view3d_object_data_by_name Move the 3D viewport to the object whose data block matches name. If allow_edits is True the object may be un-hidden and its collections enabled to make it visible.

#
Client::render_thumbnail_to_path

async fn Client::render_thumbnail_to_path(self : Client, outputPath : String) -> String

render_thumbnail_to_path — render_thumbnail_to_path Render a small, low-quality thumbnail to output_path (temporarily overrides settings).

#
Client::render_viewport_to_path

async fn Client::render_viewport_to_path(self : Client, outputPath : String) -> String

render_viewport_to_path — render_viewport_to_path Render the current scene to output_path using current render settings.

#
Client::search_api_docs

async fn Client::search_api_docs(self : Client, query : String, maxResults : Int?, context : Int?, index : Int?) -> String

search_api_docs — search_api_docs

#
Client::search_manual_docs

async fn Client::search_manual_docs(self : Client, query : String, maxResults : Int?, context : Int?, index : Int?) -> String

search_manual_docs — search_manual_docs

#
new_client

async fn new_client(server_bin : String) -> Client

new_client launches the Blender MCP server and returns a Client. If server_bin is empty, uses the default (uv run blender-mcp). Must be called within an async function.