Skip to main content
Glama
kitan23

Dedalus MCP Documentation Server

by kitan23

ask_docs

Answer questions about documentation using AI with context from documents. Get AI-generated answers with sources for technical queries.

Instructions

Answer questions about documentation using AI

Args:
    question: The question to answer
    context_docs: Optional list of document paths to use as context
    max_context_length: Maximum characters of context to include
    user_id: Optional user identifier for rate limiting

Returns:
    AI-generated answer with sources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
questionYes
context_docsNo
max_context_lengthNo
user_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the 'ask_docs' MCP tool. Decorated with @mcp.tool() for automatic schema generation and registration. Implements rate limiting, automatic context retrieval via search_docs if needed, context truncation, OpenAI GPT-4o-mini integration for answer generation (with fallback to raw context provision if no API key), source tracking, and comprehensive error handling.
    @mcp.tool()
    def ask_docs(
        question: str,
        context_docs: Optional[List[str]] = None,
        max_context_length: int = 4000,
        user_id: Optional[str] = None,
    ) -> Dict[str, Any]:
        """
        Answer questions about documentation using AI
    
        Args:
            question: The question to answer
            context_docs: Optional list of document paths to use as context
            max_context_length: Maximum characters of context to include
            user_id: Optional user identifier for rate limiting
    
        Returns:
            AI-generated answer with sources
        """
        # Rate limiting check
        identifier = user_id or 'default'
        if not rate_limiter.is_allowed(identifier):
            reset_time = rate_limiter.get_reset_time(identifier)
            return {
                'error': 'Rate limit exceeded',
                'message': f'Too many requests. Please wait {reset_time} seconds before trying again.',
                'reset_in_seconds': reset_time,
                'limit': '10 requests per minute',
            }
        # If no context docs specified, search for relevant ones
        if not context_docs:
            search_results = search_docs(question, max_results=3)
            context_docs = [result['path'] for result in search_results]
    
        # Gather context from documents
        context_parts = []
        sources = []
        total_length = 0
    
        for doc_path in context_docs:
            if total_length >= max_context_length:
                break
    
            try:
                file_path = DOCS_DIR / doc_path
                content = file_path.read_text()
    
                # Truncate if needed
                remaining = max_context_length - total_length
                if len(content) > remaining:
                    content = content[:remaining] + '...'
    
                context_parts.append(f'--- {doc_path} ---\n{content}')
                sources.append(doc_path)
                total_length += len(content)
            except (OSError, UnicodeDecodeError):
                continue
    
        if not context_parts:
            return {
                'answer': "I couldn't find relevant documentation to answer your question.",
                'sources': [],
                'confidence': 'low',
            }
    
        full_context = '\n\n'.join(context_parts)
    
        # Try to use OpenAI if API key is available
        api_key = os.getenv('OPENAI_API_KEY')
        if api_key:
            try:
                from openai import OpenAI
    
                client = OpenAI(api_key=api_key)
    
                response = client.chat.completions.create(
                    model='gpt-4o-mini',
                    messages=[
                        {
                            'role': 'system',
                            'content': 'You are a helpful assistant that answers questions based on provided documentation. Only use information from the provided context.',
                        },
                        {
                            'role': 'user',
                            'content': f"""Based on the following documentation, please answer this question: {question}
    
    Documentation:
    {full_context}
    
    Please provide a clear, concise answer based only on the provided documentation.""",
                        },
                    ],
                    temperature=0.7,
                    max_tokens=500,
                )
    
                return {
                    'answer': response.choices[0].message.content,
                    'sources': sources,
                    'context_length': total_length,
                    'model': 'gpt-4o-mini',
                    'confidence': 'high',
                }
            except Exception as e:
                # Fall back to context-only response if OpenAI fails
                return {
                    'answer': f'Error using OpenAI: {str(e)}',
                    'context': full_context[:500] + '...'
                    if len(full_context) > 500
                    else full_context,
                    'sources': sources,
                    'context_length': total_length,
                    'error': str(e),
                }
    
        # If no API key, return context for Dedalus deployment
        return {
            'question': question,
            'context': full_context[:500] + '...'
            if len(full_context) > 500
            else full_context,
            'sources': sources,
            'context_length': total_length,
            'note': "No API key found. When deployed to Dedalus, this will use the platform's LLM integration via BYOK",
        }
  • Function signature and docstring defining the input schema (question: str, context_docs: Optional[List[str]], etc.) and output format (Dict with answer, sources, etc.). Used by MCP framework for tool schema validation.
    def ask_docs(
        question: str,
        context_docs: Optional[List[str]] = None,
        max_context_length: int = 4000,
        user_id: Optional[str] = None,
    ) -> Dict[str, Any]:
        """
        Answer questions about documentation using AI
    
        Args:
            question: The question to answer
            context_docs: Optional list of document paths to use as context
            max_context_length: Maximum characters of context to include
            user_id: Optional user identifier for rate limiting
    
        Returns:
            AI-generated answer with sources
        """
  • src/main.py:42-54 (registration)
    The 'ask_docs' tool is documented and listed as available in the MCP server's instructions string, confirming its registration among available tools.
        instructions="""This MCP server provides access to documentation files with AI-powered search and Q&A capabilities.
        
    Available tools:
    - list_docs(): List all documentation files
    - search_docs(query): Search documentation with keywords
    - ask_docs(question): Get AI-powered answers from documentation
    - index_docs(): Index documents for better search
    - analyze_docs(task): Analyze documentation for specific tasks
    
    Resources:
    - docs://{path}: Access any markdown documentation file directly
    
    This server includes rate limiting (10 requests/minute) to protect API keys.""",
  • RateLimiter class used by ask_docs for API protection (10 req/min).
    class RateLimiter:
        """Simple rate limiter to protect API keys from abuse"""
    
        def __init__(self, max_requests: int = 10, window_seconds: int = 60):
            self.max_requests = max_requests
            self.window_seconds = window_seconds
            self.requests = defaultdict(list)
    
        def is_allowed(self, identifier: str) -> bool:
            """Check if request is allowed for this identifier"""
            now = time.time()
            # Clean old requests outside window
            self.requests[identifier] = [
                req_time
                for req_time in self.requests[identifier]
                if now - req_time < self.window_seconds
            ]
    
            # Check if under limit
            if len(self.requests[identifier]) < self.max_requests:
                self.requests[identifier].append(now)
                return True
            return False
    
        def get_reset_time(self, identifier: str) -> int:
            """Get seconds until rate limit resets"""
            if not self.requests[identifier]:
                return 0
            oldest = min(self.requests[identifier])
            return max(0, int(self.window_seconds - (time.time() - oldest)))
  • get_doc_metadata helper used indirectly via search_docs for document information.
    def get_doc_metadata(file_path: Path) -> Dict[str, Any]:
        """Extract metadata from markdown files"""
        if file_path in METADATA_CACHE:
            return METADATA_CACHE[file_path]
    
        metadata = {
            'title': file_path.stem.replace('-', ' ').title(),
            'path': str(file_path.relative_to(DOCS_DIR)),
            'modified': datetime.fromtimestamp(file_path.stat().st_mtime).isoformat(),
            'size': file_path.stat().st_size,
            'hash': hashlib.md5(file_path.read_bytes()).hexdigest(),
        }
    
        # Try to extract title from first # heading
        try:
            content = file_path.read_text()
            lines = content.split('\n')
            for line in lines[:10]:  # Check first 10 lines
                if line.startswith('# '):
                    metadata['title'] = line[2:].strip()
                    break
        except (OSError, UnicodeDecodeError):
            pass
    
        METADATA_CACHE[file_path] = metadata
        return metadata
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'AI-generated answer with sources' but lacks critical details: rate limits (only hinted via user_id parameter), response format beyond 'with sources', error conditions, or performance characteristics. The description is insufficient for a 4-parameter AI tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, Args, Returns) and efficiently communicates core information. However, the 'Args' and 'Returns' headings are somewhat redundant with the schema and could be more integrated with the narrative flow.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 4 parameters, 0% schema coverage, no annotations, but an output schema exists, the description is moderately complete. It covers basic parameter meanings and return type but lacks operational context about AI behavior, quality expectations, or integration with sibling tools. The output schema reduces but doesn't eliminate the need for behavioral explanation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It provides basic parameter explanations in the Args section, mapping to the 4 parameters. However, it doesn't explain parameter interactions (e.g., how context_docs and max_context_length relate), format expectations for document paths, or practical constraints for max_context_length.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Answer questions about documentation using AI' - a specific verb+resource combination. However, it doesn't distinguish this from sibling tools like 'search_docs' or 'analyze_docs', which might have overlapping functionality for documentation interaction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'search_docs' or 'analyze_docs'. There's no mention of use cases, prerequisites, or exclusions. The agent must infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/kitan23/Python_MCP_Server_Example_2'

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