MCP: Audit and harden native MCP server implementation#1290
Draft
MichaelFisher1997 wants to merge 1 commit into
Draft
MCP: Audit and harden native MCP server implementation#1290MichaelFisher1997 wants to merge 1 commit into
MichaelFisher1997 wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes several bugs, improves spec compliance, and fills in missing
functionality across the MCP module.
Bugfixes:
- Fix null-deref crash in capture action when viewport returns no image
or PNG encoding fails (mcp_bridge.cpp)
- Fix double-wrapped JSON-RPC error responses: pre-init tools/* requests
now return a proper top-level error via process_string override instead
of being nested inside a result envelope (mcp_protocol.{h,cpp})
- Fix double-wrapping on INVALID_PARAMS paths in tools/call handler
Protocol compliance:
- Update protocol version from 2024-11-05 to 2025-06-18
- Add version negotiation: echo client version if supported, else return
latest (mcp_protocol.cpp)
- Move initialized flag from initialize response to notifications/initialized
per spec lifecycle requirements
- Declare tools.listChanged capability explicitly
Security and robustness:
- Harden validate_path: segment-based .. check instead of substring match,
applied consistently to all path-accepting actions (instance_path,
resource paths, code_intel paths were previously unvalidated)
- Fix bridge concurrency: update() no longer drops an active connection
mid-command when a new peer connects
- Improve send_command: chunked reads via CharString accumulation with
single-pass UTF-8 decode to handle multi-byte chars across TCP boundaries
New functionality:
- Implement code_intel search action (recursive .gd file content search)
- Implement project_config add_input action (writes InputEventKey to
project.godot with runtime InputMap registration)
- Implement project_config add_autoload action (writes autoload entry
to project.godot)
Quality improvements:
- Add MCP tool annotations (readOnlyHint, destructiveHint, etc.) to all
5 tools per 2025-06-18 spec
- Clarify project_config schema descriptions (which params each action
uses) to prevent agent confusion
- Improve _ensure_callback_exists: word-boundary detection handles
static func and annotation prefixes
- Add signal-exists validation before connect() in scene_action
- Remove dead code (_make_text_content)
- Fill in class reference documentation for MCPServer, MCPBridge,
MCPProtocol
AI tools were used in the development of this contribution, in
accordance with the project AI Policy. All changes have been manually
tested end-to-end with a live MCP handshake across all 5 tools.
f664f8c to
1e774d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A comprehensive audit and hardening of the native MCP (Model Context Protocol) server module (
modules/mcp/). The module was functional but had several bugs, spec compliance gaps, and unimplemented actions advertised in the tool schemas.Bugfixes
captureaction when viewport returns no image (headless/first-frame) or PNG encoding failstools/*requests returned a JSON-RPC error nested inside aresultenvelope instead of a top-levelerror. Fixed via aprocess_stringoverride that gates pre-init requests and notificationsProtocol compliance
2024-11-05to2025-06-18with proper version negotiation (echoes client version if supported)initializedflag frominitializeresponse tonotifications/initializedper spec lifecycletools.listChangedcapability explicitlySecurity & robustness
validate_path: segment-based..traversal check, applied consistently to all path-accepting actions (previouslyinstance_path, resource paths, and code_intel paths were unvalidated)update()no longer drops an active connection mid-commandsend_command: chunked reads viaCharStringaccumulation with single-pass UTF-8 decodeNew functionality
code_intelsearchaction: recursive.gdfile content searchproject_configadd_inputaction: writesInputEventKeytoproject.godotwith runtimeInputMapregistrationproject_configadd_autoloadaction: writes autoload entry toproject.godotQuality
readOnlyHint,destructiveHint, etc.) on all 5 tools per 2025-06-18 specproject_configschema descriptions (which params each action uses)_ensure_callback_existsword-boundary detection (handlesstatic func, annotation prefixes)connect()inscene_actionMCPServer,MCPBridge,MCPProtocol_make_text_content)Testing
All changes manually tested end-to-end with a live MCP handshake (
--mcp-server --headless) across all 5 tools:code_intelget_symbols,get_docs,validate,searchgame_controlwait,capture,inspect_live,click,trigger_action,typeproject_configget_info,list_files,run,stop,output,read_file_res,create_file_res,set_setting,add_input,add_autoloadresource_actioninspect,inspect_asset,create,modify,duplicatescene_actionget_node,create,add,set_prop,instance,reparent,remove,connectPre-init gating verified: single requests return JSON-RPC error, notifications are silently dropped.
Notes
linuxbsdplatform, editor target).Checklist
scons platform=linuxbsd target=editor)