@acid-cat/mcp-handshake 0.11.1 → 0.11.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /** A web request handler. */
2
1
  export type WebHandler = (request: Request) => Promise<Response>;
3
2
  export interface McpHandshakeOptions {
4
3
  /** The maximum size of a request body, in bytes. Give the limit of the wrapped handler. The default is 1 MiB. */
package/dist/index.js CHANGED
@@ -1,17 +1,11 @@
1
1
  import { MCP_EVENTS_EXTENSION, MCP_PROTOCOL_VERSION, isJsonObject, readBounded } from "@acid-cat/spec-ts";
2
2
  // src/index.ts
3
- /**
4
- * The `initialize` handshake of earlier MCP revisions through HTTP (spec/bindings/mcp.md#earlier-revisions-through-http).
5
- * `mcpHandshake` wraps the web handler of an MCP server that serves revision 2026-07-28. Each request of a revision with
6
- * a handshake goes to that handler as a request of revision 2026-07-28, so the handler screens it. The wrapper keeps no
7
- * state.
8
- */
3
+ /** The `initialize` handshake of earlier MCP revisions through HTTP (spec/bindings/mcp.md#earlier-revisions-through-http). */
9
4
  const PROTOCOL_VERSION_KEY = "io.modelcontextprotocol/protocolVersion";
10
5
  const CLIENT_CAPABILITIES_KEY = "io.modelcontextprotocol/clientCapabilities";
11
6
  const SERVER_INFO_KEY = "io.modelcontextprotocol/serverInfo";
12
- /** The revisions with an `initialize` handshake that the wrapper serves, the latest first. */
13
7
  const HANDSHAKE_VERSIONS = ["2025-11-25", "2025-06-18"];
14
- /** The members of a result that only revision 2026-07-28 has. */
8
+ const [LATEST_HANDSHAKE_VERSION] = HANDSHAKE_VERSIONS;
15
9
  const CURRENT_ONLY_MEMBERS = /* @__PURE__ */ new Set([
16
10
  "_meta",
17
11
  "resultType",
@@ -32,15 +26,11 @@ function mcpHandshake(handler, options = {}) {
32
26
  return answer(handler, request, message);
33
27
  };
34
28
  }
35
- /**
36
- * Answer a request of a revision with a handshake. `initialize`, `ping` and notifications go to the handler as
37
- * `server/discover`, and the other methods go as they are.
38
- */
39
29
  async function answer(handler, request, message) {
40
30
  const method = typeof message["method"] === "string" ? message["method"] : "";
41
31
  const params = isJsonObject(message["params"]) ? message["params"] : {};
42
32
  const ownMethod = method === "tools/list" || method === "tools/call" ? method : "server/discover";
43
- const response = await handler(current(request, ownMethod, ownMethod === "server/discover" ? {} : params));
33
+ const response = await handler(asCurrentRevisionRequest(request, ownMethod, ownMethod === "server/discover" ? {} : params));
44
34
  if (!response.ok) return response;
45
35
  const reply = parseObject(await response.text()) ?? {};
46
36
  if (!("id" in message)) return new Response(null, { status: 202 });
@@ -78,16 +68,11 @@ async function answer(handler, request, message) {
78
68
  result: Object.fromEntries(Object.entries(result).filter(([member]) => !CURRENT_ONLY_MEMBERS.has(member)))
79
69
  });
80
70
  }
81
- /**
82
- * True if a request is of a revision with a handshake: its header names one, or it has no header and no revision
83
- * 2026-07-28 in its `params._meta`.
84
- */
85
71
  function isHandshakeRequest(header, metaVersion) {
86
72
  if (header === null) return metaVersion !== MCP_PROTOCOL_VERSION;
87
73
  return HANDSHAKE_VERSIONS.some((version) => version === header);
88
74
  }
89
- /** The request of revision 2026-07-28 for `method`, with the headers and the metadata that the revision requires. */
90
- function current(request, method, params) {
75
+ function asCurrentRevisionRequest(request, method, params) {
91
76
  const headers = new Headers(request.headers);
92
77
  headers.set("MCP-Protocol-Version", MCP_PROTOCOL_VERSION);
93
78
  headers.set("Mcp-Method", method);
@@ -126,7 +111,7 @@ function initializeResult(offered, discovered) {
126
111
  const instructions = typeof discovered["instructions"] === "string" ? discovered["instructions"] : void 0;
127
112
  const capabilities = isJsonObject(discovered["capabilities"]) ? discovered["capabilities"] : {};
128
113
  return {
129
- protocolVersion: HANDSHAKE_VERSIONS.find((each) => each === offered) ?? HANDSHAKE_VERSIONS[0],
114
+ protocolVersion: HANDSHAKE_VERSIONS.find((each) => each === offered) ?? LATEST_HANDSHAKE_VERSION,
130
115
  capabilities: {
131
116
  ...withoutEvents(capabilities),
132
117
  tools: { listChanged: false }
@@ -138,7 +123,6 @@ function initializeResult(offered, discovered) {
138
123
  ...instructions === void 0 ? {} : { instructions }
139
124
  };
140
125
  }
141
- /** Capabilities without the events extension. A capability object with no other extension has no `extensions` member. */
142
126
  function withoutEvents(capabilities) {
143
127
  const { extensions, ...rest } = capabilities;
144
128
  if (!isJsonObject(extensions)) return capabilities;
@@ -148,13 +132,11 @@ function withoutEvents(capabilities) {
148
132
  extensions: others
149
133
  };
150
134
  }
151
- /** The `params._meta` of a message, or an empty object. */
152
135
  function metaOf(message) {
153
136
  const params = message["params"];
154
137
  const meta = isJsonObject(params) ? params["_meta"] : void 0;
155
138
  return isJsonObject(meta) ? meta : {};
156
139
  }
157
- /** The JSON object in the body of a request, or `undefined` when the body is too large or not a JSON object. */
158
140
  async function readMessage(request, maximumBytes) {
159
141
  const body = await readBounded(request, maximumBytes);
160
142
  return "text" in body ? parseObject(body.text) : void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acid-cat/mcp-handshake",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "Serve MCP clients of the revisions with an initialize handshake from an AcidCat MCP server through HTTP, with no state. Part of the TypeScript reference implementation.",
5
5
  "keywords": [
6
6
  "acidcat",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@acid-cat/spec-ts": "0.11.1"
34
+ "@acid-cat/spec-ts": "0.11.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "26.6.6",