Skip to content

Commit d1c9acf

Browse files
Merge pull request modelcontextprotocol#58 from modelcontextprotocol/justin/upgrade-sdk
Upgrade to SDK 0.5.0, add default request timeout
2 parents 2bf84a3 + d91d7e8 commit d1c9acf

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"preview": "vite preview"
2323
},
2424
"dependencies": {
25-
"@modelcontextprotocol/sdk": "*",
25+
"@modelcontextprotocol/sdk": "0.5.0",
2626
"@radix-ui/react-icons": "^1.3.0",
2727
"@radix-ui/react-label": "^2.1.0",
2828
"@radix-ui/react-select": "^2.1.2",

client/src/App.tsx

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import SamplingTab, { PendingRequest } from "./components/SamplingTab";
5353
import Sidebar from "./components/Sidebar";
5454
import ToolsTab from "./components/ToolsTab";
5555

56+
const DEFAULT_REQUEST_TIMEOUT_MSEC = 10000;
57+
5658
const App = () => {
5759
const [connectionStatus, setConnectionStatus] = useState<
5860
"disconnected" | "connected" | "error"
@@ -220,7 +222,19 @@ const App = () => {
220222
}
221223

222224
try {
223-
const response = await mcpClient.request(request, schema);
225+
const abortController = new AbortController();
226+
const timeoutId = setTimeout(() => {
227+
abortController.abort("Request timed out");
228+
}, DEFAULT_REQUEST_TIMEOUT_MSEC);
229+
230+
let response;
231+
try {
232+
response = await mcpClient.request(request, schema, {
233+
signal: abortController.signal,
234+
});
235+
} finally {
236+
clearTimeout(timeoutId);
237+
}
224238
pushHistory(request, response);
225239

226240
if (tabKey !== undefined) {
@@ -229,10 +243,14 @@ const App = () => {
229243

230244
return response;
231245
} catch (e: unknown) {
246+
const errorString = (e as Error).message ?? String(e);
232247
if (tabKey === undefined) {
233-
toast.error((e as Error).message);
248+
toast.error(errorString);
234249
} else {
235-
setErrors((prev) => ({ ...prev, [tabKey]: (e as Error).message }));
250+
setErrors((prev) => ({
251+
...prev,
252+
[tabKey]: errorString,
253+
}));
236254
}
237255

238256
throw e;
@@ -248,7 +266,7 @@ const App = () => {
248266
await mcpClient.notification(notification);
249267
pushHistory(notification);
250268
} catch (e: unknown) {
251-
toast.error((e as Error).message);
269+
toast.error((e as Error).message ?? String(e));
252270
throw e;
253271
}
254272
};
@@ -357,10 +375,21 @@ const App = () => {
357375

358376
const connectMcpServer = async () => {
359377
try {
360-
const client = new Client({
361-
name: "mcp-inspector",
362-
version: "0.0.1",
363-
});
378+
const client = new Client(
379+
{
380+
name: "mcp-inspector",
381+
version: "0.0.1",
382+
},
383+
{
384+
capabilities: {
385+
// Support all client capabilities since we're an inspector tool
386+
sampling: {},
387+
roots: {
388+
listChanged: true,
389+
},
390+
},
391+
},
392+
);
364393

365394
const backendUrl = new URL("http://localhost:3000/sse");
366395

client/src/components/ToolsTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ const ToolsTab = ({
4141

4242
if ("content" in toolResult) {
4343
const structuredResult = toolResult as CallToolResult;
44+
const isError = structuredResult.isError ?? false;
4445

4546
return (
4647
<>
4748
<h4 className="font-semibold mb-2">
48-
Tool Result: {structuredResult.isError ? "Error" : "Success"}
49+
Tool Result: {isError ? "Error" : "Success"}
4950
</h4>
5051
{structuredResult.content.map((item, index) => (
5152
<div key={index} className="mb-2">

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"typescript": "^5.6.2"
2929
},
3030
"dependencies": {
31-
"@modelcontextprotocol/sdk": "*",
31+
"@modelcontextprotocol/sdk": "0.5.0",
3232
"cors": "^2.8.5",
3333
"eventsource": "^2.0.2",
3434
"express": "^4.21.0",

0 commit comments

Comments
 (0)