#Custom tools (MCP)
You can give AI Studio agents tools that you build and host yourself. You run an MCP server (Model Context Protocol) and register its URL in AI Studio. AI Studio reads the list of tools your server offers, and you can then add those tools to your agents.
You register and manage servers on the MCP servers screen in the AI Studio app. There is no public API for this.
#How it works
- You run an MCP server on a public HTTPS URL.
- You register the URL in AI Studio, with any headers your server needs for authentication.
- AI Studio connects, lists your tools and saves the list. You can re-sync later.
- You add tools by name to an agent.
- When the agent decides to use a tool, AI Studio calls your server with the arguments the model chose and gives the result back to the model.
#What your server must support
| Topic | Requirement |
|---|---|
| Transport | Streamable HTTP (recommended) or SSE. AI Studio tries Streamable HTTP first. If that fails for any reason, it tries SSE on the same URL. |
| Reachability | AI Studio's servers connect to your URL. It must be reachable from the internet. |
| Connections | A new connection for every operation (listing tools, or one tool call), closed afterwards. No session is kept. A stateless server is the best fit. |
| Timeout | 30 seconds per operation, covering the connection, the MCP handshake and the call, including the SSE fallback. A slower call fails with "the server did not respond in time". |
| Features used | initialize, tools/list and tools/call. Resources and prompts are not used. |
| Results | AI Studio passes the content of the tool result to the model. Return text (JSON in a text block is fine). |
Time limits at a glance
Seconds, drawn on a logarithmic scale so short and long limits fit together.
#1. Register a server
In the AI Studio app, open MCP servers and add a server:
| Field | Required | Description |
|---|---|---|
| Name | yes | A name you will recognise, for example Acme inventory. |
| URL | yes | The full MCP endpoint, for example https://mcp.example.com/mcp. |
| Headers | no | HTTP headers sent on every request to your server, for example Authorization: Bearer <token>. They are encrypted and never shown again. |
AI Studio connects and lists your tools right away. Check the server's status:
| Status | Meaning |
|---|---|
| Connected | Tools were listed and saved. |
| Error | AI Studio could not connect or list tools (wrong URL, server down, 401 from your server, timeout). Fix the cause, then edit the server or re-sync. |
| Syncing | A re-sync is in progress. |
#2. Update, re-sync or delete a server
- Update: change the name, URL or headers. If you change the URL or a header, AI Studio lists the tools again.
- Re-sync: use it after you add, remove or change tools on your server. A new tool is added, a changed description or input schema is updated, and a tool your server no longer lists is switched off. Remove it from your agents too: an agent that still has it will try to call it, and your server will answer that the tool does not exist.
- Delete: the app shows which of your agents use the server's tools first. Deleting removes the tools from those agents.
#3. Give the tools to an agent
Your MCP tools appear in the tool list next to the built-in tools, in the agent editor. Only you see your own servers' tools there. Add a tool to an agent by selecting it.
The model sees your tool's name, description and input schema exactly as your server reports them. Write the description for the model: say what the tool does, when to use it and what each argument means. Your MCP tools can also be used as steps in workflows.
#4. Side effects and evaluations
Every tool in AI Studio has a side-effect label: none, read, write or destructive. For tools of your own MCP server, AI Studio does not trust hints the server sends (such as MCP's readOnlyHint). Every tool of your server is treated as destructive.
- Agent evaluations: a destructive tool is never actually called. AI Studio records the arguments the agent chose and gives it a stand-in answer: the expected output from the test case if you wrote one, otherwise a simulated answer. Your server receives no calls from evaluation runs.
- To test a tool's real behaviour, chat with the agent instead.
Treat what your tools return as data the model will read. Do not return text you would not want the model to act on.
#5. Tool names
- Give every tool a distinctive name with your own prefix, for example
acme_get_stockrather thanget_stock. AI Studio keeps one tool per name, and a name another tool already uses can collide. - Use letters, digits and underscores.
- Do not rename tools that agents already use. A renamed tool is a new tool: the old name is switched off at the next sync, and you must update the agents that use it.
#6. Example server in Python
This server uses the official MCP Python SDK (mcp, version 1.27) and its FastMCP API, over Streamable HTTP. It checks a bearer token on every request.
pip install "mcp>=1.27" uvicornimport hmac
import os
import uvicorn
from mcp.server.fastmcp import FastMCP
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import JSONResponse
API_TOKEN = os.environ["MCP_API_TOKEN"]
# host="0.0.0.0" turns off the SDK's localhost-only Host check, which would
# otherwise refuse requests that arrive through your public domain.
mcp = FastMCP(
"acme-inventory",
host="0.0.0.0",
stateless_http=True, # every request stands alone: AI Studio opens a new connection per call
json_response=True, # plain JSON responses instead of an event stream
)
STOCK = {"SKU-1001": 42, "SKU-1002": 0}
@mcp.tool()
def acme_get_stock(sku: str) -> dict:
"""Return how many units of a product are in stock. `sku` is the product code, e.g. SKU-1001."""
if sku not in STOCK:
return {"found": False, "sku": sku}
return {"found": True, "sku": sku, "in_stock": STOCK[sku]}
class RequireBearerToken(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
expected = f"Bearer {API_TOKEN}"
given = request.headers.get("authorization", "")
if not hmac.compare_digest(given.encode(), expected.encode()):
return JSONResponse({"error": "unauthorized"}, status_code=401)
return await call_next(request)
app = mcp.streamable_http_app()
app.add_middleware(RequireBearerToken)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8000")))Run it, then put it behind HTTPS and register it:
MCP_API_TOKEN="$(openssl rand -hex 32)" python server.py| Field | Value |
|---|---|
| URL | https://mcp.example.com/mcp |
| Headers | Authorization: Bearer <the MCP_API_TOKEN value> |
The type hints and docstring become the tool's input schema and description. With a wrong or missing token the server answers 401, and AI Studio marks the server Error.