Skip to content

Implement Browser Tabs as MCP Resources #156

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

Closed
HikaruEgashira opened this issue Apr 10, 2025 · 4 comments
Closed

Implement Browser Tabs as MCP Resources #156

HikaruEgashira opened this issue Apr 10, 2025 · 4 comments

Comments

@HikaruEgashira
Copy link

HikaruEgashira commented Apr 10, 2025

Overview

Currently, in our MCP implementation, page content is returned as tool output after browser operations (tools) are executed. This causes the same content to be repeatedly included in the context, leading to context capacity issues. To resolve this, we propose implementing browser tabs using the MCP "resources" protocol and notifying changes only when snapshots are modified.

Background

MCP has two main protocols:

  • Tools: Interface for models to execute operations (action execution)
  • Resources: Mechanism to publish data and content from the server (data reference)

Browser tab state should be treated as data, making the resources protocol more appropriate for management.

Objective

  • Implement browser tabs as resources
  • Efficiently manage snapshot changes to reduce context usage
  • Establish coordination between tools and resources

Implementation Details

1. Resource Definition

// Tab resource URI schema: tab://{tabId}/snapshot

2. Resource Management Class Implementation

  • Create a class to represent tabs as resources
  • Implement a resource update notification mechanism
  • Implement a reference function using tab IDs

3. Tool and Resource Integration

  • Implement resource update processing after browser operation tool execution
  • Add a mechanism to notify only when changes occur

4. Client Notification System

  • Implement change notifications using the Resource Updates protocol
  • Efficient resource management on the client side

Technical Details

Resource Management

// Resources will have the following interface
interface TabResource {
  uri: string; // Example: tab://1/snapshot
  content: string; // Accessibility snapshot content
  contentType: string; // Example: "text/html" or "application/json"
  metadata: {
    title: string;
    url: string;
    lastUpdated: string;
  }
}

Change Detection and Notification

  • Implementation of snapshot diff detection algorithm
  • Filtering mechanism to notify only significant changes

Expected Benefits

  1. Reduced context usage
  2. Improved interaction efficiency with AI models
  3. Ability to retain more useful information within context

References

@Skn0tt
Copy link
Member

Skn0tt commented Apr 10, 2025

Hi Hikaru! I'm not aware of any MCP clients currently implementing resources in a way that would work here. Claude Desktop uses them in a way where there's human input needed to give the model access to a resource. What client are you working with? Would it work there?

@HikaruEgashira
Copy link
Author

HikaruEgashira commented Apr 10, 2025

I'm using Cline which handles MCP resources as context.
https://github.com/cline/cline/blob/f978ecce520e7184e30071efe1f3a0d1b85512d6/src/core/prompts/system.ts#L439-L449

Therefore, this change is very useful as resources can be treated like files. But I know that many clients don't support resources. What about making it switchable through an option?

@Skn0tt
Copy link
Member

Skn0tt commented Apr 10, 2025

I think it's fine to expose it without an option. Clients that don't understand resources won't suffer :D I'm not convinced this is the right approach because of the the warning at https://modelcontextprotocol.io/docs/concepts/resources, but i'll play with it!

@Skn0tt Skn0tt self-assigned this Apr 10, 2025
@Skn0tt Skn0tt added the planned label Apr 10, 2025
@Skn0tt
Copy link
Member

Skn0tt commented Apr 15, 2025

Now with Cursor removing Resources entirely, i'll deprioritise on this. Let's wait until the notion of Resources settles in the MCP ecosystem.

@Skn0tt Skn0tt removed their assignment Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants