Skip to main content
Glama
alicenjr

Dynamic Reincarnation Story

by alicenjr

handle_user_message

Processes user messages to route interactions and generate personalized reincarnation story paths based on choices and soul-searching questions.

Instructions

Main entry point - handle any user message and route accordingly

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idYes
messageYes

Implementation Reference

  • main.py:163-200 (handler)
    The core handler implementation for the 'handle_user_message' tool. Decorated with @mcp.tool() for registration. Handles user messages by managing story state, checking triggers like 'Arise', routing based on story progress (path selection, guidance questions, etc.), and delegating to other story functions.
    @mcp.tool() def handle_user_message(user_id: str, message: str) -> str: """Main entry point - handle any user message and route accordingly""" state = get_user_state(user_id) message_lower = message.strip().lower() # Check for "Arise" trigger to start the story if message_lower == "arise" and not state["story_started"]: state["story_started"] = True state["current_context"] = "User invoked 'Arise' to begin reincarnation" return str(arise_trigger_response()) + "\n\n" + str(initial_reincarnation_offer()) # If story hasn't started yet, prompt user to begin if not state["story_started"]: return """ I sense a lost soul seeking purpose... If you wish to begin your journey of reincarnation, speak the word "Arise" and we shall commence. Otherwise, tell me what brings you to this realm between life and death. """ # Route based on current story state if not state["current_path"]: # Story started but no path chosen yet if "question" in message_lower or "answer" in message_lower: return str(three_guidance_questions()) elif any(str(i) in message_lower for i in [1, 2, 3]): # User might be trying to choose a path directly return "Please first answer the three guidance questions so I can understand your soul's true desires, then I will help you choose the perfect path." else: return str(initial_reincarnation_offer()) + "\n\n" + "Would you like me to ask the three guidance questions to help you choose your path?" # If we have a path but no introduction yet if state["current_path"] and state["story_step"] == 0: return generate_path_introduction(user_id) # Normal story progression return process_user_input(user_id, message)
  • Input schema defined by type hints: user_id (str), message (str) with return type str.
    def handle_user_message(user_id: str, message: str) -> str:
  • main.py:163-163 (registration)
    The @mcp.tool() decorator registers the function as an MCP tool named 'handle_user_message'.
    @mcp.tool()
  • main.py:12-24 (helper)
    Helper function get_user_state used by handle_user_message to retrieve or initialize per-user story state.
    def get_user_state(user_id: str) -> Dict[str, Any]: """Get or create user story state""" if user_id not in story_states: story_states[user_id] = { "current_path": None, "story_step": 0, "choices_made": [], "user_answers": {}, "last_narrative": "", "current_context": "", "story_started": False } return story_states[user_id]

Latest Blog Posts

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/alicenjr/Dynamic-Reincarnation-mcp'

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