A Model Context Protocol (MCP) server that enables AI assistants to interact with running LÖVE2D games. This allows for real-time introspection, debugging, and manipulation of game state through natural language.
This project bridges LÖVE2D games with MCP-compatible AI assistants, enabling:
- Real-time introspection: Query game objects, positions, properties, and state
- Dynamic code execution: Run Lua code directly in the game context
- AI-assisted debugging: Let AI assistants analyze and manipulate your game
- Interactive development: Modify game behavior without restarting
┌─────────────┐ stdio ┌─────────────┐ TCP ┌─────────────┐
│ MCP Client │◄──────►│ MCP Server │◄──────►│ LÖVE2D │
│ (Inspector) │ │ (TypeScript)│ │ Game (Lua) │
└─────────────┘ └─────────────┘ └─────────────┘
- MCP Server: Node.js/TypeScript server communicating via stdio
- LÖVE2D Bridge: Lua TCP server embedded in your game
- Communication: JSON-RPC over TCP between server and game
- Node.js 18+ and npm
- LÖVE2D 11.0+ (download here)
- Git
- Clone the repository:
git clone https://github.com/shayarnett/love2d-mcp.git
cd love2d-mcp- Install dependencies:
npm install- Build the TypeScript server:
npm run buildlove game/You should see a window with 5 bouncing balls. The game starts a TCP server on port 12345.
In a new terminal:
npx @modelcontextprotocol/inspector node build/index.jsThis opens the MCP Inspector in your browser where you can interact with the game.
List all objects:
- Select the
list_objectstool - Execute it to see all game objects
Get object details:
- Select the
get_objecttool - Enter an object ID from the list (e.g.,
ball_1) - View detailed properties
Run custom Lua code:
- Select the
run_luatool - Try this code to count purple balls:
local count = 0
for id, obj in pairs(objects) do
if obj.type == "ball" then
if obj.b > 0.5 and obj.r > 0.5 and obj.g < 0.5 then
count = count + 1
end
end
end
return countLists all objects in the current game scene.
Parameters: None
Returns: Array of objects with id, type, x, and y properties.
Get detailed information about a specific object.
Parameters:
id(string): The object ID
Returns: Complete object data including all properties.
Execute arbitrary Lua code in the game context with access to game objects.
Parameters:
code(string): Lua code to execute
Returns: Result of the code execution (string or JSON-encoded table).
Available in code context:
objects: Table of all game objectslove: LÖVE2D API- Standard Lua functions and libraries
To add MCP support to your own LÖVE2D game:
-
Copy
game/mcp_bridge.luato your game directory -
In your
main.lua:
local mcp_bridge = require("mcp_bridge")
function love.load()
-- Initialize MCP bridge on port 12345
mcp_bridge.init(12345)
-- Provide access to your game objects
mcp_bridge.setObjectGetter(function()
return your_game_objects_table
end)
end
function love.update(dt)
-- Call this every frame to handle MCP commands
mcp_bridge.update()
-- Your game logic here
end
function love.quit()
mcp_bridge.shutdown()
end- Start your game and connect via MCP Inspector
For development with auto-rebuild:
npm run devlove2d-mcp/
├── src/
│ └── index.ts # MCP server implementation
├── game/
│ ├── main.lua # Example LÖVE2D game
│ └── mcp_bridge.lua # TCP bridge module
├── build/ # Compiled TypeScript
├── package.json
├── tsconfig.json
└── README.md
- Debugging: Query game state without adding debug UI
- Testing: Automate game testing through AI
- Prototyping: Quickly test ideas by running Lua snippets
- Learning: Explore LÖVE2D by asking AI to analyze your game
- AI-assisted development: Let AI help build game features
- Ensure LÖVE2D is installed:
love --version - Check for syntax errors in Lua files
- Verify the game is running first
- Check port 12345 isn't already in use
- Look for "MCP Bridge listening" message in game console
- Rebuild the TypeScript:
npm run build - Check Node.js version:
node --version(requires 18+)
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.
- Built with the Model Context Protocol
- Powered by LÖVE2D
- Inspired by the need for better game development tools