Merge pull request #58 from modelcontextprotocol/justin/upgrade-sdk

Upgrade to SDK 0.5.0, add default request timeout
This commit is contained in:
Justin Spahr-Summers
2024-11-16 16:02:54 +00:00
committed by GitHub
5 changed files with 46 additions and 16 deletions

View File

@@ -22,7 +22,7 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/sdk": "*", "@modelcontextprotocol/sdk": "0.5.0",
"@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0", "@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-select": "^2.1.2", "@radix-ui/react-select": "^2.1.2",

View File

@@ -53,6 +53,8 @@ import SamplingTab, { PendingRequest } from "./components/SamplingTab";
import Sidebar from "./components/Sidebar"; import Sidebar from "./components/Sidebar";
import ToolsTab from "./components/ToolsTab"; import ToolsTab from "./components/ToolsTab";
const DEFAULT_REQUEST_TIMEOUT_MSEC = 10000;
const App = () => { const App = () => {
const [connectionStatus, setConnectionStatus] = useState< const [connectionStatus, setConnectionStatus] = useState<
"disconnected" | "connected" | "error" "disconnected" | "connected" | "error"
@@ -220,7 +222,19 @@ const App = () => {
} }
try { try {
const response = await mcpClient.request(request, schema); const abortController = new AbortController();
const timeoutId = setTimeout(() => {
abortController.abort("Request timed out");
}, DEFAULT_REQUEST_TIMEOUT_MSEC);
let response;
try {
response = await mcpClient.request(request, schema, {
signal: abortController.signal,
});
} finally {
clearTimeout(timeoutId);
}
pushHistory(request, response); pushHistory(request, response);
if (tabKey !== undefined) { if (tabKey !== undefined) {
@@ -229,10 +243,14 @@ const App = () => {
return response; return response;
} catch (e: unknown) { } catch (e: unknown) {
const errorString = (e as Error).message ?? String(e);
if (tabKey === undefined) { if (tabKey === undefined) {
toast.error((e as Error).message); toast.error(errorString);
} else { } else {
setErrors((prev) => ({ ...prev, [tabKey]: (e as Error).message })); setErrors((prev) => ({
...prev,
[tabKey]: errorString,
}));
} }
throw e; throw e;
@@ -248,7 +266,7 @@ const App = () => {
await mcpClient.notification(notification); await mcpClient.notification(notification);
pushHistory(notification); pushHistory(notification);
} catch (e: unknown) { } catch (e: unknown) {
toast.error((e as Error).message); toast.error((e as Error).message ?? String(e));
throw e; throw e;
} }
}; };
@@ -357,10 +375,21 @@ const App = () => {
const connectMcpServer = async () => { const connectMcpServer = async () => {
try { try {
const client = new Client({ const client = new Client(
{
name: "mcp-inspector", name: "mcp-inspector",
version: "0.0.1", version: "0.0.1",
}); },
{
capabilities: {
// Support all client capabilities since we're an inspector tool
sampling: {},
roots: {
listChanged: true,
},
},
},
);
const backendUrl = new URL("http://localhost:3000/sse"); const backendUrl = new URL("http://localhost:3000/sse");

View File

@@ -41,11 +41,12 @@ const ToolsTab = ({
if ("content" in toolResult) { if ("content" in toolResult) {
const structuredResult = toolResult as CallToolResult; const structuredResult = toolResult as CallToolResult;
const isError = structuredResult.isError ?? false;
return ( return (
<> <>
<h4 className="font-semibold mb-2"> <h4 className="font-semibold mb-2">
Tool Result: {structuredResult.isError ? "Error" : "Success"} Tool Result: {isError ? "Error" : "Success"}
</h4> </h4>
{structuredResult.content.map((item, index) => ( {structuredResult.content.map((item, index) => (
<div key={index} className="mb-2"> <div key={index} className="mb-2">

10
package-lock.json generated
View File

@@ -28,7 +28,7 @@
"version": "0.1.0", "version": "0.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@modelcontextprotocol/sdk": "*", "@modelcontextprotocol/sdk": "0.5.0",
"@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0", "@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-select": "^2.1.2", "@radix-ui/react-select": "^2.1.2",
@@ -864,9 +864,9 @@
"link": true "link": true
}, },
"node_modules/@modelcontextprotocol/sdk": { "node_modules/@modelcontextprotocol/sdk": {
"version": "0.4.0", "version": "0.5.0",
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-0.4.0.tgz", "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-0.5.0.tgz",
"integrity": "sha512-79gx8xh4o9YzdbtqMukOe5WKzvEZpvBA1x8PAgJWL7J5k06+vJx8NK2kWzOazPgqnfDego7cNEO8tjai/nOPAA==", "integrity": "sha512-RXgulUX6ewvxjAG0kOpLMEdXXWkzWgaoCGaA2CwNW7cQCIphjpJhjpHSiaPdVCnisjRF/0Cm9KWHUuIoeiAblQ==",
"dependencies": { "dependencies": {
"content-type": "^1.0.5", "content-type": "^1.0.5",
"raw-body": "^3.0.0", "raw-body": "^3.0.0",
@@ -5868,7 +5868,7 @@
"version": "0.1.0", "version": "0.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@modelcontextprotocol/sdk": "*", "@modelcontextprotocol/sdk": "0.5.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"eventsource": "^2.0.2", "eventsource": "^2.0.2",
"express": "^4.21.0", "express": "^4.21.0",

View File

@@ -28,7 +28,7 @@
"typescript": "^5.6.2" "typescript": "^5.6.2"
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/sdk": "*", "@modelcontextprotocol/sdk": "0.5.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"eventsource": "^2.0.2", "eventsource": "^2.0.2",
"express": "^4.21.0", "express": "^4.21.0",