Tools for the AI: MCP
A plugin brings one MCP server. While the plugin is on (and signed in, if it needs to be), its tools are offered to Claude and to Codex on every turn. The chat shows each call as <Plugin name>: <tool name>.
A hosted server
"mcp": { "url": "https://mcp.acme.example/mcp" }
Streamable HTTP. With a sign-in, every request carries Authorization: Bearer <token>; AI Studio renews OAuth tokens before they expire. Published plugins need https (http://localhost works while you develop).
If the server implements MCP authorization (protected resource metadata, then dynamic client registration), use "auth": { "type": "mcp-oauth" } and AI Studio does the whole sign-in. See Sign-in.
A local server
"mcp": { "command": "node", "args": ["server/index.js"], "tokenEnv": "ACME_TOKEN" }
stdio, one JSON-RPC message per line. "node" is AI Studio's own Node.js, so it runs on machines without Node installed; published plugins must use it and ship plain JavaScript (no node_modules: bundle dependencies into one file).
Arguments that name a file in the plugin folder are turned into its full path. The server gets a minimal environment (PATH, HOME, temp folders, locale) plus:
| Variable | Value |
|---|---|
AISTUDIO_PROJECT | The open project's folder. |
AISTUDIO_PLUGIN_DIR | The plugin's own folder. |
AISTUDIO_PLUGIN_DATA | A folder for the plugin's data on this computer, kept across updates. |
tokenEnv's name | The user's token or key, when the plugin has a sign-in. |
A panel's aistudio.storage lives in <project>/.aistudio/plugins/<plugin id>.json, so a local server can read and write the same data the panel shows. The sample plugin does this.
A minimal stdio server
const TOOLS = [{
name: 'tickets_get',
description: 'A ticket by its key (like ACME-123): title, description, status.',
inputSchema: { type: 'object', properties: { key: { type: 'string' } }, required: ['key'] },
}];
const send = (m) => process.stdout.write(JSON.stringify(m) + '\n');
let buf = '';
process.stdin.on('data', (d) => {
buf += d;
let i;
while ((i = buf.indexOf('\n')) >= 0) {
const line = buf.slice(0, i); buf = buf.slice(i + 1);
if (line.trim()) handle(JSON.parse(line));
}
});
async function handle(m) {
if (m.id == null) return; // notifications
const reply = (result) => send({ jsonrpc: '2.0', id: m.id, result });
if (m.method === 'initialize') return reply({ protocolVersion: m.params.protocolVersion, capabilities: { tools: {} }, serverInfo: { name: 'tickets', version: '1.0.0' } });
if (m.method === 'tools/list') return reply({ tools: TOOLS });
if (m.method === 'tools/call') {
const r = await fetch(`https://api.acme.example/tickets/${m.params.arguments.key}`, {
headers: { Authorization: `Bearer ${process.env.ACME_TOKEN}` },
});
return reply({ content: [{ type: 'text', text: await r.text() }], isError: !r.ok });
}
send({ jsonrpc: '2.0', id: m.id, error: { code: -32601, message: `Unknown method ${m.method}` } });
}
stderr goes to the plugin's Log. Any MCP SDK works too, as long as you bundle it.
Writing tools the AI uses well
- Name them
noun_verband keep the list short; every tool is in the AI's context on every turn. - Descriptions say when to use the tool, not only what it returns.
- Return compact text or JSON. Large results cost the user tokens on each later turn.
- Put the policy (when to call what) in the plugin's prompt, not in every description.
From the panel
With mcp:call, the panel calls the same tools: aistudio.mcp.tools() and aistudio.mcp.call('tickets_get', { key: 'ACME-123' }). The result is the MCP tools/call result.
Where the calls run
On the user's computer. The AI vendor receives the tool definitions and the results, never your server's address, headers or tokens; Claude Code or Codex makes each call from the machine. Servers on a company network or VPN work for the same reason.