User Location MCP Server
Overview
Minimal MCP server (buddai-location
) that stores and retrieves the user’s current location from MongoDB. It is invoked through STDIO using the Docker image referenced in user_location.mcp.yml
.
Components
index.js
– spins up the MCP server, registering two tools for reading/writing the location.mongo.js
– MongoDB helper that persists a single document (userId: "current"
) in thelocations
collection.package.json
/Dockerfile
– Node 22 image using@modelcontextprotocol/sdk
with production dependencies only.
Exposed MCP tools
Tool | Purpose | Input |
---|---|---|
get_user_location | Returns the stored location string, defaulting to "Las Rozas de Madrid, España" when no document exists. | none |
set_user_location | Upserts the current location and timestamp for userId="current" . | location (string). |
The helpers maintain a single cached MongoDB connection and close it only when the process exits.
Configuration
The host launch definition (mcp_servers/user_location.mcp.yml
) expects a MongoDB URI:
yaml
user_location:
transport: stdio
command: docker
args:
- run
- --init
- -i
- --rm
- --network
- buddai_net
- -e
- MONGO_URI
- buddai/mcp-user-location
env:
MONGO_URI: "${MONGO_URI}"
Provide MONGO_URI
in the MCP host environment. The server writes to the default database returned by the URI and creates/uses a locations
collection.
Set DEBUG=mcp_location:*
to enable debug output.
Running locally
- Install Node.js ≥ 20 and run
npm install
. - Ensure MongoDB is reachable and export
MONGO_URI
plus optionalDEBUG
. - Launch the MCP server with
node index.js
and connect via an MCP client over STDIO.
Docker usage
bash
docker build -t buddai/mcp-user-location mcp_servers/location
Run (matching the host configuration):
bash
docker network create buddai_net # once
MONGO_URI=mongodb://mongo:27017/buddai \
docker run --rm --init -i \
--network buddai_net \
-e MONGO_URI \
-e DEBUG=mcp_location:* \
buddai/mcp-user-location
Development notes
- This service caches the Mongo client globally; when you change connection parameters, restart the process so the new URI is applied.
- Tests are inherited from other projects and are currently stale.
- Only a single logical user is supported (
userId="current"
). Extendmongo.js
if you need multi-user support.
Troubleshooting
- No updates stored: verify that the Mongo user has write permissions and that the
locations
collection exists in the target database. - Unexpected default location: call
set_user_location
at least once; the fallback string indicates no record was found.