Skip to content

Commit b4c70ed

Browse files
Merge pull request modelcontextprotocol#25 from modelcontextprotocol/justin/remember-ui
Use localStorage to remember last entered command and args
2 parents bfa23c9 + 6acd606 commit b4c70ed

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

client/src/App.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
ServerNotification,
1515
EmptyResultSchema,
1616
} from "mcp-typescript/types.js";
17-
import { useState, useRef } from "react";
17+
import { useState, useRef, useEffect } from "react";
1818
import {
1919
Send,
2020
Terminal,
@@ -57,12 +57,18 @@ const App = () => {
5757
const [tools, setTools] = useState<Tool[]>([]);
5858
const [toolResult, setToolResult] = useState<string>("");
5959
const [error, setError] = useState<string | null>(null);
60-
const [command, setCommand] = useState<string>(
61-
"/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node",
62-
);
63-
const [args, setArgs] = useState<string>(
64-
"/Users/ashwin/code/mcp/example-servers/build/everything/stdio.js",
65-
);
60+
const [command, setCommand] = useState<string>(() => {
61+
return (
62+
localStorage.getItem("lastCommand") ||
63+
"/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node"
64+
);
65+
});
66+
const [args, setArgs] = useState<string>(() => {
67+
return (
68+
localStorage.getItem("lastArgs") ||
69+
"/Users/ashwin/code/mcp/example-servers/build/everything/stdio.js"
70+
);
71+
});
6672
const [url, setUrl] = useState<string>("http://localhost:3001/sse");
6773
const [transportType, setTransportType] = useState<"stdio" | "sse">("stdio");
6874
const [requestHistory, setRequestHistory] = useState<
@@ -85,6 +91,14 @@ const App = () => {
8591
const [nextToolCursor, setNextToolCursor] = useState<string | undefined>();
8692
const progressTokenRef = useRef(0);
8793

94+
useEffect(() => {
95+
localStorage.setItem("lastCommand", command);
96+
}, [command]);
97+
98+
useEffect(() => {
99+
localStorage.setItem("lastArgs", args);
100+
}, [args]);
101+
88102
const pushHistory = (request: object, response: object) => {
89103
setRequestHistory((prev) => [
90104
...prev,

0 commit comments

Comments
 (0)