A Model Context Protocol (MCP) server for various data operations. Currently supports MongoDB operations with extensible architecture for additional data sources. See echo for a minimal example. Can be used in stdio mode or through http.
-
Ensure MongoDB is running (start it separately if needed)
-
Configure the server using a
config.jsonfileSee Configuration below for details and examples.
-
Run the server (choose transport):
# Stdio mode (default) go run main.go # HTTP mode go run main.go --transport=http
-
Configure VSCode MCP (choose transport):
Stdio Transport:
{ "servers": { "mcp-server": { "command": "/path/to/mcp/mcp --config=/path/to/config/my-config.json", "cwd": "/path/to/mcp" "args": [] } } }HTTP Transport:
{ "servers": { "mcp-server": { "type": "http", "url": "http://localhost:3001/mcp" } } }
- Ensure you have Go 1.25+ installed
- Run
go mod tidyto download dependencies
The server is configured using a config.json file in the same directory as the server.
Create a config.json file:
{
"mongodb": {
"enabled": true,
"uri": "mongodb://username:password@localhost:27017?authSource=admin"
},
"echo": {
"enabled": true
},
"server": {
"port": 3001
}
}You can enable or disable individual MCP services:
- mongodb.enabled: Set to
trueto enable MongoDB operations,falseto disable - mongodb.uri: MongoDB connection URI (database is specified per operation, not in URI)
- echo.enabled: Set to
trueto enable the echo service (for testing),falseto disable - server.port: Port for HTTP server (default: 3001)
This allows you to run only the services you need.
# Stdio mode (default) with default config
go run main.go
# HTTP mode with default config
go run main.go --transport=http
# Stdio mode with custom config file
go run main.go --config=my-config.json
# HTTP mode with custom config file
go run main.go --transport=http --config=/path/to/config.jsonThe HTTP server will start on the port specified in the config.json file (default: 3001).
echo-hello: Echoes "Hello World!" (example tool)mongodb-list-collections: List all collections in the databasemongodb-find: Query documents in a collectionmongodb-insert-one: Insert a single documentmongodb-update-one: Update a single documentmongodb-delete-one: Delete a single documentmongodb-insert-many: Insert multiple documentsmongodb-update-many: Update multiple documentsmongodb-delete-many: Delete multiple documentsmongodb-count: Count documents in a collectionmongodb-drop-collection: Drop (delete) an entire collection
The MCP server is designed to be extensible. To add support for additional data sources (PostgreSQL, Redis, etc.), simply:
- Create a new service package with
controller.goandmodel.go - Implement the
protocol.ToolCallerinterface - Add the controller to the main application in
main.go - The server automatically discovers and exposes tools from all registered controllers
Initialize the connection:
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}List available tools:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}Call tools:
// Echo hello
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "echo-hello",
"arguments": {}
}
}
// List MongoDB collections
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "mongodb-list-collections",
"arguments": {}
}
}
// Find documents
{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "mongodb-find",
"arguments": {
"collection": "users",
"filter": {},
"limit": 10
}
}
}
// Insert a document
{
"jsonrpc": "2.0",
"id": 6,
"method": "tools/call",
"params": {
"name": "mongodb-insert-one",
"arguments": {
"collection": "users",
"document": {
"name": "John Doe",
"email": "[email protected]"
}
}
}
}Note: The update parameter in MongoDB operations supports partial field updates. Only specify the fields you want to change - the operation automatically uses $set to update only those fields without replacing the entire document.
The server implements the Model Context Protocol (MCP) over both stdio and HTTP transports:
- Stdio Transport: JSON-RPC messages over stdin/stdout (default)
- HTTP Transport: JSON-RPC messages over HTTP POST to
/mcpendpoint
initialize: Initialize the MCP connectiontools/list: List available toolstools/call: Execute a tool with parameters
All communication follows the JSON-RPC 2.0 specification with MCP-specific method extensions.
This project is licensed under the MIT License - see the LICENSE file for details.