Skip to main content
Glama
itshare4u

Agent Knowledge MCP

create_document_template

Generate structured document templates for knowledge bases with AI-enhanced metadata, formatting, and organization to improve information management.

Instructions

Create a properly structured document template for knowledge base with AI-generated metadata and formatting

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesDocument title for the knowledge base entry
contentNoDocument content for AI analysis and metadata generation
priorityNoPriority level for the documentmedium
source_typeNoType of source contentmarkdown
tagsNoAdditional manual tags (will be merged with AI-generated tags)
summaryNoBrief summary description of the document content
key_pointsNoAdditional manual key points (will be merged with AI-generated points)
relatedNoList of related document IDs or references
use_ai_enhancementNoUse AI to generate intelligent tags and key points

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main FastMCP tool implementation for 'create_document_template'. Uses AI to enhance metadata, calls base helper, validates structure, and returns formatted JSON template with guidance.
    @app.tool(
        description="Create a properly structured document template for knowledge base with AI-generated metadata and formatting",
        tags={"elasticsearch", "document", "template", "knowledge-base", "ai-enhanced"}
    )
    async def create_document_template(
            title: Annotated[str, Field(description="Document title for the knowledge base entry")],
            content: Annotated[str, Field(description="Document content for AI analysis and metadata generation")] = "",
            priority: Annotated[
                str, Field(description="Priority level for the document", pattern="^(high|medium|low)$")] = "medium",
            source_type: Annotated[str, Field(description="Type of source content",
                                              pattern="^(markdown|code|config|documentation|tutorial)$")] = "markdown",
            tags: Annotated[
                List[str], Field(description="Additional manual tags (will be merged with AI-generated tags)")] = [],
            summary: Annotated[str, Field(description="Brief summary description of the document content")] = "",
            key_points: Annotated[List[str], Field(
                description="Additional manual key points (will be merged with AI-generated points)")] = [],
            related: Annotated[List[str], Field(description="List of related document IDs or references")] = [],
            use_ai_enhancement: Annotated[
                bool, Field(description="Use AI to generate intelligent tags and key points")] = True,
            ctx: Context = None
    ) -> str:
        """Create a properly structured document template for knowledge base indexing with AI-generated metadata."""
        try:
            # Initialize metadata
            final_tags = list(tags)  # Copy manual tags
            final_key_points = list(key_points)  # Copy manual key points
    
            # Use AI enhancement if requested and content is provided
            if use_ai_enhancement and content.strip() and ctx:
                try:
                    await ctx.info("๐Ÿค– Generating intelligent metadata and smart content using AI...")
                    ai_metadata = await generate_smart_metadata(title, content, ctx)
    
                    # Merge AI-generated tags with manual tags
                    ai_tags = ai_metadata.get("tags", [])
                    for tag in ai_tags:
                        if tag not in final_tags:
                            final_tags.append(tag)
    
                    # Merge AI-generated key points with manual points
                    ai_key_points = ai_metadata.get("key_points", [])
                    for point in ai_key_points:
                        if point not in final_key_points:
                            final_key_points.append(point)
    
                    # Use AI-generated smart summary if available
                    ai_summary = ai_metadata.get("smart_summary", "")
                    if ai_summary and not summary:
                        summary = ai_summary
    
                    # Use AI-enhanced content if available and better
                    ai_enhanced_content = ai_metadata.get("enhanced_content", "")
                    if ai_enhanced_content and len(ai_enhanced_content) > len(content) * 0.8:
                        content = ai_enhanced_content
    
                    await ctx.info(
                        f"โœ… AI generated {len(ai_tags)} tags, {len(ai_key_points)} key points, smart summary, and enhanced content")
    
                except Exception as e:
                    await ctx.warning(f"AI enhancement failed: {str(e)}, using manual metadata only")
    
            # Generate auto-summary if not provided and content is available
            if not summary and content.strip():
                if len(content) > 200:
                    summary = content[:200].strip() + "..."
                else:
                    summary = content.strip()
    
            template = create_doc_template_base(
                title=title,
                priority=priority,
                source_type=source_type,
                tags=final_tags,
                summary=summary,
                key_points=final_key_points,
                related=related
            )
    
            ai_info = ""
            if use_ai_enhancement and ctx:
                ai_info = f"\n๐Ÿค– **AI Enhancement Used**: Generated {len(final_tags)} total tags and {len(final_key_points)} total key points\n"
    
            return (f"โœ… Document template created successfully with AI-enhanced metadata!\n\n" +
                    f"{json.dumps(template, indent=2, ensure_ascii=False)}\n" +
                    ai_info +
                    f"\nThis template can be used with the 'index_document' tool.\n\n" +
                    f"โš ๏ธ **CRITICAL: Search Before Creating - Avoid Duplicates**:\n" +
                    f"   ๐Ÿ” **STEP 1**: Use 'search' tool to check if similar content already exists\n" +
                    f"   ๐Ÿ”„ **STEP 2**: If found, UPDATE existing document instead of creating new one\n" +
                    f"   ๐Ÿ“ **STEP 3**: For SHORT content (< 1000 chars): Add directly to 'content' field\n" +
                    f"   ๐Ÿ“ **STEP 4**: For LONG content: Create file only when truly necessary\n" +
                    f"   ๐Ÿงน **STEP 5**: Clean up outdated documents regularly to maintain quality\n" +
                    f"   ๐ŸŽฏ **Remember**: Knowledge base quality > quantity - avoid bloat!")
    
        except Exception as e:
            return f"โŒ Failed to create document template: {str(e)}"
  • Base helper function imported as 'create_doc_template_base' and used by the main handler to generate the core document structure with ID generation and schema validation.
    def create_document_template(
        title: str,
        priority: str = "medium",
        source_type: str = "markdown",
        tags: Optional[List[str]] = None,
        summary: str = "",
        key_points: Optional[List[str]] = None,
        related: Optional[List[str]] = None
    ) -> Dict[str, Any]:
        """
        Create a document template with proper structure.
        
        Args:
            title: Document title
            priority: Priority level (high/medium/low)
            source_type: Type of source
            tags: List of tags
            summary: Brief description
            key_points: List of key points
            related: List of related document IDs
            
        Returns:
            Properly structured document
        """
        document = {
            "id": generate_document_id(title, source_type),
            "title": title,
            "summary": summary or f"Brief description of {title}",
            "content": "",  # Will be filled with actual content
            "last_modified": datetime.now().isoformat() + "Z",
            "priority": priority,
            "tags": tags or [],
            "related": related or [],
            "source_type": source_type,
            "key_points": key_points or []
        }
        
        return validate_document_structure(document)
  • Mounting of the elasticsearch_document sub-server app into the main Elasticsearch FastMCP app, which registers the 'create_document_template' tool as part of the document operations.
    from .sub_servers.elasticsearch_document import app as document_app
    from .sub_servers.elasticsearch_index import app as index_app
    from .sub_servers.elasticsearch_search import app as search_app
    from .sub_servers.elasticsearch_batch import app as batch_app
    
    # Create unified FastMCP application
    app = FastMCP(
        name="AgentKnowledgeMCP-Elasticsearch",
        version="2.0.0",
        instructions="Unified Elasticsearch tools for comprehensive knowledge management via modular server mounting"
    )
    
    # ================================
    # SERVER MOUNTING - MODULAR ARCHITECTURE
    # ================================
    
    print("๐Ÿ—๏ธ Mounting Elasticsearch sub-servers...")
    
    # Mount all sub-servers into unified interface
    app.mount(snapshots_app)           # 3 tools: snapshot management
    app.mount(index_metadata_app)      # 3 tools: metadata governance  
    app.mount(document_app)            # 3 tools: document operations
    app.mount(index_app)               # 3 tools: index management
    app.mount(search_app)              # 2 tools: search & validation
    app.mount(batch_app)               # 2 tools: batch operations
  • Pydantic-based input schema definitions using Annotated[Type, Field(...)] for the tool parameters, providing validation, descriptions, patterns, and defaults.
    title: Annotated[str, Field(description="Document title for the knowledge base entry")],
    content: Annotated[str, Field(description="Document content for AI analysis and metadata generation")] = "",
    priority: Annotated[
        str, Field(description="Priority level for the document", pattern="^(high|medium|low)$")] = "medium",
    source_type: Annotated[str, Field(description="Type of source content",
                                      pattern="^(markdown|code|config|documentation|tutorial)$")] = "markdown",
    tags: Annotated[
        List[str], Field(description="Additional manual tags (will be merged with AI-generated tags)")] = [],
    summary: Annotated[str, Field(description="Brief summary description of the document content")] = "",
    key_points: Annotated[List[str], Field(
        description="Additional manual key points (will be merged with AI-generated points)")] = [],
    related: Annotated[List[str], Field(description="List of related document IDs or references")] = [],
    use_ai_enhancement: Annotated[
        bool, Field(description="Use AI to generate intelligent tags and key points")] = True,
    ctx: Context = None
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions AI-generated metadata and formatting, but doesn't cover critical aspects like whether this is a read-only or destructive operation, authentication requirements, rate limits, or what the output looks like. For a creation tool with zero annotation coverage, this leaves significant gaps.

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 a single, efficient sentence that clearly states the tool's purpose. It's appropriately sized and front-loaded with the core functionality. There's no wasted verbiage, though it could potentially benefit from slightly more detail given the tool's complexity.

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 the tool's complexity (9 parameters, creation operation) and the presence of an output schema, the description is moderately complete. It covers the basic purpose but lacks behavioral details that would be important for a creation tool. The output schema existence reduces the need to describe return values, but more context about the creation process would be helpful.

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?

The description adds minimal parameter semantics beyond what the schema provides. It mentions 'AI-generated metadata and formatting' which relates to the 'use_ai_enhancement' parameter, but doesn't explain how parameters interact or provide additional context. With 100% schema description coverage, the baseline is 3 as the schema already documents all parameters well.

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: 'Create a properly structured document template for knowledge base with AI-generated metadata and formatting.' It specifies the verb ('create'), resource ('document template'), and context ('knowledge base'), but doesn't explicitly differentiate from sibling tools like 'create_index' or 'create_index_metadata' which might serve related purposes.

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. It doesn't mention sibling tools like 'create_index' or 'index_document', nor does it specify prerequisites or exclusions. Usage is implied through the description but not explicitly stated.

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/itshare4u/AgentKnowledgeMCP'

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