@orkestrel/mcp 0.0.34 → 0.0.36

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.
@@ -249,6 +249,8 @@ var JSONRPC_INTERNAL_ERROR = -32603;
249
249
  * Retained for the legacy branch alone. A modern fault answers
250
250
  * {@link JSONRPC_INTERNAL_ERROR}; this code survives only where an old-wire peer was
251
251
  * already characterized against it.
252
+ * A `handshake` hook that rejects with an `MCPError` answers the legacy `initialize`
253
+ * with that error's own code and data.
252
254
  */
253
255
  var JSONRPC_SERVER_ERROR = -32e3;
254
256
  /**
@@ -4752,6 +4754,23 @@ var MCPLegacy = class {
4752
4754
  }) === void 0) return buildJSONRPCError(void 0, JSONRPC_INVALID_REQUEST, "Invalid Request");
4753
4755
  switch (invocation.method) {
4754
4756
  case "initialize": {
4757
+ if (this.#options.handshake !== void 0) {
4758
+ const closure = new AbortController();
4759
+ const resolved = buildMethodOptions(options ?? {}, closure.signal);
4760
+ try {
4761
+ await this.#options.handshake(resolved);
4762
+ } catch (error) {
4763
+ if (resolved.signal.aborted) throw error;
4764
+ if (isMCPError(error)) {
4765
+ const context = (0, _orkestrel_contract.attempt)(() => (0, _orkestrel_contract.parseJSON)(JSON.stringify(error.context)));
4766
+ return buildJSONRPCError(id, error.code, error.message, context.success ? context.value : void 0);
4767
+ }
4768
+ this.emitter.emit("error", error);
4769
+ return buildJSONRPCError(id, JSONRPC_INTERNAL_ERROR, "Server error");
4770
+ } finally {
4771
+ closure.abort();
4772
+ }
4773
+ }
4755
4774
  const requested = invocation.params?.["protocolVersion"];
4756
4775
  return buildJSONRPCResult(id, buildInitializeResult(this.#options.identity.name, this.#options.identity.version, (0, _orkestrel_contract.isString)(requested) ? requested : void 0));
4757
4776
  }
@@ -5111,6 +5130,9 @@ var MCPServer = class {
5111
5130
  get identity() {
5112
5131
  return this.#options.identity;
5113
5132
  }
5133
+ get handshake() {
5134
+ return this.#options.handshake;
5135
+ }
5114
5136
  get methods() {
5115
5137
  return this.#methods;
5116
5138
  }
@@ -6753,7 +6775,8 @@ function createMCPServer(options) {
6753
6775
  function createMCPLegacy(server) {
6754
6776
  return new MCPLegacy({
6755
6777
  dispatcher: server,
6756
- identity: server.identity
6778
+ identity: server.identity,
6779
+ ...server.handshake === void 0 ? {} : { handshake: server.handshake }
6757
6780
  });
6758
6781
  }
6759
6782
  /**