7
7
ReadResourceResultSchema ,
8
8
CallToolResultSchema ,
9
9
ListPromptsResultSchema ,
10
+ Tool ,
11
+ ClientRequest ,
10
12
} from "mcp-typescript/types.js" ;
11
13
import { useState } from "react" ;
12
14
import {
@@ -28,8 +30,9 @@ import RequestsTab from "./components/RequestsTabs";
28
30
import ResourcesTab , { Resource } from "./components/ResourcesTab" ;
29
31
import NotificationsTab from "./components/NotificationsTab" ;
30
32
import PromptsTab , { Prompt } from "./components/PromptsTab" ;
31
- import ToolsTab , { Tool as ToolType } from "./components/ToolsTab" ;
33
+ import ToolsTab from "./components/ToolsTab" ;
32
34
import History from "./components/History" ;
35
+ import { AnyZodObject } from "node_modules/zod/lib" ;
33
36
34
37
const App = ( ) => {
35
38
const [ connectionStatus , setConnectionStatus ] = useState <
@@ -39,7 +42,7 @@ const App = () => {
39
42
const [ resourceContent , setResourceContent ] = useState < string > ( "" ) ;
40
43
const [ prompts , setPrompts ] = useState < Prompt [ ] > ( [ ] ) ;
41
44
const [ promptContent , setPromptContent ] = useState < string > ( "" ) ;
42
- const [ tools , setTools ] = useState < ToolType [ ] > ( [ ] ) ;
45
+ const [ tools , setTools ] = useState < Tool [ ] > ( [ ] ) ;
43
46
const [ toolResult , setToolResult ] = useState < string > ( "" ) ;
44
47
const [ error , setError ] = useState < string | null > ( null ) ;
45
48
const [ command , setCommand ] = useState < string > (
@@ -57,7 +60,7 @@ const App = () => {
57
60
null ,
58
61
) ;
59
62
const [ selectedPrompt , setSelectedPrompt ] = useState < Prompt | null > ( null ) ;
60
- const [ selectedTool , setSelectedTool ] = useState < ToolType | null > ( null ) ;
63
+ const [ selectedTool , setSelectedTool ] = useState < Tool | null > ( null ) ;
61
64
62
65
const pushHistory = ( request : object , response : object ) => {
63
66
setRequestHistory ( ( prev ) => [
@@ -66,10 +69,10 @@ const App = () => {
66
69
] ) ;
67
70
} ;
68
71
69
- const makeRequest = async (
70
- request : Parameters < Client [ "request" ] > [ 0 ] ,
71
- schema : Parameters < Client [ "request" ] > [ 1 ] ,
72
- ) : Promise < ReturnType < Client [ "request" ] > > => {
72
+ const makeRequest = async < T extends AnyZodObject > (
73
+ request : ClientRequest ,
74
+ schema : T ,
75
+ ) => {
73
76
if ( ! mcpClient ) {
74
77
throw new Error ( "MCP client not connected" ) ;
75
78
}
@@ -114,9 +117,7 @@ const App = () => {
114
117
} ,
115
118
ListPromptsResultSchema ,
116
119
) ;
117
- if ( response . prompts ) {
118
- setPrompts ( response . prompts ) ;
119
- }
120
+ setPrompts ( response . prompts ) ;
120
121
} ;
121
122
122
123
const getPrompt = async ( name : string , args : Record < string , string > = { } ) => {
@@ -137,9 +138,7 @@ const App = () => {
137
138
} ,
138
139
ListToolsResultSchema ,
139
140
) ;
140
- if ( response . tools ) {
141
- setTools ( response . tools ) ;
142
- }
141
+ setTools ( response . tools ) ;
143
142
} ;
144
143
145
144
const callTool = async ( name : string , params : Record < string , unknown > ) => {
0 commit comments