Use localStorage to remember last entered command and args

This commit is contained in:
Justin Spahr-Summers
2024-10-21 14:23:20 +01:00
parent 567c15a1cf
commit 6acd606a7e

View File

@@ -14,7 +14,7 @@ import {
ServerNotification, ServerNotification,
EmptyResultSchema, EmptyResultSchema,
} from "mcp-typescript/types.js"; } from "mcp-typescript/types.js";
import { useState, useRef } from "react"; import { useState, useRef, useEffect } from "react";
import { import {
Send, Send,
Terminal, Terminal,
@@ -56,12 +56,18 @@ const App = () => {
const [tools, setTools] = useState<Tool[]>([]); const [tools, setTools] = useState<Tool[]>([]);
const [toolResult, setToolResult] = useState<string>(""); const [toolResult, setToolResult] = useState<string>("");
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [command, setCommand] = useState<string>( const [command, setCommand] = useState<string>(() => {
"/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node", return (
localStorage.getItem("lastCommand") ||
"/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node"
); );
const [args, setArgs] = useState<string>( });
"/Users/ashwin/code/mcp/example-servers/build/everything/stdio.js", const [args, setArgs] = useState<string>(() => {
return (
localStorage.getItem("lastArgs") ||
"/Users/ashwin/code/mcp/example-servers/build/everything/stdio.js"
); );
});
const [url, setUrl] = useState<string>("http://localhost:3001/sse"); const [url, setUrl] = useState<string>("http://localhost:3001/sse");
const [transportType, setTransportType] = useState<"stdio" | "sse">("stdio"); const [transportType, setTransportType] = useState<"stdio" | "sse">("stdio");
const [requestHistory, setRequestHistory] = useState< const [requestHistory, setRequestHistory] = useState<
@@ -84,6 +90,14 @@ const App = () => {
const [nextToolCursor, setNextToolCursor] = useState<string | undefined>(); const [nextToolCursor, setNextToolCursor] = useState<string | undefined>();
const progressTokenRef = useRef(0); const progressTokenRef = useRef(0);
useEffect(() => {
localStorage.setItem("lastCommand", command);
}, [command]);
useEffect(() => {
localStorage.setItem("lastArgs", args);
}, [args]);
const pushHistory = (request: object, response: object) => { const pushHistory = (request: object, response: object) => {
setRequestHistory((prev) => [ setRequestHistory((prev) => [
...prev, ...prev,