Integration guide
MCP server guide: expose CAPTCHA solving to your MCP clients
GateSolver does not ship an MCP server, but writing your own takes one short Python file. This guide builds it, connects it to a client, and covers the details that make it dependable.
Why write your own
The Model Context Protocol lets an assistant or agent discover and call tools offered by a separate process, called a server. A small server of your own, wrapping the GateSolver HTTP API, makes CAPTCHA solving available to every MCP capable client you use, with the API key held in one place. Writing it yourself also means you decide exactly which task types are allowed, how long a call may take and how many solves a session may run. We do not publish an official server, so the file on this page is something you own and maintain, and it calls the same public endpoints as every other integration.
Install the Python SDK
Use Python 3.10 or newer. Install the official SDK and an HTTP client with pip install "mcp[cli]" httpx. At the time of writing the SDK includes FastMCP, a high level server class that turns decorated functions into tools, reading type hints for the input schema and docstrings for descriptions. A TypeScript SDK exists as well if your team prefers Node.js; the structure is the same, but check its docs for the current registration method.
The server
# captcha_mcp.py
import asyncio, os, sys, httpx
from typing import Literal # enum values in the tool schema
from mcp.server.fastmcp import FastMCP
server = FastMCP("captcha-tools")
API_HOST = "https://gatesolver.com"
WIDGET_TASKS = {"turnstile": "AntiTurnstileTaskProxyLess", "recaptcha_v2": "ReCaptchaV2TaskProxyLess",
"recaptcha_v3": "ReCaptchaV3TaskProxyLess"}
async def gs(route: str, body: dict) -> dict:
payload = {"clientKey": os.environ["GATESOLVER_KEY"], **body}
async with httpx.AsyncClient(base_url=API_HOST, timeout=30) as c:
return (await c.post(route, json=payload)).json()
@server.tool()
async def solve_captcha(widget: Literal["recaptcha_v2", "recaptcha_v3", "turnstile"],
page_url: str, site_key: str, page_action: str = "") -> dict:
"""Get a token for a CAPTCHA widget. page_action is needed only for reCAPTCHA v3."""
task = {"type": WIDGET_TASKS[widget], "websiteURL": page_url, "websiteKey": site_key}
if page_action:
task.update(pageAction=page_action)
opened = await gs("/createTask", {"task": task})
if (opened.get("errorId") or 0) > 0:
return {"ok": False, "error": opened.get("errorCode"), "hint": "check inputs, do not retry as is"}
for _ in range(40):
await asyncio.sleep(3)
probe = await gs("/getTaskResult", {"taskId": opened["taskId"]})
if probe.get("status") == "ready":
sol = probe["solution"]
return {"ok": True, "token": sol.get("gRecaptchaResponse") or sol.get("token"),
"userAgent": sol.get("userAgent"), "field": "cf-turnstile-response"
if widget == "turnstile" else "g-recaptcha-response"}
if probe.get("errorId") or probe.get("status") == "failed":
return {"ok": False, "error": probe.get("errorCode", "failed"), "hint": "free, one retry is fine"}
return {"ok": False, "error": "timeout", "hint": "stop and report"}
@server.tool()
async def captcha_balance() -> str:
"""Return the GateSolver account balance."""
data = await gs("/getBalance", {})
return f"Balance: {data.get('balance')}" if not data.get("errorId") else data.get("errorCode", "error")
if __name__ == "__main__":
print("captcha-tools starting", file=sys.stderr)
server.run()
Two choices stand out. The widget argument uses short names mapped to API types, so clients see a small, clear choice and cannot request types you did not list. And the solve tool returns a structured object with ok, the token, the field name it belongs in, and a hint, which gives the calling model everything it needs to act without parsing prose.
Adding an image tool
Text image CAPTCHAs fit the same server with one more tool that accepts a base64 string (without the data:image prefix), sends an ImageToTextTask, polls every second and returns the text. Image tasks cost $0.28 per 1,000 and usually return under 1 seconds. Many MCP clients can pass images to tools only as data the model already has, so this tool works best when another tool in the same client captures the image, for example a browser tool that screenshots an element and returns base64.
The stdio rule
By default server.run() speaks the protocol over standard input and output. Anything else your code prints to stdout corrupts the message stream and the client disconnects with a confusing error. Send logs to stderr, as the startup line does, or use the logging module, which writes to stderr by default. This one rule accounts for a large share of "my server will not connect" problems.
Connecting a client
Most desktop and IDE clients register local servers in a JSON settings file with a command, its arguments and environment variables. The exact file name and location differ by client, so check its docs; the entry itself usually looks like this:
{
"mcpServers": {
"captcha-tools": {
"command": "python",
"args": ["/home/you/tools/captcha_mcp.py"],
"env": { "GATESOLVER_KEY": "YOUR_API_KEY" }
}
}
}
Putting the key in env keeps it out of the server source. Before wiring a client, try the server with the SDK's development tooling (at the time of writing, mcp dev captcha_mcp.py opens an inspector), call captcha_balance, and then solve_captcha against a page you control.
Where the inputs come from
An MCP tool receives only what the client passes, so the client side needs the page URL and site key. Pair this server with whatever browser or fetch tools your client already has: the model reads data-sitekey from the page through those tools and then calls solve_captcha. The returned field tells it where the token goes, and the token should be submitted at once because it expires within a couple of minutes. For finding keys by hand, see reading the reCAPTCHA site key.
Timeouts, errors and limits
A solve can take tens of seconds, and some clients cancel tool calls that run long. If yours does, split the work into two tools: start_captcha returns the task id immediately, and check_captcha polls once and returns the status. The model then calls the check tool every few seconds. Errors come back as data with a hint rather than as exceptions, so the model knows whether to fix inputs, retry once (failed tasks are free) or stop. To cap spending per session, keep a counter in a module level variable and refuse after a set number of solves. Charges follow the task type, for example $0.56 per 1,000 for the checkbox and $0.84 for Turnstile.
Security habits for a solving server
A tool that spends money deserves a few habits. Read the key only from the environment and never return it in a tool result or error message. Validate page_url with urllib.parse and reject anything that is not http or https, so a confused model cannot send junk tasks. Log each solve to stderr with the time, widget type and host, which gives you an audit trail without storing tokens. And keep the tool list short: clients show every tool to the model, and a tool that is not needed is one more thing the model might call at the wrong moment.
Running it for a team
For a shared setup, the SDK can serve over HTTP instead of stdio (recent versions accept a transport argument such as "streamable-http" in run(); check the docs). A network facing server needs authentication in front of it, since anyone who can call it spends your balance, so keep it on a private network or behind your existing gateway. The API allows unlimited concurrent tasks and 600 requests per minute per key, which a team server shares. Limit the tools to legitimate work such as QA, public data collection and accessibility support. Related reading: MCP in our glossary and tools for agents that meet CAPTCHAs.
Common questions
Does GateSolver provide an official MCP server?
No. This guide shows how to write your own small server that calls the public HTTP API with your key.
Why does my client fail to connect to the server?
The most common cause is output printed to stdout, which breaks the stdio protocol. Log to stderr instead and try again.
Can I write the server in TypeScript instead?
Yes. The official TypeScript SDK supports the same tool concept; the API calls are identical fetch requests to createTask and getTaskResult.
How do I stop a client from spending too much?
Keep a solve counter in the server and refuse after a limit, and only list the task types you actually need in the tool schema.
Should the server run on a public address?
Only behind authentication. Anyone who can call the tool spends your balance, so local stdio or a private network is the safer default.
Keep reading
- Model Context Protocol (MCP)The open protocol that lets AI assistants discover and call tools and data sources through a standard server interface.
- How do I give an AI agent a CAPTCHA tool?Wrap createTask and getTaskResult in one function with a clear schema, register it as a tool, and let the agent call it.
- OpenAI Agents SDKA Python function tool for the OpenAI Agents SDK that solves over HTTP and keeps long tokens out of the model context.
- API docscreateTask, getTaskResult, getBalance, error codes and the in.php format.