Skip to content

Commit c866cc3

Browse files
committed
fix: address comments
1 parent f03a3e1 commit c866cc3

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,22 +304,47 @@ The MongoDB MCP Server can be configured using multiple methods, with the follow
304304
| `apiClientId` | <not set> | Atlas API client ID for authentication. Required for running Atlas tools. |
305305
| `apiClientSecret` | <not set> | Atlas API client secret for authentication. Required for running Atlas tools. |
306306
| `connectionString` | <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. |
307-
| `logPath` | see note\* | Folder to store logs. |
307+
| `loggers` | disk,mcp | Comma separated values, possible values are `mcp`, `disk` and `stderr`. See [Logger Options](#logger-options) for details. |
308+
| `logPath` | see note* | Folder to store logs. |
308309
| `disabledTools` | <not set> | An array of tool names, operation types, and/or categories of tools that will be disabled. |
309310
| `readOnly` | false | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. |
310311
| `indexCheck` | false | When set to true, enforces that query operations must use an index, rejecting queries that perform a collection scan. |
311312
| `telemetry` | enabled | When set to disabled, disables telemetry collection. |
312313
| `transport` | stdio | Either 'stdio' or 'http'. |
313314
| `httpPort` | 3000 | Port number. |
314315
| `httpHost` | 127.0.0.1 | Host to bind the http server. |
315-
| `logger` | disk,mcp | Comma separated values, possible values are `mcp`, `disk` and `stderr`. |
316316

317-
#### Log Path
317+
#### Logger Options
318318

319-
Default log location is as follows:
319+
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:
320320

321-
- Windows: `%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs`
322-
- macOS/Linux: `~/.mongodb/mongodb-mcp/.app-logs`
321+
- `mcp`: Sends logs to the MCP client (if supported by the client/transport).
322+
- `disk`: Writes logs to disk files. Log files are stored in the log path (see `logPath` above).
323+
- `stderr`: Outputs logs to standard error (stderr), useful for debugging or when running in containers.
324+
325+
**Default:** `disk,mcp` (logs are written to disk and sent to the MCP client).
326+
327+
You can combine multiple loggers, e.g. `--loggers disk,stderr` or `export MDB_MCP_LOGGERS="mcp,stderr"`.
328+
329+
##### Example: Set logger via environment variable
330+
331+
```shell
332+
export MDB_MCP_LOGGERS="disk,stderr"
333+
```
334+
335+
##### Example: Set logger via command-line argument
336+
337+
```shell
338+
npx -y mongodb-mcp-server --loggers mcp,stderr
339+
```
340+
341+
##### Log File Location
342+
343+
When using the `disk` logger, log files are stored in:
344+
- **Windows:** `%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs`
345+
- **macOS/Linux:** `~/.mongodb/mongodb-mcp/.app-logs`
346+
347+
You can override the log directory with the `logPath` option.
323348

324349
#### Disabled Tools
325350

src/transports/streamableHttpTransport.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
44
import { config } from "../common/config.js";
55
import logger, { LogId } from "../common/logger.js";
66

7+
const JSON_RPC_ERROR_CODE_PROCESSING_REQUEST_FAILED = -32000;
8+
79
export function createHttpTransport(): StreamableHTTPServerTransport {
810
const app = express();
9-
app.use(express.json());
1011
app.enable("trust proxy"); // needed for reverse proxy support
1112
app.use(express.urlencoded({ extended: true }));
1213
app.use(express.json());
@@ -24,7 +25,13 @@ export function createHttpTransport(): StreamableHTTPServerTransport {
2425
"streamableHttpTransport",
2526
`Error handling request: ${error instanceof Error ? error.message : String(error)}`
2627
);
27-
res.sendStatus(400);
28+
res.status(400).json({
29+
jsonrpc: "2.0",
30+
error: {
31+
code: JSON_RPC_ERROR_CODE_PROCESSING_REQUEST_FAILED,
32+
message: `Error handling request: ${error instanceof Error ? error.message : String(error)}`,
33+
},
34+
});
2835
}
2936
});
3037

@@ -37,7 +44,13 @@ export function createHttpTransport(): StreamableHTTPServerTransport {
3744
"streamableHttpTransport",
3845
`Error handling request: ${error instanceof Error ? error.message : String(error)}`
3946
);
40-
res.sendStatus(400);
47+
res.status(400).json({
48+
jsonrpc: "2.0",
49+
error: {
50+
code: JSON_RPC_ERROR_CODE_PROCESSING_REQUEST_FAILED,
51+
message: `Error handling request: ${error instanceof Error ? error.message : String(error)}`,
52+
},
53+
});
4154
}
4255
});
4356

@@ -50,7 +63,13 @@ export function createHttpTransport(): StreamableHTTPServerTransport {
5063
"streamableHttpTransport",
5164
`Error handling request: ${error instanceof Error ? error.message : String(error)}`
5265
);
53-
res.sendStatus(400);
66+
res.status(400).json({
67+
jsonrpc: "2.0",
68+
error: {
69+
code: JSON_RPC_ERROR_CODE_PROCESSING_REQUEST_FAILED,
70+
message: `Error handling request: ${error instanceof Error ? error.message : String(error)}`,
71+
},
72+
});
5473
}
5574
});
5675

0 commit comments

Comments
 (0)