A template for building interactive CLI chat agents using OpenAI's Agents SDK and Arcade MCP Gateways. Built with Bun and TypeScript.
- Bun installed on your computer
- An OpenAI API Key
- An Arcade MCP Gateway URL
Install dependencies:
bun installSet up your environment variables:
cp .env.example .env
# fill it out with your information!The .env file requires:
OPENAI_API_KEY— Your OpenAI API keyOPENAI_MODEL— The model to use (e.g.gpt-5.2)LOG_LEVEL— Logging verbosity (info,debug, etc.)ARCADE_GATEWAY_URL— Your Arcade MCP Gateway URL
Start an interactive chat session:
./agent.ts chatStart a chat with an initial message:
./agent.ts chat "What can you help me with?"Override the gateway URL via CLI flag:
./agent.ts chat --gateway-url https://api.arcade.dev/mcp/your-gateway-slugclear— Clear conversation history and start freshquit/exit— End the session
Build a single-file executable:
bun build ./agent.ts --compile --outfile agentThen run it directly with ./agent.
agent.ts — CLI entrypoint (Commander-based)
agents/general.ts — General-purpose chat agent
classes/config.ts — Environment variable configuration
classes/logger.ts — Logging with timestamps and spinners
classes/wrappedAgent.ts — Base agent class (history, streaming, interactive chat)
utils/client.ts — OpenAI client setup
utils/tools.ts — Arcade MCP server connection with OAuth
The agent connects to an Arcade MCP Gateway, which provides tools the LLM can call during conversation. On first use, it opens a browser for OAuth authentication and caches tokens locally. Conversations are streamed to the terminal in real time.
bun testAll OpenAI API calls are mocked, so no API key is needed for tests.
- Why Bun + TypeScript? JS is the most popular programming language, and type-safety helps when learning. Bun eliminates TS compilation headaches and makes it easy to package and distribute binaries.