From 6acd606a7e9e7192b786c1fcaf4e4c0ef5afdd67 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 21 Oct 2024 14:23:20 +0100 Subject: [PATCH] Use localStorage to remember last entered command and args --- client/src/App.tsx | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 4226d13..9ed40da 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -14,7 +14,7 @@ import { ServerNotification, EmptyResultSchema, } from "mcp-typescript/types.js"; -import { useState, useRef } from "react"; +import { useState, useRef, useEffect } from "react"; import { Send, Terminal, @@ -56,12 +56,18 @@ const App = () => { const [tools, setTools] = useState([]); const [toolResult, setToolResult] = useState(""); const [error, setError] = useState(null); - const [command, setCommand] = useState( - "/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node", - ); - const [args, setArgs] = useState( - "/Users/ashwin/code/mcp/example-servers/build/everything/stdio.js", - ); + const [command, setCommand] = useState(() => { + return ( + localStorage.getItem("lastCommand") || + "/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node" + ); + }); + const [args, setArgs] = useState(() => { + return ( + localStorage.getItem("lastArgs") || + "/Users/ashwin/code/mcp/example-servers/build/everything/stdio.js" + ); + }); const [url, setUrl] = useState("http://localhost:3001/sse"); const [transportType, setTransportType] = useState<"stdio" | "sse">("stdio"); const [requestHistory, setRequestHistory] = useState< @@ -84,6 +90,14 @@ const App = () => { const [nextToolCursor, setNextToolCursor] = useState(); const progressTokenRef = useRef(0); + useEffect(() => { + localStorage.setItem("lastCommand", command); + }, [command]); + + useEffect(() => { + localStorage.setItem("lastArgs", args); + }, [args]); + const pushHistory = (request: object, response: object) => { setRequestHistory((prev) => [ ...prev,