swing2mcp
Adds support for Spring applications: the AI tool can list Spring beans, view application screens separately, and open Spring screen beans directly without navigating menus.
swing2mcp
swing2mcp lets AI coding tools see and use legacy Java Swing applications, without touching their code.
On the web, an AI tool can open the page and check its own work, with tools such as Playwright. For Swing applications that loop is usually missing: the AI tool writes code that it cannot try. swing2mcp closes the loop. The AI tool reads the screen as text, clicks and types like a user, and sees the result of a code change without a restart.
It works with Claude Code, Cursor, Codex, OpenCode and any tool that supports MCP, also with a local model.
Early release (0.x). swing2mcp works and is covered by tests, but tool names and options may still change before 1.0. Releases are on Maven Central and on the GitHub releases page.
flowchart LR
ai["<b>AI tool</b><br/>Claude Code, Cursor, Codex, OpenCode<br/>or any MCP client, also with a local model"]
server["<b>swing2mcp MCP server</b><br/>Java 8+"]
subgraph jvm["JVM of your application (Java 8+)"]
agent["<b>swing2mcp agent</b><br/>Java agent, no dependencies"]
ui["<b>Swing windows</b><br/>your code, unchanged"]
agent <-->|"Swing / AWT API<br/>real key and mouse events"| ui
end
ai <-->|"MCP<br/>stdio"| server
server <-->|"HTTP on 127.0.0.1<br/>random port + token"| agentswing2mcp runs on your machine and sends nothing off it. What the AI tool does with the screen content it reads depends on the AI tool and the model you connect; with a local model, nothing leaves the machine.
Quick start (Maven project)
1. Add the plugin to your project's pom.xml. This is the only part you need to add:
<build>
<plugins>
<plugin>
<groupId>io.github.ibrahimcavdar</groupId>
<artifactId>swing2mcp-maven-plugin</artifactId>
<version>0.1.0</version>
</plugin>
</plugins>
</build>2. Connect your AI tool. Once per machine:
mvn swing2mcp:setupThe command asks which of your AI tools to connect (Claude Code, Cursor, Codex, OpenCode), lists the changes it is about to make, and waits for your yes. It then:
copies the MCP server to
~/.swing2mcp/binadds one entry named
swingto the MCP settings of the tools you picked
Nothing else on your machine changes, and nothing is added to your project.
mvn swing2mcp:uninstall removes all of it again. For other MCP clients, or to do it by hand, see
Connecting an AI tool by hand.
3. Start your application with swing2mcp, instead of your usual way:
mvn swing2mcp:runIt compiles the project and starts your application in its own Java process, with the swing2mcp agent loaded into it. The application behaves as always; the agent is what lets the AI tool see and use it. Close the application or press Ctrl+C, and both stop. Nothing is written into your jar or your code.
Main class not found? Add -Dswing2mcp.mainClass=com.example.Main. Application already open? See
Connecting to an application that is already open.
4. Tell the AI tool what you want it to do, for example: "Log in with admin/admin, add a customer named Ali Veli from İzmir and check that it shows up in the table." That prompt works as it is on the demo application.
Requirements
Java 8 or newer, for everything: your application, Maven and the MCP server. Tested with Java 8, 21 and 25. One Java is enough; they do not have to be the same.
Maven 3.6.3 or newer.
Related MCP server: Autonomo MCP
Beyond the quick start
An application that is already open. Say "connect to the open application": the AI tool attaches without a restart, and the logged-in session and open screens are kept. More
Hot reload. The AI tool changes the code, compiles it and applies the change to the running application, without a restart. More
Spring. In Spring applications the AI tool can list the screens and open one directly, with no extra setting. More
Options and other setups.
swing2mcp:runoptions, connecting an AI tool by hand.
What the AI tool can use
Tool | Description |
| Lists running Java applications / connects to one; if it has no agent, places it without a restart |
| Text summary of the windows, with |
| PNG image of a window or component |
| Real mouse click on a button, table cell, list item or tree node (by text or path); double click, right click, column header, with Ctrl/Shift |
| Types real keys into a text field, password, spinner or editable combo |
| Enter, Escape, Tab, arrows, F-keys and shortcuts such as Ctrl+S |
| Combo, list, tab, table cell, tree node (by path); several rows, items or nodes with Ctrl/Shift clicks, ranges included |
| Mouse drag (pan a map, move a slider, a split pane divider, a table column) and drag and drop between components |
| Reads tables, lists, trees and combos page by page, as they are shown |
| Expands or collapses a tree node by its path |
| Chooses a menu path such as "File > Open", also in context menus |
| Answers a message box, input dialog or file chooser |
| Waits for a text to appear or disappear |
| Applies compiled code changes without a restart; rebuilds the screen if needed |
| Lists the beans in Spring applications (screens are shown separately) |
| Opens a Spring screen bean directly, without navigating the menu |
| Starts / closes the application from the AI tool, for projects without Maven |
Example snapshot:
- frame "ACME Customer Manager 3.2 - admin" [ref=e10] 900x620 active class=MainFrame
- menubar [ref=e11]
- menu "File" [ref=e12] items=3 (closed)
- tabs [ref=e15] tabs=["Customers"(selected), "Orders", "Reports"] field=tabs
- panel CustomerPanel [ref=e16] field=customerPanel
- group "Customer Details" [ref=e17]
- textfield "Full Name" [ref=e18] value="" field=txtName
- combobox "City" [ref=e20] value="Ankara" options=["Ankara", "İstanbul", ...] field=cmbCity
- button "Save" [ref=e23] field=btnSave
- table [ref=e26] rows=3 cols=5 field=tblCustomers
- columns: ID | Full Name | Email | City | Active
- row 0: 1 | Ayşe Yılmaz | ayse@example.com | Ankara | [x]field= is the name of the Java field that holds the component in the application; it makes matching the screen with the code easier.
Actions work like a real user: real key and mouse events, so the application's listeners and validation run, and the window does not have to be in front. Details: How actions behave.
How does it work?
The AI tool starts the MCP server as a local process and talks to it over stdio. The agent lives inside the application's JVM, so it reads the screen as text from the component tree instead of from pixels, and it works while the window is in the background.
The agent gets into the application in one of three ways, always on an explicit request:
How | Who starts it |
| You start the application from Maven, with the agent |
| The AI tool starts the application with a command you would use yourself |
| The AI tool attaches to an application that is already running |
The agent listens only on 127.0.0.1, with a random port and token. More on this in
SECURITY.md; a request step by step in docs/usage.md;
why it is built this way in docs/design.md.
Contributing
mvn install with JDK 17+ builds everything and runs the tests.
The rules of the code base, testing and releases are in CONTRIBUTING.md; changes
between versions are in CHANGELOG.md. Security model and how to report a vulnerability:
SECURITY.md.
License
Created and maintained by Halil İbrahim Çavdar. Licensed under the Apache License 2.0.
Available Tools
19 toolsclickA
Click a component like a user would, with real mouse press/release events: a focusable component takes the focus first (so the previous field's input verifier and focus-lost handlers run). Menu items, even inside closed menus, are activated directly. For tables, lists and trees pass value (the cell's text, the item's text, or a tree path like "Root/Child") or row (and col for tables). Use clickCount=2 for double-click, button=right for context menus, modifiers="Ctrl" or "Shift" to add to or extend the selection (select_option with values/indexes does several at once). Waits first (up to timeoutMs) until the component is visible, enabled, editable where needed, and not blocked by a modal dialog or busy overlay, so no wait_for is needed for a component that is about to become usable. Returns the new snapshot.
Inputs: ref (required), x, y, col, +8 more.
connect_appA
Connect to a running Java application by pid (see list_apps). If it was started without swing2mcp, the agent is loaded into it first: no restart, and the application keeps its state (open windows, logged-in user). Works with Java 8+ processes of the same OS user.
Inputs: pid (required).
dragA
Drag with the mouse like a user: press at the start, move, release at the end. The start is ref (an item by value/row/col, a slider's thumb, a split pane's divider, x/y, or its center; edge=right starts at a cell's or header column's right border, e.g. to resize a column). The end is dx/dy from the start, or toRef with toValue (item text or tree path; a number for a slider value or divider location), toRow/toCol, at=before/on/after, or toX/toY. mode=auto (default) picks: mouse - real mouse events inside the application (pan a map or canvas, move a slider, a divider, a table column; window may be in the background); transfer - drag and drop between components through the application's TransferHandlers (lists, tables, trees, text, drop zones): the source's data is dropped on the target at a real drop location, canImport/importData and the source's exportDone run as for a user, without the operating system's drag and drop; picked for drag-enabled sources; os - the real mouse pointer (window comes to the front; only for drag and drop that needs the operating system). The result says what changed (slider value, divider, column widths, a custom component's picture) or what the drop did. Waits first (up to timeoutMs) until the component is visible, enabled, editable where needed, and not blocked by a modal dialog or busy overlay, so no wait_for is needed for a component that is about to become usable. Returns the new snapshot.
Inputs: ref (required), x, y, at, +22 more.
expand_nodeA
Expand (or collapse) a tree node given by its path, like clicking its toggle: ancestors are expanded on the way and expansion listeners run, so trees that load children on expand fill in. Says if the application vetoed it. Waits first (up to timeoutMs) until the component is visible, enabled, editable where needed, and not blocked by a modal dialog or busy overlay, so no wait_for is needed for a component that is about to become usable. Returns the new snapshot.
Inputs: ref (required), path (required), collapse, timeoutMs.
handle_dialogA
Answer a dialog like a user: press one of its buttons by text or by role (ok, yes, no, cancel; open/save in file choosers; these work in any UI language), "close" for the window's close box. text first types the answer of an input dialog (or picks it in its combo box); path first puts a file or directory path into a file chooser and, unless button says otherwise, presses its Open/Save button. Without ref: the open modal dialog (or the newest dialog). The result repeats the dialog's title and message. To answer a dialog that an action will open, pass dialog= to that action instead. Waits first (up to timeoutMs) until the component is visible, enabled, editable where needed, and not blocked by a modal dialog or busy overlay, so no wait_for is needed for a component that is about to become usable. Returns the new snapshot.
Inputs: ref, path, text, button, +1 more.
hot_reloadA
Apply code changes to the running application without restarting it. Workflow: edit the Java sources, compile them (e.g. mvn -q compile in the application's module, or let the IDE build), then call hot_reload. Changed classes are found in the class directories (target/classes) and loaded into the running JVM. If only event handlers, painting or business logic changed, open screens keep their state; if a screen's construction code changed (constructor, initComponents, @PostConstruct...), that screen is rebuilt. Changes that add or remove methods or fields (including new lambdas) cannot be applied on a standard JVM: the result explains which, and nothing is changed; then restart the application. Only classes whose code really changed are reloaded, even if the build rewrote all class files. In a multi-module project, a module that the application runs from its jar needs classesDir (or start the application with mvn swing2mcp:run -Dswing2mcp.classesDirs=...). Returns the new snapshot.
Inputs: refs, rebuild, classesDir.
launch_appA
Start a Java Swing application with the swing2mcp agent injected and connect to it. command is a shell command line, e.g. java -jar app.jar or a start script; the agent is added through JAVA_TOOL_OPTIONS, so the application itself is not changed. Application output goes to a log file. Returns once the agent is up, usually before the first window: call wait_for next.
Inputs: command (required), cwd, timeoutSeconds.
list_appsA
List running Java applications. Those with the swing2mcp agent show their windows; the connected one is marked with *. The others can be connected with connect_app, which loads the agent into them without restarting.
Inputs: no named parameters.
open_spring_beanA
For Spring applications: show a window or panel bean directly instead of navigating menus. Windows and dialogs are opened (prototype beans give a fresh instance); a panel that is not on screen yet is shown in a new frame; a panel in a hidden tab gets its tab selected. Returns the new snapshot.
Inputs: name (required).
press_keyA
Press keys like a user: "Enter", "Escape", "Tab", "Shift+Tab", "Up", "F5", "Ctrl+S", "Alt+F4", or several separated by spaces ("Tab Tab Enter"). Keys go to the component that has the keyboard focus (marked "focused" in the snapshot), or to ref after focusing it, so key bindings, menu shortcuts, the default button and focus traversal work as for a user. Without ref, keys go to the open modal dialog if there is one. The application window does not need to be in front. The result says where the focus is afterwards. Waits first (up to timeoutMs) until the component is visible, enabled, editable where needed, and not blocked by a modal dialog or busy overlay, so no wait_for is needed for a component that is about to become usable. Returns the new snapshot.
Inputs: key (required), ref, mode, dialog, +1 more.
read_itemsA
Read the contents of a table, list, tree or combo box, page by page, as the user sees them (the text the cells show, with the underlying value where it reads differently). The snapshot shows only the first rows. Table: rows from start (view order, as sorted/filtered on screen), optionally only some columns. Tree: without path, the visible rows; with path, that node and its descendants down to depth levels, read from the tree model without expanding anything (trees that load children on expand need expand_node first). find keeps only entries containing that text.
Inputs: ref (required), find, path, depth, +3 more.
screenshotA
PNG image of a window or component, painted by Swing itself (works even if the window is covered). Without ref: the modal dialog, active window or main frame.
Inputs: ref.
select_optionA
Select an entry by visible text (value) or position (index) in a combo box, list, tab pane, table or tree. Table: value is the text of any cell of the row (limit it to a column with col); the cell is selected as by a click. Tree: value is a path like "Root/Child/Leaf" (the root may be left out; " > " also separates); ancestors are expanded on the way, as a user would. Several entries of a list, table or tree: values or indexes (ranges like "2-5"), or a range from value/index to another; they are selected with real clicks, the first plain, the others with Ctrl, a range's end with Shift. add=true keeps the current selection; deselect=true Ctrl-clicks the given entries that are selected. The result lists what is selected afterwards. Waits first (up to timeoutMs) until the component is visible, enabled, editable where needed, and not blocked by a modal dialog or busy overlay, so no wait_for is needed for a component that is about to become usable. Returns the new snapshot.
Inputs: ref (required), to, add, col, +7 more.
snapshotA
Describe what is on screen: every visible window as an indented outline of components (role, label, value, state) with a [ref=eN] for each element. Use refs with click, type_text, select_option and screenshot. Refs stay valid while the component exists. field= is the Java field holding the component, class= an application class. Prefer this over screenshot; use screenshot for custom-painted parts and layout.
Inputs: window, maxRows, expandMenus.
spring_beansA
For Spring applications: list the beans of the application's Spring context, which is found automatically without any change to the application. Window and panel beans are listed first and can be shown with open_spring_bean. Fails politely if the application has no Spring.
Inputs: filter.
stop_appC
Terminate an application (default: the connected one).
Inputs: pid.
type_textA
Type into a text field, text area, password field, spinner or editable combo box like a user: the field gets the focus (the previous field's input verifier runs; if it refuses, nothing is typed and the result says why), the old text is selected and each character is sent as real key events, so key listeners, document filters and formatters run. Replaces the content unless append=true; submit=true then presses Enter. "\n" types Enter and "\t" types Tab (moves to the next field). Formatted fields and spinners commit on Enter or when the focus leaves them. The application window does not need to be in front. mode=set sets the text directly without key events (faster, but skips key listeners). Waits first (up to timeoutMs) until the component is visible, enabled, editable where needed, and not blocked by a modal dialog or busy overlay, so no wait_for is needed for a component that is about to become usable. Returns the new snapshot.
Inputs: ref (required), text (required), mode, append, +3 more.
wait_forA
Wait until text appears anywhere in the snapshot (or disappears with gone=true). Without text, waits for the first window to appear, which is useful right after launch_app. Returns the snapshot; a timeout is an error, with the snapshot at that moment.
Inputs: gone, text, timeoutMs.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 19 tools
Each tool targets a distinct interaction (click, type_text, drag, select_menu, handle_dialog, expand_node), and the lifecycle tools (launch/connect/list/stop_app) are clearly separated. A few boundaries blur: click on table/list items overlaps with select_option, and click can activate menu items that select_menu also handles, but the descriptions explain when to prefer each (multi-select ranges, menu-open side effects). Minor overlap only, well mitigated.
All names are snake_case and mostly verb-led (launch_app, connect_app, read_items, type_text, handle_dialog, expand_node), which is predictable. A handful are bare nouns/verbs without an object (snapshot, click, drag, screenshot) and spring_beans is a noun, so it is not a strict uniform verb_noun pattern, but it is consistently readable.
19 tools is on the heavy side of the suggested 3-15 range, but the UI-automation domain genuinely needs distinct primitives for pointer, keyboard, selection, trees, menus, dialogs, waiting, and app lifecycle. Each tool covers a real, non-redundant capability, so the count is justified rather than padded.
Coverage is strong: app lifecycle, full snapshot + screenshot, mouse/keyboard/text input, table/list/tree reading and selection, menus, dialogs, waiting, hot reload, and Spring integration. Minor gaps remain, such as explicit scrolling within long lists/tables or window-level operations (resize/maximize/close), though snapshots and waiting behavior largely work around them.
Maintenance
Related MCP Connectors
Ship better Java with your coding agent.
500+ typed UI atoms an agent composes into real rendered interfaces. Free, no API key.
Connect ChatGPT, Claude, Cursor or VS Code to your Windows PC: files, terminal, browser, apps.
Reach your own computers from any AI app: files, commands, screen and mouse, approvals and alerts.
Related MCP Servers
- FlicenseNot gradedqualityBmaintenanceDesktop UI automation for AI agents: screenshots, window management, mouse, keyboard, UI Automation tree, OCR. Single Windows x64 binary, no dependencies.3-
- FlicenseNot gradedqualityDmaintenanceGives AI coding assistants live, structured access to running apps' state and UI elements, enabling real-time verification and interaction across web, mobile, and desktop.36-
- AlicenseNot gradedqualityAmaintenanceEnables interaction with Java Swing applications through MCP, allowing launching, attaching, taking snapshots, clicking, filling forms, and other UI automation via natural language.4MIT
- AlicenseNot gradedqualityCmaintenanceEnables controlling desktop windows and input on Windows and Linux (X11), with tools for listing apps and windows, taking screenshots, clicking, typing, scrolling, and dragging. It also provides a JVM agent to inspect and automate Java Swing applications.12 npmMIT