Z User
phase7: MCP stdio smoke test (handshake + tools/list + get_roots 6:74) — 4/4 tests PASS
54a6341 Download node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js from bravesigma/quran-md-plugin: direct link, hf CLI and curl.
- Browser
- Download file 2.34 kB
-
https://huggingface.co/datasets/bravesigma/quran-md-plugin/resolve/main/node_modules/%40modelcontextprotocol/sdk/dist/esm/server/express.js
- Command line
-
hf download hf://datasets/bravesigma/quran-md-plugin/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js
-
curl -L -o express.js https://huggingface.co/datasets/bravesigma/quran-md-plugin/resolve/main/node_modules/%40modelcontextprotocol/sdk/dist/esm/server/express.js
2.34 kB
| import express from 'express'; | |
| import { hostHeaderValidation, localhostHostValidation } from './middleware/hostHeaderValidation.js'; | |
| /** | |
| * Creates an Express application pre-configured for MCP servers. | |
| * | |
| * When the host is '127.0.0.1', 'localhost', or '::1' (the default is '127.0.0.1'), | |
| * DNS rebinding protection middleware is automatically applied to protect against | |
| * DNS rebinding attacks on localhost servers. | |
| * | |
| * @param options - Configuration options | |
| * @returns A configured Express application | |
| * | |
| * @example | |
| * ```typescript | |
| * // Basic usage - defaults to 127.0.0.1 with DNS rebinding protection | |
| * const app = createMcpExpressApp(); | |
| * | |
| * // Custom host - DNS rebinding protection only applied for localhost hosts | |
| * const app = createMcpExpressApp({ host: '0.0.0.0' }); // No automatic DNS rebinding protection | |
| * const app = createMcpExpressApp({ host: 'localhost' }); // DNS rebinding protection enabled | |
| * | |
| * // Custom allowed hosts for non-localhost binding | |
| * const app = createMcpExpressApp({ host: '0.0.0.0', allowedHosts: ['myapp.local', 'localhost'] }); | |
| * ``` | |
| */ | |
| export function createMcpExpressApp(options = {}) { | |
| const { host = '127.0.0.1', allowedHosts } = options; | |
| const app = express(); | |
| // If allowedHosts is explicitly provided, use that for validation | |
| if (allowedHosts) { | |
| app.use(hostHeaderValidation(allowedHosts)); | |
| } | |
| else { | |
| // Apply DNS rebinding protection automatically for localhost hosts | |
| const localhostHosts = ['127.0.0.1', 'localhost', '::1']; | |
| if (localhostHosts.includes(host)) { | |
| app.use(localhostHostValidation()); | |
| } | |
| else if (host === '0.0.0.0' || host === '::') { | |
| // Warn when binding to all interfaces without DNS rebinding protection | |
| // eslint-disable-next-line no-console | |
| console.warn(`Warning: Server is binding to ${host} without DNS rebinding protection. ` + | |
| 'Consider using the allowedHosts option to restrict allowed hosts, ' + | |
| 'or use authentication to protect your server.'); | |
| } | |
| } | |
| // The JSON body parser runs after the Host header validation, so a request | |
| // with a disallowed Host is answered 403 without its body being read. | |
| app.use(express.json()); | |
| return app; | |
| } | |
| //# sourceMappingURL=express.js.map |