Skip to content

feat: add streamable http [MCP-42] #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
rm -rf node_modules
npm pkg set scripts.prepare="exit 0"
npm install --omit=dev
- run: npx -y @modelcontextprotocol/inspector --cli --method tools/list -- node dist/index.js --connectionString "mongodb://localhost"
- run: npx -y @modelcontextprotocol/inspector --cli --method tools/list -- node dist/index.js
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/dist/index.js",
"runtimeExecutable": "npm",
"runtimeArgs": ["start"],
"preLaunchTask": "tsc: build - tsconfig.build.json",
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RUN addgroup -S mcp && adduser -S mcp -G mcp
RUN npm install -g mongodb-mcp-server@${VERSION}
USER mcp
WORKDIR /home/mcp
ENV MDB_MCP_LOGGERS=stderr,mcp
ENTRYPOINT ["mongodb-mcp-server"]
LABEL maintainer="MongoDB Inc <[email protected]>"
LABEL description="MongoDB MCP Server"
Expand Down
81 changes: 67 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,27 @@ With Atlas API credentials:
}
```

#### Option 6: Running as an HTTP Server

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.

To start the server with HTTP transport, use the `--transport http` option:

```shell
npx -y mongodb-mcp-server --transport http
```

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:

```shell
npx -y mongodb-mcp-server --transport http --httpHost=0.0.0.0 --httpPort=8080
```

- `--httpHost` (default: 127.0.0.1): The host to bind the HTTP server.
- `--httpPort` (default: 3000): The port number for the HTTP server.

> **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.

## 🛠️ Supported Tools

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

### Configuration Options

| Option | Description |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `apiClientId` | Atlas API client ID for authentication. Required for running Atlas tools. |
| `apiClientSecret` | Atlas API client secret for authentication. Required for running Atlas tools. |
| `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. |
| `logPath` | Folder to store logs. |
| `disabledTools` | An array of tool names, operation types, and/or categories of tools that will be disabled. |
| `readOnly` | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. |
| `indexCheck` | When set to true, enforces that query operations must use an index, rejecting queries that perform a collection scan. |
| `telemetry` | When set to disabled, disables telemetry collection. |
| CLI Option | Environment Variable | Default | Description |
| ----------------------- | --------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `apiClientId` | `MDB_MCP_API_CLIENT_ID` | <not set> | Atlas API client ID for authentication. Required for running Atlas tools. |
| `apiClientSecret` | `MDB_MCP_API_CLIENT_SECRET` | <not set> | Atlas API client secret for authentication. Required for running Atlas tools. |
| `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. |
| `loggers` | `MDB_MCP_LOGGERS` | disk,mcp | Comma separated values, possible values are `mcp`, `disk` and `stderr`. See [Logger Options](#logger-options) for details. |
| `logPath` | `MDB_MCP_LOG_PATH` | see note\* | Folder to store logs. |
| `disabledTools` | `MDB_MCP_DISABLED_TOOLS` | <not set> | An array of tool names, operation types, and/or categories of tools that will be disabled. |
| `readOnly` | `MDB_MCP_READ_ONLY` | false | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. |
| `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. |
| `telemetry` | `MDB_MCP_TELEMETRY` | enabled | When set to disabled, disables telemetry collection. |
| `transport` | `MDB_MCP_TRANSPORT` | stdio | Either 'stdio' or 'http'. |
| `httpPort` | `MDB_MCP_HTTP_PORT` | 3000 | Port number. |
| `httpHost` | `MDB_MCP_HTTP_HOST` | 127.0.0.1 | Host to bind the http server. |
| `idleTimeoutMs` | `MDB_MCP_IDLE_TIMEOUT_MS` | 600000 | Idle timeout for a client to disconnect (only applies to http transport). |
| `notificationTimeoutMs` | `MDB_MCP_NOTIFICATION_TIMEOUT_MS` | 540000 | Notification timeout for a client to be aware of diconnect (only applies to http transport). |

#### Logger Options

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:

- `mcp`: Sends logs to the MCP client (if supported by the client/transport).
- `disk`: Writes logs to disk files. Log files are stored in the log path (see `logPath` above).
- `stderr`: Outputs logs to standard error (stderr), useful for debugging or when running in containers.

**Default:** `disk,mcp` (logs are written to disk and sent to the MCP client).

You can combine multiple loggers, e.g. `--loggers disk stderr` or `export MDB_MCP_LOGGERS="mcp,stderr"`.

##### Example: Set logger via environment variable

```shell
export MDB_MCP_LOGGERS="disk,stderr"
```

##### Example: Set logger via command-line argument

```shell
npx -y mongodb-mcp-server --loggers mcp stderr
```

##### Log File Location

#### Log Path
When using the `disk` logger, log files are stored in:

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

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

#### Disabled Tools

Expand Down
Loading
Loading