first commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
@@ -0,0 +1,2 @@
|
||||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
||||
@@ -0,0 +1,3 @@
|
||||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
/android/
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
uid://mcipi7y664aq
|
||||
@@ -0,0 +1,7 @@
|
||||
[plugin]
|
||||
|
||||
name="Godot MCP"
|
||||
description="A plugin to enable communication between Godot Editor and Model Context Protocol (MCP) clients."
|
||||
author="Your Name"
|
||||
version="0.1.0"
|
||||
script="plugin.gd"
|
||||
@@ -0,0 +1,140 @@
|
||||
# Structure for addons/godot_mcp/plugin.gd
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
const SERVER_PORT = 6400
|
||||
var server: TCPServer = null
|
||||
var active_connections = []
|
||||
var command_handler
|
||||
|
||||
func _enter_tree():
|
||||
# Initialize the plugin
|
||||
print("Godot MCP Plugin activated")
|
||||
|
||||
# Create command handler
|
||||
command_handler = preload("res://addons/godot_mcp/command_handler.gd").new()
|
||||
command_handler.set_editor_plugin(self)
|
||||
|
||||
# Start the TCP server
|
||||
server = TCPServer.new()
|
||||
var error = server.listen(SERVER_PORT)
|
||||
if error != OK:
|
||||
push_error("Failed to start Godot MCP Server on port %d: %s" % [SERVER_PORT, error])
|
||||
return
|
||||
|
||||
print("Godot MCP Server listening on port %d" % SERVER_PORT)
|
||||
|
||||
# Add UI
|
||||
add_control_to_bottom_panel(
|
||||
preload("res://addons/godot_mcp/ui/mcp_panel.tscn").instantiate(),
|
||||
"MCP"
|
||||
)
|
||||
|
||||
func _exit_tree():
|
||||
# Clean up the plugin when disabled
|
||||
if server:
|
||||
server.stop()
|
||||
server = null
|
||||
|
||||
for connection in active_connections:
|
||||
if connection.get_status() == StreamPeerTCP.STATUS_CONNECTED:
|
||||
connection.disconnect_from_host()
|
||||
|
||||
active_connections.clear()
|
||||
|
||||
# Remove UI
|
||||
remove_control_from_bottom_panel(get_editor_interface().get_base_control().get_node("MCPPanel"))
|
||||
print("Godot MCP Plugin deactivated")
|
||||
|
||||
func _process(delta):
|
||||
# Check for new connections
|
||||
if server and server.is_connection_available():
|
||||
var connection = server.take_connection()
|
||||
if connection:
|
||||
active_connections.append(connection)
|
||||
print("New MCP connection established")
|
||||
|
||||
# Process existing connections
|
||||
var i = 0
|
||||
while i < active_connections.size():
|
||||
var connection = active_connections[i]
|
||||
|
||||
# Check connection status
|
||||
if connection.get_status() != StreamPeerTCP.STATUS_CONNECTED:
|
||||
active_connections.remove_at(i)
|
||||
print("MCP connection closed")
|
||||
continue
|
||||
|
||||
# Check for incoming messages
|
||||
if connection.get_available_bytes() > 0:
|
||||
var data = _read_message(connection)
|
||||
if data.size() > 0:
|
||||
# Process the command
|
||||
var response = _process_command(data)
|
||||
|
||||
# Send the response
|
||||
_send_message(connection, response)
|
||||
|
||||
i += 1
|
||||
|
||||
func _read_message(connection):
|
||||
# Read data from the connection
|
||||
var data = PackedByteArray()
|
||||
var bytes_available = connection.get_available_bytes()
|
||||
|
||||
if bytes_available > 0:
|
||||
data = connection.get_data(bytes_available)[1]
|
||||
|
||||
# Attempt to parse as JSON
|
||||
var json_string = data.get_string_from_utf8()
|
||||
var json = JSON.new()
|
||||
var error = json.parse(json_string)
|
||||
|
||||
if error == OK:
|
||||
return json.get_data()
|
||||
else:
|
||||
print("Failed to parse JSON: ", json.get_error_message())
|
||||
|
||||
return {}
|
||||
|
||||
func _send_message(connection, data):
|
||||
# Convert to JSON and send
|
||||
var json_string = JSON.stringify(data)
|
||||
connection.put_data(json_string.to_utf8_buffer())
|
||||
|
||||
|
||||
|
||||
func _process_command(data):
|
||||
# Process the command and return a response
|
||||
if data == null or typeof(data) != TYPE_DICTIONARY:
|
||||
return {
|
||||
"status": "error",
|
||||
"error": "Invalid command format. Expected a dictionary."
|
||||
}
|
||||
|
||||
if not data.has("type") or not data.has("params"):
|
||||
return {
|
||||
"status": "error",
|
||||
"error": "Invalid command format. Expected 'type' and 'params' fields."
|
||||
}
|
||||
|
||||
var command_type = data["type"]
|
||||
var params = data["params"]
|
||||
|
||||
if command_type == "ping":
|
||||
return {"status": "success", "result": {"message": "pong"}}
|
||||
|
||||
# Forward to command handler
|
||||
var result = command_handler.handle_command(command_type, params)
|
||||
|
||||
# Check if result is valid
|
||||
if result == null:
|
||||
return {
|
||||
"status": "error",
|
||||
"error": "Command handler returned null result"
|
||||
}
|
||||
|
||||
if result.has("error"):
|
||||
return {"status": "error", "error": result.error}
|
||||
else:
|
||||
return {"status": "success", "result": result}
|
||||
@@ -0,0 +1 @@
|
||||
uid://ddfhkiyge45tn
|
||||
@@ -0,0 +1,77 @@
|
||||
# addons/godot_mcp/ui/mcp_panel.gd
|
||||
@tool
|
||||
extends Control
|
||||
|
||||
var status_label: Label
|
||||
var port_field: SpinBox
|
||||
var start_button: Button
|
||||
var stop_button: Button
|
||||
var log_display: TextEdit
|
||||
|
||||
func _ready():
|
||||
# Set up references to UI elements
|
||||
status_label = $VBoxContainer/StatusPanel/StatusLabel
|
||||
port_field = $VBoxContainer/ConfigPanel/PortField
|
||||
start_button = $VBoxContainer/ButtonPanel/StartButton
|
||||
stop_button = $VBoxContainer/ButtonPanel/StopButton
|
||||
log_display = $VBoxContainer/LogPanel/LogDisplay
|
||||
|
||||
# Initialize UI
|
||||
port_field.value = 6400 # Default port
|
||||
start_button.disabled = false
|
||||
stop_button.disabled = true
|
||||
|
||||
# Connect signals
|
||||
start_button.pressed.connect(_on_start_button_pressed)
|
||||
stop_button.pressed.connect(_on_stop_button_pressed)
|
||||
|
||||
# Set initial status
|
||||
update_status("Not running")
|
||||
add_log_message("Godot MCP Plugin initialized")
|
||||
|
||||
func update_status(status_text: String, is_error: bool = false):
|
||||
status_label.text = "Status: " + status_text
|
||||
if is_error:
|
||||
status_label.add_theme_color_override("font_color", Color(1, 0.3, 0.3))
|
||||
else:
|
||||
status_label.remove_theme_color_override("font_color")
|
||||
|
||||
func add_log_message(message: String):
|
||||
var timestamp = Time.get_datetime_string_from_system()
|
||||
log_display.text += "[" + timestamp + "] " + message + "\n"
|
||||
log_display.scroll_vertical = log_display.get_line_count()
|
||||
|
||||
func _on_start_button_pressed():
|
||||
# This function will be called from the plugin.gd script
|
||||
# when the server is actually started
|
||||
update_status("Running on port " + str(port_field.value))
|
||||
start_button.disabled = true
|
||||
stop_button.disabled = false
|
||||
add_log_message("MCP Server started on port " + str(port_field.value))
|
||||
|
||||
func _on_stop_button_pressed():
|
||||
# This function will be called from the plugin.gd script
|
||||
# when the server is actually stopped
|
||||
update_status("Stopped")
|
||||
start_button.disabled = false
|
||||
stop_button.disabled = true
|
||||
add_log_message("MCP Server stopped")
|
||||
|
||||
# Function to be called from plugin.gd when a client connects
|
||||
func on_client_connected():
|
||||
add_log_message("Client connected")
|
||||
update_status("Client connected")
|
||||
|
||||
# Function to be called from plugin.gd when a client disconnects
|
||||
func on_client_disconnected():
|
||||
add_log_message("Client disconnected")
|
||||
update_status("Running (no clients)")
|
||||
|
||||
# Function to be called from plugin.gd when a command is received
|
||||
func on_command_received(command_type, params):
|
||||
add_log_message("Command received: " + command_type)
|
||||
|
||||
# Function to be called from plugin.gd when a response is sent
|
||||
func on_response_sent(command_type, success):
|
||||
var status = "Success" if success else "Failed"
|
||||
add_log_message("Response sent for " + command_type + ": " + status)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bqabyd7ce60u0
|
||||
@@ -0,0 +1,69 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dxvt86ck6b2a4"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/godot_mcp/ui/mcp_panel.gd" id="1_4g23r"]
|
||||
|
||||
[node name="MCPPanel" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_4g23r")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="StatusPanel" type="PanelContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="StatusLabel" type="Label" parent="VBoxContainer/StatusPanel"]
|
||||
layout_mode = 2
|
||||
text = "Status: Not running"
|
||||
|
||||
[node name="ConfigPanel" type="PanelContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/ConfigPanel"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="PortLabel" type="Label" parent="VBoxContainer/ConfigPanel/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Port:"
|
||||
|
||||
[node name="PortField" type="SpinBox" parent="VBoxContainer/ConfigPanel"]
|
||||
layout_mode = 2
|
||||
min_value = 1024.0
|
||||
max_value = 65535.0
|
||||
value = 6400.0
|
||||
alignment = 1
|
||||
|
||||
[node name="ButtonPanel" type="PanelContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/ButtonPanel"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="StartButton" type="Button" parent="VBoxContainer/ButtonPanel"]
|
||||
layout_mode = 2
|
||||
text = "Start Server"
|
||||
|
||||
[node name="StopButton" type="Button" parent="VBoxContainer/ButtonPanel"]
|
||||
layout_mode = 2
|
||||
disabled = true
|
||||
text = "Stop Server"
|
||||
|
||||
[node name="LogPanel" type="PanelContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="LogDisplay" type="TextEdit" parent="VBoxContainer/LogPanel"]
|
||||
layout_mode = 2
|
||||
editable = false
|
||||
wrap_mode = 1
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
|
||||
|
After Width: | Height: | Size: 995 B |
@@ -0,0 +1,43 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://drj7e8fs1pl5e"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
@@ -0,0 +1,27 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Territory-Autobattler"
|
||||
config/features=PackedStringArray("4.6", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
enabled=PackedStringArray("res://addons/godot_mcp/plugin.cfg")
|
||||
|
||||
[physics]
|
||||
|
||||
3d/physics_engine="Jolt Physics"
|
||||
|
||||
[rendering]
|
||||
|
||||
rendering_device/driver.windows="d3d12"
|
||||
Reference in New Issue
Block a user