Skip to content

Commit 998669a

Browse files
Enabling vector-search tool as well as Authentication
1 parent 91c99e5 commit 998669a

21 files changed

+1692
-18
lines changed

.dockerignore

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1+
### Runtime build context reduction
2+
### Runtime build context reduction
13
dist
24
node_modules
3-
.vscode
4-
.github
5+
6+
### VCS / metadata
57
.git
6-
# Environment variables
8+
.github
9+
.smithery
10+
11+
### Tool / editor configs
12+
.vscode
13+
*.swp
14+
*.tmp
15+
*.DS_Store
16+
Thumbs.db
17+
18+
### Logs
19+
*.log
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
23+
24+
### Temp
25+
tmp
26+
**/tmp
27+
28+
### Environment variables & secrets
729
.env
30+
.env.*
31+
env.list
832

33+
### Tests & coverage (not needed in runtime image)
934
tests
1035
coverage
11-
scripts
36+
scripts/accuracy
37+
**/test-data-dumps
38+
.vitest
39+
40+
### Local certificates (copy explicitly if needed)
41+
certs
42+
43+
### Misc local exports
44+
exports

Dockerfile

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,87 @@
1-
FROM node:22-alpine
2-
ARG VERSION=latest
1+
###
2+
# Optimized multi-stage Dockerfile for mongodb-mcp-server
3+
#
4+
# Build args:
5+
# NODE_VERSION Node.js version (default 22-alpine)
6+
# INSTALL_DEV Keep dev dependencies (true|false, default: false)
7+
# RUNTIME_IMAGE Base runtime image (default: node:22-alpine)
8+
#
9+
# Typical build:
10+
# docker build -t mongodb-mcp-server:local .
11+
# docker build --build-arg INSTALL_DEV=true -t mongodb-mcp-server:dev .
12+
#
13+
# Runtime (stdio transport):
14+
# docker run --rm -it mongodb-mcp-server:local --transport stdio
15+
#
16+
# Runtime (http transport):
17+
# docker run --rm -p 3000:3000 mongodb-mcp-server:local --transport http --httpHost 0.0.0.0
18+
# curl -s -X POST http://localhost:3000/mcp -H 'Content-Type: application/json' \
19+
# -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{}}}'
20+
#
21+
# Optional HTTP auth (Azure Managed Identity):
22+
# docker run --rm -p 3000:3000 \
23+
# -e MDB_MCP_HTTP_AUTH_MODE=azure-managed-identity \
24+
# -e MDB_MCP_AZURE_MANAGED_IDENTITY_TENANT_ID=<tenant-guid> \
25+
# -e MDB_MCP_AZURE_MANAGED_IDENTITY_CLIENT_ID=<app-client-id> \
26+
# mongodb-mcp-server:local --transport http --httpHost 0.0.0.0
27+
###
28+
29+
# syntax=docker/dockerfile:1.7-labs
30+
31+
ARG NODE_VERSION=22-alpine
32+
ARG RUNTIME_IMAGE=node:${NODE_VERSION}
33+
ARG INSTALL_DEV=false
34+
35+
#############################################
36+
# Builder Stage
37+
#############################################
38+
FROM node:${NODE_VERSION} AS builder
39+
WORKDIR /app
40+
41+
# Leverage Docker layer caching: copy only dependency manifests + tsconfigs first (needed by build scripts)
42+
COPY package.json package-lock.json* .npmrc* tsconfig*.json eslint.config.js vitest.config.ts ./
43+
44+
# Install dependencies without running lifecycle scripts (avoid premature build via prepare)
45+
RUN --mount=type=cache,target=/root/.npm \
46+
npm ci --ignore-scripts
47+
48+
# Copy application sources
49+
COPY src ./src
50+
COPY scripts ./scripts
51+
52+
# Now run the build explicitly (includes prepare sequence tasks)
53+
RUN npm run build
54+
55+
# Optionally prune dev dependencies for slimmer runtime
56+
ARG INSTALL_DEV
57+
RUN if [ "${INSTALL_DEV}" != "true" ]; then npm prune --omit=dev; fi
58+
59+
#############################################
60+
# Runtime Stage
61+
#############################################
62+
FROM ${RUNTIME_IMAGE} AS runtime
63+
ENV NODE_ENV=production \
64+
MDB_MCP_LOGGERS=stderr,mcp
65+
66+
# Create non-root user
367
RUN addgroup -S mcp && adduser -S mcp -G mcp
4-
RUN npm install -g mongodb-mcp-server@${VERSION}
5-
USER mcp
668
WORKDIR /home/mcp
7-
ENV MDB_MCP_LOGGERS=stderr,mcp
8-
ENTRYPOINT ["mongodb-mcp-server"]
9-
LABEL maintainer="MongoDB Inc <info@mongodb.com>"
10-
LABEL description="MongoDB MCP Server"
11-
LABEL version=${VERSION}
69+
70+
# Copy only required artifacts (preserve ownership in a single layer)
71+
COPY --chown=mcp:mcp --from=builder /app/package*.json ./
72+
COPY --chown=mcp:mcp --from=builder /app/node_modules ./node_modules
73+
COPY --chown=mcp:mcp --from=builder /app/dist ./dist
74+
75+
USER mcp
76+
77+
# Expose default HTTP port (matches default config httpPort=3000)
78+
EXPOSE 3000
79+
80+
LABEL maintainer="MongoDB Inc <info@mongodb.com>" \
81+
org.opencontainers.image.title="mongodb-mcp-server" \
82+
org.opencontainers.image.description="MongoDB MCP Server" \
83+
org.opencontainers.image.source="https://github.com/mongodb-js/mongodb-mcp-server"
84+
85+
# Use exec form for clarity; default command may be overridden at runtime
86+
ENTRYPOINT ["node", "dist/index.js"]
87+
CMD ["--transport", "http"]

package-lock.json

Lines changed: 118 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
"start": "node dist/index.js --transport http --loggers stderr mcp",
3636
"start:stdio": "node dist/index.js --transport stdio --loggers stderr mcp",
3737
"prepare": "npm run build",
38-
"build:clean": "rm -rf dist",
38+
"build:clean": "rimraf dist",
3939
"build:update-package-version": "tsx scripts/updatePackageVersion.ts",
4040
"build:esm": "tsc --project tsconfig.esm.json",
4141
"build:cjs": "tsc --project tsconfig.cjs.json",
4242
"build:universal-package": "tsx scripts/createUniversalPackage.ts",
43-
"build:chmod": "chmod +x dist/esm/index.js",
43+
"build:chmod": "node -e \"try{if(process.platform!=='win32'){require('fs').chmodSync('dist/esm/index.js',0o755)}}catch(e){console.error(e);process.exit(1)}\"",
4444
"build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:universal-package && npm run build:chmod",
4545
"inspect": "npm run build && mcp-inspector -- dist/esm/index.js",
4646
"prettier": "prettier",
@@ -87,6 +87,7 @@
8787
"openapi-typescript": "^7.9.1",
8888
"prettier": "^3.6.2",
8989
"proper-lockfile": "^4.1.2",
90+
"rimraf": "^5.0.10",
9091
"semver": "^7.7.2",
9192
"simple-git": "^3.28.0",
9293
"tsx": "^4.20.5",
@@ -104,6 +105,7 @@
104105
"@mongosh/service-provider-node-driver": "^3.17.0",
105106
"bson": "^6.10.4",
106107
"express": "^5.1.0",
108+
"jose": "^5.9.6",
107109
"lru-cache": "^11.1.0",
108110
"mongodb-connection-string-url": "^3.0.2",
109111
"mongodb-log-writer": "^2.4.1",

0 commit comments

Comments
 (0)