Skip to content

Fix clipboard issues in MCP Inspector extension#2144

Merged
kanushka merged 5 commits intowso2:mainfrom
dan-niles:fix-mcp-inspector-clipboard-issues
Apr 30, 2026
Merged

Fix clipboard issues in MCP Inspector extension#2144
kanushka merged 5 commits intowso2:mainfrom
dan-niles:fix-mcp-inspector-clipboard-issues

Conversation

@dan-niles
Copy link
Copy Markdown
Contributor

@dan-niles dan-niles commented Apr 30, 2026

Purpose

Fixes wso2/product-integrator#1325

This PR fixes clipboard issues in the MCP inspector extension, where we cannot paste values into the form fields, and use the Server FIles and Server Entries copy buttons to copy items to the clipboard.

Screen.Recording.2026-04-30.at.10.53.21.AM.mov

Summary by CodeRabbit

  • Bug Fixes
    • Clipboard functionality (copy, paste, cut) now works reliably in the MCP Inspector webview
    • System clipboard is properly synchronized between the inspector interface and VS Code
    • Users can now seamlessly copy/paste content in input fields, text areas, and other editable content within the inspector

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@dan-niles has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 22 minutes and 54 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cc4d64d8-3af8-4989-b801-fb963a8b4842

📥 Commits

Reviewing files that changed from the base of the PR and between 70085e3 and dc4d631.

📒 Files selected for processing (4)
  • workspaces/mcp-inspector/mcp-inspector-extension/CHANGELOG.md
  • workspaces/mcp-inspector/mcp-inspector-extension/scripts/inject-theme.js
  • workspaces/mcp-inspector/mcp-inspector-extension/src/MCPInspectorViewProvider.ts
  • workspaces/mcp-inspector/mcp-inspector-extension/src/extension.ts
📝 Walkthrough

Walkthrough

Implements clipboard bridging between a VS Code webview iframe and the extension host. The runtime script intercepts clipboard operations (copy, cut, paste) inside the webview and patches the Clipboard API, while a new message relay mechanism routes clipboard read/write requests through the parent webview to the extension's clipboard access.

Changes

Cohort / File(s) Summary
Clipboard Bridge Infrastructure
MCPInspectorViewProvider.ts, extension.ts
Adds attachClipboardBridge() static method to forward clipboard read/write messages between iframe and extension host via VS Code's vscode.env.clipboard API; integrates bridge attachment into webview panel initialization.
Runtime Clipboard Interception
scripts/inject-theme.js
Injects runtime JS that intercepts clipboard events (paste, copy, cut) in focused inputs, routes requests to parent webview via mcp-inspector-request-paste and mcp-inspector-request-clipboard-write messages, patches navigator.clipboard.writeText() to use injected bridge with fallback to execCommand, and dispatches input events after programmatic clipboard operations.

Sequence Diagrams

sequenceDiagram
    participant Iframe as Iframe Content
    participant WebviewScript as Webview Script
    participant ExtensionHost as Extension Host
    participant ClipboardAPI as VS Code Clipboard API
    
    rect rgba(100, 150, 200, 0.5)
    Note over Iframe,ClipboardAPI: Paste Operation
    Iframe->>WebviewScript: mcp-inspector-request-paste
    WebviewScript->>ExtensionHost: onDidReceiveMessage (readText)
    ExtensionHost->>ClipboardAPI: readText()
    ClipboardAPI-->>ExtensionHost: clipboard content
    ExtensionHost-->>WebviewScript: postMessage (paste-response)
    WebviewScript-->>Iframe: mcp-inspector-paste-response
    Iframe->>Iframe: Insert text & dispatch input event
    end
    
    rect rgba(150, 100, 200, 0.5)
    Note over Iframe,ClipboardAPI: Copy/Cut Operation
    Iframe->>Iframe: Capture selection
    Iframe->>WebviewScript: mcp-inspector-request-clipboard-write
    WebviewScript->>ExtensionHost: onDidReceiveMessage (writeText)
    ExtensionHost->>ClipboardAPI: writeText()
    ClipboardAPI-->>ExtensionHost: complete
    ExtensionHost-->>WebviewScript: postMessage (write-result)
    WebviewScript-->>Iframe: mcp-inspector-clipboard-write-result
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A bridge of hops from frame to frame,
Where clipboard whispers play their game,
Paste and copy now flow with grace,
From iframe to the extension's place! 📋✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete and missing multiple required sections from the template, including Goals, Approach, UI Component Development, Icons, User Stories, Release Notes, Documentation, Training, Certification, Marketing, Tests, Security Checks, Samples, Related PRs, Migrations, Test Environment, and Learning. Complete the PR description by filling out all required template sections, particularly Goals (solution approach), Approach (implementation details), Documentation (impact analysis), and Testing/Security sections with relevant information or 'N/A' with explanations.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing clipboard issues in the MCP Inspector extension. It is concise, clear, and directly reflects the core objective evident in all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 22 minutes and 54 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@dan-niles dan-niles force-pushed the fix-mcp-inspector-clipboard-issues branch from 6759ee8 to 70085e3 Compare April 30, 2026 05:22
@dan-niles dan-niles requested a review from Copilot April 30, 2026 05:22
@dan-niles
Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes clipboard interoperability in the MCP Inspector VS Code extension by adding an extension-host clipboard bridge so the embedded cross-origin inspector iframe can reliably paste into form fields and copy server items.

Changes:

  • Add an extension-host clipboard read/write bridge via vscode.env.clipboard for webviews.
  • Add parent-webview ↔ iframe postMessage plumbing for clipboard operations.
  • Patch the inspector client (theme injection script) to intercept paste/copy/select-all and to provide clipboard write fallbacks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
workspaces/mcp-inspector/mcp-inspector-extension/src/extension.ts Attaches clipboard bridge for the standalone inspector panel webview.
workspaces/mcp-inspector/mcp-inspector-extension/src/MCPInspectorViewProvider.ts Attaches clipboard bridge for the view-container webview and relays clipboard messages between iframe and extension host.
workspaces/mcp-inspector/mcp-inspector-extension/scripts/inject-theme.js Injects iframe-side keyboard interception + clipboard write fallback logic into the inspector client.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread workspaces/mcp-inspector/mcp-inspector-extension/src/MCPInspectorViewProvider.ts Outdated
Comment thread workspaces/mcp-inspector/mcp-inspector-extension/src/MCPInspectorViewProvider.ts Outdated
Comment thread workspaces/mcp-inspector/mcp-inspector-extension/src/extension.ts Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@workspaces/mcp-inspector/mcp-inspector-extension/scripts/inject-theme.js`:
- Around line 114-123: The cut handler currently deletes the selection
immediately and swallows clipboard errors; change it to perform the delete only
after the clipboard write succeeds by calling
window.__mcpInspectorWriteClipboard(ctx.text) and then, in the success callback
(or await the promise), call deleteSelection(ctx) only if k === 'x'. Make the
event handler use async/Promise flow so e.preventDefault()/e.stopPropagation()
still run but defer deletion until the write resolves; also ensure
getSelectionContext() returns a cloned Range (e.g., include
ctx.range.cloneRange()) for contenteditable selections so that
deleteSelection(ctx) applied later still targets the original selection. Ensure
you do not delete on rejection/timeouts and continue to swallow or surface
errors per existing policy.
- Around line 38-58: isPasteableInput currently includes 'number' but
insertTextAt unconditionally uses selection APIs
(selectionStart/selectionEnd/setSelectionRange) which aren't supported for
input[type="number"]; update the logic so paste won't fail by either removing
'number' from the pasteableTypes array in isPasteableInput or by guarding
insertTextAt with a type check (e.g., skip
selectionStart/selectionEnd/setSelectionRange and fallback to
appending/replacing value when el.type === 'number'), and ensure you still use
the native setter (the existing nativeSetter.call(...) logic) so React onChange
behavior is preserved; reference isPasteableInput and insertTextAt when making
the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b49e396d-63ae-4826-afde-bd56dc2da067

📥 Commits

Reviewing files that changed from the base of the PR and between 3c92a95 and 70085e3.

📒 Files selected for processing (3)
  • workspaces/mcp-inspector/mcp-inspector-extension/scripts/inject-theme.js
  • workspaces/mcp-inspector/mcp-inspector-extension/src/MCPInspectorViewProvider.ts
  • workspaces/mcp-inspector/mcp-inspector-extension/src/extension.ts

Comment thread workspaces/mcp-inspector/mcp-inspector-extension/scripts/inject-theme.js Outdated
@dan-niles dan-niles marked this pull request as ready for review April 30, 2026 05:40
@dan-niles dan-niles requested review from gigara and hevayo as code owners April 30, 2026 05:40
@dan-niles dan-niles force-pushed the fix-mcp-inspector-clipboard-issues branch from 7e5502b to dc4d631 Compare April 30, 2026 06:01
@kanushka kanushka merged commit 3f7a3c8 into wso2:main Apr 30, 2026
7 checks passed
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.

Unable to paste values inside fields in the MCP inspector

3 participants