Skip to main content
Glama

mc_execute

Execute Groovy code in a running Minecraft session to explore the Java API or perform custom operations not covered by native tools.

Instructions

Execute GROOVY code in the Minecraft session (the runtime migrated from Lua to Apache Groovy 5 in mid-2026 — see the migration note at the end if you knew the old surface). The binding is persistent: undeclared assignments (x = 5) survive to later calls; def x is script-local.

PREFER NATIVE TOOLS WHERE POSSIBLE — they're faster and avoid script overhead:

  • Player state (x/y/z/yaw/pitch/look/velocity/vehicle/raycast target/world): mc_snapshot

  • Nearby entities or one entity's details: mc_nearby_entities / mc_entity_details

  • Nearby block entities (signs, chests, etc.): mc_nearby_blocks / mc_block_details

  • Open screen / inventory contents: mc_screen_inspect

  • Recent chat: mc_chat_history

  • Item textures: mc_get_item_texture (by slot or by id) Reach for mc_execute when you need to explore the Java API or do something the native tools don't cover.

Pre-bound globals: mc (Minecraft instance), player, level — plus the "java" helper.

Mojang names everywhere, on every Minecraft version: obj.foo reads a field (JavaBean getter fallback), obj.foo(args) calls a method. Overloads resolve by argument types; decimal literals coerce to double/float params.

Minecraft classes can't be named directly on obfuscated builds — load them via java.type: def Vec3 = java.type('net.minecraft.world.phys.Vec3'); construct with Vec3(1, 2, 3) or Vec3.create(1, 2, 3). (Single-quote class names: double-quoted GStrings interpolate the $ in inner-class names.)

The "java" helper provides:

  • java.type(className) - class handle for statics + construction, by Mojang name

  • java.list(x) - Java collection/array -> Groovy List (use for iteration)

  • java.typeName(obj) - the Mojang class name

  • java.isNull(obj) - null check

  • java.ref(refId) - retrieve a stored object reference ($ref_N from results)

  • sync { ... } - run the closure ON THE GAME THREAD in one hop. Use it to batch bulk loops (hundreds of entities/slots run in milliseconds instead of one thread-hop per call): sync { java.list(level.entitiesForRendering()).collect { java.typeName(it) } }

Reflection helpers for exploring API:

  • java.describe(obj) - full dump: class, fields, methods, supers

  • java.methods(obj, [filter]) - list methods (optional name filter)

  • java.fields(obj, [filter]) - list fields (optional name filter)

  • java.supers(obj) - class hierarchy and interfaces

  • java.find(pattern, [scope]) - search mappings for classes/methods/fields

Plain JDK classes work natively (System.currentTimeMillis(), new File(path).text = "..."). Sandbox: Runtime / ProcessBuilder / java.net.* are blocked; file I/O is allowed. Caveat: bridge-wrapped Minecraft objects don't auto-unwrap when passed to NATIVE Java calls like new File(wrappedFile, name) — pass strings/primitives or unwrap with wrapped.getTarget(). Bridge-dispatched calls (anything on mc/player/level or a java.type class) unwrap arguments automatically.

Use "return " to get a value back; println/print output is captured. Returned Minecraft objects serialize as {className, ref, toString, fields} — resume them later with java.ref(ref).

timeoutMs: optional per-call deadline in ms (default 10000, max 300000 = 5 min). Bump it for bulk reflection or heavy file I/O — but prefer sync{} batching or a native tool over raising the timeout.

MIGRATING FROM THE OLD LUA SURFACE (pre-2026-06): obj:method(args) -> obj.method(args); java.import(name) -> java.type(name); java.new(Cls, args) -> Cls(args) or Cls.create(args); java.iter/java.array -> java.list; java.typeof -> java.typeName; java.cast - removed (dispatch walks the runtime hierarchy, no cast needed); io.open(...) -> new File(...); os.time() -> System.currentTimeMillis(); print(x) -> println x; pcall -> try/catch; local x -> def x; {a = 1} tables -> [a: 1] maps and [1, 2, 3] lists.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesGroovy code to execute
timeoutMsNoOptional per-call execution deadline in milliseconds. Range 1000-300000, default 10000 (10s). Use a longer value for bulk reflection or heavy file I/O.
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, but the description thoroughly covers persistent binding, sandbox restrictions, thread hopping, return value handling, serialization, timeout, and migration from Lua.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Long but well-structured, front-loaded with key usage guidance and progressive detail. Every section earns its place, though minor redundancy possible.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given complexity, no annotations or output schema, the description covers all critical aspects: return values, error handling, threading, serialization, migration, and sandbox restrictions.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, baseline 3. Description adds valuable context for both parameters: code is Groovy script with persistence, timeoutMs has default and usage tips.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Execute GROOVY code in the Minecraft session' and distinguishes from sibling tools by listing preferred native tools for specific tasks.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly advises to prefer native tools when possible, lists alternatives for common tasks, and specifies when to use mc_execute (exploring Java API or unsupported cases).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/use-ai-for-mc/mcdev-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server