{"id":8309,"library":"mcpforunityserver","title":"MCP for Unity Server","description":"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.","status":"active","version":"9.6.6","language":"en","source_language":"en","source_url":"https://github.com/CoplayDev/unity-mcp.git","tags":["unity","game-dev","protocol","server","async","realtime"],"install":[{"cmd":"pip install mcpforunityserver","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for asynchronous HTTP client/server communication.","package":"aiohttp"},{"reason":"Core dependency for WebSocket communication with Unity clients.","package":"websockets"},{"reason":"Optional dependency for performance improvement with asyncio event loop.","package":"uvloop","optional":true}],"imports":[{"symbol":"Server","correct":"from mcpforunityserver import Server"},{"note":"Types and core classes like UnityClient, ServerConfig, and Message were moved to the 'types' submodule in v9.6.0.","wrong":"from mcpforunityserver import UnityClient","symbol":"UnityClient","correct":"from mcpforunityserver.types import UnityClient"},{"note":"Types and core classes like UnityClient, ServerConfig, and Message were moved to the 'types' submodule in v9.6.0.","wrong":"from mcpforunityserver import Message","symbol":"Message","correct":"from mcpforunityserver.types import Message"}],"quickstart":{"code":"import asyncio\nfrom mcpforunityserver import Server\n\nasync def main():\n    server = Server(\n        port=25001,\n        server_name='MyUnityServer',\n        server_version='1.0.0'\n    )\n    \n    @server.on_connect\n    async def handle_connect(client):\n        print(f'Client connected: {client.id}')\n\n    @server.on_disconnect\n    async def handle_disconnect(client):\n        print(f'Client disconnected: {client.id}')\n\n    await server.start()\n    print(f'MCP Server started on port {server.port}')\n    \n    # Keep the server running indefinitely\n    while True:\n        await asyncio.sleep(3600) # Sleep for an hour\n\nif __name__ == '__main__':\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"fix":"Review the latest documentation or source code for `Server` and `UnityClient` constructors. Update parameter names and types. Remove any reliance on `message_id` from message processing logic.","message":"The constructor signatures for `Server` and `UnityClient` classes, along with their associated parameters, underwent significant changes. Additionally, the `message_id` field was removed from all message types.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Migrate all existing synchronous callback functions to `async def` functions. Ensure that any calls to these callbacks are properly `await`ed where applicable.","message":"The library's callback system was refactored to be exclusively asynchronous. All event handlers and callbacks must now be defined as `async def` functions and awaited if they perform asynchronous operations.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Update import statements from `from mcpforunityserver import MyType` to `from mcpforunityserver.types import MyType` for all affected symbols.","message":"Key types and core classes (e.g., `UnityClient`, `ServerConfig`, `Message`) were moved from the top-level `mcpforunityserver` package directly into the `mcpforunityserver.types` submodule for better organization.","severity":"gotcha","affected_versions":">=9.6.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Remove any code that attempts to access or set the `message_id` attribute on server or client objects, or messages.","cause":"The `message_id` field was deprecated and removed from all message types in version 9.0.0 as it was unused.","error":"AttributeError: 'Server' object has no attribute 'message_id'"},{"fix":"Ensure that any function registered as a callback (e.g., for `on_connect`, `on_message`) is defined using `async def`.","cause":"Prior to v8.0.0, synchronous callbacks were supported. From v8.0.0 onwards, all callbacks are expected to be asynchronous (coroutines).","error":"TypeError: object NoneType can't be used in 'await' expression (for callbacks) OR RuntimeWarning: coroutine 'your_callback' was never awaited"},{"fix":"Change your import statement from `from mcpforunityserver import UnityClient` to `from mcpforunityserver.types import UnityClient`.","cause":"Many common classes and types, including `UnityClient`, `ServerConfig`, and `Message`, were reorganized into the `mcpforunityserver.types` submodule in version 9.6.0.","error":"ImportError: cannot import name 'UnityClient' from 'mcpforunityserver' (/path/to/mcpforunityserver/__init__.py)"}]}