Skip to content

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

CTX7-2768: Disable unused MCP subscriptions (#3194)

Fahreddin Özcan5ed5e9a41999
diff --git a/.changeset/quiet-streams-rest.md b/.changeset/quiet-streams-rest.md
new file mode 100644
index 00000000..019ee2ef
--- /dev/null
+++ b/.changeset/quiet-streams-rest.md
@@ -0,0 +1,5 @@
+---
+"@upstash/context7-mcp": patch
+---
+
+Disable unused MCP notification subscriptions so clients do not hold open SSE streams for static tool, prompt, and resource collections.
diff --git a/.env.example b/.env.example
index 774cc5b0..08b3b892 100644
--- a/.env.example
+++ b/.env.example
@@ -17,8 +17,9 @@ VERCEL_MARKETPLACE_OIDC_AUDIENCE=
# 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
+# Maximum concurrent MCP notification subscriptions per process. Context7's
+# advertised capabilities are static, so subscriptions are disabled by default.
+MCP_MAX_SUBSCRIPTIONS=0
# Network / certificates
HTTPS_PROXY=
diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.ts
index 6656dcbc..1930ac5a 100644
--- a/packages/mcp/src/index.ts
+++ b/packages/mcp/src/index.ts
@@ -195,11 +195,16 @@ function createMcpServer(mcpContext: McpRequestContext) {
],
};
const serverOptions = {
- // Declaring the capabilities makes the SDK install prompts/list,
- // resources/list, and resources/templates/list handlers that answer
- // with the registered (i.e. empty) collections, for clients that
- // request them unconditionally.
- capabilities: { prompts: {}, resources: {} },
+ // The collections are static for the process lifetime. Explicitly disabling
+ // change notifications prevents clients from opening subscriptions/listen
+ // streams for events this server never publishes. Declaring prompts and
+ // resources still installs their empty list handlers for clients that call
+ // them unconditionally.
+ capabilities: {
+ tools: { listChanged: false },
+ prompts: { listChanged: false },
+ resources: { listChanged: false, subscribe: false },
+ },
instructions: `Use this server to fetch current documentation whenever the user asks about a library, framework, SDK, API, CLI tool, or cloud service — even well-known ones like React, Next.js, Prisma, Express, Tailwind, Django, or Spring Boot. This includes API syntax, configuration, version migration, library-specific debugging, setup instructions, and CLI tool usage. Use even when you think you know the answer — your training data may not reflect recent changes. Prefer this over web search for library docs.
Do not use for: refactoring, writing scripts from scratch, debugging business logic, code review, or general programming concepts.`,
@@ -687,6 +692,7 @@ async function main() {
},
{
transport: stdioTransport,
+ maxSubscriptions: getMaxSubscriptions(),
onerror: (error) => console.error("MCP stdio error:", error),
}
);
diff --git a/packages/mcp/src/lib/subscriptions.ts b/packages/mcp/src/lib/subscriptions.ts
index 3ce64f21..d99f4d31 100644
--- a/packages/mcp/src/lib/subscriptions.ts
+++ b/packages/mcp/src/lib/subscriptions.ts
@@ -1,11 +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;
+// Context7's tools, prompts, and resources are static for the process lifetime,
+// so notification subscriptions provide no useful events.
+export const DEFAULT_MAX_SUBSCRIPTIONS = 0;
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;
+ 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
index 8e8efbff..9127b0a5 100644
--- a/packages/mcp/test/subscriptions.test.ts
+++ b/packages/mcp/test/subscriptions.test.ts
@@ -6,21 +6,20 @@ describe("getMaxSubscriptions", () => {
vi.restoreAllMocks();
});
- test("defaults to 16000 subscriptions", () => {
+ test("disables subscriptions by default", () => {
expect(getMaxSubscriptions(undefined)).toBe(DEFAULT_MAX_SUBSCRIPTIONS);
+ expect(DEFAULT_MAX_SUBSCRIPTIONS).toBe(0);
});
- test("accepts a positive integer override", () => {
+ test("accepts non-negative integer overrides", () => {
+ expect(getMaxSubscriptions("0")).toBe(0);
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(() => {});
+ test.each(["-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();
- }
- );
+ expect(getMaxSubscriptions(value)).toBe(DEFAULT_MAX_SUBSCRIPTIONS);
+ expect(warn).toHaveBeenCalledOnce();
+ });
});