@hydradb/mcp 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Configuration for the remotely hostable HTTP transport.
3
+ *
4
+ * There are two configurations here, and they belong to two different people.
5
+ *
6
+ * - {@link resolveHttpServerConfig} is the OPERATOR's config: the port, the
7
+ * bind address, and the Host/Origin allowlists that decide who may reach the
8
+ * process at all. It is read once at startup from the environment.
9
+ *
10
+ * - {@link resolveRequestCredentials} is the CALLER's config: which Hydra DB
11
+ * account, database and collection a single request runs against. On a
12
+ * multi-tenant deployment (one process serving `mcp.hydradb.com` for many
13
+ * users) this MUST come per request, from headers, because the process has
14
+ * no single tenant of its own. It is resolved fresh on every `/mcp` call.
15
+ *
16
+ * The stdio server ({@link file://./index.ts}) has only the second concern and
17
+ * reads it from the environment via {@link file://./config.ts}; a hosted server
18
+ * cannot, because one env-configured key would make every user share one
19
+ * account. So the header path is the substantive new surface, and it falls back
20
+ * to the environment only to keep the single-tenant self-hosting story (set the
21
+ * env, expose the port, done) working unchanged.
22
+ */
23
+ import { type EnvSource, type GraphConfig } from "./config.js";
24
+ export interface HttpServerConfig {
25
+ /** TCP port to listen on. */
26
+ port: number;
27
+ /**
28
+ * Interface to bind. Defaults to loopback so an unconfigured server is not
29
+ * reachable off-box; a hosted deployment sets `0.0.0.0` deliberately.
30
+ */
31
+ bindAddress: string;
32
+ /** CORS allowlist. Empty means no cross-origin browser request is accepted. */
33
+ allowedOrigins: string[];
34
+ /** Accepted `Host` headers, lowercased. Loopback + the configured port always. */
35
+ allowedHosts: Set<string>;
36
+ /**
37
+ * Express's `trust proxy` setting. `false` (the default) trusts no
38
+ * `X-Forwarded-*`, so a direct client cannot spoof its address in the logs;
39
+ * a deployment behind a known proxy sets `TRUST_PROXY` to a hop count or a
40
+ * subnet preset so the real client IP is recovered without trusting all hops.
41
+ */
42
+ trustProxy: boolean | number | string;
43
+ }
44
+ export declare const DEFAULT_PORT = 8080;
45
+ export declare const DEFAULT_BIND_ADDRESS = "127.0.0.1";
46
+ /** Split a comma-separated env var into trimmed, non-empty entries. */
47
+ export declare function parseList(value: string | undefined): string[];
48
+ /**
49
+ * A port, or the default when the value is absent or not a usable port.
50
+ *
51
+ * A typo'd `PORT` should not crash startup with a stack trace; it should fall
52
+ * back and let the startup banner show what it actually bound. Ports outside
53
+ * 1-65535 fall back for the same reason `parseInt("8080abc")` must not become
54
+ * `8080` silently — `Number` rejects the trailing garbage that `parseInt` keeps.
55
+ */
56
+ export declare function parsePort(raw: string | undefined, fallback?: number): number;
57
+ /**
58
+ * The set of `Host` headers this server answers to.
59
+ *
60
+ * Loopback names on the bound port are always included so a local run works with
61
+ * no configuration. A hosted deployment adds its public hostname(s) via
62
+ * `ALLOWED_HOSTS`. The bare (portless) loopback names cover clients that omit
63
+ * the port on the default HTTP/HTTPS port.
64
+ */
65
+ export declare function buildAllowedHosts(port: number, extra: string[]): Set<string>;
66
+ /**
67
+ * Interpret `TRUST_PROXY` for Express's `trust proxy` setting.
68
+ *
69
+ * Absent → `false` (trust nothing, the safe default). `true`/`false` → boolean.
70
+ * An integer → that many hops. Anything else is passed through as an Express
71
+ * preset or subnet list (e.g. `loopback`, `10.0.0.0/8`), so an operator can name
72
+ * exactly their proxy without this needing to know the syntax.
73
+ */
74
+ export declare function parseTrustProxy(raw: string | undefined): boolean | number | string;
75
+ export declare function resolveHttpServerConfig(env?: EnvSource): HttpServerConfig;
76
+ /**
77
+ * Header names a caller uses to select and authenticate against their tenant.
78
+ *
79
+ * Lowercased because Node lowercases incoming header names, and every lookup
80
+ * here goes through {@link headerValue} which reads them off `req.headers`.
81
+ *
82
+ * The API key is read from the standard `Authorization: Bearer <key>` first;
83
+ * `X-HydraDB-Api-Key` exists only for clients whose MCP config cannot set an
84
+ * `Authorization` header. Everything else — which database, which collection —
85
+ * has no standard header, so it takes an `X-HydraDB-*` one.
86
+ */
87
+ export declare const HEADER_AUTHORIZATION = "authorization";
88
+ export declare const HEADER_API_KEY = "x-hydradb-api-key";
89
+ export declare const HEADER_DATABASE = "x-hydradb-database";
90
+ export declare const HEADER_COLLECTION = "x-hydradb-collection";
91
+ export declare const HEADER_GRAPH_DATABASE = "x-hydradb-graph-database";
92
+ export declare const HEADER_GRAPH_COLLECTION = "x-hydradb-graph-collection";
93
+ /** The request headers this resolver reads. Matches Node's `IncomingHttpHeaders`. */
94
+ export type RequestHeaders = Record<string, string | string[] | undefined>;
95
+ /**
96
+ * Everything needed to construct a scoped {@link HydraDB} for one request.
97
+ *
98
+ * `baseUrl`, `timeoutSeconds` and `maxRetries` are deliberately absent from the
99
+ * header surface: they are OPERATOR knobs read from the environment, not caller
100
+ * ones. Letting a caller set `baseUrl` per request would point this server's
101
+ * outbound calls at a host of the caller's choosing, which is a request-forgery
102
+ * primitive the tenant selection has no reason to hand out.
103
+ */
104
+ export interface RequestCredentials {
105
+ apiKey: string;
106
+ database: string;
107
+ collection: string;
108
+ baseUrl?: string;
109
+ timeoutSeconds?: number;
110
+ maxRetries?: number;
111
+ graph: GraphConfig;
112
+ }
113
+ /**
114
+ * Resolution is either credentials or the exact HTTP failure to return.
115
+ *
116
+ * The status and message are carried out rather than thrown so the caller can
117
+ * answer with a JSON-RPC error body at the right code — 401 when nothing
118
+ * authenticated the request, 400 when it authenticated but named no database —
119
+ * instead of a generic 500 that tells the client nothing about what to fix.
120
+ */
121
+ export type CredentialResolution = {
122
+ ok: true;
123
+ credentials: RequestCredentials;
124
+ } | {
125
+ ok: false;
126
+ status: number;
127
+ message: string;
128
+ };
129
+ /**
130
+ * Turn one request's headers (falling back to the environment) into the tenant
131
+ * credentials for that request.
132
+ *
133
+ * The API key and the database resolve TOGETHER, not field-by-field, which is
134
+ * the security-relevant part:
135
+ * - When the key comes from a request header, the request is
136
+ * "caller-authenticated" and its database MUST also come from a header. The
137
+ * env is NOT consulted for the database, so a caller who sends their own key
138
+ * but omits `X-HydraDB-Database` is refused (400) rather than silently run
139
+ * against the operator's env database. Likewise the graph scope defaults to
140
+ * the request's own database, never the operator's `HYDRADB_GRAPH_DATABASE`.
141
+ * - When there is no key header, the request is unauthenticated and falls back
142
+ * entirely to the operator's env credentials — the single-tenant self-host
143
+ * case, identical to the stdio server. A hosted, multi-tenant process sets
144
+ * no tenant env, so such a request is refused (401).
145
+ *
146
+ * Resolving field-by-field instead would let a caller's key pair with the
147
+ * operator's database (or graph namespace), mixing two identities into one
148
+ * request. `baseUrl`/`timeoutSeconds`/`maxRetries` are read from the environment
149
+ * only — they are the operator's, not the caller's (see {@link RequestCredentials}).
150
+ */
151
+ export declare function resolveRequestCredentials(headers: RequestHeaders, env?: EnvSource): CredentialResolution;
152
+ /** A JSON-RPC error body, so every HTTP failure speaks the protocol's dialect. */
153
+ export declare function jsonRpcError(code: number, message: string): {
154
+ jsonrpc: "2.0";
155
+ error: {
156
+ code: number;
157
+ message: string;
158
+ };
159
+ id: null;
160
+ };
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Configuration for the remotely hostable HTTP transport.
3
+ *
4
+ * There are two configurations here, and they belong to two different people.
5
+ *
6
+ * - {@link resolveHttpServerConfig} is the OPERATOR's config: the port, the
7
+ * bind address, and the Host/Origin allowlists that decide who may reach the
8
+ * process at all. It is read once at startup from the environment.
9
+ *
10
+ * - {@link resolveRequestCredentials} is the CALLER's config: which Hydra DB
11
+ * account, database and collection a single request runs against. On a
12
+ * multi-tenant deployment (one process serving `mcp.hydradb.com` for many
13
+ * users) this MUST come per request, from headers, because the process has
14
+ * no single tenant of its own. It is resolved fresh on every `/mcp` call.
15
+ *
16
+ * The stdio server ({@link file://./index.ts}) has only the second concern and
17
+ * reads it from the environment via {@link file://./config.ts}; a hosted server
18
+ * cannot, because one env-configured key would make every user share one
19
+ * account. So the header path is the substantive new surface, and it falls back
20
+ * to the environment only to keep the single-tenant self-hosting story (set the
21
+ * env, expose the port, done) working unchanged.
22
+ */
23
+ import { DEFAULT_COLLECTION, nonNegativeInt, positiveInt, readEnv, resolveGraphConfig, } from "./config.js";
24
+ export const DEFAULT_PORT = 8080;
25
+ export const DEFAULT_BIND_ADDRESS = "127.0.0.1";
26
+ /** Split a comma-separated env var into trimmed, non-empty entries. */
27
+ export function parseList(value) {
28
+ if (!value)
29
+ return [];
30
+ return value
31
+ .split(",")
32
+ .map((v) => v.trim())
33
+ .filter((v) => v.length > 0);
34
+ }
35
+ /**
36
+ * A port, or the default when the value is absent or not a usable port.
37
+ *
38
+ * A typo'd `PORT` should not crash startup with a stack trace; it should fall
39
+ * back and let the startup banner show what it actually bound. Ports outside
40
+ * 1-65535 fall back for the same reason `parseInt("8080abc")` must not become
41
+ * `8080` silently — `Number` rejects the trailing garbage that `parseInt` keeps.
42
+ */
43
+ export function parsePort(raw, fallback = DEFAULT_PORT) {
44
+ const value = Number(raw);
45
+ return raw != null && Number.isInteger(value) && value >= 1 && value <= 65535
46
+ ? value
47
+ : fallback;
48
+ }
49
+ /**
50
+ * The set of `Host` headers this server answers to.
51
+ *
52
+ * Loopback names on the bound port are always included so a local run works with
53
+ * no configuration. A hosted deployment adds its public hostname(s) via
54
+ * `ALLOWED_HOSTS`. The bare (portless) loopback names cover clients that omit
55
+ * the port on the default HTTP/HTTPS port.
56
+ */
57
+ export function buildAllowedHosts(port, extra) {
58
+ return new Set([
59
+ `localhost:${port}`,
60
+ `127.0.0.1:${port}`,
61
+ `[::1]:${port}`,
62
+ "localhost",
63
+ "127.0.0.1",
64
+ "[::1]",
65
+ ...extra,
66
+ ].map((h) => h.toLowerCase()));
67
+ }
68
+ /**
69
+ * Interpret `TRUST_PROXY` for Express's `trust proxy` setting.
70
+ *
71
+ * Absent → `false` (trust nothing, the safe default). `true`/`false` → boolean.
72
+ * An integer → that many hops. Anything else is passed through as an Express
73
+ * preset or subnet list (e.g. `loopback`, `10.0.0.0/8`), so an operator can name
74
+ * exactly their proxy without this needing to know the syntax.
75
+ */
76
+ export function parseTrustProxy(raw) {
77
+ const value = raw?.trim();
78
+ if (!value)
79
+ return false;
80
+ if (value.toLowerCase() === "true")
81
+ return true;
82
+ if (value.toLowerCase() === "false")
83
+ return false;
84
+ if (/^\d+$/.test(value))
85
+ return Number(value);
86
+ return value;
87
+ }
88
+ export function resolveHttpServerConfig(env = process.env) {
89
+ const port = parsePort(env.PORT);
90
+ return {
91
+ port,
92
+ bindAddress: env.BIND_ADDRESS?.trim() || DEFAULT_BIND_ADDRESS,
93
+ allowedOrigins: parseList(env.ALLOWED_ORIGINS),
94
+ allowedHosts: buildAllowedHosts(port, parseList(env.ALLOWED_HOSTS)),
95
+ trustProxy: parseTrustProxy(env.TRUST_PROXY),
96
+ };
97
+ }
98
+ // --- Per-request tenant credentials ---
99
+ /**
100
+ * Header names a caller uses to select and authenticate against their tenant.
101
+ *
102
+ * Lowercased because Node lowercases incoming header names, and every lookup
103
+ * here goes through {@link headerValue} which reads them off `req.headers`.
104
+ *
105
+ * The API key is read from the standard `Authorization: Bearer <key>` first;
106
+ * `X-HydraDB-Api-Key` exists only for clients whose MCP config cannot set an
107
+ * `Authorization` header. Everything else — which database, which collection —
108
+ * has no standard header, so it takes an `X-HydraDB-*` one.
109
+ */
110
+ export const HEADER_AUTHORIZATION = "authorization";
111
+ export const HEADER_API_KEY = "x-hydradb-api-key";
112
+ export const HEADER_DATABASE = "x-hydradb-database";
113
+ export const HEADER_COLLECTION = "x-hydradb-collection";
114
+ export const HEADER_GRAPH_DATABASE = "x-hydradb-graph-database";
115
+ export const HEADER_GRAPH_COLLECTION = "x-hydradb-graph-collection";
116
+ /** One header value, taking the first when a header arrives repeated. */
117
+ function headerValue(headers, name) {
118
+ const raw = headers[name];
119
+ const value = Array.isArray(raw) ? raw[0] : raw;
120
+ const trimmed = value?.trim();
121
+ return trimmed ? trimmed : undefined;
122
+ }
123
+ /**
124
+ * The token from an `Authorization` header, accepting `Bearer <token>` or a bare
125
+ * token. The scheme is matched case-insensitively (RFC 7235 says it is
126
+ * case-insensitive, and clients send `bearer`, `Bearer` and `BEARER` in the
127
+ * wild); a bare value is accepted because some MCP hosts drop the scheme.
128
+ */
129
+ function bearerToken(authorization) {
130
+ if (!authorization)
131
+ return undefined;
132
+ const match = /^\s*Bearer\s+(.+)$/i.exec(authorization);
133
+ if (match)
134
+ return match[1].trim() || undefined;
135
+ return authorization.trim() || undefined;
136
+ }
137
+ /**
138
+ * Turn one request's headers (falling back to the environment) into the tenant
139
+ * credentials for that request.
140
+ *
141
+ * The API key and the database resolve TOGETHER, not field-by-field, which is
142
+ * the security-relevant part:
143
+ * - When the key comes from a request header, the request is
144
+ * "caller-authenticated" and its database MUST also come from a header. The
145
+ * env is NOT consulted for the database, so a caller who sends their own key
146
+ * but omits `X-HydraDB-Database` is refused (400) rather than silently run
147
+ * against the operator's env database. Likewise the graph scope defaults to
148
+ * the request's own database, never the operator's `HYDRADB_GRAPH_DATABASE`.
149
+ * - When there is no key header, the request is unauthenticated and falls back
150
+ * entirely to the operator's env credentials — the single-tenant self-host
151
+ * case, identical to the stdio server. A hosted, multi-tenant process sets
152
+ * no tenant env, so such a request is refused (401).
153
+ *
154
+ * Resolving field-by-field instead would let a caller's key pair with the
155
+ * operator's database (or graph namespace), mixing two identities into one
156
+ * request. `baseUrl`/`timeoutSeconds`/`maxRetries` are read from the environment
157
+ * only — they are the operator's, not the caller's (see {@link RequestCredentials}).
158
+ */
159
+ export function resolveRequestCredentials(headers, env = process.env) {
160
+ const headerKey = bearerToken(headerValue(headers, HEADER_AUTHORIZATION)) ??
161
+ headerValue(headers, HEADER_API_KEY);
162
+ // Whether the CALLER authenticated this request with their own key decides
163
+ // whether the operator's env is allowed to supply the rest of the identity.
164
+ const callerAuthenticated = headerKey != null;
165
+ const apiKey =
166
+ // The env fallback reuses the exact same canonical/legacy alias rules as
167
+ // the stdio server, so a self-host configured for stdio needs no new vars.
168
+ headerKey ?? readEnv(env, "HYDRADB_API_KEY", "HYDRA_DB_API_KEY", noopWarn);
169
+ if (!apiKey) {
170
+ return {
171
+ ok: false,
172
+ status: 401,
173
+ message: "Missing Hydra DB credentials. Send `Authorization: Bearer <api-key>` " +
174
+ "(or the `X-HydraDB-Api-Key` header). Get a key at https://app.hydradb.com.",
175
+ };
176
+ }
177
+ const headerDatabase = headerValue(headers, HEADER_DATABASE);
178
+ // A caller-authenticated request takes its database ONLY from the header;
179
+ // the env database belongs to the operator's identity, not the caller's.
180
+ const database = callerAuthenticated
181
+ ? headerDatabase
182
+ : (headerDatabase ?? readEnv(env, "HYDRADB_DATABASE", "HYDRA_DB_TENANT_ID", noopWarn));
183
+ if (!database) {
184
+ return {
185
+ ok: false,
186
+ status: 400,
187
+ message: "Missing Hydra DB database. Send the `X-HydraDB-Database` header naming " +
188
+ "the database (tenant) this request should run against.",
189
+ };
190
+ }
191
+ // Collection is a partition WITHIN the resolved database, not a cross-tenant
192
+ // boundary, so an env default is safe for either mode.
193
+ const collection = headerValue(headers, HEADER_COLLECTION) ??
194
+ readEnv(env, "HYDRADB_COLLECTION", "HYDRA_DB_SUB_TENANT_ID", noopWarn) ??
195
+ DEFAULT_COLLECTION;
196
+ // Operator-owned transport knobs. Same env vars, same parsing as resolveConfig.
197
+ const baseUrl = readEnv(env, "HYDRADB_BASE_URL", "HYDRA_DB_BASE_URL", noopWarn);
198
+ const timeoutSeconds = positiveInt(env.HYDRADB_TIMEOUT_SECONDS);
199
+ const maxRetries = nonNegativeInt(env.HYDRADB_MAX_RETRIES);
200
+ return {
201
+ ok: true,
202
+ credentials: {
203
+ apiKey,
204
+ database,
205
+ collection,
206
+ ...(baseUrl != null ? { baseUrl } : {}),
207
+ ...(timeoutSeconds != null ? { timeoutSeconds } : {}),
208
+ ...(maxRetries != null ? { maxRetries } : {}),
209
+ graph: resolveRequestGraphConfig(headers, env, database, callerAuthenticated),
210
+ },
211
+ };
212
+ }
213
+ /**
214
+ * Graph scope for one request: the operator's `enabled` flag, but the caller's
215
+ * database and collection.
216
+ *
217
+ * The graph database defaults to the request's OWN database, so a caller that
218
+ * names only `X-HydraDB-Database` gets a coherent graph scope without a second
219
+ * header. The operator's `HYDRADB_GRAPH_DATABASE` is honoured as that default
220
+ * ONLY for an unauthenticated (env-credential) request — for a caller-
221
+ * authenticated one it would pin every tenant to the operator's single graph
222
+ * namespace, the mixing this resolver exists to prevent. Header overrides always
223
+ * win, letting a caller address a graph in a different namespace than their
224
+ * memory database — which, because the two are genuinely separate stores, is a
225
+ * real need.
226
+ */
227
+ function resolveRequestGraphConfig(headers, env, database, callerAuthenticated) {
228
+ // For a caller-authenticated request the fallback database is the request's
229
+ // own, so `resolveGraphConfig`'s env default is deliberately not consulted.
230
+ const base = resolveGraphConfig(env, database);
231
+ const defaultDatabase = callerAuthenticated ? database : base.database;
232
+ return {
233
+ enabled: base.enabled,
234
+ database: headerValue(headers, HEADER_GRAPH_DATABASE) ?? defaultDatabase,
235
+ collection: headerValue(headers, HEADER_GRAPH_COLLECTION) ?? base.collection,
236
+ };
237
+ }
238
+ /**
239
+ * Credential resolution must not emit deprecation warnings.
240
+ *
241
+ * `readEnv` warns once per process when a legacy alias is used. On the header
242
+ * path the env is only a fallback and is read on EVERY request; routing its
243
+ * warning through the process-wide dedupe would still fire on the first request
244
+ * and, worse, tie a per-request code path to shared mutable warning state. The
245
+ * stdio/startup path already surfaces any legacy-alias warning, so silence here
246
+ * drops nothing.
247
+ */
248
+ function noopWarn() { }
249
+ /** A JSON-RPC error body, so every HTTP failure speaks the protocol's dialect. */
250
+ export function jsonRpcError(code, message) {
251
+ return { jsonrpc: "2.0", error: { code, message }, id: null };
252
+ }
253
+ //# sourceMappingURL=http-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-config.js","sourceRoot":"","sources":["../src/http-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACN,kBAAkB,EAGlB,cAAc,EACd,WAAW,EACX,OAAO,EACP,kBAAkB,GAClB,MAAM,aAAa,CAAC;AAyBrB,MAAM,CAAC,MAAM,YAAY,GAAG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CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,yBAAyB,CACjC,OAAuB,EACvB,GAAc,EACd,QAAgB,EAChB,mBAA4B;IAE5B,4EAA4E;IAC5E,4EAA4E;IAC5E,MAAM,IAAI,GAAG,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC/C,MAAM,eAAe,GAAG,mBAAmB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;IACvE,OAAO;QACN,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,QAAQ,EAAE,WAAW,CAAC,OAAO,EAAE,qBAAqB,CAAC,IAAI,eAAe;QACxE,UAAU,EAAE,WAAW,CAAC,OAAO,EAAE,uBAAuB,CAAC,IAAI,IAAI,CAAC,UAAU;KAC5E,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,QAAQ,KAAU,CAAC;AAE5B,kFAAkF;AAClF,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,OAAe;IAKzD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AAC/D,CAAC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The remotely hostable HTTP transport.
4
+ *
5
+ * This is the server behind a URL like `https://mcp.hydradb.com/mcp`: instead of
6
+ * every user installing and spawning the stdio binary ({@link file://./index.ts}),
7
+ * one process answers MCP over HTTP and each user points their client at the URL.
8
+ *
9
+ * It reuses the whole tool surface unchanged — {@link createHydraDBServer} builds
10
+ * exactly the same server the stdio path does. The only things this file adds are
11
+ * the ones a network endpoint needs and a pipe does not: a Host/Origin
12
+ * allowlist, CORS, and PER-REQUEST tenant credentials (see
13
+ * {@link file://./http-config.ts}), because one hosted process has no single
14
+ * ambient account to run as.
15
+ *
16
+ * Sessions are stateless: MCP's Protocol object binds to one transport, so a
17
+ * shared process serving many independent callers builds a fresh server +
18
+ * transport per request and tears it down when the response closes. That is the
19
+ * transport's documented stateless mode (`sessionIdGenerator: undefined`).
20
+ */
21
+ import { type Express } from "express";
22
+ import { buildAllowedHosts, type HttpServerConfig, parseList, parsePort, resolveHttpServerConfig } from "./http-config.js";
23
+ /**
24
+ * Build the Express app for the HTTP transport.
25
+ *
26
+ * Exported (and taking its config as an argument rather than reading the
27
+ * environment) so tests exercise the exact wiring production runs, against an
28
+ * arbitrary allowlist, with no process-global state.
29
+ */
30
+ export declare function createHttpApp(config: HttpServerConfig): Express;
31
+ export { buildAllowedHosts, parseList, parsePort, resolveHttpServerConfig };