Skip to content

[MCP] Crashlytics auto-detection can fail in Flutter projects and hide Crashlytics tools #10211

Closed

Description

@lukemmtt

Summary

I ran into a Firebase MCP discovery problem in a Flutter app that already has Crashlytics configured.

When the server starts in its default auto-detect mode, Crashlytics tools are not exposed. After digging into it locally, the reason appears to be an internal exception during feature detection, as opposed to something missing in my Crashlytics config.

The same install exposes the Crashlytics tools immediately if I force features with --only, so this looks like an MCP auto-detection bug.

Environment

  • firebase-tools 15.11.0
  • macOS arm64
  • Flutter app with firebase_crashlytics in pubspec.yaml
  • lib/firebase_options.dart generated by FlutterFire
  • Android project also applies the Crashlytics Gradle plugin

Steps to reproduce

  1. Use a Flutter app that has Firebase configured and firebase_crashlytics installed.
  2. Start Firebase MCP in the app root without forcing features:
    firebase mcp --dir /path/to/flutter_app
  3. Have an MCP client list tools.

I also reproduced this directly in-process with the installed server:

const { FirebaseMcpServer } = require("firebase-tools/lib/mcp/index.js");

(async () => {
  const server = new FirebaseMcpServer({ projectRoot: "/path/to/flutter_app" });
  await new Promise(r => setTimeout(r, 500));
  await server.mcpListTools();
})();

Expected behavior

Crashlytics tools should be exposed automatically for a Flutter project that already has Crashlytics configured.

Actual behavior

Tool listing fails during auto-detection with:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at Object.join (node:path:1339:7)
    at /opt/homebrew/lib/node_modules/firebase-tools/lib/appUtils.js:172:53
    at Array.map (<anonymous>)
    at detectAppIdsForPlatform (/opt/homebrew/lib/node_modules/firebase-tools/lib/appUtils.js:171:52)
    at async processFlutterDir (/opt/homebrew/lib/node_modules/firebase-tools/lib/appUtils.js:92:27)
    at async Promise.all (index 0)
    at async Promise.all (index 1)
    at async detectApps (/opt/homebrew/lib/node_modules/firebase-tools/lib/appUtils.js:42:72)
    at async getPlatformsFromFolder (/opt/homebrew/lib/node_modules/firebase-tools/lib/appUtils.js:32:18)
    at async isCrashlyticsInstalled (/opt/homebrew/lib/node_modules/firebase-tools/lib/mcp/util/crashlytics/availability.js:14:23)

Workaround

If I start MCP with forced features, Crashlytics tools show up immediately:

firebase mcp --dir /path/to/flutter_app --only core,auth,crashlytics,firestore,functions,messaging,database,remoteconfig,storage

With forced features, the server exposes the expected Crashlytics tools, including:

  • crashlytics_get_issue
  • crashlytics_get_report
  • crashlytics_list_events
  • crashlytics_batch_get_events

Suspected cause

This looks like an ordering problem in MCP startup.

mcpListTools() calls detectActiveFeatures() and detectProjectRoot() in parallel:

await Promise.all([this.detectActiveFeatures(), this.detectProjectRoot()]);

But detectActiveFeatures() builds its context from this.cachedProjectDir, and _createMcpContext() uses that cached dir immediately.

So it looks possible for Crashlytics availability detection to run before the project root has been cached, which then leads to path.join(dirPath, file) getting undefined inside detectAppIdsForPlatform().

Related issues

This feels related in spirit to earlier MCP Crashlytics discovery issues, but not identical:

I can provide more detail if it would be helpful, but the in-process reproduction above seems to capture the failure pretty directly.

Activity

  1. added
    api: mcp
    on Mar 30, 2026
  2. aalej commented on Mar 30, 2026

    @aalej
    Contributor

    Hey @lukemmtt, thanks for the detailed report and for opening up a PR! I'm trying to reproduce this issue, but so far I haven't encountered the error. Here's my MCVE, could you let me know in case I'm missing anything here to reproduce the issue?

    If possible, could you share a minimal reproducible example with us? This will also help us verify the fix.

  3. added
    Needs: Author Feedback
    on Mar 30, 2026
  4. lukemmtt commented on Mar 30, 2026

    @lukemmtt
    ContributorAuthor

    Hello @aalej, thanks for looking into this!

    I took a closer look at your MCVE, and I saw the same thing you did: it wasn’t reproducing the issue when running via the normal initialized MCP stdio flow. However, if I invoke the same repo directly from a parent or unrelated directory, using the direct in-process method described in my original issue, I was able to reproduce the problem.

    Here’s a concise repro script demonstrating the issue clearly under these conditions:

    const { FirebaseMcpServer } = require("firebase-tools/lib/mcp/index.js");
    
    (async () => {
      const server = new FirebaseMcpServer({ projectRoot: "/path/to/issues-10211" });
      await new Promise(r => setTimeout(r, 500));
      await server.detectActiveFeatures();
    })();

    The underlying cause seems to be that in this direct invocation scenario, detectActiveFeatures() executes before the project root (cachedProjectDir) has been populated. This causes feature detection to incorrectly depend on process.cwd() rather than the explicitly provided projectRoot, resulting in the original error (TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined).

    That’s why #10213 seems to me to be the correct fix: it explicitly ensures the project root is resolved before running feature detection, eliminating this unintended dependency on the startup sequence and invocation context.

  5. lukemmtt commented on Mar 30, 2026

    @lukemmtt
    ContributorAuthor

    I did not mean to close this 😭;

    Edit: Thanks for permission to reopen!

  6. added and removed
    Needs: Author Feedback
    on Mar 31, 2026
  7. aalej commented on Mar 31, 2026

    @aalej
    Contributor

    Thanks for the clarification @lukemmtt! I tried running a script similar to the one you provided, though in my case instead of getting an error, it outputs:

    active features: [
      'core',
      'firestore',
      'storage',
      'auth',
      'messaging',
      'functions',
      'remoteconfig',
      'database',
      'developerknowledge'
    ]
    

    With the code change in #10213, the output changes to below, which correctly reflects what features I have on the app

    active features: [ 'core', 'crashlytics', 'apptesting', 'developerknowledge' ]
    
    Node js script
    // pulls the globally installed firebase-tools so this can be run anywhere
    const { execSync } = require("child_process");
    const npmSpawnPath = execSync("npm root -g");
    const firebaseToolsPath = `${npmSpawnPath.toString().trim()}/firebase-tools`
    const { FirebaseMcpServer } = require(`${firebaseToolsPath}/lib/mcp/index.js`);
    
    (async () => {
        const server = new FirebaseMcpServer({ projectRoot: "YOUR_PROJECT_ROOT_HERE" });
        await new Promise(r => setTimeout(r, 500));
        const features = await server.detectActiveFeatures();
    
        console.log("active features:", features);
    })();

    I'll discuss this issue with our engineering team during our sync to get their feedback on this as well. Just to verify, did you encounter any errors when running with firebase mcp --dir /path/to/flutter_app? As you mentioned, the await Promise.all([this.detectActiveFeatures(), this.detectProjectRoot()]); might be causing a race condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attentionapi: mcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions