mcp-proxy 6.5.3 → 6.5.4

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { D as __toESM, E as __commonJSMin, a as startHTTPServer, i as Client, n as serializeMessage, o as proxyServer, r as Server, t as ReadBuffer, w as InMemoryEventStore } from "../stdio-DNR9B0BZ.mjs";
2
+ import { D as __toESM, E as __commonJSMin, a as startHTTPServer, i as Client, n as serializeMessage, o as proxyServer, r as Server, t as ReadBuffer, w as InMemoryEventStore } from "../stdio-BQunCFor.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { basename, dirname, extname, join, normalize, relative, resolve } from "path";
5
5
  import { format, inspect } from "util";
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as NEVER, S as _coercedNumber, T as AuthenticationMiddleware, _ as looseObject, a as startHTTPServer, b as string, c as LATEST_PROTOCOL_VERSION, d as isJSONRPCResultResponse, f as ZodNumber, g as literal, h as boolean, i as Client, l as isInitializedNotification, m as array, n as serializeMessage, o as proxyServer, p as any, r as Server, s as JSONRPCMessageSchema, t as ReadBuffer, u as isJSONRPCRequest, v as number$1, w as InMemoryEventStore, x as url, y as object } from "./stdio-DNR9B0BZ.mjs";
1
+ import { C as NEVER, S as _coercedNumber, T as AuthenticationMiddleware, _ as looseObject, a as startHTTPServer, b as string, c as LATEST_PROTOCOL_VERSION, d as isJSONRPCResultResponse, f as ZodNumber, g as literal, h as boolean, i as Client, l as isInitializedNotification, m as array, n as serializeMessage, o as proxyServer, p as any, r as Server, s as JSONRPCMessageSchema, t as ReadBuffer, u as isJSONRPCRequest, v as number$1, w as InMemoryEventStore, x as url, y as object } from "./stdio-BQunCFor.mjs";
2
2
  import process from "node:process";
3
3
 
4
4
  //#region node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/compat.js
@@ -15884,6 +15884,16 @@ const createJsonRpcErrorResponse = (code, message) => {
15884
15884
  jsonrpc: "2.0"
15885
15885
  });
15886
15886
  };
15887
+ const getRequestId = (body) => {
15888
+ if (typeof body !== "object" || body === null || Array.isArray(body) || !("id" in body)) return null;
15889
+ return body.id;
15890
+ };
15891
+ const isJsonRpcMessage = (message) => {
15892
+ return JSONRPCMessageSchema.safeParse(message).success;
15893
+ };
15894
+ const isJsonRpcBody = (body) => {
15895
+ return Array.isArray(body) ? body.every(isJsonRpcMessage) : isJsonRpcMessage(body);
15896
+ };
15887
15897
  const getWWWAuthenticateHeader = (oauth, options) => {
15888
15898
  if (!oauth) return;
15889
15899
  const params = [];
@@ -15903,6 +15913,23 @@ const getWWWAuthenticateHeader = (oauth, options) => {
15903
15913
  if (params.length === 0) return;
15904
15914
  return `Bearer ${params.join(", ")}`;
15905
15915
  };
15916
+ const sendSessionUnauthorizedResponse = ({ body, oauth, res }) => {
15917
+ const message = "Unauthorized: No valid session ID provided";
15918
+ res.setHeader("Content-Type", "application/json");
15919
+ const wwwAuthHeader = getWWWAuthenticateHeader(oauth, {
15920
+ error: "invalid_token",
15921
+ error_description: message
15922
+ });
15923
+ if (wwwAuthHeader) res.setHeader("WWW-Authenticate", wwwAuthHeader);
15924
+ res.writeHead(401).end(JSON.stringify({
15925
+ error: {
15926
+ code: -32e3,
15927
+ message
15928
+ },
15929
+ id: getRequestId(body),
15930
+ jsonrpc: "2.0"
15931
+ }));
15932
+ };
15906
15933
  const isScopeChallengeError = (error$1) => {
15907
15934
  return typeof error$1 === "object" && error$1 !== null && "name" in error$1 && error$1.name === "InsufficientScopeError" && "data" in error$1 && typeof error$1.data === "object" && error$1.data !== null && "error" in error$1.data && error$1.data.error === "insufficient_scope";
15908
15935
  };
@@ -16023,6 +16050,14 @@ const handleStreamRequest = async ({ activeTransports, authenticate, authMiddlew
16023
16050
  if (sessionId) {
16024
16051
  const activeTransport = activeTransports[sessionId];
16025
16052
  if (!activeTransport) {
16053
+ if (authenticate && isJsonRpcBody(body)) {
16054
+ sendSessionUnauthorizedResponse({
16055
+ body,
16056
+ oauth,
16057
+ res
16058
+ });
16059
+ return true;
16060
+ }
16026
16061
  res.setHeader("Content-Type", "application/json");
16027
16062
  res.writeHead(404).end(createJsonRpcErrorResponse(-32001, "Session not found"));
16028
16063
  return true;
@@ -16118,6 +16153,14 @@ const handleStreamRequest = async ({ activeTransports, authenticate, authMiddlew
16118
16153
  await transport.handleRequest(req, res, body);
16119
16154
  return true;
16120
16155
  } else {
16156
+ if (authenticate && isJsonRpcBody(body)) {
16157
+ sendSessionUnauthorizedResponse({
16158
+ body,
16159
+ oauth,
16160
+ res
16161
+ });
16162
+ return true;
16163
+ }
16121
16164
  res.setHeader("Content-Type", "application/json");
16122
16165
  res.writeHead(400).end(createJsonRpcErrorResponse(-32e3, "Bad Request: No valid session ID provided"));
16123
16166
  return true;
@@ -16145,10 +16188,24 @@ const handleStreamRequest = async ({ activeTransports, authenticate, authMiddlew
16145
16188
  res.writeHead(405, { Allow: "POST" }).end("Method Not Allowed");
16146
16189
  return true;
16147
16190
  }
16191
+ if (authenticate) {
16192
+ sendSessionUnauthorizedResponse({
16193
+ oauth,
16194
+ res
16195
+ });
16196
+ return true;
16197
+ }
16148
16198
  res.writeHead(400).end("No sessionId");
16149
16199
  return true;
16150
16200
  }
16151
16201
  if (!activeTransport) {
16202
+ if (authenticate) {
16203
+ sendSessionUnauthorizedResponse({
16204
+ oauth,
16205
+ res
16206
+ });
16207
+ return true;
16208
+ }
16152
16209
  res.writeHead(400).end("No active transport");
16153
16210
  return true;
16154
16211
  }
@@ -16162,12 +16219,26 @@ const handleStreamRequest = async ({ activeTransports, authenticate, authMiddlew
16162
16219
  console.log("[mcp-proxy] received delete request");
16163
16220
  const sessionId = req.headers["mcp-session-id"];
16164
16221
  if (!sessionId) {
16222
+ if (authenticate) {
16223
+ sendSessionUnauthorizedResponse({
16224
+ oauth,
16225
+ res
16226
+ });
16227
+ return true;
16228
+ }
16165
16229
  res.writeHead(400).end("Invalid or missing sessionId");
16166
16230
  return true;
16167
16231
  }
16168
16232
  console.log("[mcp-proxy] received delete request for session", sessionId);
16169
16233
  const activeTransport = activeTransports[sessionId];
16170
16234
  if (!activeTransport) {
16235
+ if (authenticate) {
16236
+ sendSessionUnauthorizedResponse({
16237
+ oauth,
16238
+ res
16239
+ });
16240
+ return true;
16241
+ }
16171
16242
  res.writeHead(400).end("No active transport");
16172
16243
  return true;
16173
16244
  }
@@ -24824,4 +24895,4 @@ function serializeMessage(message) {
24824
24895
 
24825
24896
  //#endregion
24826
24897
  export { NEVER as C, __toESM as D, __commonJSMin as E, _coercedNumber as S, AuthenticationMiddleware as T, looseObject as _, startHTTPServer as a, string as b, LATEST_PROTOCOL_VERSION as c, isJSONRPCResultResponse as d, ZodNumber as f, literal as g, boolean as h, Client as i, isInitializedNotification as l, array as m, serializeMessage as n, proxyServer as o, any as p, Server as r, JSONRPCMessageSchema as s, ReadBuffer as t, isJSONRPCRequest as u, number as v, InMemoryEventStore as w, url as x, object as y };
24827
- //# sourceMappingURL=stdio-DNR9B0BZ.mjs.map
24898
+ //# sourceMappingURL=stdio-BQunCFor.mjs.map