Skip to content

Commit 7b11d1e

Browse files
feat(minecraft): disable debug servers by default (#1193)
1 parent 583b54b commit 7b11d1e

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

services/minecraft/.env

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,18 @@ BOT_PORT=''
2828
# #
2929
# BOT_AUTH='microsoft'
3030
BOT_VERSION=''
31+
32+
# ==============================================================================
33+
# Debug and Development Tools
34+
# ==============================================================================
35+
# SECURITY NOTICE:
36+
# The MCP Server, Debug Server, and Prismarine Viewer endpoints are completely
37+
# unauthenticated. Enabling these exposes your bot's internal state and
38+
# capabilities to anyone who can reach the ports. This can lead to Remote
39+
# Code Execution (RCE) and full compromise of the bot if exposed to the internet
40+
# or untrusted local networks. Only enable these if you know what you are doing
41+
# and ensure they are not externally accessible.
42+
# ==============================================================================
43+
ENABLE_MCP_SERVER=false
44+
ENABLE_DEBUG_SERVER=false
45+
ENABLE_MINECRAFT_VIEWER=false

services/minecraft/src/cognitive/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { MineflayerPlugin } from '../libs/mineflayer'
22
import type { CognitiveEngineOptions, MineflayerWithAgents } from './types'
33

4+
import { config } from '../composables/config'
45
import { DebugService } from '../debug'
56
import { McpReplServer } from '../debug/mcp-repl-server'
67
import { ChatMessageHandler } from '../libs/mineflayer'
@@ -25,8 +26,11 @@ export function CognitiveEngine(options: CognitiveEngineOptions): MineflayerPlug
2526
const reflexManager = container.resolve('reflexManager')
2627
const taskExecutor = container.resolve('taskExecutor')
2728
const debugService = DebugService.getInstance()
28-
mcpReplServer = new McpReplServer(brain)
29-
mcpReplServer.start()
29+
30+
if (config.debug.mcp) {
31+
mcpReplServer = new McpReplServer(brain)
32+
mcpReplServer.start()
33+
}
3034

3135
debugService.onCommand('request_repl_state', () => {
3236
debugService.emit('debug:repl_state', brain.getReplState())
@@ -81,11 +85,8 @@ export function CognitiveEngine(options: CognitiveEngineOptions): MineflayerPlug
8185
// Initialize perception pipeline (raw events + detectors)
8286
perceptionPipeline.init(botWithAgents)
8387

84-
let tickCount = 0
8588
bot.onTick('tick', () => {
86-
tickCount++
87-
if (tickCount % 5 !== 0)
88-
return
89+
// Empty listener
8990
})
9091

9192
// Resolve EventBus for message handling

services/minecraft/src/composables/config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export const configSchema = z.object({
3939
model: requiredString('OPENAI_MODEL'),
4040
reasoningModel: requiredString('OPENAI_REASONING_MODEL'),
4141
}),
42+
debug: z.object({
43+
mcp: z.boolean().default(false),
44+
server: z.boolean().default(false),
45+
viewer: z.boolean().default(false),
46+
}),
4247
bot: z.object({
4348
username: requiredString('BOT_USERNAME'),
4449
host: requiredString('BOT_HOSTNAME'),
@@ -86,6 +91,11 @@ const defaultConfig: Omit<Config, 'openai'> = {
8691
wsBaseUrl: 'ws://localhost:6121/ws',
8792
clientName: 'minecraft-bot',
8893
},
94+
debug: {
95+
mcp: false,
96+
server: false,
97+
viewer: false,
98+
},
8999
}
90100

91101
// Create a singleton config instance
@@ -103,6 +113,11 @@ export function initEnv(): void {
103113
model: env.OPENAI_MODEL,
104114
reasoningModel: env.OPENAI_REASONING_MODEL,
105115
},
116+
debug: {
117+
mcp: env.ENABLE_MCP_SERVER === 'true',
118+
server: env.ENABLE_DEBUG_SERVER === 'true',
119+
viewer: env.ENABLE_MINECRAFT_VIEWER === 'true',
120+
},
106121
bot: {
107122
username: env.BOT_USERNAME || defaultConfig.bot.username,
108123
host: env.BOT_HOSTNAME || defaultConfig.bot.host,
@@ -127,6 +142,7 @@ export function initEnv(): void {
127142
config.openai = parsedConfig.data.openai
128143
config.bot = parsedConfig.data.bot
129144
config.airi = parsedConfig.data.airi
145+
config.debug = parsedConfig.data.debug
130146

131147
logger.withFields({ config }).log('Environment variables initialized')
132148
}

services/minecraft/src/main.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,26 @@ async function main() {
2323
initLogger() // todo: save logs to file
2424
initEnv()
2525

26+
if (config.debug.server || config.debug.viewer || config.debug.mcp) {
27+
useLogger().warn(
28+
[
29+
'==============================================================================',
30+
'SECURITY NOTICE:',
31+
'The MCP Server, Debug Server, and/or Prismarine Viewer endpoints are currently',
32+
'enabled. These endpoints are completely unauthenticated. Enabling these exposes',
33+
'your bot\'s internal state and capabilities to anyone who can reach the ports.',
34+
'This can lead to Remote Code Execution (RCE) and full compromise of the bot',
35+
'if exposed to the internet or untrusted local networks. Ensure they are not',
36+
'externally accessible.',
37+
'==============================================================================',
38+
].join('\n'),
39+
)
40+
}
41+
2642
// Start debug server
27-
DebugService.getInstance().start()
43+
if (config.debug.server) {
44+
DebugService.getInstance().start()
45+
}
2846

2947
const { bot } = await initBot({
3048
botConfig: config.bot,
@@ -42,7 +60,9 @@ async function main() {
4260
},
4361
})
4462

45-
setupMineflayerViewer(bot, { port: 3007, firstPerson: true })
63+
if (config.debug.viewer) {
64+
setupMineflayerViewer(bot, { port: 3007, firstPerson: true })
65+
}
4666

4767
// Connect airi server
4868
const airiClient = new Client({

0 commit comments

Comments
 (0)