Skip to content

Feat: Add CRUD operations for Shader files via MCP #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Tanichael
Copy link

@Tanichael Tanichael commented Apr 18, 2025

This pull request introduces a new tool within the MCP bridge for managing Unity shader files directly from an external process.

Motivation

To enable external build tools, content pipelines, or automated scripts to create, read, update, and delete Unity shader assets programmatically without direct user interaction with the Unity Editor UI. This enhances automation capabilities for shader development workflows.

Key Changes

  • New ManageShader class: Added a dedicated class (UnityMcpBridge.Editor.Tools.ManageShader) to handle shader-specific operations.
  • CRUD Actions: Implements the core HandleCommand method to support the following actions:
    • create: Creates a new .shader file. Accepts optional initial content (plain text or Base64 encoded). Generates default shader content if none is provided.
    • read: Reads the content of an existing .shader file. Returns plain text content and also Base64 encoded content if the file is large.
    • update: Overwrites the content of an existing .shader file. Requires content to be provided.
    • delete: Deletes a .shader file using AssetDatabase.DeleteAsset.
  • Path Handling: Correctly resolves file paths relative to the Assets/ directory. Defaults to placing new shaders in a "Shaders" subdirectory if no path is specified. Handles forward and backslashes.
  • Name Validation: Includes basic validation for the provided shader name.
  • Base64 Support: Added utility methods (EncodeBase64, DecodeBase64) to handle potentially large shader contents efficiently via Base64 encoding in the request/response payload.
  • Unity Integration: Utilizes AssetDatabase.ImportAsset and AssetDatabase.DeleteAsset to ensure Unity's asset database is correctly updated after file operations.
  • Error Handling: Provides specific error responses for file not found, file already exists, invalid parameters, file system errors, and decoding failures.

This addition significantly expands the MCP bridge's functionality, providing robust external control over shader assets.

Please review the changes.

@Tanichael Tanichael closed this Apr 18, 2025
@Tanichael Tanichael changed the title Feature/manage shader Feat: Add CRUD operations for Shader files via MCP Apr 18, 2025
@Tanichael Tanichael reopened this Apr 18, 2025
@bhadrik
Copy link

bhadrik commented May 20, 2025

I have created agent inside of Unity instead of managing MCP, check it out here.
https://github.com/bhadrik/unity-autopilot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants