Commit graph inspector/server
Author SHA1 Message Date
Jerome
3207959af0
Linting 2025-06-13 16:04:25 +01:00
Felix Weinberger
17740daaf5
fix: address @jenn-newton comments
- Add authentication and origin validation middleware to /config endpoint
- Implement timing-safe token comparison using crypto.timingSafeEqual()
- Add config read to initial env setup s.t. /config call is authenticated
2025-06-12 18:30:56 +01:00
Felix Weinberger
9dbd17343c
feat: disable auto-open when authentication is enabled
- Auto-open browser only works when DANGEROUSLY_OMIT_AUTH=true
- When auth is enabled (default), users must use the secure URL with token
- Server displays clear message that auto-open is disabled with auth
- Updates documentation to reflect this behavior

This improves UX by preventing the browser from opening without auth token,
forcing users to use the secure pre-filled URL instead.
2025-06-10 18:16:38 +01:00
Felix Weinberger
15ecb59a96
feat: add origin validation to prevent DNS rebinding attacks
- Add origin validation middleware to check Origin header
- Default allowed origins respect CLIENT_PORT environment variable
- Support ALLOWED_ORIGINS environment variable for additional origins
- Apply validation to all protected endpoints before auth check
- Return 403 Forbidden with clear message for invalid origins
- Add DNS Rebinding Protection section to README

This completes the security hardening by preventing malicious websites
from making requests to the local proxy server.
2025-06-10 18:16:35 +01:00
Felix Weinberger
111e282386
feat: add session token authentication to proxy server
- Generate random session token on server startup using crypto.randomBytes
- Add authentication middleware requiring Bearer token for all sensitive endpoints
- Apply auth to /mcp, /stdio, /sse, and /message endpoints
- Display session token in console on startup
- Add DANGEROUSLY_OMIT_AUTH environment variable to disable auth for development
- Update README with authentication documentation

This prevents unauthorized access to the proxy server's ability to execute
local processes and connect to MCP servers.
2025-06-10 18:16:28 +01:00
Felix Weinberger
e8e990987c
fix: bind to localhost by default to prevent DNS rebinding attacks
- Change default binding from 0.0.0.0 (all interfaces) to 127.0.0.1 (localhost only)
- Add HOST environment variable to override binding address when needed
- Update console output to show actual binding address
- Document security change in README with warnings about binding to all interfaces

This prevents remote attackers from accessing the MCP Inspector proxy server,
which has the ability to execute local processes. The proxy should only be
accessible from the local machine unless explicitly configured otherwise.
2025-06-10 18:16:24 +01:00
Cliff Hall
cf07937f8e
Merge branch 'main' into normalize-connection-logging 2025-06-05 16:55:27 -04:00
cliffhall
8ef91e359e Bump Inspector packages to 0.14.0, and sdk to 1.12.1 2025-06-04 16:13:35 -04:00
cliffhall
c485e57a39 Add reporting of the Proxy <-> Server sessionId. It's only possible to get the session id for this leg of the proxy if it is a StreamableHttp connection.
* In server/src/index.ts
  - slight format tweak of the Client <-> Proxy message so that the two messages will line up when displayed
* In server/src/mcpProxy.ts
  - add reportedServerSession boolean initialized to false
  - in transportToServer.onmessage,
    - if reportedServerSession isn't set yet, report the sessionId if present on the transport, and then set reportedServerSession to true
2025-06-03 17:46:57 -04:00
Cliff Hall
789c90cc0b
Merge branch 'main' into normalize-connection-logging 2025-06-02 10:25:30 -04:00
Cliff Hall
7df0ac40c5
Merge pull request #470 from cliffhall/send-delete-on-streamable-http-disconnect
Send HTTP DELETE on streamable transport disconnect
2025-06-02 10:05:30 -04:00
Cliff Hall
021e6a423b
Merge branch 'main' into fix/header 2025-05-30 18:39:01 -04:00
cliffhall
b732ab4085 prettier 2025-05-30 17:51:22 -04:00
cliffhall
2df723804b Normalize the reporting of connection setup and connection errors. The logging is verbose and different for every server type. This is an attempt to make the console output cleaner and more readable.
* In server/index.js
  - in createTransport()
    - stringify query params to put them on one line
    - remove logging of transport creation (done in callers)
  - in /mcp POST handler
    - report POST request if session id is present
    - otherwise, report new StreamableHttp connection request
    - report creation of server transport
    - report creation of client transport
  - in /stdio GET handler
    - report new STDIO connection request
    - report creation of server transport
    - report creation of client transport
    - report 401 as authentication error without stack
    - in stderr data handler
      - if it includes "MODULE_NOT_FOUND"
        - report "Command not found"
        - remove transports
      - otherwise send to client as usual
  - in /sse GET handler
    - report SSE connection request
    - report 401 as authentication error without stack
    - report 404 as server that may not support SSE
    - report error with "ECONNREFUSED" as "Connection refused" without stack
    - only create, map, and proxy transports if serverTransport was successfully created
  - in /message POST handler
    - report received POST message

* In mcpProxy.ts
  - in onServerError()
    - if error message includes 404 OR error.cause includes ECONNREFUSED, report "Connection refused."
2025-05-30 17:13:53 -04:00
xiaoli
3510e1a561 fix: preserve capitalization in custom headers
Express converts all header names to lowercase, which prevents custom headers with uppercase characters from being properly passed to the target service. This fix ensures that custom headers preserve their original capitalization when forwarded through the proxy.
2025-05-30 21:34:40 +08:00
cliffhall
02aacb46a2 Send HTTP/DELETE when disconnecting client
* In server/src/index.ts
  - add delete handler for /mcp endpoint
    - gets the server transport for the sessionId
    - calls terminateSession on it
    - removes the webapp and server transports for the sessionId from the maps
    - returns status 200 to the client.

* In client/src/lib/hooks/useConnection.ts
  - import Transport
  - add useState for clientTransport, type Transport or null initialized to null
  - in connect() function
    - move creation of client transport down a ways, just before calling client.connect with it
    - immendiately efter calling client.connect, call setClientTransport with the connected transport (has to happen after, so that what's saved has the abort controller, etc. otherwise it doesn't work to save it prior.
    - in disconnect() function
      - immediately call clientTransport.terminateSession if transportType is "streamable-http"
      - setClientTransport to null
2025-05-29 19:54:36 -04:00
Xiaoli
ee8c29b3ad
Merge branch 'main' into fix/header 2025-05-29 23:30:11 +08:00
cliffhall
0c1962c2d0 prettier 2025-05-28 15:46:07 -04:00
cliffhall
9bc6bd725e Address [comment](https://github.com/modelcontextprotocol/inspector/pull/428/files/f04470ace7080f53233d1387e2dbb4d232bd5f7d#r2109509222) [by](https://github.com/modelcontextprotocol/inspector/pull/428/files/f04470ace7080f53233d1387e2dbb4d232bd5f7d#r2108137150) @olaservo 2025-05-28 13:46:58 -04:00
cliffhall
bc90f11dc8 Address [comment](https://github.com/modelcontextprotocol/inspector/pull/428/files/f04470ace7080f53233d1387e2dbb4d232bd5f7d#r2109509222) by @olaservo 2025-05-28 13:44:55 -04:00
Cliff Hall
692c863f5b
Revert "fix: handle the client disconnect so that the server does not crash." 2025-05-28 12:56:55 -04:00
xiaoli
2870441fea fix: fix review comments, again😉
- Remove unnecessary auth header name check
- Extract operations on headers into a function
2025-05-25 11:17:37 +08:00
cliffhall
f04470ace7 Allow multiple client connections to the MCP server, by making a unique server tranpsort for each web app transport.
* In server/src/index.ts
  - add serverTransports map

  - remove backingServerTransport var

  - in /mcp POST handler, when a new connection is being made
    - create a server transport
    - map the server transport using the session id from the web app connection
    - pass serverTransport to the mcpProxy instead of backingServerTransport

  - in /stdio GET handler, when a new connection is being made
    - create a server transport
    - map the server transport using the session id from the web app connection
    - pass serverTransport to the mcpProxy instead of backingServerTransport

  - in /sse GET handler, when a new connection is being made
    - create a server transport
    - map the server transport using the session id from the web app connection
    - pass serverTransport to the mcpProxy instead of backingServerTransport
2025-05-21 17:45:19 -04:00
Cliff Hall
efa4959ec4
Merge branch 'main' into main 2025-05-21 16:27:13 -04:00
ihrpr
7cf85b526a
update TS sdk 2025-05-21 20:56:25 +01:00
ihrpr
b0db14c3a7
0.13.0 bump version 2025-05-21 20:33:19 +01:00
Shane
a61a1b0df2
format update with prettier 2025-05-20 09:25:47 -07:00
xiaoli
13f736033a fix: fix review comments
- Avoid calling .lowerCase twice
- Keep 'Bearer ' prefix when header equals 'Authorization'
- Remove unnecessary Array type checks
2025-05-20 13:10:55 +08:00
xiaoli
618f24a9ac feat: support custom authorization headers, fix #395 2025-05-20 10:38:03 +08:00
ihrpr
2f6a9fca11
format 2025-05-19 19:03:22 +01:00
ihrpr
13eb077329
fix auth conect 2025-05-19 18:29:42 +01:00
Shane
7df1936b3c
fixed the error handling in async call 2025-05-18 23:33:19 -07:00
Shane
b9b3682350
format fix 2025-05-18 21:45:39 -07:00
Shane
fa236ea2c7
handle the case that client disconnects so that the server does not crash 2025-05-18 21:45:38 -07:00
Ola Hungerford
f7b936e102 Bump version to 0.12.0 2025-05-07 05:28:24 -07:00
kavinkumarbaskar
b00b271d65 fix: upgrade package json in cli, client, and server 2025-05-06 00:16:06 +05:30
cliffhall
b3fc199d25 Bump release to 0.11.0
* In main.yml
  - reversed a change from last release that did an explicit build, because the prepare script was no longer in package.json
* In package.json
  - replaced prepare script, which will cause automatic build after npm install
  - set version to 0.11.0
  - set versions of inspector-cli, inspector-client, and inspector-server to  ^0.11.0
* In package.lock.json
  - updated versions of inspector, inspector-cli, inspector-client, and inspector-server to  ^0.11.0
* In cli/package.json
  - set version to 0.11.0
  - set versions of sdk to 1.10.2
* In client/package.json
  - set version to 0.11.0
  - set versions of sdk to 1.10.2
* In server/package.json
  - set version to 0.11.0
  - set versions of sdk to 1.10.2
2025-04-25 11:49:39 -04:00
cliffhall
5d0c3c48f6 Prettier 2025-04-24 12:01:02 -04:00
cliffhall
7b9cd1e74d In server/index.ts
- Add last-event-id to STREAMABLE_HTTP_HEADERS_PASSTHROUGH.
2025-04-24 11:39:48 -04:00
Shiv Deepak Muddada
1ec4e3b556 fix cors issue with accessing mcp-session-id header 2025-04-23 01:43:49 -07:00
cliffhall
6e4dcd6120 WIP: Attempting to proxy streamable-http connections. Inspector still works fine with STDIO and SSE servers.
* In index.ts,
  - refactor transport webAppTransports to be a map with the session id as key and transport as value.

* Implement /mcp GET and POST endpoints using StreamableHTTPServerTransport and doing the new session in the POST (opposite from SSE) handler.

* In package.json
  - update the SDK to 1.10.2

* In useConnection.ts
  - import StreamableHTTPClientTransport
    - NOTE: while we NEED to do this, it causes useConnection.test.ts to fail with " ReferenceError: TransformStream is not defined"
  - in connect method
    - instantiate the appropriate transport
2025-04-22 18:25:47 -04:00
cliffhall
3a2e248527 Prettier 2025-04-21 11:40:01 -04:00
cliffhall
e5f6524eb6 Fix support for streamable-http connections.
* In server/index.js
  - add get/post handlers for /mcp
  - amend console log on SSE connect, with deprecation message
  - add /stdio GET handler and refactored /sse GET handler to not also do stdio. Each transport has its own handler now
  - add appropriate headers to streamable-http request

* In /client/src/lib/hooks/useConnection.ts
  - in connect function
    - create server url properly based on new transport type.
2025-04-21 11:34:55 -04:00
Shiv Deepak Muddada
8213402185 attach auth headers to the streamable http request 2025-04-17 21:34:17 -07:00
Shiv Deepak Muddada
36178632fc
Merge branch 'main' into main 2025-04-17 21:33:53 -07:00
David Soria Parra
bbe4924c88
bump 2025-04-18 00:08:56 +01:00
cliffhall
2720d68417 Bump inspector, cli, client, server to 0.10.1 2025-04-17 18:11:41 -04:00
Cliff Hall
b3971259d2
Merge branch 'main' into main 2025-04-17 16:40:48 -04:00
cliffhall
958c9a36f1 Bump typescript-sdk version to 1.10.0 throughout 2025-04-17 15:42:56 -04:00
cliffhall
92bf9abb40 Bump version to 0.10.0 in
* cli/package.json
* client/package.json
* server/package.json
* package.json
  - also bump npm dependencies for cli, client, and server to 0.10.0
* package-lock.json
2025-04-17 14:21:22 -04:00