Skip to content

Context7 Platform -- Up-to-date docs for AI agents

fix(mcp): increase HTTP subscription capacity (#3101)

Fahreddin Özcan4e980f6b494d
diff --git a/.changeset/quiet-dodos-listen.md b/.changeset/quiet-dodos-listen.md
new file mode 100644
index 00000000..feb7d0d2
--- /dev/null
+++ b/.changeset/quiet-dodos-listen.md
@@ -0,0 +1,5 @@
+---
+"@upstash/context7-mcp": patch
+---
+
+Increase the default HTTP subscription capacity and allow deployments to configure it with `MCP_MAX_SUBSCRIPTIONS`.
diff --git a/.env.example b/.env.example
index f3ef285b..44f67c1b 100644
--- a/.env.example
+++ b/.env.example
@@ -13,6 +13,9 @@ OPENAI_APPS_CHALLENGE_TOKEN=
# Required for hosted HTTP deployments. Must match context7.com.
MCP_CLIENT_IP_ASSERTION_KEY=
+# Maximum concurrent MCP subscription streams per HTTP process.
+MCP_MAX_SUBSCRIPTIONS=16000
+
# Temporary legacy rollout key. Removal is tracked by CTX7-2536.
CLIENT_IP_ENCRYPTION_KEY=
diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.ts
index 2465db4a..009fb7e4 100644
--- a/packages/mcp/src/index.ts
+++ b/packages/mcp/src/index.ts
@@ -24,6 +24,7 @@ import {
OPENAI_APPS_CHALLENGE_TOKEN,
} from "./lib/constants.js";
import { maybeElicitAuthSignIn } from "./lib/auth/auth-prompt.js";
+import { getMaxSubscriptions } from "./lib/subscriptions.js";
/** Default HTTP server port */
const DEFAULT_PORT = 3000;
@@ -380,6 +381,7 @@ async function main() {
// go idle and the gateway reaps them at streamIdleTimeout (300s).
const mcpHandler = createMcpHandler(() => createMcpServer(), {
keepAliveMs: 0,
+ maxSubscriptions: getMaxSubscriptions(),
onerror: (error) => console.error("MCP handler error:", error),
});
// Without onerror, request-conversion / handler.fetch throws are answered
diff --git a/packages/mcp/src/lib/subscriptions.ts b/packages/mcp/src/lib/subscriptions.ts
new file mode 100644
index 00000000..3ce64f21
--- /dev/null
+++ b/packages/mcp/src/lib/subscriptions.ts
@@ -0,0 +1,12 @@
+// 16k stayed near baseline latency in Docker; 32,768 raised tools/list p95 to ~39 ms.
+export const DEFAULT_MAX_SUBSCRIPTIONS = 16_000;
+
+export function getMaxSubscriptions(value = process.env.MCP_MAX_SUBSCRIPTIONS): number {
+ if (value === undefined) return DEFAULT_MAX_SUBSCRIPTIONS;
+
+ const parsed = Number(value);
+ if (Number.isSafeInteger(parsed) && parsed > 0) return parsed;
+
+ console.warn(`Invalid MCP_MAX_SUBSCRIPTIONS; using the default of ${DEFAULT_MAX_SUBSCRIPTIONS}.`);
+ return DEFAULT_MAX_SUBSCRIPTIONS;
+}
diff --git a/packages/mcp/test/subscriptions.test.ts b/packages/mcp/test/subscriptions.test.ts
new file mode 100644
index 00000000..8e8efbff
--- /dev/null
+++ b/packages/mcp/test/subscriptions.test.ts
@@ -0,0 +1,26 @@
+import { afterEach, describe, expect, test, vi } from "vitest";
+import { DEFAULT_MAX_SUBSCRIPTIONS, getMaxSubscriptions } from "../src/lib/subscriptions.js";
+
+describe("getMaxSubscriptions", () => {
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ test("defaults to 16000 subscriptions", () => {
+ expect(getMaxSubscriptions(undefined)).toBe(DEFAULT_MAX_SUBSCRIPTIONS);
+ });
+
+ test("accepts a positive integer override", () => {
+ expect(getMaxSubscriptions("8192")).toBe(8_192);
+ });
+
+ test.each(["0", "-1", "1.5", "invalid", "Infinity"])(
+ "falls back for invalid value %s",
+ (value) => {
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
+
+ expect(getMaxSubscriptions(value)).toBe(DEFAULT_MAX_SUBSCRIPTIONS);
+ expect(warn).toHaveBeenCalledOnce();
+ }
+ );
+});