Skip to content
Back to skills

unity-mpc-skill

ASecurity

Configura y gestiona servidores MCP (Model Context Protocol) para Unity: conexión como proveedor de servicio e integraciones correctas.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 17, 2026
ai-agentspythongoc#shellnodeapidatabasedocumentation

Works with

  • cli
  • api
  • mcp

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned November 17, 2026

npx -y skills add Json55Hdz/OpenACM --skill skills --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of unity-mpc-skill?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for unity-mpc-skill
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/json55hdz-unity-mpc-skill/badge)](https://www.skillsdirectory.com/skills/json55hdz-unity-mpc-skill)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: "unity-mpc-skill"
description: "Configura y gestiona servidores MCP (Model Context Protocol) para Unity: conexión como proveedor de servicio e integraciones correctas."
category: "development"
author: "OpenACM"
---

# Unity MPC Skill

## Overview

This skill enables configuration and management of **Model Context Protocol (MCP)** servers within Unity environments. MCP is an open standard (originally by Anthropic, now community-driven) that allows AI assistants to connect to external data sources and tools through standardized JSON-RPC interfaces.

**When to activate this skill:**
- User mentions "MCP server", "Model Context Protocol", or "MCP client"
- Need to integrate Unity with external AI tools, databases, or APIs via MCP
- Configuring Unity as an MCP client (consumer) or MCP server (provider)
- Troubleshooting MCP connection issues in Unity Editor or Runtime
- Implementing `stdio` or Server-Sent Events (SSE) transport layers in C#

**Scope:** Covers both **Editor tooling** (Unity Editor extensions that connect to MCP servers) and **Runtime applications** (games/apps that consume MCP services), with emphasis on C# implementation patterns, process management, and Unity-specific threading constraints.

---

## Guidelines

### 1. Architecture Decision Framework

**Determine the mode first:**
- **Unity as MCP Client** (most common): Unity connects to external MCP servers (Python, Node.js, etc.) to access tools/resources
- **Unity as MCP Server** (advanced): Unity exposes its internals (Scene hierarchy, AssetDatabase) as MCP resources to external AI clients

**Transport Selection:**
- **Stdio Transport**: For local servers (Python/Node scripts). Use `System.Diagnostics.Process` with redirected streams
- **SSE Transport**: For remote servers or containerized services. Use `UnityEngine.Networking.UnityWebRequest` or `System.Net.Http`

### 2. Implementation Patterns

#### A. Client Initialization (Stdio)
```csharp
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;

public class McpClient : IDisposable
{
    private Process _serverProcess;
    private StreamWriter _stdin;
    private StreamReader _stdout;
    private int _requestId = 0;
    
    public async Task Initialize(string serverCommand, string arguments)
    {
        var psi = new ProcessStartInfo
        {
            FileName = serverCommand,
            Arguments = arguments,
            RedirectStandardInput = true,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };

        _serverProcess = new Process { StartInfo = psi };
        _serverProcess.Start();
        
        _stdin = _serverProcess.StandardInput;
        _stdout = _serverProcess.StandardOutput;
        
        // Initialize MCP session
        await SendRequest("initialize", new
        {
            protocolVersion = "2024-11-05",
            capabilities = new { },
            clientInfo = new { name = "UnityMCPClient", version = "1.0.0" }
        });
    }
    
    private async Task<JsonElement> SendRequest(string method, object parameters)
    {
        var request = new
        {
            jsonrpc = "2.0",
            id = ++_requestId,
            method,
            @params = parameters
        };
        
        var json = JsonSerializer.Serialize(request);
        await _stdin.WriteLineAsync(json);
        await _stdin.FlushAsync();
        
        // Read response (handle in Unity Main Thread for UI updates)
        var response = await _stdout.ReadLineAsync();
        return JsonSerializer.Deserialize<JsonElement>(response);
    }
    
    public void Dispose()
    {
        _stdin?.Close();
        _serverProcess?.Kill();
        _serverProcess?.Dispose();
    }
}
```

#### B. Unity Main Thread Safety
All MCP responses that interact with Unity API must marshal to main thread:
```csharp
// Using UniTask (recommended)
await UniTask.SwitchToMainThread();
// OR using Unity's MainThreadDispatcher
MainThreadDispatcher.Enqueue(() => {
    // Update Unity objects here
});
```

#### C. Capability Negotiation
Always verify server capabilities before calling tools:
```csharp
public async Task<List<McpTool>> ListTools()
{
    var response = await SendRequest("tools/list", null);
    // Parse and cache available tools
    return ParseTools(response);
}

public async Task<JsonElement> CallTool(string toolName, JsonElement arguments)
{
    return await SendRequest("tools/call", new 
    { 
        name = toolName, 
        arguments = arguments 
    });
}
```

### 3. Server Configuration Patterns

**Configuration File Structure** (mcp-config.json):
```json
{
  "mcpServers": {
    "unity-asset-db": {
      "command": "node",
      "args": ["/path/to/unity-mcp-server/dist/index.js"],
      "env": {
        "UNITY_PROJECT_PATH": "${workspaceFolder}"
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
    }
  }
}
```

**Unity-Specific Server Setup:**
When creating Unity-facing MCP servers, ensure they handle these Unity-specific concerns:
- **AssetDatabase paths**: Convert between absolute system paths and `Assets/` relative paths
- **GUID resolution**: Support lookup by Unity GUID, not just filename
- **Scene object references**: Use `GlobalObjectId` for stable references across sessions

### 4. Error Handling & Lifecycle

**Graceful Degradation:**
```csharp
try 
{
    await mcpClient.Initialize("node", "server.js");
}
catch (Exception ex)
{
    Debug.LogWarning($"MCP Server unavailable: {ex.Message}. Falling back to local implementation.");
    // Enable offline mode or local cache
}
```

**Process Cleanup:**
- Always implement `IDisposable`
- Handle Unity Editor playmode changes: Kill servers when exiting Play mode
- Handle domain reloads in Editor: Store process IDs in `EditorPrefs` for cleanup

---

## Examples

### Example 1: Unity Editor Tool with MCP FileSystem Server

**Scenario:** Create an Editor window that uses MCP to read documentation files from disk and generate Unity scripts.

```csharp
using UnityEditor;
using UnityEngine;
using System.Threading.Tasks;

public class McpDocumentationTool : EditorWindow
{
    private McpClient _client;
    private string _filePath = "Docs/api-reference.md";
    private string _generatedCode = "";
    
    [MenuItem("Window/MCP Documentation")]
    static void Init() => GetWindow<McpDocumentationTool>("MCP Docs");

    async void OnEnable()
    {
        _client = new McpClient();
        // Connect to filesystem server
        await _client.Initialize("npx", "-y @modelcontextprotocol/server-filesystem ./Docs");
    }

    void OnGUI()
    {
        _filePath = EditorGUILayout.TextField("Doc Path:", _filePath);
        
        if (GUILayout.Button("Generate Script from Doc"))
        {
            GenerateFromDoc();
        }
        
        EditorGUILayout.TextArea(_generatedCode, GUILayout.ExpandHeight(true));
    }

    async void GenerateFromDoc()
    {
        // Read file via MCP
        var resource = await _client.ReadResource($"file://{_filePath}");
        string content = resource.GetProperty("contents")[0].GetProperty("text").GetString();
        
        // Use another MCP server (e.g., AI code generator) with the content
        var result = await _client.CallTool("generate-unity-script", 
            JsonSerializer.SerializeToElement(new { documentation = content }));
            
        _generatedCode = result.GetProperty

Files in this skill

  • blender-modeling.md13.8 KB
  • flutter-app-creator.md6.9 KB
  • index.json1.5 KB
  • unity-mpc-skill.md7.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.