A Minecraft Bedrock Edition bot powered by OpenAI that connects to your server and responds to player queries via chat. Includes a built-in web dashboard for monitoring bot and server status.
- AI-Powered Chat - Players can ask questions by typing
bot <question>in chat, and the bot responds using OpenAI's API. - Realtime Web Search (Tavily) - AI can call
askTavilyvia OpenAI tool-calling to fetch up-to-date information (news, weather, prices, scores, recent releases) when training data is insufficient. Falls back to model knowledge ifTAVILY_API_KEYis not set or search fails. - Auto-Reconnect - Automatically reconnects after death or disconnection with a 30-second delay.
- Web Dashboard - Real-time status page showing bot connection state and server details (players, version, ping, MOTD).
- Health Endpoint -
/healthendpoint for uptime monitoring. - Offline Mode Support - Works with both online and offline Minecraft servers.
- Configurable AI Model - Use any OpenAI-compatible API endpoint with your preferred model.
- Node.js 18+
- A Minecraft Bedrock Edition server
- An OpenAI API key (or any OpenAI-compatible API)
- (Optional) A Tavily API key for realtime search - if omitted the bot answers from model training data only
-
Clone the repository:
git clone https://github.com/surajit20107/mc-bot-new-test.git cd mc-bot-new-test -
Install dependencies:
npm install
-
Create a
.envfile from the sample:cp .env.sample .env
-
Configure your environment variables in
.env:MC_HOST="" # your server IP MC_PORT="" # your server port MC_USERNAME="" # bot name MC_PLATFORM="bedrock" # options: [bedrock or java] MC_VERSION="" # optional: override auto-detected version OPENAI_BASE_URL="" # any OpenAI compatible API endpoint OPENAI_API_KEY="" # your AI API key AI_MODEL="" # your AI model (e.g. gpt-4, gpt-3.5-turbo) default: auto TAVILY_API_KEY="" # optional: Tavily API key for realtime web search
-
Start the bot:
npm start
Once running, the bot connects to your Minecraft server automatically.
- In-game: Type
bot <your question>in chat to get an AI-generated response.- Example realtime queries:
bot what is the latest Minecraft update?,bot weather in Kolkata today,bot score of yesterday's match. When a realtime query is detected, the AI calls Tavily (src/bot/tavily.js) and answers with fresh results.
- Example realtime queries:
- Dashboard: Visit
http://localhost:3000(or your configuredPORT) to view the bot and server status. - Health Check:
GET /healthreturns200 OKwhen the bot is running.
minecraft-bot/
├── src/
│ ├── server.js # Entry point — starts Express + bot
│ ├── bot/
│ │ ├── BotManager.js # Connection, lifecycle & auto-reconnect
│ │ ├── tavily.js # Tavily realtime search wrapper (askTavily)
│ │ ├── index.js # Bot exports
│ │ └── handlers/
│ │ └── chat.handler.js # `bot <question>` handler
│ ├── config/
│ │ ├── index.js # Env config & validation
│ │ └── constants.js # Default constants & AI prompt
│ ├── services/
│ │ ├── ai.service.js # OpenAI integration + Tavily tool-calling logic
│ │ └── serverStatus.service.js # Server ping & dynamic version resolution
│ ├── utils/
│ │ └── logger.js # Structured logger
│ └── web/
│ ├── app.js # Express app factory
│ ├── routes/
│ │ ├── health.routes.js # GET /health
│ │ └── dashboard.routes.js # GET /
│ └── views/
│ └── dashboard.view.js # Dashboard HTML template
├── package.json # Dependencies and scripts (@tavily/core included)
├── .env.sample # Environment variable template
├── .gitignore # Git ignore rules
└── profiles/ # Cached auth tokens (gitignored)
| Variable | Required | Default | Description |
|---|---|---|---|
MC_HOST |
Yes | - | Minecraft server IP or hostname |
MC_PORT |
No | 19132 |
Minecraft server port |
MC_USERNAME |
No | surajit_bot |
Bot's in-game username |
MC_PLATFORM |
No | bedrock |
Server platform (bedrock or java) |
MC_VERSION |
No | (auto) | Minecraft version override (auto-resolved from server ping if empty) |
OPENAI_BASE_URL |
Yes | - | OpenAI-compatible API endpoint |
OPENAI_API_KEY |
Yes | - | Your API key |
AI_MODEL |
No | auto |
Model to use for chat completions |
TAVILY_API_KEY |
No | - | Tavily API key for realtime search (src/bot/tavily.js). If unset, askTavily returns false and AI falls back to training data |
PORT |
No | 3000 |
Web server port |
HOST |
No | 0.0.0.0 |
Web server host |
- The bot resolves the Minecraft version dynamically via the ping API (
src/services/serverStatus.service.js) orMC_VERSIONif set, then connects usingbedrock-protocol(src/bot/BotManager.js). - It listens for incoming
text(chat) packets viasrc/bot/handlers/chat.handler.js. - When a message starts with
bot, the rest of the message is sent to the OpenAI-compatible API (src/services/ai.service.js). - The AI is configured with a function tool
askTavily(defined insrc/services/ai.service.js:22and implemented insrc/bot/tavily.js:3). If the user asks about current events, news, weather, prices, etc., the model calls the tool;askTavilyqueries Tavily (searchDepth: "advanced",includeAnswer: "basic") and returnsansweror top 3resultscontent. The result is appended as atoolmessage and the model generates a final grounded answer. Providers without tool support fall back to a plain completion without Tavily. - The AI response is sent back to the server as a chat message.
- If the bot dies or disconnects,
BotManagerwaits 30 seconds and reconnects automatically. The web dashboard (src/web/) exposes bot/server status atGET /andGET /health.
- File:
src/bot/tavily.js:3— exportsaskTavily(query) - Dependency:
@tavily/core@^0.7.13(seepackage.json:11) - Behaviour: Returns
response.answerif present, otherwise joined top-3results[].content, otherwisefalse. On missing key or error it logs and returnsfalsesoai.service.js:100can instruct the model to fall back to training data. - Env:
TAVILY_API_KEY— see.env.sample:12
MIT