Skip to content

Commit f8e5000

Browse files
authored
feat: add streamable http [MCP-42] (#361)
1 parent 7856bb9 commit f8e5000

25 files changed

+1951
-1173
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/inspector --cli --method tools/list -- node dist/index.js --connectionString "mongodb://localhost"
58+
- run: npx -y @modelcontextprotocol/inspector --cli --method tools/list -- node dist/index.js

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"request": "launch",
1919
"name": "Launch Program",
2020
"skipFiles": ["<node_internals>/**"],
21-
"program": "${workspaceFolder}/dist/index.js",
21+
"runtimeExecutable": "npm",
22+
"runtimeArgs": ["start"],
2223
"preLaunchTask": "tsc: build - tsconfig.build.json",
2324
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
2425
}

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ RUN addgroup -S mcp && adduser -S mcp -G mcp
44
RUN npm install -g mongodb-mcp-server@${VERSION}
55
USER mcp
66
WORKDIR /home/mcp
7+
ENV MDB_MCP_LOGGERS=stderr,mcp
78
ENTRYPOINT ["mongodb-mcp-server"]
89
LABEL maintainer="MongoDB Inc <[email protected]>"
910
LABEL description="MongoDB MCP Server"

README.md

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,27 @@ With Atlas API credentials:
228228
}
229229
```
230230

231+
#### Option 6: Running as an HTTP Server
232+
233+
You can run the MongoDB MCP Server as an HTTP server instead of the default stdio transport. This is useful if you want to interact with the server over HTTP, for example from a web client or to expose the server on a specific port.
234+
235+
To start the server with HTTP transport, use the `--transport http` option:
236+
237+
```shell
238+
npx -y mongodb-mcp-server --transport http
239+
```
240+
241+
By default, the server will listen on `http://127.0.0.1:3000`. You can customize the host and port using the `--httpHost` and `--httpPort` options:
242+
243+
```shell
244+
npx -y mongodb-mcp-server --transport http --httpHost=0.0.0.0 --httpPort=8080
245+
```
246+
247+
- `--httpHost` (default: 127.0.0.1): The host to bind the HTTP server.
248+
- `--httpPort` (default: 3000): The port number for the HTTP server.
249+
250+
> **Note:** The default transport is `stdio`, which is suitable for integration with most MCP clients. Use `http` transport if you need to interact with the server over HTTP.
251+
231252
## 🛠️ Supported Tools
232253

233254
### Tool List
@@ -281,23 +302,55 @@ The MongoDB MCP Server can be configured using multiple methods, with the follow
281302

282303
### Configuration Options
283304

284-
| Option | Description |
285-
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
286-
| `apiClientId` | Atlas API client ID for authentication. Required for running Atlas tools. |
287-
| `apiClientSecret` | Atlas API client secret for authentication. Required for running Atlas tools. |
288-
| `connectionString` | MongoDB connection string for direct database connections. Optional, if not set, you'll need to call the `connect` tool before interacting with MongoDB data. |
289-
| `logPath` | Folder to store logs. |
290-
| `disabledTools` | An array of tool names, operation types, and/or categories of tools that will be disabled. |
291-
| `readOnly` | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. |
292-
| `indexCheck` | When set to true, enforces that query operations must use an index, rejecting queries that perform a collection scan. |
293-
| `telemetry` | When set to disabled, disables telemetry collection. |
305+
| CLI Option | Environment Variable | Default | Description |
306+
| ----------------------- | --------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
307+
| `apiClientId` | `MDB_MCP_API_CLIENT_ID` | <not set> | Atlas API client ID for authentication. Required for running Atlas tools. |
308+
| `apiClientSecret` | `MDB_MCP_API_CLIENT_SECRET` | <not set> | Atlas API client secret for authentication. Required for running Atlas tools. |
309+
| `connectionString` | `MDB_MCP_CONNECTION_STRING` | <not set> | MongoDB connection string for direct database connections. Optional, if not set, you'll need to call the `connect` tool before interacting with MongoDB data. |
310+
| `loggers` | `MDB_MCP_LOGGERS` | disk,mcp | Comma separated values, possible values are `mcp`, `disk` and `stderr`. See [Logger Options](#logger-options) for details. |
311+
| `logPath` | `MDB_MCP_LOG_PATH` | see note\* | Folder to store logs. |
312+
| `disabledTools` | `MDB_MCP_DISABLED_TOOLS` | <not set> | An array of tool names, operation types, and/or categories of tools that will be disabled. |
313+
| `readOnly` | `MDB_MCP_READ_ONLY` | false | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. |
314+
| `indexCheck` | `MDB_MCP_INDEX_CHECK` | false | When set to true, enforces that query operations must use an index, rejecting queries that perform a collection scan. |
315+
| `telemetry` | `MDB_MCP_TELEMETRY` | enabled | When set to disabled, disables telemetry collection. |
316+
| `transport` | `MDB_MCP_TRANSPORT` | stdio | Either 'stdio' or 'http'. |
317+
| `httpPort` | `MDB_MCP_HTTP_PORT` | 3000 | Port number. |
318+
| `httpHost` | `MDB_MCP_HTTP_HOST` | 127.0.0.1 | Host to bind the http server. |
319+
| `idleTimeoutMs` | `MDB_MCP_IDLE_TIMEOUT_MS` | 600000 | Idle timeout for a client to disconnect (only applies to http transport). |
320+
| `notificationTimeoutMs` | `MDB_MCP_NOTIFICATION_TIMEOUT_MS` | 540000 | Notification timeout for a client to be aware of diconnect (only applies to http transport). |
321+
322+
#### Logger Options
323+
324+
The `loggers` configuration option controls where logs are sent. You can specify one or more logger types as a comma-separated list. The available options are:
325+
326+
- `mcp`: Sends logs to the MCP client (if supported by the client/transport).
327+
- `disk`: Writes logs to disk files. Log files are stored in the log path (see `logPath` above).
328+
- `stderr`: Outputs logs to standard error (stderr), useful for debugging or when running in containers.
329+
330+
**Default:** `disk,mcp` (logs are written to disk and sent to the MCP client).
331+
332+
You can combine multiple loggers, e.g. `--loggers disk stderr` or `export MDB_MCP_LOGGERS="mcp,stderr"`.
333+
334+
##### Example: Set logger via environment variable
335+
336+
```shell
337+
export MDB_MCP_LOGGERS="disk,stderr"
338+
```
339+
340+
##### Example: Set logger via command-line argument
341+
342+
```shell
343+
npx -y mongodb-mcp-server --loggers mcp stderr
344+
```
345+
346+
##### Log File Location
294347

295-
#### Log Path
348+
When using the `disk` logger, log files are stored in:
296349

297-
Default log location is as follows:
350+
- **Windows:** `%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs`
351+
- **macOS/Linux:** `~/.mongodb/mongodb-mcp/.app-logs`
298352

299-
- Windows: `%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs`
300-
- macOS/Linux: `~/.mongodb/mongodb-mcp/.app-logs`
353+
You can override the log directory with the `logPath` option.
301354

302355
#### Disabled Tools
303356

0 commit comments

Comments
 (0)