Mcp-mongo-server with Gemini doesn't work

Hi there! I’ve tried to use Google Gemini 2.0 flash with MCP in my agent and faced the issue. Everything was working correctly if I used a @modelcontextprotocol/server-filesystem based example but none was working when I switched it to mcp-mongo-server. My database connection string is 100% correct and looks like the agent stuck somewhere at self._arun in the agent.py.
Here’s how my agent initialization code looks like:

async def create_mongodb_agent(session):
    """Create and configure a mongodb agent with MCP tools."""
    # Initialize the MCP toolkit
    mcp_tools = MCPTools(session=session)
    await mcp_tools.initialize()

    # Create an agent with the MCP toolkit
    return Agent(
        model=Gemini(
            id="google/gemini-2.0-flash-001",
            project_id=PROJECT_ID,
            location=LOCATION,
            vertexai=True
        ),
        tools=[mcp_tools],
        instructions=dedent("""\
            You are a MongoDB assistant. Help users explore collections.

            - Navigate collections to answer questions
            - Use the query, aggregate and count tools to explore collections
            - Provide clear context about collections or entities you examine
            - Use headings to organize your responses
            - Be concise and focus on relevant information\
        """),
        markdown=True,
        show_tool_calls=True
    )

async def run_agent(message: str) -> None:
    """Run mongodb agent with the given message."""
    # Initialize the MCP server
    server_params = StdioServerParameters(
        command="npx",
        args=[
            "-y",
            "mcp-mongo-server",
            "mongodb://localhost/mydemodb",
        ],
    )
    
    # Create a client session to connect to the MCP server
    async with stdio_client(server_params) as (read, write):        
        async with ClientSession(read, write) as session:
            agent = await create_mongodb_agent(session)
            print('running...')
            # Run the agent
            await agent.aprint_response(message, stream=True)

Also, I can see 7 tools registered for mcp-mongo-server in debugging logs. Do you have any ideas/hints?

I’ve also tried to comment instructions but it didn’t help at all.

After deeper debugging I caught an exception in gemini.py at line 123:

if schema_type == "ARRAY":
        items = _convert_schema(schema_dict["items"])
        return Schema(type=schema_type, description=description, items=items)
    else:
        return Schema(type=schema_type, description=description)

Any ideas why schema_dict["items"] is not defined? Will changing if condition to if schema_type == "ARRAY" and schema_dict.get("items"): fix the issue?

Hi @Vasyaga
Thanks for reaching out and for using Agno! I’ve looped in the right engineers to help with your question. We usually respond within 48 hours, but if this is urgent, just let us know, and we’ll do our best to prioritize it.
Appreciate your patience—we’ll get back to you soon! :smile:

1 Like

Hi @Vasyaga
It seems the MCP for Mongo has an incorrect definition. Ideally we should process the items in a schema_dict instead of passing it by. I am struggling to replicate, because I need a locally running MongoDB to do so.

Ok I have Mongo running locally, replicating

I have a fix out to address the issue.

1 Like