The ai cannot seem to get firestore to work correctly

This is my second project that, when trying to get the firestore database functionality working, the AI does not seem to be able to successfully complete the conversion. There are major problems with authentication for server functions and firestore access. Just to clarify, everything works fine with ‘Dangerous’ rules. Even the least restrictive rules to allow authenticated users only fail since the server functions cannot authenticate the client. The firebase admin SDK is proposed by the AI as a solution, but it is unable to get it to work either.

A new option has recently been introduced where you can use a MCP (model context protocol) server to interact with things like Firestore.

Create a mcp.jsonfile and place it in the .idx folder:

{
    "mcpServers": {
      "firebase": {
        "command": "npx",
        "args": [
          "-y",
          "firebase-tools@latest",
          "experimental:mcp",
          "--dir",
          "/home/user/studio"
        ]
      }
    }
  }

If you’re looking for a more traditional route, ensure the firebase admin service account in Google Cloud Platform (GCP) has access to Firestore.

Feel free to send a direct message to me if you want to walk through it together.

Thanks! I am not familiar with using MCP. How would I use this in my development? Will the AI use it automatically or will I need to give it specific instructions?

1 Like

Once you create the file, the AI will now have additional context to assist with Firebase tools. It will use it automatically.

You can go above and beyond by creating a file called GEMINI.md and placing the file in your root project.

GEMINI.md is a text/markup file (similar to README.md) that you can use to give the model additional instructions. You can instruct the model to use the features of Firebase in the GEMINI.md file and it should follow those orders. Best if used in “Code” mode.

@PPars as far as authenticated users, you may need to allow list the development domain. Authentication > Settings > Authorized Domains depending on the auth provider you are using.

You can get the preview domain by popping the preview window out into it’s own tab and reading the address bar.

Once you start using real rules on Firestore that involves checking authenticated users, authentication needs to be working properly.

Another issue could arise if Firebase Authentication is using an emulator but Firestore database isn’t. The two will not communicate and Firestore will not have a way to authenticate the user.

1 Like

Will this work with the prototyper?

Yes, you can pop the preview out into it’s own tab using this button on the preview window.