firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

feat(mcp, firestore): Add 'select' parameter to get_documents tool

Open boraberkcetintas opened this issue 3 months ago • 3 comments

Description

Adds a 'select' parameter to the firestore_get_documents MCP tool. This allows developers to specify which fields of a document to return, preventing token limit errors when dealing with large documents.

The select parameter accepts an array of field paths (e.g., ['field1', 'nested.field']). The MCP server will still fetch the full document from Firestore but will apply this field mask before sending the response to the LLM.

If select is not provided or is an empty array, the full document is returned. The __path__ field is always preserved in the response for context.

Scenarios Tested

A comprehensive suite of unit tests has been added to cover the new functionality.

Sample Commands

firebase firestore documents get "my-collection/my-doc" --select "field1,nested.field"

Fixes #9043

boraberkcetintas avatar Sep 01 '25 20:09 boraberkcetintas

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Sep 01 '25 20:09 google-cla[bot]

@joehan Gemini’s idea seems fair. I developed the suggested method, but I couldn’t figure out how to use the Firestore Emulator and MCP together to test it myself. Since the Admin SDK has a select feature, I think this approach could work.

I also built the package locally with npm run build and tested it using npm link. In addition, if the Admin SDK supports it, we could also make direct API requests as an alternative.

API reference: https://firebase.google.com/docs/firestore/reference/rest/v1beta1/projects.databases.documents/batchGet

boraberkcetintas avatar Sep 05 '25 21:09 boraberkcetintas

Looks like you just need to run 'npm run format' to fix the linter issues, and then this LGTM

joehan avatar Sep 09 '25 20:09 joehan