Agent: Cursor Integration
Relevant source files
The following files were used as context for generating this wiki page:
The Cursor integration for React Grab connects the visual context selected in the browser directly to the Cursor coding agent. This allows developers to initiate code edits from their web application's UI, sending component information, file paths, and a prompt to the Cursor agent, which then modifies the codebase directly. This eliminates the need for manual copy-pasting of context and streamlines the frontend development workflow.
The integration is one of several available agent providers, which act as adapters between React Grab and various coding agents. The goal is to make the agent "jump straight to the exact file, line, and column" instead of guessing.
Sources: packages/website/app/blog/agent/page.tsx:169-175, 804-816, packages/react-grab/README.md:47-51
Architecture
The Cursor integration operates on a client-server model. A client-side script, loaded in the browser during development, captures the element context. When a user submits a prompt, this context is sent to a local server. This server, specific to the Cursor provider, acts as a bridge, interfacing with the cursor-agent command-line tool to execute the changes in the local filesystem.
Sources: packages/website/app/blog/agent/page.tsx:817-828, packages/react-grab/README.md:129-132
The following diagram illustrates the architectural flow of the Cursor agent integration.
Installation and Setup
The Cursor integration can be installed automatically using the React Grab CLI or set up manually. A prerequisite is having the cursor-agent CLI installed.
Sources: packages/react-grab/README.md:127
CLI Installation
The recommended way to add the Cursor integration is by using the grab CLI.
- Initialize React Grab (if not already done):
npx grab@latest init - Add the Cursor Agent:
You can add the agent during initialization by selecting "Cursor" from the list, or add it to an existing installation with theaddcommand.npx grab@latest add cursor
The CLI will detect your project's framework (e.g., Next.js, Vite) and automatically apply the necessary changes to your package.json and layout files. If other agents are already installed, the CLI will prompt whether to replace them or add Cursor alongside.
Sources: packages/cli/src/commands/init.ts:101-104, 603-613, packages/cli/src/commands/add.ts:30-34, 76-101
Manual Setup
Manual setup involves configuring both a server-side script and adding a client-side script to your application's HTML head.
Server Setup
The provider server interfaces with the cursor-agent CLI and runs on port 5567. To enable it, modify the dev script in your package.json.
{
"scripts": {
"dev": "npx @react-grab/cursor@latest && next dev"
}
}
Sources: packages/website/app/blog/agent/page.tsx:422-435, packages/react-grab/README.md:131-139
Client Setup
The client script enables the in-browser UI for the Cursor agent. It should be added to your main layout file after the core react-grab script.
For a Next.js App Router project, the app/layout.tsx would look like this:
import Script from "next/script";
export default function RootLayout({ children }) {
return (
<html>
<head>
{process.env.NODE_ENV === "development" && (
<>
<Script
src="//unpkg.com/react-grab/dist/index.global.js"
strategy="beforeInteractive"
/>
<Script
src="//unpkg.com/@react-grab/cursor/dist/client.global.js"
strategy="lazyOnload"
/>
</>
)}
</head>
<body>{children}</body>
</html>
);
}
Sources: packages/website/app/blog/agent/page.tsx:444-469, packages/react-grab/README.md:148-173
Agent Provider Summary
React Grab supports multiple agent providers, each running on a dedicated port.
| Agent Provider | Package | Default Port |
|---|---|---|
| Claude Code | @react-grab/claude-code | 4567 |
| Cursor | @react-grab/cursor | 5567 |
| OpenCode | @react-grab/opencode | 6567 |
| Codex | @react-grab/codex | 7567 |
| Gemini | @react-grab/gemini | 8567 |
| Amp | @react-grab/amp | 9567 |
| Factory Droid | @react-grab/droid | 10567 |
Sources: packages/website/app/blog/agent/page.tsx:327, 422, 483, 544, 605, 666, 727, CONTRIBUTING.md:21-27
User Workflow
The workflow is designed to keep the developer in the browser, minimizing context switching.
- Hold
⌘C(or the configured activation key) and click on a UI element. - A small label appears showing the component name.
- Press
Enterto expand a prompt input. - Type the desired change (e.g., "make this button blue").
- Press
Enteragain to submit the task to the Cursor agent. - The label streams status updates from the agent.
- Once completed, the app reloads with the applied changes.
Sources: packages/website/app/blog/agent/page.tsx:267-280, 471-481
This sequence diagram shows the interaction between the user and the system components.
Summary
The React Grab Cursor integration provides a powerful "visual editing" capability by creating a direct channel between the developer's browser and the Cursor agent. By automating the collection and submission of contextual information, it significantly speeds up UI development and iteration cycles. The setup is streamlined via the official CLI, making it easy to incorporate into any React project.
Sources: packages/website/app/blog/agent/page.tsx:169-175, 282-286, packages/react-grab/README.md:47-51