Skip to content

Commit 5a03f03

Browse files
committed
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into gagik/add-explain
2 parents d78d7f6 + 8ca583a commit 5a03f03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1748
-1229
lines changed

.github/workflows/code_health.yaml

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
---
22
name: Code Health
33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
88
jobs:
9-
check-style:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-node@v4
15-
with:
16-
node-version-file: package.json
17-
cache: "npm"
18-
- name: Install dependencies
19-
run: npm ci
20-
- name: Run style check
21-
run: npm run check
9+
check-style:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version-file: package.json
17+
cache: "npm"
18+
- name: Install dependencies
19+
run: npm ci
20+
- name: Run style check
21+
run: npm run check
2222

23-
run-tests:
24-
runs-on: ubuntu-latest
25-
steps:
26-
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
27-
- uses: actions/checkout@v4
28-
- uses: actions/setup-node@v4
29-
with:
30-
node-version-file: package.json
31-
cache: "npm"
32-
- name: Install dependencies
33-
run: npm ci
34-
- name: Run tests
35-
run: npm test
23+
run-tests:
24+
strategy:
25+
matrix:
26+
os: [ubuntu-latest, macos-latest, windows-latest]
27+
fail-fast: false
28+
runs-on: ${{ matrix.os }}
29+
steps:
30+
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
31+
if: matrix.os != 'windows-latest'
32+
- name: Install keyring deps on Ubuntu
33+
if: matrix.os == 'ubuntu-latest'
34+
run: |
35+
sudo apt update -y
36+
sudo apt install -y gnome-keyring libdbus-1-dev
37+
38+
- uses: actions/checkout@v4
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version-file: package.json
42+
cache: "npm"
43+
- name: Install dependencies
44+
run: npm ci
45+
- name: Run tests
46+
run: npm test

.github/workflows/publish.yaml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
---
22
name: Publish
33
on:
4-
push:
5-
tags:
6-
- v*
4+
push:
5+
tags:
6+
- v*
77
jobs:
8-
publish:
9-
runs-on: ubuntu-latest
10-
environment: Production
11-
steps:
12-
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-node@v4
15-
with:
16-
node-version-file: package.json
17-
registry-url: "https://registry.npmjs.org"
18-
cache: "npm"
19-
- name: Build package
20-
run: |
21-
npm ci
22-
npm run build
23-
- name: Publish to NPM
24-
run: npm publish
25-
env:
26-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
27-
- name: Publish Github release
28-
run: |
29-
gh release create ${{ github.ref }} --title "${{ github.ref }}" --notes "Release ${{ github.ref }}" --generate-notes
8+
publish:
9+
runs-on: ubuntu-latest
10+
environment: Production
11+
steps:
12+
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version-file: package.json
17+
registry-url: "https://registry.npmjs.org"
18+
cache: "npm"
19+
- name: Build package
20+
run: |
21+
npm ci
22+
npm run build
23+
- name: Publish to NPM
24+
run: npm publish
25+
env:
26+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
27+
- name: Publish Github release
28+
run: |
29+
gh release create ${{ github.ref }} --title "${{ github.ref }}" --notes "Release ${{ github.ref }}" --generate-notes

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ node_modules
88

99
# Sensitive
1010
state.json
11+
12+
tests/tmp

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
dist
22
coverage
33
package-lock.json
4+
tests/tmp
5+
src/common/atlas/openapi.d.ts

.prettierrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"singleQuote": false,
66
"printWidth": 120,
77
"overrides": [
8+
{
9+
"files": "*.ts",
10+
"options": {
11+
"insertPragma": false,
12+
"proseWrap": "preserve"
13+
}
14+
},
815
{
916
"files": "*.json",
1017
"options": {
@@ -18,6 +25,13 @@
1825
"tabWidth": 2,
1926
"printWidth": 80
2027
}
28+
},
29+
{
30+
"files": "*.yaml",
31+
"options": {
32+
"tabWidth": 2,
33+
"printWidth": 80
34+
}
2135
}
2236
]
2337
}

README.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ npm run build
4848

4949
#### MongoDB Atlas Tools
5050

51-
- `atlas-auth` - Authenticate to MongoDB Atlas
5251
- `atlas-list-clusters` - Lists MongoDB Atlas clusters
5352
- `atlas-list-projects` - Lists MongoDB Atlas projects
5453
- `atlas-inspect-cluster` - Inspect a specific MongoDB Atlas cluster
5554
- `atlas-create-free-cluster` - Create a free MongoDB Atlas cluster
5655
- `atlas-create-access-list` - Configure IP/CIDR access list for MongoDB Atlas clusters
5756
- `atlas-inspect-access-list` - Inspect IP/CIDR ranges with access to MongoDB Atlas clusters
57+
- `atlas-list-db-users` - List MongoDB Atlas database users
58+
- `atlas-create-db-user` - List MongoDB Atlas database users
5859

5960
#### MongoDB Database Tools
6061

@@ -110,6 +111,8 @@ It should look like this
110111
}
111112
```
112113

114+
Notes: You can configure the server with atlas access, make sure to follow configuration section for more details.
115+
113116
Step 3: Open the copilot chat and check that the toolbox icon is visible and has the mcp server listed.
114117

115118
Step 4: Try running a command
@@ -146,10 +149,79 @@ Paste the mcp server configuration into the file
146149

147150
Step 3: Launch Claude Desktop and click on the hammer icon, the Demo MCP server should be detected. Type in the chat "show me a demo of MCP" and allow the tool to get access.
148151

149-
- Detailed instructions with screenshots can be found in this [document](https://docs.google.com/document/d/1_C8QBMZ5rwImV_9v4G96661OqcBk1n1SfEgKyNalv9c/edit?tab=t.2hhewstzj7ck#bookmark=id.nktw0lg0fn7t).
150-
151152
Note: If you make changes to your MCP server code, rebuild the project with `npm run build` and restart the server and Claude Desktop.
152153

154+
## Configuration
155+
156+
The MongoDB MCP Server can be configured using multiple methods, with the following precedence (highest to lowest):
157+
158+
1. Command-line arguments
159+
2. Environment variables
160+
161+
### Configuration Options
162+
163+
| Option | Description |
164+
| ------------------ | --------------------------------------------------------------------------------------------------------------------- |
165+
| `apiClientId` | Atlas API client ID for authentication |
166+
| `apiClientSecret` | Atlas API client secret for authentication |
167+
| `connectionString` | MongoDB connection string for direct database connections (optional users may choose to inform it on every tool call) |
168+
| `logPath` | Folder to store logs |
169+
170+
**Default Log Path:**
171+
172+
- Windows: `%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs`
173+
- macOS/Linux: `~/.mongodb/mongodb-mcp/.app-logs`
174+
175+
### Atlas API Access
176+
177+
To use the Atlas API tools, you'll need to create a service account in MongoDB Atlas:
178+
179+
1. **Create a Service Account:**
180+
181+
- Log in to MongoDB Atlas at [cloud.mongodb.com](https://cloud.mongodb.com)
182+
- Navigate to Access Manager > Organization Access
183+
- Click Add New > Applications > Service Accounts
184+
- Enter name, description and expiration for your service account (e.g., "MCP, MCP Server Access, 7 days")
185+
- Select appropriate permissions (for full access, use Organization Owner)
186+
- Click "Create"
187+
188+
2. **Save Client Credentials:**
189+
190+
- After creation, you'll be shown the Client ID and Client Secret
191+
- **Important:** Copy and save the Client Secret immediately as it won't be displayed again
192+
193+
3. **Add Access List Entry (Optional but recommended):**
194+
195+
- Add your IP address to the API access list
196+
197+
4. **Configure the MCP Server:**
198+
- Use one of the configuration methods below to set your `apiClientId` and `apiClientSecret`
199+
200+
### Configuration Methods
201+
202+
#### Environment Variables
203+
204+
Set environment variables with the prefix `MDB_MCP_` followed by the option name in uppercase with underscores:
205+
206+
```shell
207+
# Set Atlas API credentials
208+
export MDB_MCP_API_CLIENT_ID="your-atlas-client-id"
209+
export MDB_MCP_API_CLIENT_SECRET="your-atlas-client-secret"
210+
211+
# Set a custom MongoDB connection string
212+
export MDB_MCP_CONNECTION_STRING="mongodb+srv://username:[email protected]/myDatabase"
213+
214+
export MDB_MCP_LOG_PATH="/path/to/logs"
215+
```
216+
217+
#### Command-Line Arguments
218+
219+
Pass configuration options as command-line arguments when starting the server:
220+
221+
```shell
222+
node dist/index.js --apiClientId="your-atlas-client-id" --apiClientSecret="your-atlas-client-secret" --connectionString="mongodb+srv://username:[email protected]/myDatabase" --logPath=/path/to/logs
223+
```
224+
153225
## 🤝 Contributing
154226

155227
Interested in contributing? Great! Please check our [Contributing Guide](CONTRIBUTING.md) for guidelines on code contributions, standards, adding new tools, and troubleshooting information.

eslint.config.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,32 @@ import globals from "globals";
44
import tseslint from "typescript-eslint";
55
import eslintConfigPrettier from "eslint-config-prettier/flat";
66

7+
const files = ["src/**/*.ts", "scripts/**/*.ts", "tests/**/*.test.ts", "eslint.config.js", "jest.config.js"];
8+
79
export default defineConfig([
8-
{ files: ["src/**/*.ts"], plugins: { js }, extends: ["js/recommended"] },
9-
{ files: ["src/**/*.ts"], languageOptions: { globals: globals.node } },
10-
tseslint.configs.recommended,
11-
eslintConfigPrettier,
10+
{ files, plugins: { js }, extends: ["js/recommended"] },
11+
{ files, languageOptions: { globals: globals.node } },
12+
tseslint.configs.recommendedTypeChecked,
13+
{
14+
languageOptions: {
15+
parserOptions: {
16+
projectService: true,
17+
tsconfigRootDir: import.meta.dirname,
18+
},
19+
},
20+
},
1221
{
13-
files: ["src/**/*.ts"],
22+
files,
1423
rules: {
24+
"@typescript-eslint/switch-exhaustiveness-check": "error",
1525
"@typescript-eslint/no-non-null-assertion": "error",
1626
},
1727
},
18-
globalIgnores(["node_modules", "dist"]),
28+
// Ignore features specific to TypeScript resolved rules
29+
tseslint.config({
30+
// TODO: Configure tests and scripts to work with this.
31+
ignores: ["eslint.config.js", "jest.config.js", "tests/**/*.ts", "scripts/**/*.ts"],
32+
}),
33+
globalIgnores(["node_modules", "dist", "src/common/atlas/openapi.d.ts"]),
34+
eslintConfigPrettier,
1935
]);

0 commit comments

Comments
 (0)