AutoHotkey v2 MCP Server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@AutoHotkey v2 MCP Serverinspect my active window"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
AutoHotkey v2 MCP Server
Created by Xeo786
What is it?
This is a custom Model Context Protocol (MCP) server built in Python, designed specifically to bridge the gap between AI coding assistants and the AutoHotkey v2 ecosystem on Windows.
MCP is an open standard that enables AI models to connect securely to local data sources and tools. This server exposes powerful, specialized tools to the AI, granting it the context, execution, and live debugging capabilities needed to write perfect AHK scripts.
Why was it created?
AutoHotkey v2 introduced strict object-oriented syntax, removing graceful failures and silent errors that existed in v1. When an AI tries to write AHK code blindly, it often:
Mixes up v1 and v2 syntax.
Cannot tell if the target window title or class is correct.
Cannot verify if the script even launches without crashing.
Doesn't know what custom libraries the user already has installed.
Cannot debug running scripts to diagnose issues.
No record of past work: Without history, it's hard to "bring back" or review a script the AI ran 5 minutes ago.
This server solves all of these problems by giving the AI eyes (inspect active window), knowledge (search library), hands (validate and run), a full debugger (DBGp protocol integration), and now a complete action history with a dedicated GUI.
How does it help the AI? (Features)
The server exposes tools in two categories:
Core Tools
1. validate_ahk_syntax
What it does: Runs external AHK code through AutoHotkey's
/Validateswitch, sending syntax errors to/ErrorStdOut.How it helps: The AI can verify that the code it just wrote is syntactically sound, catching missing braces, undefined variables, or v1 legacy commands before handing the script to the user.
2. run_ahk_script
What it does: Executes a temporary script and forcefully captures standard output (
FileAppend(text, "*")) and runtime errors, strictly enforcing a timeout (e.g., 3 seconds) to prevent infinite loops.How it helps: The AI can test logical behavior (e.g., "Does this Regex expression actually match correctly in AHK?"). Fast feedback loops mean fewer broken scripts.
3. inspect_active_window
What it does: Runs a tiny script returning the Title, Class (
ahk_class), and Executable (ahk_exe) of whatever window the user currently has focused.How it helps: Finding correct window hooks is tedious. The user can just focus an app, ask the AI to "write a script for my active window," and the AI can pull the exact selectors needed for
WinActivateorControlSend.
4. search_global_library
What it does: Performs a text search through the user's master AHK library folder.
How it helps: Instead of reinventing the wheel (like creating a new WebSocket class), the AI can search the user's local drive, read the existing custom wrappers, and write code that utilizes the user's preferred ecosystem.
5. configure_paths
What it does: Sets and persists the
AHK_PATHandGLOBAL_LIB_PATHto the user'sAppData.New Feature: Supports
use_dialog=Trueto pop up native Windows file/directory selection dialogs on the host machine for easy setup.How it helps: Allows the server to remain portable and tool-neutral, letting the user (or AI) configure the exact binaries and libraries to use without editing the source code.
6. get_action_history & restore_action
What it does: Allows the AI to retrieve metadata about past scripts it has run and "restore" them (copy from history) back to its current workspace.
How it helps: Enables the AI to recall previous successful logic or bring back a script the user previously saw but didn't save.
Action History & GUI
The server now automatically logs every script execution to %AppData%\AutoHotkey_MCP_Server\history\.
MCP Action History GUI
A standalone AHK v2 GUI is included (MCP Action History.ahk) within the server directory.
Features:
*Live View: Browse all past actions in a sortable ListView.
Preview: Inspect the source code of any historical action.
Workspace Affinity: Each action logs the workspace (CWD) where it was run.
One-Click Restore: Quickly restore any script back to its original workspace with a timestamped filename.
History Management: Delete selected entries or wipe the entire history to keep your workspace clean.
DBGp Live Debugger Tools
These tools allow the AI to attach to and debug running AutoHotkey scripts in real-time using the DBGp protocol. This is the same protocol used by SciTE4AutoHotkey and VS Code debug adapters.
Connection Management
Tool | Description |
| Attach to a running AHK script by PID. Starts a TCP listener and sends |
| Detach from the debug session, letting the script continue normally. |
| Get the current debugger state ( |
Execution Control
Tool | Description |
| Pause execution of a running script. |
| Resume execution: |
Inspection & Evaluation
Tool | Description |
| Get the current call stack (file, line, function). |
| Get all variables in a context ( |
| Get a single variable by name. |
| Set a variable's value at runtime. |
| Evaluate any AHK expression in the current context. |
| Retrieve source code from the debugged script. |
Breakpoints
Tool | Description |
| Set a line breakpoint. |
| List all active breakpoints. |
| Remove a breakpoint by ID. |
I/O
Tool | Description |
| Redirect script stdout to the debugger: |
Example Workflows
Basic: Write and Validate a Script
User: "Write a script that closes my active window and logs it using my MyLogger.ahk library."
AI Process (Under the hood):
AI calls
inspect_active_window-> Finds out the user is in "Notepad" (ahk_class Notepad).AI calls
search_global_library("MyLogger")-> Discovers it needs to useLogger.Info("Closed").AI writes the draft script.
AI calls
validate_ahk_syntax-> Realizes it forgot a closing brace.AI fixes the code and gives the user a guaranteed-to-work script.
Advanced: Debug a Stuck Script
User: "My script PID 12345 seems stuck. Can you figure out why?"
AI Process:
AI calls
dbg_attach(pid=12345)-> Connects to the running script.AI calls
dbg_break()-> Pauses execution.AI calls
dbg_stack()-> Sees script is stuck inMyFunction()at line 42.AI calls
dbg_get_vars(context=0)-> Inspects local variables, findsretryCount = 999.AI calls
dbg_eval("retryCount := 0")-> Resets the counter.AI calls
dbg_continue(mode="run")-> Resumes the script.AI calls
dbg_detach()-> Disconnects cleanly.AI explains: "Your script was stuck in an infinite retry loop. I reset
retryCountto 0."
Restoration: "Bring back the script you ran earlier"
User: "Can you bring back that window inspection script you ran a few minutes ago? I want to keep it in my project."
AI Process:
AI calls
get_action_history-> Finds the ID of the recentinspect_active_windowtool call.AI calls
restore_action(id, "s:/path/to/project/InspectHelper.ahk")-> Copies the script from history back to the user's project folder.AI explains: "I've restored that script to your project as
InspectHelper.ahk."
Installation
Install Python 3.10+.
Install dependencies:
pip install -r requirements.txtConfigure your AutoHotkey and Library paths using the
configure_pathstool.
Connecting to Antigravity
Antigravity can leverage this server to provide expert AutoHotkey assistance. To connect this server to your Antigravity instance, add it to your antigravity.json or your global MCP configuration:
{
"mcpServers": {
"ahk-v2-server": {
"command": "python",
"args": ["path/to/server.py"],
"env": {
"AHK_PATH": "C:\\Program Files\\AutoHotkey\\v2\\AutoHotkey64.exe",
"GLOBAL_LIB_PATH": "C:\\Users\\YourUser\\Documents\\AutoHotkey\\Lib"
}
}
}
}Zero Configuration (Antigravity Only)
If you are an Antigravity user, you can skip manual JSON editing:
Clone this repository locally.
Open an Antigravity chat and tell it the absolute path to the repo.
Ask it to: "Connect to the MCP server in this directory."
The Experience: Once connected, try asking:
"Can you use the AutoHotkey v2 MCP? How does it feel to have these tools at your disposal?"
You will see that with these "eyes and hands," Antigravity's ability to automate your Windows environment becomes exponentially more effective—transforming from a guessing assistant into a precise systems architect.
What can you ask Antigravity?
Once connected, you can leverage the full power of AutoHotkey through simple prompts:
System Awareness: "Inspect my active window and tell me its class."
Live Debugging: "Attach to my script (PID 1234) and find out why it's stuck."
Library Integration: "Write a new automation script using my existing local libraries."
Office Automation: "Highlight row X on my active Excel workbook using ComObject."
Web Automation: "Use Rufaydium to create a Chrome session and inspect the target webpage."
Error Resolution: "I have an AutoHotkey error popup; please diagnose and fix it."
Complex Workflows: "Scan my document, extract all keywords, and create a summary table in a new Excel workbook."
History Management: "Show me the last 5 things you did," or "Restore the script from my last execution to this folder."
License
This project is licensed under the GNU GPL 3.0. See the LICENSE file for details.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Xeo786/AutohotkeyV2_MCPServer'
If you have feedback or need assistance with the MCP directory API, please join our Discord server