ImportError: cannot import name 'FakeConnection' from 'fakeredis.aioredis' on startup

View original issue on GitHub  ·  Variant 2

Why am I getting "ImportError: cannot import name 'FakeConnection' from 'fakeredis.aioredis'" when starting FastMCP?

You might encounter this error when starting your FastMCP server: ImportError: cannot import name 'FakeConnection' from 'fakeredis.aioredis'. This typically happens immediately after successful authentication and prevents the server from running.

What's causing this error?

The root cause lies in a dependency conflict between docket, which FastMCP relies on, and the fakeredis library. Specifically, docket attempts to import FakeConnection from fakeredis.aioredis. However, newer versions of fakeredis have either removed or renamed this class, leading to the ImportError. This issue is particularly prevalent when fakeredis is upgraded to a version incompatible with the expected API of docket.

How can I fix it?

The most straightforward solution is to constrain the version of fakeredis to a compatible version. Based on community feedback, fakeredis versions prior to 2.26 are known to work. You can enforce this version constraint when launching your FastMCP server. The exact method depends on how you're deploying FastMCP, but here's a common solution using uvx, as mentioned in the discussion:

Modify your ~/.claude.json configuration file. Within your project's snowflake MCP server configuration, locate the args array. Insert "--with" and "fakeredis<2.26" immediately after the git source URL but before "mcp-server-snowflake". This tells uvx to install fakeredis version less than 2.26.


{
  "args": [
    "--from",
    "git+https://github.com/Snowflake-Labs/mcp",
    "--with",
    "fakeredis<2.26",
    "mcp-server-snowflake",
    ...rest of args...
  ]
}

After making this change, restart your Claude environment and attempt to connect to the MCP server again using the /mcp command.

Important Considerations