Skip to content

Conversation

@KhanhPham2411
Copy link

🍪 Add Cookie Retrieval Tool to MCP Chrome Server

📋 Summary

This PR adds a new chrome_get_cookie tool to the MCP Chrome Server, enabling AI assistants to retrieve cookies from specified websites through the Model Context Protocol.

✨ New Feature

  • Tool Name: chrome_get_cookie
  • Purpose: Retrieve all cookies from a specified website domain
  • Input: URL of the target website
  • Output: Structured cookie data and formatted cookie string

🔧 Technical Changes

1. Shared Package Updates (packages/shared/src/tools.ts)

  • Added GET_COOKIE: 'chrome_get_cookie' to TOOL_NAMES.BROWSER
  • Added tool schema with input validation for URL parameter
  • Tool requires url parameter (string) starting with http/https

2. Chrome Extension Implementation (app/chrome-extension/entrypoints/background/tools/browser/cookie.ts)

  • Created new GetCookieTool class extending BaseBrowserToolExecutor
  • Implements Chrome's chrome.cookies.getAll() API
  • Handles URL validation and domain parsing
  • Returns both structured cookie metadata and formatted cookie string

3. Tool Registration (app/chrome-extension/entrypoints/background/tools/browser/index.ts)

  • Exported getCookieTool from browser tools index
  • Integrated with existing tool handling system

4. Permission Updates (app/chrome-extension/wxt.config.ts)

  • Added cookies permission to extension manifest
  • Enables access to Chrome's cookie API

📊 Output Format

{
  "success": true,
  "message": "Successfully retrieved X cookies from example.com",
  "url": "https://example.com",
  "domain": "example.com",
  "cookies": [
    {
      "name": "session_id",
      "value": "abc123",
      "domain": "example.com",
      "path": "/",
      "secure": true,
      "httpOnly": false,
      "expirationDate": 1234567890,
      "sameSite": "Lax"
    }
  ],
  "cookieString": "session_id=abc123; user_pref=dark_mode"
}

🎯 Use Cases

  • Session Management: Retrieve authentication cookies for API requests
  • Debugging: Inspect cookie values during development
  • Automation: Use cookies in automated browser workflows
  • Security Testing: Analyze cookie security attributes

🔒 Security Considerations

  • Only retrieves cookies for the specified domain
  • Respects Chrome's cookie permissions and security policies
  • No ability to modify or create cookies (read-only access)
  • Requires explicit cookies permission in extension manifest

�� Testing

  • ✅ Tool schema validation
  • ✅ URL format validation
  • ✅ Domain parsing and cookie retrieval
  • ✅ Error handling for invalid URLs
  • ✅ Empty cookie handling
  • ✅ Cookie string formatting

📝 Example Usage

// MCP client call
{
  name: 'chrome_get_cookie',
  args: {
    url: 'https://github.com'
  }
}

// Returns cookies for github.com domain

🚀 Benefits

  • AI Integration: Enables AI assistants to access browser cookies
  • Automation: Supports cookie-based authentication workflows
  • Debugging: Provides visibility into browser cookie state
  • Consistency: Follows existing tool patterns and architecture

📋 Checklist

  • Tool schema added to shared package
  • Tool implementation created
  • Tool exported from browser tools index
  • Cookies permission added to manifest
  • Error handling implemented
  • Logging and debugging support
  • Follows existing code patterns
  • No breaking changes to existing functionality

�� Related Issues

  • Addresses feature request for cookie access in MCP Chrome Server
  • Enables cookie-based authentication workflows
  • Supports debugging and development use cases

Ready for Review
Breaking Changes: None
Testing Required: Manual testing with Chrome extension
Documentation: Updated tool schemas and examples

Copy link
Owner

Choose a reason for hiding this comment

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

It is not recommended to modify the extensionId here.

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