DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Frame Buffer Hashing for Visual Regression on Embedded Devices
  • How to Interpret the Number of Spring ApplicationContexts in Integration Tests
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It
  • Good Data, Bad Metric: A Mutation Testing Pattern for Analytics Engineering

Trending

  • Managing, Updating, and Organizing Agent Skills
  • Why Your AI Agent's Logs Aren't Earning Trust
  • Give Your AI Assistant Long-Term Memory With perag
  • Native SQL in Java Without JDBC Boilerplate — Meet Ujorm3
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Testing the MongoDB MCP Server Using SingleStore Kai

Testing the MongoDB MCP Server Using SingleStore Kai

In this article, learn how to set up and test the MongoDB MCP Server with SingleStore Kai using MCPHost, notebooks, and real-time queries powered by Ollama LLM.

By 
Akmal Chaudhri user avatar
Akmal Chaudhri
DZone Core CORE ·
Jul. 11, 25 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
1.4K Views

Join the DZone community and get the full member experience.

Join For Free

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:

Plain Text
 
mongodb://admin:<password>@<host>:27017/?authMechanism=PLAIN&tls=true&loadBalanced=true


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:

Python
 
import json
import requests

from bson import ObjectId
from pymongo import MongoClient


Next, we'll connect to Kai:

Python
 
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}'")


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

Next, we'll download some data about books:

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

response = requests.get(url)


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

Python
 
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}")


Finally, we'll store the book's data:

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


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:

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


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:

Shell
 
ollama pull qwen2.5:7b


Install MCPHost

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

Run MCPHost

Now, we'll run MCPHost as follows:

Shell
 
~/go/bin/mcphost -m ollama:qwen2.5:7b


Example Queries

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

Plain Text
 
I am using the kai_test_db database. What collections can you see?


Example output:

Plain Text
 
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!


First Query

Let's try a simple count.

Plain Text
 
How many documents are in the books collection?


Example output:

Plain Text
 
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?


Second Query

Now let's look at some data.

Plain Text
 
Show me any 2 documents from the books collection.


Example output:

Plain Text
 
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!


Third Query

Let's try something a bit more complex.

Plain Text
 
What is the title and price of the most expensive book?


Example output:

Plain Text
 
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?


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.

MongoDB Testing SingleStore

Published at DZone with permission of Akmal Chaudhri. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Frame Buffer Hashing for Visual Regression on Embedded Devices
  • How to Interpret the Number of Spring ApplicationContexts in Integration Tests
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It
  • Good Data, Bad Metric: A Mutation Testing Pattern for Analytics Engineering

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook