ask_stylus
Get answers to Stylus development questions, debug code issues, or understand concepts with version-specific guidance for smart contract creation.
Instructions
Ask questions about Stylus development, get concept explanations, or debug code issues. Supports version-specific guidance.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| question | Yes | The question to answer | |
| code_context | No | Optional code snippet for context (e.g., for debugging) | |
| question_type | No | Type of question for optimized response (default: general) | general |
| target_version | No | Target stylus-sdk version for version-specific guidance (default: 0.10.0). |
Implementation Reference
- src/mcp/tools/ask_stylus.py:251-380 (handler)The `execute` method of `AskStylusTool` class handles the logic for answering questions about Stylus development, including input validation, context retrieval, prompt generation, LLM interaction, and response parsing.
def execute( self, question: str, code_context: Optional[str] = None, question_type: str = "general", target_version: Optional[str] = None, **kwargs, ) -> dict: """ Answer a question about Stylus development. Args: question: The question to answer. code_context: Optional code snippet for context (e.g., for debugging). question_type: Type of question (concept, debugging, comparison, howto, general). target_version: Target stylus-sdk version for version-specific guidance. Returns: Dict with answer, code_examples, references, follow_up_questions. """ # Validate input if not question or not question.strip(): return {"error": "Question is required and cannot be empty"} question = question.strip() # Check if question is Stylus-related stylus_keywords = [ "stylus", "rust", "contract", "arbitrum", "storage", "entrypoint", "sol_storage", "erc", "token", "deploy", "wasm", "sdk", ] is_stylus_related = any(kw in question.lower() for kw in stylus_keywords) if not is_stylus_related and not code_context: return { "answer": ( "This question doesn't appear to be" " related to Stylus or Arbitrum" " development. I'm specialized in" " helping with Stylus smart contract" " development. Please ask about" " Stylus concepts, code," " or debugging." ), "code_examples": [], "references": [], "follow_up_questions": [ "What is Stylus and how does it work?", "How do I create my first Stylus contract?", "What are the benefits of Stylus over Solidity?", ], } # Default to main version if not specified if not target_version: target_version = get_main_version() try: # Retrieve relevant context with version-aware scoring context_result = self.context_tool.execute( query=question, n_results=5, content_type="all", rerank=True, category_boosts=None, # Use default Stylus-focused boosts target_version=target_version, ) references = [] context_text = "" if "contexts" in context_result: for ctx in context_result["contexts"]: references.append( { "title": ctx["metadata"].get("title", "Reference"), "source": ctx["source"], "relevance": f"Relevance score: {ctx['relevance_score']:.2f}", } ) context_text += ( f"\n--- Reference: {ctx['source']} ---\n{ctx['content'][:1200]}\n" ) # Build prompt user_prompt = self._build_prompt( question=question, code_context=code_context, question_type=question_type, context_text=context_text, ) # Generate answer with version-aware system prompt messages = [ {"role": "system", "content": get_system_prompt(target_version)}, {"role": "user", "content": user_prompt}, ] response = self._call_llm( messages=messages, temperature=0.3, max_tokens=2048, ) # Parse response answer, code_examples = self._parse_response(response, target_version=target_version) # Generate follow-up questions follow_up_questions = self._generate_follow_ups(question, answer) return { "answer": answer, "code_examples": code_examples, "references": references[:5], # Limit to 5 references "follow_up_questions": follow_up_questions, } except Exception as e: return {"error": f"Failed to answer question: {str(e)}"}