You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> **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.
279
280
281
+
### HTTP Authentication Middleware
282
+
283
+
<aname="http-authentication"></a>
284
+
285
+
The HTTP transport supports pluggable authentication strategies selected via the `httpAuthMode` configuration option.
286
+
287
+
Current modes:
288
+
289
+
-`none` (default) – No authentication. Every request is accepted. Only use this in local / trusted network environments. Do **NOT** expose an unauthenticated instance to the public internet.
290
+
-`azure-managed-identity` – Validates Azure Entra ID (Managed Identity / Service Principal) issued **access tokens** presented via `Authorization: Bearer <token>`.
291
+
292
+
This setting is ONLY evaluated when `transport` is `http`; it is ignored for the default `stdio` transport.
293
+
294
+
#### Azure Managed Identity / Entra ID Options
295
+
296
+
Environment variables map 1:1 to the camelCase keys with the `MDB_MCP_` prefix:
297
+
298
+
| Key | Env Var | Required | Description |
299
+
| --- | ------- | -------- | ----------- |
300
+
|`httpAuthMode`|`MDB_MCP_HTTP_AUTH_MODE`| No (defaults to `none`) | Set to `azure-managed-identity` to enable Azure token validation. |
301
+
|`azureManagedIdentityTenantId`|`MDB_MCP_AZURE_MANAGED_IDENTITY_TENANT_ID`| Yes (when `httpAuthMode=azure-managed-identity`) | Azure Entra tenant ID used to resolve OpenID configuration and signing keys. |
302
+
|`azureManagedIdentityClientId`|`MDB_MCP_AZURE_MANAGED_IDENTITY_CLIENT_ID`| No | Fallback expected audience (token `aud`) if `azureManagedIdentityAudience` is not supplied. Typically your application (service principal) client ID. |
303
+
|`azureManagedIdentityAudience`|`MDB_MCP_AZURE_MANAGED_IDENTITY_AUDIENCE`| No | Explicit audience override. If set, token `aud` must match this value (takes precedence over clientId). |
304
+
|`azureManagedIdentityAllowedAppIds`|`MDB_MCP_AZURE_MANAGED_IDENTITY_ALLOWED_APP_IDS`| No | Comma-separated allow‑list of `appid`/`azp` claim values. If provided, token must match one. |
305
+
|`azureManagedIdentityRequiredRoles`|`MDB_MCP_AZURE_MANAGED_IDENTITY_REQUIRED_ROLES`| No | Comma-separated list of application roles (in the `roles` claim) that must be present. |
306
+
|`azureManagedIdentityRoleMatchMode`|`MDB_MCP_AZURE_MANAGED_IDENTITY_ROLE_MATCH_MODE`| No (defaults to `all`) | Whether **all** or **any** of the required roles must be present. |
> The actual HTTP path structure follows the MCP Streamable HTTP transport spec. For simple readiness checks you can hit the root path; authenticated RPC calls must include the Bearer token header.
359
+
360
+
#### Role & App ID Enforcement
361
+
362
+
- If `azureManagedIdentityAllowedAppIds` is set, the token must contain an `appid` (or `azp`) claim matching one of the values.
363
+
- If `azureManagedIdentityRequiredRoles` is set, the token `roles` claim must contain roles based on `azureManagedIdentityRoleMatchMode` (`all` vs `any`).
364
+
365
+
#### Adding New Auth Modes
366
+
367
+
You can introduce additional HTTP auth strategies (e.g. API keys, other OIDC providers) by:
368
+
369
+
1. Creating a new provider/middleware under `src/transports/auth/` implementing the required interface.
370
+
2. Extending the factory (`createAuthMiddleware`) to map a new `httpAuthMode` string to your middleware.
371
+
3. Adding any new configuration keys (environment variables should follow the `MDB_MCP_` + SNAKE_CASE pattern).
372
+
4. Documenting the new mode (update this section & configuration table) and adding tests.
373
+
374
+
This design keeps the core transport decoupled from auth specifics.
375
+
376
+
Authentication for the HTTP transport is selected via the `httpAuthMode` configuration option. The server uses a factory function (`createAuthMiddleware` in `src/transports/auth/authMiddlewareFactory.ts`) to resolve and attach the proper Express middleware. All auth strategies live under `src/transports/auth/` which keeps the transport implementation decoupled from individual authentication strategies so new modes can be added with minimal changes.
377
+
280
378
## 🛠️ Supported Tools
281
379
282
380
### Tool List
@@ -355,6 +453,13 @@ The MongoDB MCP Server can be configured using multiple methods, with the follow
355
453
|`transport`|`MDB_MCP_TRANSPORT`| stdio | Either 'stdio' or 'http'. |
356
454
|`httpPort`|`MDB_MCP_HTTP_PORT`| 3000 | Port number. |
357
455
|`httpHost`|`MDB_MCP_HTTP_HOST`| 127.0.0.1 | Host to bind the http server. |
456
+
|`httpAuthMode`|`MDB_MCP_HTTP_AUTH_MODE`| none | HTTP auth strategy when `transport=http`. Supported: `none`, `azure-managed-identity`. Ignored for `stdio` transport. |
457
+
|`azureManagedIdentityTenantId`|`MDB_MCP_AZURE_MANAGED_IDENTITY_TENANT_ID`| <notset> | Required when `httpAuthMode=azure-managed-identity`. Azure Entra tenant used to fetch OpenID configuration & signing keys. |
458
+
|`azureManagedIdentityClientId`|`MDB_MCP_AZURE_MANAGED_IDENTITY_CLIENT_ID`| <notset> | Optional expected audience/client id if `azureManagedIdentityAudience` not provided. |
459
+
|`azureManagedIdentityAudience`|`MDB_MCP_AZURE_MANAGED_IDENTITY_AUDIENCE`| <notset> | Optional explicit audience override for access token `aud` claim (takes precedence over client id fallback). |
460
+
|`azureManagedIdentityAllowedAppIds`|`MDB_MCP_AZURE_MANAGED_IDENTITY_ALLOWED_APP_IDS`| <notset> | Optional comma-separated allow-list of `appid` / `azp` claim values; if set the token must match one. |
461
+
|`azureManagedIdentityRequiredRoles`|`MDB_MCP_AZURE_MANAGED_IDENTITY_REQUIRED_ROLES`| <notset> | Optional comma-separated list of application roles the token must include (in `roles` claim). |
462
+
|`azureManagedIdentityRoleMatchMode`|`MDB_MCP_AZURE_MANAGED_IDENTITY_ROLE_MATCH_MODE`| all | Whether `all` or `any` of the listed required roles must be present. |
358
463
|`idleTimeoutMs`|`MDB_MCP_IDLE_TIMEOUT_MS`| 600000 | Idle timeout for a client to disconnect (only applies to http transport). |
359
464
|`maxBytesPerQuery`|`MDB_MCP_MAX_BYTES_PER_QUERY`| 16777216 (16MiB) | The maximum size in bytes for results from a `find` or `aggregate` tool call. This serves as an upper bound for the `responseBytesLimit` parameter in those tools. |
360
465
|`maxDocumentsPerQuery`|`MDB_MCP_MAX_DOCUMENTS_PER_QUERY`| 100 | The maximum number of documents that can be returned by a `find` or `aggregate` tool call. For the `find` tool, the effective limit will be the smaller of this value and the tool's `limit` parameter. |
0 commit comments