Skip to content

Implement auto-open feature for browser launch on server start #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The MCP Inspector supports the following configuration settings. To change them,
| `MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS` | Reset timeout on progress notifications | true |
| `MCP_REQUEST_MAX_TOTAL_TIMEOUT` | Maximum total timeout for requests sent to the MCP server (ms) (Use with progress notifications) | 60000 |
| `MCP_PROXY_FULL_ADDRESS` | Set this if you are running the MCP Inspector Proxy on a non-default address. Example: http://10.1.1.22:5577 | "" |
| `MCP_AUTO_OPEN_ENABLED` | Enable automatic browser opening when inspector starts | true |

These settings can be adjusted in real-time through the UI and will persist across sessions.

Expand Down
4 changes: 4 additions & 0 deletions client/bin/start.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

import open from "open";
import { resolve, dirname } from "path";
import { spawnPromise } from "spawn-rx";
import { fileURLToPath } from "url";
Expand Down Expand Up @@ -99,6 +100,9 @@ async function main() {

if (serverOk) {
try {
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
open(`http://127.0.0.1:${CLIENT_PORT}`);
}
await spawnPromise("node", [inspectorClientPath], {
env: { ...process.env, PORT: CLIENT_PORT },
signal: abort.signal,
Expand Down
20 changes: 16 additions & 4 deletions client/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ const Sidebar = ({
/>
) : typeof configItem.value === "boolean" ? (
<Select
data-testid={`${configKey}-select`}
value={configItem.value.toString()}
onValueChange={(val) => {
const newConfig = { ...config };
Expand All @@ -415,12 +414,25 @@ const Sidebar = ({
setConfig(newConfig);
}}
>
<SelectTrigger id={`${configKey}-input`}>
<SelectTrigger
id={`${configKey}-input`}
data-testid={`${configKey}-input`}
>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="true">True</SelectItem>
<SelectItem value="false">False</SelectItem>
<SelectItem
data-testid={`${configKey}-input-true`}
value="true"
>
True
</SelectItem>
<SelectItem
data-testid={`${configKey}-input-false`}
value="false"
>
False
</SelectItem>
</SelectContent>
</Select>
) : (
Expand Down
27 changes: 27 additions & 0 deletions client/src/components/__tests__/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,33 @@ describe("Sidebar Environment Variables", () => {
);
});

it("should update auto browser open disabled", () => {
const setConfig = jest.fn();
renderSidebar({ config: DEFAULT_INSPECTOR_CONFIG, setConfig });

openConfigSection();

const autoOpenDisabledInput = screen.getByTestId(
"MCP_AUTO_OPEN_ENABLED-input",
);
fireEvent.click(autoOpenDisabledInput);
const falseOption = screen.getByTestId(
"MCP_AUTO_OPEN_ENABLED-input-false",
);
fireEvent.click(falseOption);

expect(setConfig).toHaveBeenCalledWith(
expect.objectContaining({
MCP_AUTO_OPEN_ENABLED: {
label: "Auto Browser Open Enabled",
description:
"Enable automatic browser opening when inspector starts",
value: false,
},
}),
);
});

it("should maintain configuration state after multiple updates", () => {
const setConfig = jest.fn();
const { rerender } = renderSidebar({
Expand Down
5 changes: 5 additions & 0 deletions client/src/lib/configurationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ export type InspectorConfig = {
* The full address of the MCP Proxy Server, in case it is running on a non-default address. Example: http://10.1.1.22:5577
*/
MCP_PROXY_FULL_ADDRESS: ConfigItem;

/**
* Disable automatic browser opening when inspector starts.
*/
MCP_AUTO_OPEN_ENABLED: ConfigItem;
};
5 changes: 5 additions & 0 deletions client/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ export const DEFAULT_INSPECTOR_CONFIG: InspectorConfig = {
"Set this if you are running the MCP Inspector Proxy on a non-default address. Example: http://10.1.1.22:5577",
value: "",
},
MCP_AUTO_OPEN_ENABLED: {
label: "Auto Browser Open Enabled",
description: "Enable automatic browser opening when inspector starts",
value: true,
},
} as const;
141 changes: 141 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@modelcontextprotocol/inspector-server": "^0.10.2",
"@modelcontextprotocol/sdk": "^1.10.0",
"concurrently": "^9.0.1",
"open": "^10.1.0",
"shell-quote": "^1.8.2",
"spawn-rx": "^5.1.2",
"ts-node": "^10.9.2",
Expand Down