DEV Community

Cover image for Testing the MongoDB® MCP Server using SingleStore Kai
Akmal Chaudhri for SingleStore

Posted on • Edited on

1

Testing the MongoDB® MCP Server using SingleStore Kai

Abstract

MongoDB recently announced the release of an official MCP Server. At the time of writing this article, the release version was shown as 0.1.0. In this article we'll test this early release version against SingleStore Kai, a MongoDB-compatible API developed by SingleStore, designed to enable applications built for MongoDB to run on SingleStore with minimal changes. We'll configure and test the MongoDB MCP Server using a freely available tool called MCPHost.

The notebook file used in this article is available on GitHub.

Introduction

In a previous article, we successfully tested the SingleStore MCP Server. Since SingleStore also supports a MongoDB-compatible API, we can also test it against the MongoDB MCP Server to determine the level of compatibility.

Create a SingleStore account

A previous article showed the steps to create a free SingleStore Cloud account. We'll use the Standard Tier with the following settings:

  • Workspace Group Name: MCP Demo Group
  • Cloud Provider: AWS
  • Region: US East 1 (N. Virginia)
  • Workspace Name: mcp-demo
  • Size: S-00
  • Settings:
    • SingleStore Kai selected

Once the workspace is available, we'll make a note of the MongoDB connection string from mcp-demo > Connect > MongoDB Client. The connection string will be similar to the following:

mongodb://admin:<password>@<host>:27017/?authMechanism=PLAIN&tls=true&loadBalanced=true
Enter fullscreen mode Exit fullscreen mode

The values for <password> and <host> will be pre-filled.

Import the notebook

We'll download the notebook from GitHub.

From the left navigation pane in the SingleStore cloud portal, we'll select DEVELOP > Data Studio.

In the top right of the web page, we'll select New Notebook > Import From File. We'll use the wizard to locate and import the notebook we downloaded from GitHub.

Run the notebook

Before running the notebook code cells, we'll select the mcp-demo workspace from the pull-down menu just above the notebook.

First, some imports:

import json
import requests

from bson import ObjectId
from pymongo import MongoClient
Enter fullscreen mode Exit fullscreen mode

Next, we'll connect to Kai:

try:
    client = MongoClient(connection_url_kai)
    db = client["kai_test_db"]
    client.drop_database(db)
    collection = db["books"]
    print("Connected to Kai successfully")
except Exception as e:
    print(f"Could not connect to Kai: '{e}'")
Enter fullscreen mode Exit fullscreen mode

Note that if the database kai_test_db already exists, it will be deleted.

Next, we'll download some data about books:

url = "https://raw.githubusercontent.com/VeryFatBoy/fast-ai-on-json/refs/heads/main/datasets/bookstore/books.json"

response = requests.get(url)
Enter fullscreen mode Exit fullscreen mode

Then we'll prepare the data for loading into Kai:

documents = []

for idx, line in enumerate(response.text.strip().splitlines(), start = 1):
    try:
        doc = json.loads(line)
        if "_id" in doc and "$oid" in doc["_id"]:
            doc["_id"] = ObjectId(doc["_id"]["$oid"])
        documents.append(doc)
    except Exception as e:
        print(f"[Line {idx}] Unexpected error: {e}")
Enter fullscreen mode Exit fullscreen mode

Finally, we'll store the books data:

if documents:
    collection.insert_many(documents)
    print(f"Inserted {len(documents)} documents into Kai.")
else:
    print("No valid documents to insert.")
Enter fullscreen mode Exit fullscreen mode

We've now created a database and loaded a collection with some test data.

Local test environment

The MongoDB MCP Server requires Node.js, version 20 or later.

We'll now create a json file called ~/.mcp.json as follows:

{
  "mcpServers": {
    "MongoDB": {
      "command": "npx",
      "args": [
        "-y",
        "mongodb-mcp-server",
        "--connectionString",
        "mongodb://admin:<password>@<host>:27017/?authMechanism=PLAIN&tls=true&loadBalanced=true"
      ]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

We'll replace <password> and <host> with the values that we saved earlier.

Install Ollama

We'll use Ollama and download and install the appropriate version.

Once installed, we'll pull an LLM. For example:

ollama pull qwen2.5:7b
Enter fullscreen mode Exit fullscreen mode

Install MCPHost

We'll use MCPHost and follow the installation instructions on GitHub.

Run MCPHost

Now we'll run MCPHost, as follows:

~/go/bin/mcphost -m ollama:qwen2.5:7b
Enter fullscreen mode Exit fullscreen mode

Example queries

Let's test the MCP Server. To start, we'll ask the following:

I am using the kai_test_db database. What collections can you see?
Enter fullscreen mode Exit fullscreen mode

Example output:

Assistant:


  The kai_test_db database contains a collection named books.

  If you need more details about this collection or any other
  operations, let me know!
Enter fullscreen mode Exit fullscreen mode

First query

Let's try a simple count.

How many documents are in the books collection?
Enter fullscreen mode Exit fullscreen mode

Example output:

Assistant:


  The books collection in the kai_test_db database contains
  2000 documents.

  Is there anything else you would like to know or do with
  this collection?
Enter fullscreen mode Exit fullscreen mode

Second query

Now let's look at some data.

Show me any 2 documents from the books collection.
Enter fullscreen mode Exit fullscreen mode

Example output:

Assistant:


  Here are two documents from the books collection:

  1. Document 1:

    {
        "_id": {"$oid": "64e3d055c330effc84b2067a"},
        "title": "Kalaikaḷ, ur̲avum urumār̲r̲amum",
        "subjects": ["Arts, Indic", "Arts", "Indic Arts"],
        "description": "On various form of arts in Tamil Nadu.",
        "price": 12.88,
        "type": "audio",
        "createdAt": "2009-12-09T20:23:01.985607",
        "updatedAt": "2020-12-06T00:51:46.276201"
    }

  2. Document 2:

    {
        "_id": {"$oid": "64e3d055c330effc84b2079f"},
        "title": "America's star-crossed sweethearts",
        "subjects": ["Baseball players", "Man-woman
  relationships", "Fathers and sons", "Fiction", "Fiction,
  romance, general"],
        "description": "\"The private life of baseball
  superstar Angelo \"\"The Angel\"\" Casali is a mystery, but
  sources say a reunion with his estranged father is his
  reason for returning to Italy And now that he's been seen
  stepping off the plane with stunning--and scandalous--
  starlet Atlanta Jackson, he has added fuel to the media fire.
  After his latest injury, Angelo's career is in its final
  inning. Is this notorious playboy ready to settle down?
  Something tells us we haven't heard the last of our Angel...
  !\"--Publisher's website.",
        "price": 41.03,
        "type": "hardcover",
        "createdAt": "2017-06-24T12:24:56.397915",
        "updatedAt": "2020-08-28T14:53:01.087094"
    }

  If you need more information or further operations on these
  documents, let me know!
Enter fullscreen mode Exit fullscreen mode

Third query

Let's try something a bit more complex.

What is the title and price of the most expensive book?
Enter fullscreen mode Exit fullscreen mode

Example output:

Assistant:


  The title and price of the most expensive book in the books
  collection are as follows:

  • Title: "Charles Dickens' Oliver Twist"
  • Price: $99.96

  Is there anything else you need help with regarding this
  information?
Enter fullscreen mode Exit fullscreen mode

Summary

In this article, we saw how to quickly configure and run the MongoDB MCP Server using SingleStore Kai and MCPHost. We launched MCPHost using an Ollama model, but MCPHost also supports alternative providers and models.

Top comments (0)