mysql-mcp-server: startup self-test crashes the first real query with "bound to a different event loop"
Describe the bug
With --connection_method MYSQL_WIRE_PROTOCOL or MYSQL_WIRE_IAM_PROTOCOL, the server logs a successful startup validation and then crashes on the very first real query from an MCP client.
Expected Behavior
After "Successfully validated database connection to MySQL", the server serves queries normally.
Current Behavior
The startup self-test passes and logs success, then the first run_query/get_table_schema call from a client raises:
RuntimeError: <aiorwlock._RWLockCore object at 0x...> is bound to a different event loopFull traceback from my repro below:
Traceback (most recent call last):
File "asyncmy_pool_connection.py", line 227, in check_expiry
async with self.rw_lock.reader_lock:
File "aiorwlock/__init__.py", line 218, in __aenter__
await self.acquire()
File "aiorwlock/__init__.py", line 245, in acquire
await self._lock.acquire_read()
File "aiorwlock/__init__.py", line 64, in _get_loop
raise RuntimeError(f"{self!r} is bound to a different event loop")Reproduction Steps
This reproduces with the real AsyncmyPoolConnection class, asyncmy stubbed out since the crash never reaches a real query:
import asyncio, sys, types
fake = types.ModuleType("asyncmy")
class FakePool:
def acquire(self):
raise AssertionError("not reached")
async def fake_create_pool(**kw):
return FakePool()
fake.create_pool = fake_create_pool
fake.Pool = FakePool
fake_cursors = types.ModuleType("asyncmy.cursors")
fake_cursors.DictCursor = object
fake.cursors = fake_cursors
sys.modules["asyncmy"] = fake
sys.modules["asyncmy.cursors"] = fake_cursors
from awslabs.mysql_mcp_server.connection.asyncmy_pool_connection import AsyncmyPoolConnection
conn = AsyncmyPoolConnection(
host="db.example.internal", port=3306, database="app", readonly=True,
secret_arn="", db_user="", region="us-east-1", is_iam_auth=False, is_test=True,
)
asyncio.run(conn.check_expiry()) # mirrors main()'s startup self-test asyncio.run(run_query(...))
asyncio.run(conn.check_expiry()) # mirrors mcp.run() serving on a fresh loop -> crashes hereSecond asyncio.run() call raises the RuntimeError above. Tested against current main (83ac9137, awslabs.mysql-mcp-server 1.1.2), Python 3.12.
Possible Solution
postgres-mcp-server had the identical symptom (startup self-test succeeds, then the first query crashes the same way) and it looks like #4514 just fixed that one. Might be worth checking whether mysql-mcp-server needs the same treatment.
Additional Information/Context
Found while looking at #4380, which describes the postgres-mcp-server side of this.
OS
Not OS-specific, this is server-side asyncio/event-loop behavior.
Server
mysql-mcp-server
Server Version
1.1.2
Region
Not region-specific, the crash happens before any query reaches the database.
Service quota
Not applicable, this bug is unrelated to service quotas.
Source: awslabs/mcp