Skip to content

Add MCPToolController and fix 5 failing MCPToolControllerE2ETest cases#374

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-test-case-bugs
Draft

Add MCPToolController and fix 5 failing MCPToolControllerE2ETest cases#374
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-test-case-bugs

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

MCPToolController and MCPToolControllerE2ETest were absent from the codebase despite being referenced. The controller also had incorrect WebDriver method names (navigatenavigateTo, screenshotcaptureScreenshot) and used several non-existent WebDriver methods.

Changes

SessionManager.kt

  • Added getAllSessions(): List<ManagedSession> and deleteAllSessions(): Int required by the controller's list/close-all/kill-all session handlers

MCPToolController.kt (new)

  • POST /mcp/call-tool — routes session-management tools (open_session, close_session, list_sessions, close_all_sessions, kill_all_sessions, delete_session_data) directly, dispatches all other tools to the session's WebDriver
  • GET /mcp/tools — returns the full tool list consumed by browser4-cli
  • Fixed WebDriver method names: navigateTo, captureScreenshot
  • Implemented missing WebDriver methods (dblclick, select_option, dialog_accept, dialog_dismiss, resize, keydown, keyup, mousedown, mouseup) via driver.evaluate()
  • ObjectMapper in companion object (shared); errorResponse sets isError = true with the raw message

MCPToolControllerE2ETest.kt (new)

  • 45 @Tag("E2ETest") tests covering all browser4-cli→MCP tool mappings
  • Includes the 5 previously failing cases:
@Test
@DisplayName("Calling an unknown tool returns an error")
fun testUnknownToolReturnsError() {
    val sid = openSession()
    val response = callTool("nonexistent_tool_xyz", mapOf("sessionId" to sid))
    assertIsError(response)
    assertTrue(textContent(response).contains("Unknown tool"))
}

@Test
@DisplayName("close_session returns error for unknown sessionId")
fun testCloseSessionNotFound() {
    val response = callTool("close_session", mapOf("sessionId" to "non-existent-id"))
    assertIsError(response)
    assertTrue(textContent(response).contains("Session not found"))
}

@Test
@DisplayName("delete_session_data clears cookies and storage (cli: delete-data)")
fun testDeleteSessionData() {
    val sid = openAndNavigate(MOCK_PRODUCT_DETAIL_URL)
    val response = callTool("delete_session_data", mapOf("sessionId" to sid))
    assertNotError(response)
    assertTrue(textContent(response).contains("User data deleted"))
}

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: galaxyeye <1701451+galaxyeye@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bugs in MCPToolControllerE2ETest cases Add MCPToolController and fix 5 failing MCPToolControllerE2ETest cases Mar 13, 2026
Copilot AI requested a review from galaxyeye March 13, 2026 06:09
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