Skip to content

fix: wire lifespan into FastMCP and remove asyncio.sleep placeholder#24

Open
mkostersitz wants to merge 1 commit into
CursorTouch:masterfrom
mkostersitz:fix/deferred-device-connection
Open

fix: wire lifespan into FastMCP and remove asyncio.sleep placeholder#24
mkostersitz wants to merge 1 commit into
CursorTouch:masterfrom
mkostersitz:fix/deferred-device-connection

Conversation

@mkostersitz
Copy link
Copy Markdown

Problem

lifespan() was defined but never passed to FastMCP():

# before
mcp = FastMCP(name="Android-MCP", instructions=instructions)

This meant lifespan was dead code — silently ignored on every startup. Any future initialization or shutdown logic added there would never run.

Additionally, the body of lifespan contained await asyncio.sleep(1) with a comment saying "Simulate startup latency" — a debugging artefact that added a 1-second delay to every server start for no reason.

Fix

  • Pass lifespan=lifespan to the FastMCP constructor
  • Remove the asyncio.sleep(1) placeholder
  • Drop the now-unused asyncio import
# after
mcp = FastMCP(name="Android-MCP", instructions=instructions, lifespan=lifespan)

Notes

The upstream code is already ahead of the version distributed via the Claude extension marketplace (which still had the original eager-connect crash). This is a small but real correctness fix — without it the lifespan hook is inert and can't be relied on for any future startup work (e.g. pre-warming the ADB connection, logging server info, etc.).

🤖 Generated with Claude Code

@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Wire lifespan into FastMCP and remove sleep placeholder

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Wire lifespan hook into FastMCP constructor
• Remove unused asyncio.sleep(1) placeholder
• Drop now-unused asyncio import
Diagram
flowchart LR
  A["lifespan function<br/>defined but unused"] -->|"wire via<br/>lifespan= kwarg"| B["FastMCP constructor<br/>receives lifespan"]
  C["asyncio.sleep(1)<br/>placeholder"] -->|"remove"| D["Clean startup<br/>no delay"]
  E["asyncio import<br/>unused"] -->|"drop"| F["Reduced imports"]

Loading

Grey Divider

File Changes

1. src/android_mcp/__main__.py 🐞 Bug fix +1/-3

Wire lifespan hook and remove sleep placeholder

• Removed unused asyncio import
• Removed await asyncio.sleep(1) placeholder from lifespan() function
• Passed lifespan=lifespan parameter to FastMCP constructor
• Lifespan hook now properly wired for startup/shutdown logic

src/android_mcp/main.py


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Jun 5, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

lifespan() was defined but never passed to FastMCP(), so it was dead
code. Any future startup/shutdown logic added there would silently never
run. Wire it in via the lifespan= kwarg.

Also remove the asyncio.sleep(1) placeholder that served no purpose and
drop the now-unused asyncio import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant