Skip to content

Commit

Permalink
Merge pull request #25 from modelcontextprotocol/justin/remember-ui
Browse files Browse the repository at this point in the history
Use localStorage to remember last entered command and args
  • Loading branch information
jspahrsummers authored Oct 22, 2024
2 parents bfa23c9 + 6acd606 commit b4c70ed
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -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,
@@ -57,12 +57,18 @@ const App = () => {
const [tools, setTools] = useState<Tool[]>([]);
const [toolResult, setToolResult] = useState<string>("");
const [error, setError] = useState<string | null>(null);
const [command, setCommand] = useState<string>(
"/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 [command, setCommand] = useState<string>(() => {
return (
localStorage.getItem("lastCommand") ||
"/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node"
);
});
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 [transportType, setTransportType] = useState<"stdio" | "sse">("stdio");
const [requestHistory, setRequestHistory] = useState<
@@ -85,6 +91,14 @@ const App = () => {
const [nextToolCursor, setNextToolCursor] = useState<string | undefined>();
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,

0 comments on commit b4c70ed

Please sign in to comment.