Skip to content

Commit d3b4d6b

Browse files
committed
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into assistant-tool
2 parents bb5e585 + 85909c5 commit d3b4d6b

File tree

131 files changed

+9946
-4269
lines changed

Some content is hidden

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

131 files changed

+9946
-4269
lines changed

.github/copilot-instructions.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Project Overview
2+
3+
This project is a server implementing the MCP (Model Context Protocol) that allows users to interact with their MongoDB clusters
4+
and MongoDB Atlas accounts. It is built using TypeScript, Node.js and the official Anthropic
5+
@modelcontextprotocol/sdk SDK.
6+
7+
## Folder Structure
8+
9+
- `/src`: Contains the source code of the MCP Server.
10+
- `/src/tools`: Contains the implementation of MCP tools.
11+
- `/src/tools/atlas/`: Contains the implementation of MCP tools that are specific to MongoDB Atlas.
12+
- `/src/tools/mongodb/`: Contains the implementation of MCP tools that are specific to MongoDB clusters.
13+
- `/src/resources`: Contains the implementation of MCP Resources.
14+
- `/tests`: Contains the test code for the MCP Server.
15+
- `/tests/accuracy`: Contains the test code for the accuracy tests, that use different models to ensure that tools have reliable descriptions.
16+
- `/tests/integration`: Contains tests that start the MCP Server and interact with it to ensure that functionality is correct.
17+
- `/tests/unit`: Contains simple unit tests to cover specific functionality of the MCP Server.
18+
19+
## Libraries and Frameworks
20+
21+
- Zod for message and schema validation.
22+
- Express for the HTTP Transport implementation.
23+
- mongosh NodeDriverServiceProvider for connecting to MongoDB.
24+
- vitest for testing.
25+
- @modelcontextprotocol/sdk for the protocol implementation.
26+
27+
## Coding Standards
28+
29+
- For declarations, use types. For usage, rely on type inference unless it is not clear enough.
30+
- Always follow the eslint and prettier rule formats specified in `.eslint.config.js` and `.prettierrc.json`.
31+
- Use classes for stateful components and functions for stateless pure logic.
32+
- Use dependency injection to provide dependencies between components.
33+
- Avoid using global variables as much as possible.
34+
- New functionality MUST be under test.
35+
- Tools MUST HAVE integration tests.
36+
- Tools MUST HAVE unit tests.
37+
- Tools MAY HAVE accuracy tests.
38+
39+
## Architectural Guidelines and Best Practices
40+
41+
Every agent connected to the MCP Server has a Session object attached to it. The Session is the main entrypoint for
42+
dependencies to other components. Any component that MUST be used by either a tool or a resource MUST be provided
43+
through the Session.
44+
45+
### Guidelines for All Tools
46+
47+
- The name of the tool should describe an action: `create-collection`, `insert-many`.
48+
- The description MUST be a simple and accurate prompt that defines what the tool does in an unambiguous way.
49+
- All tools MUST provide a Zod schema that clearly specifies the API of the tool.
50+
- The Operation type MUST be clear:
51+
- `metadata`: Reads metadata for an entity (for example, a cluster). Example: CollectionSchema.
52+
- `read`: Reads information from a cluster or Atlas.
53+
- `create`: Creates resources, like a collection or a cluster.
54+
- `delete`: Deletes resources or documents, like collections, documents or clusters.
55+
- `update`: Modifies resources or documents, like collections, documents or clusters.
56+
- `connects`: Connects to a MongoDB cluster.
57+
- If a new tool is added, or the tool description is modified, the accuracy tests MUST be updated too.
58+
59+
### Guidelines for MongoDB Tools
60+
61+
- The tool category MUST be `mongodb`.
62+
- They MUST call `this.ensureConnected()` before attempting to query MongoDB.
63+
- They MUST return content sanitized using `formatUntrustedData`.
64+
- Documents should be serialized with `EJSON.stringify`.
65+
- Ensure there are proper timeout mechanisms to avoid long-running queries that can affect the server.
66+
- Tools that require elicitation MUST implement `getConfirmationMessage` and provide an easy-to-understand message for a human running the operation.
67+
- If a tool requires elicitation, it must be added to `src/common/config.ts` in the `confirmationRequiredTools` list in the defaultUserConfig.
68+
69+
### Guidelines for Atlas Tools
70+
71+
- The tool category MUST be `atlas`.

.github/workflows/accuracy-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
steps:
3030
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
3131
- uses: actions/checkout@v5
32-
- uses: actions/setup-node@v4
32+
- uses: actions/setup-node@v5
3333
with:
3434
node-version-file: package.json
3535
cache: "npm"

.github/workflows/check.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
1919
- uses: actions/checkout@v5
20-
- uses: actions/setup-node@v4
20+
- uses: actions/setup-node@v5
2121
with:
2222
node-version-file: package.json
2323
cache: "npm"
@@ -31,7 +31,7 @@ jobs:
3131
steps:
3232
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
3333
- uses: actions/checkout@v5
34-
- uses: actions/setup-node@v4
34+
- uses: actions/setup-node@v5
3535
with:
3636
node-version-file: package.json
3737
cache: "npm"
@@ -45,7 +45,7 @@ jobs:
4545
steps:
4646
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
4747
- uses: actions/checkout@v5
48-
- uses: actions/setup-node@v4
48+
- uses: actions/setup-node@v5
4949
with:
5050
node-version-file: package.json
5151
cache: "npm"
@@ -55,4 +55,4 @@ jobs:
5555
rm -rf node_modules
5656
npm pkg set scripts.prepare="exit 0"
5757
npm install --omit=dev
58-
- run: npx -y @modelcontextprotocol/[email protected].2 --cli --method tools/list -- node dist/esm/index.js
58+
- run: npx -y @modelcontextprotocol/[email protected].5 --cli --method tools/list -- node dist/esm/index.js

.github/workflows/code_health.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
runs-on: ${{ matrix.os }}
2020
steps:
2121
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
22-
if: matrix.os != 'windows-latest'
22+
if: matrix.os == 'ubuntu-latest'
2323
- uses: actions/checkout@v5
24-
- uses: actions/setup-node@v4
24+
- uses: actions/setup-node@v5
2525
with:
2626
node-version-file: package.json
2727
cache: "npm"
@@ -43,7 +43,7 @@ jobs:
4343
steps:
4444
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
4545
- uses: actions/checkout@v5
46-
- uses: actions/setup-node@v4
46+
- uses: actions/setup-node@v5
4747
with:
4848
node-version-file: package.json
4949
cache: "npm"
@@ -54,7 +54,7 @@ jobs:
5454
MDB_MCP_API_CLIENT_ID: ${{ secrets.TEST_ATLAS_CLIENT_ID }}
5555
MDB_MCP_API_CLIENT_SECRET: ${{ secrets.TEST_ATLAS_CLIENT_SECRET }}
5656
MDB_MCP_API_BASE_URL: ${{ vars.TEST_ATLAS_BASE_URL }}
57-
run: npm test -- --exclude "tests/unit/**" --exclude "tests/integration/tools/mongodb/**" --exclude "tests/integration/*.ts"
57+
run: npm test -- tests/integration/tools/atlas
5858
- name: Upload test results
5959
uses: actions/upload-artifact@v4
6060
if: always()
@@ -69,7 +69,7 @@ jobs:
6969
needs: [run-tests, run-atlas-tests]
7070
steps:
7171
- uses: actions/checkout@v5
72-
- uses: actions/setup-node@v4
72+
- uses: actions/setup-node@v5
7373
with:
7474
node-version-file: package.json
7575
cache: "npm"

.github/workflows/code_health_fork.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
runs-on: ${{ matrix.os }}
1919
steps:
2020
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
21-
if: matrix.os != 'windows-latest'
21+
if: matrix.os == 'ubuntu-latest'
2222
- uses: actions/checkout@v5
23-
- uses: actions/setup-node@v4
23+
- uses: actions/setup-node@v5
2424
with:
2525
node-version-file: package.json
2626
cache: "npm"

.github/workflows/jira-issue.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
6363
- name: Remove create-jira label
6464
if: github.event.action == 'labeled' && github.event.label.name == 'create-jira'
65-
uses: actions/github-script@v7
65+
uses: actions/github-script@v8
6666
with:
6767
script: |
6868
try {

.github/workflows/prepare_release.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ jobs:
2323
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
2424
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
2525
- uses: actions/checkout@v5
26-
- uses: actions/setup-node@v4
26+
- uses: actions/setup-node@v5
2727
with:
2828
node-version-file: package.json
2929
registry-url: "https://registry.npmjs.org"
3030
cache: "npm"
31+
- name: Install dependencies
32+
run: npm ci
3133
- name: Bump version
3234
id: bump-version
3335
run: |

.github/workflows/publish.yaml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ jobs:
1212
outputs:
1313
VERSION_EXISTS: ${{ steps.check-version.outputs.VERSION_EXISTS }}
1414
VERSION: ${{ steps.get-version.outputs.VERSION }}
15+
RELEASE_CHANNEL: ${{ steps.npm-tag.outputs.RELEASE_CHANNEL }}
1516
steps:
1617
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
1718
- uses: actions/checkout@v5
1819
with:
1920
fetch-depth: 0
20-
- uses: actions/setup-node@v4
21+
- uses: actions/setup-node@v5
2122
with:
2223
node-version-file: package.json
2324
registry-url: "https://registry.npmjs.org"
@@ -42,6 +43,33 @@ jobs:
4243
else
4344
echo "VERSION_EXISTS=false" >> "$GITHUB_OUTPUT"
4445
fi
46+
- name: Get npm tag
47+
id: npm-tag
48+
shell: bash
49+
run: |
50+
set -e
51+
VERSION="${{ steps.get-version.outputs.VERSION }}"
52+
53+
# Extract the release channel (latest, alpha, beta, rc)
54+
if [[ $VERSION =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-(.+))?$ ]]; then
55+
if [[ -n "${BASH_REMATCH[2]}" ]]; then
56+
CAPTURED_CHANNEL="${BASH_REMATCH[2]}"
57+
# The captured channel might have more dots, cases like
58+
# v1.2.3-alpha.1 For such cases we only want the channel relevant
59+
# part which is alpha.
60+
RELEASE_CHANNEL="${CAPTURED_CHANNEL%%.*}"
61+
else
62+
RELEASE_CHANNEL="latest"
63+
fi
64+
else
65+
echo "::error title=Invalid Version::Encountered unexpected version ${{ steps.get-version.outputs.VERSION }}, cannot proceed!"
66+
exit 1
67+
fi
68+
69+
echo "RELEASE_CHANNEL=${RELEASE_CHANNEL}" >> "$GITHUB_OUTPUT"
70+
- name: Output deployment info
71+
run: echo "::notice title=Deployment Info::Deploying version ${{ steps.get-version.outputs.VERSION }} to channel ${{ steps.npm-tag.outputs.RELEASE_CHANNEL }}"
72+
4573
publish:
4674
runs-on: ubuntu-latest
4775
environment: Production
@@ -53,21 +81,22 @@ jobs:
5381
steps:
5482
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
5583
- uses: actions/checkout@v5
56-
- uses: actions/setup-node@v4
84+
- uses: actions/setup-node@v5
5785
with:
5886
node-version-file: package.json
5987
registry-url: "https://registry.npmjs.org"
6088
cache: "npm"
89+
6190
- name: Build package
6291
run: |
6392
npm ci
6493
npm run build
6594
- name: Publish to NPM
66-
run: npm publish
95+
run: npm publish --tag ${{ needs.check.outputs.RELEASE_CHANNEL }}
6796
env:
6897
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6998
- name: Publish git release
7099
env:
71100
GH_TOKEN: ${{ github.token }}
72101
run: |
73-
gh release create ${{ needs.check.outputs.VERSION }} --title "${{ needs.check.outputs.VERSION }}" --generate-notes --target ${{ github.sha }}
102+
gh release create ${{ needs.check.outputs.VERSION }} --title "${{ needs.check.outputs.VERSION }}" --generate-notes --target ${{ github.sha }} ${{ (needs.check.outputs.RELEASE_CHANNEL != 'latest' && '--prerelease') || ''}}

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
pull-requests: write
1616
steps:
1717
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
18-
- uses: actions/stale@v9
18+
- uses: actions/stale@v10
1919
id: stale
2020
with:
2121
repo-token: ${{ secrets.GITHUB_TOKEN }}

.smithery/Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
# ----- Build Stage -----
33
FROM node:lts-alpine AS builder
44

5-
RUN adduser -D mcpuser
6-
USER mcpuser
5+
RUN addgroup -S mcp && adduser -S mcp -G mcp -s /sbin/nologin
6+
RUN chown -R mcp:mcp /home/mcp
7+
USER mcp
78

8-
WORKDIR /app
9+
WORKDIR /home/mcp
910

1011
# Copy package and configuration
1112
COPY ../package.json ../package-lock.json ../tsconfig.json ../tsconfig.build.json ./
@@ -18,9 +19,12 @@ RUN npm ci && npm run build
1819

1920
# ----- Production Stage -----
2021
FROM node:lts-alpine
22+
RUN addgroup -S mcp && adduser -S mcp -G mcp -s /sbin/nologin
23+
RUN chown -R mcp:mcp /dist
24+
USER mcp
2125

2226
# Copy built artifacts
23-
COPY --from=builder /app/dist ./dist
27+
COPY --from=builder /home/mcp/dist ./dist
2428

2529
# Copy package.json for production install
2630
COPY ../package.json ../package-lock.json ./

0 commit comments

Comments
 (0)