Skip to content

fix: preserve MCP session lifecycle across sequential tool calls#3143

Draft
leonam13 wants to merge 1 commit intomobile-dev-inc:mainfrom
leonam13:fix/mcp-persistent-session-lifecycle
Draft

fix: preserve MCP session lifecycle across sequential tool calls#3143
leonam13 wants to merge 1 commit intomobile-dev-inc:mainfrom
leonam13:fix/mcp-persistent-session-lifecycle

Conversation

@leonam13
Copy link
Copy Markdown

@leonam13 leonam13 commented Apr 5, 2026

Summary

This solves this issue: #3142

  • keep MCP tool executions in persistent Maestro sessions by reusing session instances when closeOnCompletion is disabled
  • preserve one-shot CLI behavior by retaining explicit close-and-cleanup on completion for default session mode
  • harden cleanup flow to avoid masking primary command failures when close operations fail

Test plan

  • ./gradlew :maestro-cli:compileKotlin
  • Run MCP flow twice in same server process (e.g. launch_app then run_flow) and verify no repeated driver reinstall
  • Restart MCP server and verify first call initializes a fresh session as expected

Keep MCP tools from tearing down Maestro sessions after each invocation by reusing persistent sessions and isolating one-shot cleanup to CLI flows. This avoids repeated driver reinstall/startup between back-to-back MCP commands while preserving original command failures when cleanup also errors.

Made-with: Cursor
@simon-gilmurray
Copy link
Copy Markdown
Contributor

Had a test of this @leonam13 and it still seemed to be failing after a while for me - also then running CLI separately afterwards still had an error launching app too - have you tested this out?

@leonam13
Copy link
Copy Markdown
Author

leonam13 commented Apr 8, 2026

@simon-gilmurray there are two different issues. When running MCP and then running CLI, the latter will drop the former. I've been experiencing this issue and the workaround was to avoid using CLI while the MCP session is on.

For a pure MCP test, this did it work for me, the agent was able to launch and stop the app multiple times, only invoking the launch app tool.

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.

2 participants