Skip to content

Results of find tool query return first document? #795

@gruenbergera

Description

@gruenbergera

Hello,

I am having some difficulty understanding (and then debugging) the actual query executed once the tool call is made with the provided arguments.

I have done my best to turn on all verbose logging and traced all of the executions made by the MCP server, and it should be right, but, for some reason, once the LLM configures the correct arguments for find, the returned document is wrong, and consistently wrong at that. It returns the "first" document in the collection every time.

When I run the query with the arguments in mongosh it returns the correct document with the correct projection.

I am kind of losing my mind as it is adopting and leveraging LLMs as it is, but this one is leaving me pretty confused.

Our MongoDB version is "MongoDB 7.0.26 Enterprise" and is an Atlas cloud implementation.

Some strange clues in this black box mystery.
Essentially, the query should resemble the following:
mydb.myCollection.find({sid:740}, {_id:0, mw:1, sid: 1},{sort:{}}) when this is run in mongosh, it returns as expected.

The tool call arguments for "find" are as follows:
tool_calls=[{'name': 'find', 'args': {'collection': 'myCollection', 'database': 'mydb', 'filter': {'sid': 740}, 'limit': 1, 'projection': {'_id': 0, 'mw': 1, 'sid': 1}, 'responseBytesLimit': 1048576, 'sort': {}}, 'id': 'ae1fc560-cd2d-40f3-bc81-f89fee43e51a', 'type': 'tool_call'}]

Each time it does this, it returns with the same document, which happens to be the "first" document on a find({}).

What am I missing here?
I am using mcp-use, which is a wrapper of langchain agents, I believe.

Note: I have tried to "scrub" the code there. In any case, as far as I can tell, the arguments are correctly typed and passed to the point where it will return the number of documents with respect to the limit argument.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions