@@ -25,6 +25,9 @@ yarn add use-mcp
25
25
- 🔄 Automatic connection management with reconnection and retries
26
26
- 🔐 OAuth authentication flow handling with popup and fallback support
27
27
- 📦 Simple React hook interface for MCP integration
28
+ - 🧰 Full support for MCP tools, resources, and prompts
29
+ - 📄 Access server resources and read their contents
30
+ - 💬 Use server-provided prompt templates
28
31
- 🧰 TypeScript types for editor assistance and type checking
29
32
- 📝 Comprehensive logging for debugging
30
33
- 🌐 Works with both HTTP and SSE (Server-Sent Events) transports
@@ -38,8 +41,12 @@ function MyAIComponent() {
38
41
const {
39
42
state, // Connection state: 'discovering' | 'pending_auth' | 'authenticating' | 'connecting' | 'loading' | 'ready' | 'failed'
40
43
tools, // Available tools from MCP server
44
+ resources, // Available resources from MCP server
45
+ prompts, // Available prompts from MCP server
41
46
error, // Error message if connection failed
42
47
callTool, // Function to call tools on the MCP server
48
+ readResource, // Function to read resource contents
49
+ getPrompt, // Function to get prompt messages
43
50
retry, // Retry connection manually
44
51
authenticate, // Manually trigger authentication
45
52
clearStorage, // Clear stored tokens and credentials
@@ -83,6 +90,32 @@ function MyAIComponent() {
83
90
))}
84
91
</ul >
85
92
<button onClick = { handleSearch } >Search</button >
93
+
94
+ { /* Example: Display and read resources */ }
95
+ { resources .length > 0 && (
96
+ <div >
97
+ <h3 >Resources: { resources .length } </h3 >
98
+ <button onClick = { async () => {
99
+ const content = await readResource (resources [0 ].uri )
100
+ console .log (' Resource content:' , content )
101
+ }} >
102
+ Read First Resource
103
+ </button >
104
+ </div >
105
+ )}
106
+
107
+ { /* Example: Use prompts */ }
108
+ { prompts .length > 0 && (
109
+ <div >
110
+ <h3 >Prompts: { prompts .length } </h3 >
111
+ <button onClick = { async () => {
112
+ const result = await getPrompt (prompts [0 ].name )
113
+ console .log (' Prompt messages:' , result .messages )
114
+ }} >
115
+ Get First Prompt
116
+ </button >
117
+ </div >
118
+ )}
86
119
</div >
87
120
)
88
121
}
@@ -176,10 +209,17 @@ function useMcp(options: UseMcpOptions): UseMcpResult
176
209
| ---------- | ------ | ------------ - |
177
210
| ` state ` | ` string ` | Current connection state : ' discovering' , ' pending_auth' , ' authenticating' , ' connecting' , ' loading' , ' ready' , ' failed' |
178
211
| ` tools ` | ` Tool[] ` | Available tools from the MCP server |
212
+ | ` resources ` | ` Resource[] ` | Available resources from the MCP server |
213
+ | ` resourceTemplates ` | ` ResourceTemplate[] ` | Available resource templates from the MCP server |
214
+ | ` prompts ` | ` Prompt[] ` | Available prompts from the MCP server |
179
215
| ` error ` | ` string \| undefined ` | Error message if connection failed |
180
216
| ` authUrl ` | ` string \| undefined ` | Manual authentication URL if popup is blocked |
181
217
| ` log ` | ` { level: 'debug' \| 'info' \| 'warn' \| 'error'; message: string; timestamp: number }[] ` | Array of log messages |
182
218
| ` callTool ` | ` (name: string, args?: Record<string, unknown>) => Promise<any> ` | Function to call a tool on the MCP server |
219
+ | ` listResources ` | ` () => Promise<void> ` | Refresh the list of available resources |
220
+ | ` readResource ` | ` (uri: string) => Promise<{ contents: Array<...> }> ` | Read the contents of a specific resource |
221
+ | ` listPrompts ` | ` () => Promise<void> ` | Refresh the list of available prompts |
222
+ | ` getPrompt ` | ` (name: string, args?: Record<string, string>) => Promise<{ messages: Array<...> }> ` | Get a specific prompt with optional arguments |
183
223
| ` retry ` | ` () => void ` | Manually attempt to reconnect |
184
224
| ` disconnect ` | ` () => void ` | Disconnect from the MCP server |
185
225
| ` authenticate ` | ` () => void ` | Manually trigger authentication |
0 commit comments