@mcp-index/sdk 0.18.0 → 0.19.0

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.md +178 -0
  3. package/dist/src/ai.d.ts +96 -0
  4. package/dist/src/ai.d.ts.map +1 -0
  5. package/dist/src/ai.js +151 -0
  6. package/dist/src/ai.js.map +1 -0
  7. package/dist/src/lock/check.d.ts +143 -0
  8. package/dist/src/lock/check.d.ts.map +1 -0
  9. package/dist/src/lock/check.js +274 -0
  10. package/dist/src/lock/check.js.map +1 -0
  11. package/dist/src/lock/digest.d.ts +48 -0
  12. package/dist/src/lock/digest.d.ts.map +1 -0
  13. package/dist/src/lock/digest.js +234 -0
  14. package/dist/src/lock/digest.js.map +1 -0
  15. package/dist/src/lock/events.d.ts +82 -0
  16. package/dist/src/lock/events.d.ts.map +1 -0
  17. package/dist/src/lock/events.js +80 -0
  18. package/dist/src/lock/events.js.map +1 -0
  19. package/dist/src/lock/index.d.ts +20 -0
  20. package/dist/src/lock/index.d.ts.map +1 -0
  21. package/dist/src/lock/index.js +14 -0
  22. package/dist/src/lock/index.js.map +1 -0
  23. package/dist/src/lock/lock.d.ts +195 -0
  24. package/dist/src/lock/lock.d.ts.map +1 -0
  25. package/dist/src/lock/lock.js +1075 -0
  26. package/dist/src/lock/lock.js.map +1 -0
  27. package/dist/src/lock/pg.d.ts +150 -0
  28. package/dist/src/lock/pg.d.ts.map +1 -0
  29. package/dist/src/lock/pg.js +539 -0
  30. package/dist/src/lock/pg.js.map +1 -0
  31. package/dist/src/lock/rawList.d.ts +127 -0
  32. package/dist/src/lock/rawList.d.ts.map +1 -0
  33. package/dist/src/lock/rawList.js +561 -0
  34. package/dist/src/lock/rawList.js.map +1 -0
  35. package/dist/src/lock/signing.d.ts +35 -0
  36. package/dist/src/lock/signing.d.ts.map +1 -0
  37. package/dist/src/lock/signing.js +85 -0
  38. package/dist/src/lock/signing.js.map +1 -0
  39. package/dist/src/lock/store.d.ts +149 -0
  40. package/dist/src/lock/store.d.ts.map +1 -0
  41. package/dist/src/lock/store.js +459 -0
  42. package/dist/src/lock/store.js.map +1 -0
  43. package/dist/src/wrap.d.ts.map +1 -1
  44. package/dist/src/wrap.js +85 -3
  45. package/dist/src/wrap.js.map +1 -1
  46. package/package.json +31 -2
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Lock mode for the official MCP TypeScript client, at the transport.
3
+ *
4
+ * `Client.listTools()` returns tools after its zod schema has stripped unknown
5
+ * members, so a digest over that result is not a digest over what the server
6
+ * sent. LockedTransport sits between the Client and its real Transport and
7
+ * works on the parsed JSON-RPC message instead. The transports parse each
8
+ * message with JSON.parse and check only the envelope, so every member inside
9
+ * `result.tools`, `__proto__` included, is still there as sent.
10
+ *
11
+ * For a `tools/list` request from the client it:
12
+ * - starts a listing (section 9.2.1) when it sends the request. Until the
13
+ * listing is decided or fails, every `tools/call` is refused with
14
+ * `no-listing`. A second cursorless `tools/list` abandons the first, whose
15
+ * request is answered with an error;
16
+ * - classifies every frame from the server as section 9.2.2 says
17
+ * (classifyFrame): only the response to an unanswered `tools/list`,
18
+ * matched by id with exact JSON type and value, can carry tools, and only
19
+ * that or the `initialize` or `server/discover` response can carry
20
+ * instructions. Anything else that carries them, or has both a method and
21
+ * a result or error, is dropped and reported to onerror. A client request
22
+ * whose id it matches is answered with an error under that id and is no
23
+ * longer pending; when that request is the listing's, or one of its page
24
+ * requests, the listing fails. A response whose id matches no request is
25
+ * dropped too;
26
+ * - follows `nextCursor` itself, sending its own page requests under private
27
+ * ids, so one listing is every page (section 9.2). The client gets one
28
+ * response with every shown tool and no cursor. A client request that
29
+ * carries a cursor is answered with an error, since there is no partial
30
+ * listing in lock mode;
31
+ * - loads a lock snapshot, runs checkListing on the raw tools, installs the
32
+ * decision in the CallGate, emits a listing event, and passes on only the
33
+ * shown raw entries, without a top-level `_meta` that the decision removes
34
+ * (section 9.2.3). The client then parses exactly those.
35
+ *
36
+ * Every outgoing `tools/call` goes through the CallGate first. A refused call
37
+ * is never sent; the client gets a -32011 error with data.reason. This covers
38
+ * callTool, request, requestStream and the task helpers alike, because they
39
+ * all end in Transport.send. A call on a snapshot older than maxStalenessMs
40
+ * (default 60 s) reloads it first; the reload can only shrink the allow-list,
41
+ * and if it fails the call gets `lock-stale` and the next call tries again.
42
+ *
43
+ * `notifications/tools/list_changed` is passed on and marks a listing as due.
44
+ * It does not change the allow-list, and this adapter does not start a
45
+ * listing on its own (the spec's SHOULD); the client asks for one. A listing
46
+ * that fails (an error response, a result with no tools array, a page that
47
+ * cannot be requested or gets no response, a page or tool limit exceeded)
48
+ * refuses every call with `unreachable` until a listing completes (section
49
+ * 9.5). Server instructions arrive in the initialize or server/discover
50
+ * result; they are checked there and stripped when the check says so.
51
+ *
52
+ * Unanswered requests are tracked in bounded maps. An entry leaves on its
53
+ * response, on the client's notifications/cancelled, after REQUEST_TTL_MS, or,
54
+ * when the map is full, oldest first. If that entry is the listing in
55
+ * progress, the listing fails.
56
+ *
57
+ * Lock mode has no auto-accept, first-use pin or re-pin, and this adapter
58
+ * takes no option that would add one.
59
+ */
60
+ import type { JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
61
+ import type { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
62
+ import { CallGate, DEFAULT_MAX_STALENESS_MS } from "./check.js";
63
+ import type { Decision } from "./check.js";
64
+ import type { LockEventSink } from "./events.js";
65
+ import type { Identity, Posture } from "./lock.js";
66
+ import type { LockStore } from "./store.js";
67
+ /** Pages and tools one listing may span before the server is treated as unreachable. */
68
+ export declare const MAX_LIST_PAGES = 100;
69
+ export declare const MAX_LIST_TOOLS = 10000;
70
+ /** Unanswered requests tracked at once; past this the oldest is forgotten. */
71
+ export declare const MAX_OUTSTANDING = 4096;
72
+ /** Age after which an unanswered request is forgotten (its late response is dropped). */
73
+ export declare const REQUEST_TTL_MS = 600000;
74
+ export { DEFAULT_MAX_STALENESS_MS };
75
+ export interface LockOptions {
76
+ readonly store: LockStore;
77
+ /** This server's identity (section 3), from host configuration. */
78
+ readonly identity: Identity;
79
+ readonly posture: Posture;
80
+ /** The host name written into events. */
81
+ readonly host?: string;
82
+ readonly sink?: LockEventSink;
83
+ /**
84
+ * Age after which a call reloads the snapshot, so a revoke reaches a live
85
+ * connection; if the reload fails the call gets lock-stale. Default 60 s.
86
+ */
87
+ readonly maxStalenessMs?: number;
88
+ readonly now?: () => number;
89
+ }
90
+ /** Section 9.2.2: `id` equals one of `ids` in JSON type and value. Null matches nothing. */
91
+ export declare function idMatches(id: unknown, ids: readonly unknown[]): boolean;
92
+ /** Requests whose response may carry instructions (section 9.2.2). */
93
+ export declare const HANDSHAKE_METHODS: readonly string[];
94
+ export type FrameKind = "listing" | "handshake" | "drop" | "relay";
95
+ /**
96
+ * What the host does with one frame from the server (section 9.2.2):
97
+ * `listing` (a page of the listing whose request it answers), `handshake`
98
+ * (the initialize or server/discover response; its instructions are
99
+ * checked), `drop`, or `relay`. `isInflight` and `isHandshake` say whether an
100
+ * id matches an unanswered tools/list or handshake request; unanswered
101
+ * tools/list requests are matched first.
102
+ */
103
+ export declare function classifyFrame(frame: unknown, isInflight: (id: unknown) => boolean, isHandshake: (id: unknown) => boolean): FrameKind;
104
+ export declare class LockedTransport implements Transport {
105
+ #private;
106
+ onclose?: () => void;
107
+ onerror?: (error: Error) => void;
108
+ onmessage?: <T extends JSONRPCMessage>(message: T, extra?: MessageExtraInfo) => void;
109
+ readonly gate: CallGate;
110
+ constructor(inner: Transport, options: LockOptions);
111
+ get sessionId(): string | undefined;
112
+ setProtocolVersion(version: string): void;
113
+ /** True after a list_changed notification until the next listing completes. */
114
+ get listingDue(): boolean;
115
+ /** The decision for the latest complete listing on this connection, or null. */
116
+ get decision(): Decision | null;
117
+ start(): Promise<void>;
118
+ close(): Promise<void>;
119
+ send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
120
+ }
121
+ /** Anything with the Client.connect signature. */
122
+ export interface ConnectableClient {
123
+ connect(transport: Transport): Promise<void>;
124
+ }
125
+ /** Wrap `transport` in lock mode and connect `client` through it. */
126
+ export declare function lockClient(client: ConnectableClient, transport: Transport, options: LockOptions): Promise<LockedTransport>;
127
+ //# sourceMappingURL=rawList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rawList.d.ts","sourceRoot":"","sources":["../../../src/lock/rawList.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AAErG,OAAO,EAAE,QAAQ,EAAE,wBAAwB,EAA4D,MAAM,YAAY,CAAC;AAC1H,OAAO,KAAK,EAAc,QAAQ,EAAc,MAAM,YAAY,CAAC;AAEnE,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,QAAQ,EAAmB,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpE,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1D,wFAAwF;AACxF,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,8EAA8E;AAC9E,eAAO,MAAM,eAAe,OAAQ,CAAC;AACrC,yFAAyF;AACzF,eAAO,MAAM,cAAc,SAAU,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,CAAC;AAIpC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,C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