MCP for Unity Server

9.6.6 · active · verified Thu Apr 16

MCP for Unity Server is a Python library that provides the server-side implementation for the Model Context Protocol (MCP), enabling seamless integration and communication with Unity clients. It facilitates real-time data exchange and command execution between Python applications and the Unity Editor. The current version is 9.6.6, and it sees regular updates, often with significant architectural changes between major versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize and start an MCP server, setting up basic connection and disconnection event handlers. The server listens on port 25001 and remains active indefinitely.

import asyncio
from mcpforunityserver import Server

async def main():
    server = Server(
        port=25001,
        server_name='MyUnityServer',
        server_version='1.0.0'
    )
    
    @server.on_connect
    async def handle_connect(client):
        print(f'Client connected: {client.id}')

    @server.on_disconnect
    async def handle_disconnect(client):
        print(f'Client disconnected: {client.id}')

    await server.start()
    print(f'MCP Server started on port {server.port}')
    
    # Keep the server running indefinitely
    while True:
        await asyncio.sleep(3600) # Sleep for an hour

if __name__ == '__main__':
    asyncio.run(main())

view raw JSON →