Skip to content

Feat/resources and prompts #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jem-computer
Copy link
Contributor

@jem-computer jem-computer commented Jun 20, 2025

adds support for Resources and Prompts in useMCP hook

Motivation and Context

see #4

How Has This Been Tested?

  • the Inspector example has been updated to fetch resources and prompts. I've tried it with a real-world example of https://docs.mcp.cloudflare.com/sse, and also connecting to a local toy MCP server that exposes Resources & Prompts

Breaking Changes

N/A

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

  • should we grab resources & prompts from the main useMCP hook or something like usePrompts(…)

@geelen
Copy link
Collaborator

geelen commented Jun 30, 2025

Thanks for the PR! This repo hasn't been in a good state to accept changes like this, but it should be a lot better now/tomorrow. If you can rebase against main you should get some basic E2E tests now, and it would be great to expand them to cover resources/sampling too, though that could be a follow-up PR.

I'll take a proper look at this as soon as I've gotten the new chat example out.

jem-computer and others added 4 commits July 2, 2025 14:22
- Add Resource and ResourceTemplate types from MCP SDK
- Add resources and resourceTemplates arrays to UseMcpResult
- Fetch resources automatically after tools during connection
- Add listResources() method to manually refresh resources list
- Add readResource(uri) method to read resource contents
- Clear resources state on disconnect

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add Prompt type from MCP SDK
- Add prompts array to UseMcpResult
- Fetch prompts automatically after resources during connection
- Add listPrompts() method to manually refresh prompts list
- Add getPrompt(name, args) method to get specific prompt messages
- Clear prompts state on disconnect

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Import and export Resource, ResourceTemplate, and Prompt types
- Add state management for resources and prompts in McpServers component
- Add UI sections to display available resources and prompts
- Implement readResource functionality with content display
- Implement getPrompt functionality with argument inputs
- Show resource templates with visual distinction
- Add expand/collapse UI for resources and prompts
- Display prompt messages with proper formatting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Wrap resources/list and prompts/list calls in try-catch blocks
- Continue with connection even if server doesn't support these methods
- Update logging to only show counts for features that are supported
- Fix TypeScript types for optional responses

This allows the hook to work with servers that only implement the core
tools functionality without resources or prompts support.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jem-computer jem-computer force-pushed the feat/resources-and-prompts branch from 352407f to 5fc712f Compare July 2, 2025 21:25
jem-computer and others added 2 commits July 2, 2025 16:01
- Add resources, resourceTemplates, and prompts to all feature lists
- Document new properties returned by useMcp hook
- Document new methods: listResources, readResource, listPrompts, getPrompt
- Add code examples showing how to use resources and prompts
- Update quick start examples to demonstrate all features
- Add note about graceful handling of servers with partial MCP support

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix formatting issues in cf-agents, hono-mcp, and test files
- Update dependencies in example servers

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jem-computer jem-computer force-pushed the feat/resources-and-prompts branch 2 times, most recently from f00b0ef to e33de7c Compare July 3, 2025 01:27
@jem-computer jem-computer marked this pull request as ready for review July 3, 2025 01:31
Transform the generic example server into a fun Vengabus-themed MCP server with:
- Replace generic tools with party-themed tools (party capacity calculator, vengabus schedule)
- Update resources to use party-themed URIs and content
- Replace generic prompts with party invitations and announcements
- Fix resource URI handling to strip trailing slashes
- Fix TypeScript errors with proper resource template typing
- Use docs:// protocol for party manual resource

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jem-computer
Copy link
Contributor Author

rebased, updated the tests, and uh……made the Hono test server more vengabus-y (important)

image
CleanShot 2025-07-02 at 18 36 22@2x

currently figuring out how to integrate Prompts and Resources into the chat-ui example

I haven't implemented Sampling but we can do that elsewhere

@jem-computer jem-computer force-pushed the feat/resources-and-prompts branch from e33de7c to 6a42f9d Compare July 3, 2025 01:39
Copy link
Collaborator

@geelen geelen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!

@geelen
Copy link
Collaborator

geelen commented Jul 3, 2025

Running to lunch rn, will merge when I'm back. This is FANTASTIC though, thank you <3

I'll have a think about how to expose this in the new chat example I'm working on (WIP at https://chat.use-mcp.dev) too.

@jem-computer
Copy link
Contributor Author

:) i would do anything for the magic island ofc! ~

ya sooo one of the reasons I wanted to do this PR is because I've seen vanishingly few examples of client UIs that actually use Prompts & Resources ~ I figured having an easy API to pull them into experiments will help us figure out patterns for using them?

WIP (not committed): I added a palette that just inserts them into the chat, idk?
CleanShot 2025-07-02 at 18 57 03@2x

(and no rush, I'm gonna break for the evening also)

@geelen
Copy link
Collaborator

geelen commented Jul 3, 2025

That looks great! I think if we can change that bottom-right line to show:

  • There are X servers connected (of Y total)
  • There are Z tools enabled (of W total)
  • There are A prompts
  • There are B resources

And then hovering/clicking each of them gives you a tooltip/modal to configure?

I don't think emoji is going to cut it, but with the right icons I think we can drop the words servers and tools there and fit everything in.

Gonna merge/release this now, we can hack on the rest of that later.

@geelen geelen merged commit 94ba6ff into modelcontextprotocol:main Jul 3, 2025
1 of 2 checks passed
@geelen
Copy link
Collaborator

geelen commented Jul 3, 2025

@jem-computer I have released v0.0.19 with your changes. I realised I had a UX idea around prompts & resources, but I'm a long way from executing on it, so I thought I'd at least describe it here and get your take:

Instead of having to click around the UI to add stuff to the context, make the / key (or something else, or more than one) the main hook for tweaking the context while you're typing. A bit like the way Notion uses /?

But the main thing is to play with how integrated prompts & resources can be with the actual flow of writing a message to an AI. Then extend that to a potential pattern for tweaking, say, which MCP servers are enabled for the current conversation, without taking your hands off the keyboard...

Anyway, just an idea for now. Wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants