Skip to content

Commit 94ba6ff

Browse files
authored
Merge pull request #5 from jem-computer/feat/resources-and-prompts
Feat/resources and prompts
2 parents 25797dd + 6a42f9d commit 94ba6ff

File tree

16 files changed

+919
-55
lines changed

16 files changed

+919
-55
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ yarn add use-mcp
2525
- 🔄 Automatic connection management with reconnection and retries
2626
- 🔐 OAuth authentication flow handling with popup and fallback support
2727
- 📦 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
2831
- 🧰 TypeScript types for editor assistance and type checking
2932
- 📝 Comprehensive logging for debugging
3033
- 🌐 Works with both HTTP and SSE (Server-Sent Events) transports
@@ -38,8 +41,12 @@ function MyAIComponent() {
3841
const {
3942
state, // Connection state: 'discovering' | 'pending_auth' | 'authenticating' | 'connecting' | 'loading' | 'ready' | 'failed'
4043
tools, // Available tools from MCP server
44+
resources, // Available resources from MCP server
45+
prompts, // Available prompts from MCP server
4146
error, // Error message if connection failed
4247
callTool, // Function to call tools on the MCP server
48+
readResource, // Function to read resource contents
49+
getPrompt, // Function to get prompt messages
4350
retry, // Retry connection manually
4451
authenticate, // Manually trigger authentication
4552
clearStorage, // Clear stored tokens and credentials
@@ -83,6 +90,32 @@ function MyAIComponent() {
8390
))}
8491
</ul>
8592
<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+
)}
86119
</div>
87120
)
88121
}
@@ -176,10 +209,17 @@ function useMcp(options: UseMcpOptions): UseMcpResult
176209
|----------|------|-------------|
177210
| `state` | `string` | Current connection state: 'discovering', 'pending_auth', 'authenticating', 'connecting', 'loading', 'ready', 'failed' |
178211
| `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 |
179215
| `error` | `string \| undefined` | Error message if connection failed |
180216
| `authUrl` | `string \| undefined` | Manual authentication URL if popup is blocked |
181217
| `log` | `{ level: 'debug' \| 'info' \| 'warn' \| 'error'; message: string; timestamp: number }[]` | Array of log messages |
182218
| `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 |
183223
| `retry` | `() => void` | Manually attempt to reconnect |
184224
| `disconnect` | `() => void` | Disconnect from the MCP server |
185225
| `authenticate` | `() => void` | Manually trigger authentication |

examples/inspector/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ A minimal demo showcasing the `use-mcp` React hook for connecting to Model Conte
66

77
- Connect to any MCP server via URL
88
- View available tools and their schemas
9+
- Browse and read server resources
10+
- Interact with server-provided prompts
911
- Real-time connection status monitoring
1012
- Debug logging for troubleshooting
1113
- Clean, minimal UI focused on MCP functionality
@@ -31,7 +33,7 @@ pnpm dev
3133

3234
3. Open your browser and navigate to the displayed local URL
3335

34-
4. Enter an MCP server URL to test the connection and explore available tools
36+
4. Enter an MCP server URL to test the connection and explore available tools, resources, and prompts
3537

3638
## What This Demonstrates
3739

@@ -46,7 +48,17 @@ const connection = useMcp({
4648
autoRetry: false
4749
})
4850

49-
// Access connection.state, connection.tools, connection.error, etc.
51+
// Access connection.state, connection.tools, connection.resources,
52+
// connection.prompts, connection.error, etc.
5053
```
5154

52-
The `McpServers` component wraps this hook to provide a complete UI for server management and tool inspection.
55+
The `McpServers` component wraps this hook to provide a complete UI for server management, tool inspection, resource browsing, and prompt interaction.
56+
57+
## Supported MCP Features
58+
59+
- **Tools**: Execute server-provided tools with custom arguments and view results
60+
- **Resources**: Browse available resources and read their contents (text or binary)
61+
- **Resource Templates**: View dynamic resource templates with URI patterns
62+
- **Prompts**: Interact with server prompts, provide arguments, and view generated messages
63+
64+
Note: Not all MCP servers implement all features. The inspector will gracefully handle servers that only support a subset of the MCP specification.

0 commit comments

Comments
 (0)