create-extension Guide Skill
This skill allows Tars to create new Gemini CLI extensions with MCP servers.
Instructions
When you need to build a new tool or integration:
- •Plan the Extension: Define the name and the MCP tools it will expose.
- •Create the Directory: Move to
~/.gemini/extensions/<name>. - •Initialize npm: Run
npm init -y. - •Install Dependencies: Install
@modelcontextprotocol/sdkand any other required libraries. - •Write the Server (JavaScript): Create a
server.jsfile.- •CRITICAL: Use plain JavaScript for runtime-created extensions to avoid a build step.
- •Use the
@modelcontextprotocol/sdkto define tools and handle stdio.
- •Create Manifest: Create
gemini-extension.json. - •Register: Run
gemini extensions install .from the directory.
Manifest Template (gemini-extension.json)
json
{
"name": "my-extension",
"version": "1.0.0",
"mcpServers": {
"main": {
"command": "node",
"args": ["${extensionPath}/server.js"],
"env": {
"NODE_ENV": "production"
}
}
}
}
Server Template (server.js)
javascript
#!/usr/bin/env node
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';
const server = new McpServer({
name: 'my-extension',
version: '1.0.0'
});
server.registerTool(
'my_tool',
{
description: 'Describe tool here',
inputSchema: z.object({}).shape
},
async (args) => {
return {
content: [{ type: 'text', text: 'Hello from Tars extension!' }]
};
}
);
const transport = new StdioServerTransport();
await server.connect(transport);
🔒 Handling Secrets & Authentication
Do NOT pass API keys or credentials as tool arguments. This exposes them in the conversation history and logs.
Standard Workflow:
- •Access: Use
process.env.MY_SECRET_KEYin your extension. - •Missing Key Handling: If missing, return an error message:
"❌ API Key missing. Please run 'tars secret set MY_SECRET_KEY YOUR_KEY' and restart Tars." - •Storage: Tars manages these via
~/.tars/.envwith private permissions.