Skip to main content
Glama

Minecraft MCP Bot

by kilgorjn
llm_handlers.js2.76 kB
// llm_handlers.js // Handler functions for LLM-driven bot event responses // Example: Low health handler function handleLowHealth(event, mcpServer) { // Issue MCP command to move bot to safety or heal // Example: mcpServer.executeBotCommand('chat', ['I need healing!']); // Example: mcpServer.pathfindToPosition({ x: event.safeX, y: event.safeY, z: event.safeZ, range: 2 }); console.log('Handling low health event:', event); } // Example: Hostile mob nearby handler function handleHostileMobNearby(event, mcpServer) { // Directly alert the LLM (this module) to decide and act console.log('ALERT: Hostile mob detected near bot:', event); llmDecideHostileMobAction(event, mcpServer); } // LLM decision function for hostile mob events function llmDecideHostileMobAction(event, mcpServer) { // Notify the LLM of the hostile mob event and provide all context // The LLM should decide dynamically what action to take if (typeof global.llmDynamicDecision === 'function') { global.llmDynamicDecision('hostileMobNearby', event, mcpServer); } else { console.log('LLM needs to decide dynamically for hostile mob event:', event); } } // Example: Special chat handler function handleSpecialChat(event, mcpServer) { console.log('Handling special chat event:', event); // Use MCP sampling to send event to LLM and get decision const samplingRequest = { messages: [ { role: 'user', content: { type: 'text', text: `Special chat event: ${JSON.stringify(event)}. What should the bot do or say in response?` } } ] }; mcpServer.sampling.createMessage(samplingRequest).then(response => { const llmDecision = response.content.text; console.log('LLM sampling decision:', llmDecision); // Parse and execute the LLM's decision if (llmDecision.includes('chat') || llmDecision.includes('say')) { // Extract message from response const messageMatch = llmDecision.match(/"([^"]*)"/); const message = messageMatch ? messageMatch[1] : 'Hello!'; mcpServer.executeBotCommand('chat', [message]); } }).catch(err => { console.error('Sampling failed:', err); // Fallback mcpServer.executeBotCommand('chat', ['I received your message!']); }); } // LLM dynamic decision function function llmDynamicDecision(eventType, event, mcpServer) { // This is where the LLM decides what to do based on eventType and event context // Example: Log the event and prompt for decision (to be replaced by actual LLM logic) console.log(`LLM dynamic decision required for event type: ${eventType}`, event); // TODO: Implement actual LLM-driven decision logic here } module.exports = { handleLowHealth, handleHostileMobNearby, handleSpecialChat, llmDynamicDecision };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kilgorjn/minecraft_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server