Skip to main content
Glama

create_article

Create and publish articles on a Joomla website by providing text content, title, category, and publication settings.

Instructions

Create a new article on the Joomla website.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
article_textYes
titleNo
category_idNo
convert_plain_textNo
publishedNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:115-198 (handler)
    The primary handler function decorated with @mcp.tool, implementing the logic to create a new Joomla article: handles input parameters, converts text to HTML if needed, generates alias, validates category, and posts to Joomla API.
    @mcp.tool(description="Create a new article on the Joomla website.")
    async def create_article(
        article_text: str,
        title: str = None,
        category_id: int = None,
        convert_plain_text: bool = True,
        published: bool = True,
    ) -> str:
        """
        Create a new article on the Joomla website via its API. User will provide title, content,
        category, and publication status.
    
        Args:
            article_text (str): The content of the article (plain text or HTML).
            title (str, optional): The article title. Inferred from content if not provided.
            category_id (int, optional): The ID of the category. If not provided, lists available categories.
            convert_plain_text (bool): Convert plain text to HTML if True. Defaults to True.
            published (bool): Publish the article (True for state=1, False for state=0). Defaults to True.
    
        Returns:
            Success message with article title and category ID, or an error message if the request fails.
        """
        try:
            if convert_plain_text:
                article_text = convert_text_to_html(article_text)
            if not title:
                title = (
                    article_text[:50].strip() + "..."
                    if len(article_text) > 50
                    else article_text
                )
                title = title.replace("\n", " ").strip()
            alias = generate_alias(title)
            if category_id is None:
                categories_display = await get_joomla_categories()
                return f"{categories_display}\nPlease specify a category ID."
            if not isinstance(category_id, int):
                return "Error: Category ID must be an integer."
            headers = {
                "Accept": "application/vnd.api+json",
                "Content-Type": "application/json",
                "User-Agent": "JoomlaArticlesMCP/1.0",
                "Authorization": f"Bearer {BEARER_TOKEN}",
            }
            async with httpx.AsyncClient() as client:
                response = await client.get(JOOMLA_CATEGORIES_API_URL, headers=headers)
            if response.status_code != 200:
                return f"Failed to fetch categories: HTTP {response.status_code} - {response.text}"
            try:
                data = json.loads(response.text)
                categories = data.get("data", [])
                if not isinstance(categories, list) or not categories:
                    return "Failed to create article: No valid categories found."
            except json.JSONDecodeError:
                return f"Failed to create article: Invalid category JSON - {response.text}"
            valid_category = any(
                category.get("attributes", {}).get("id") == category_id
                for category in categories
            )
            if not valid_category:
                return f"Error: Category ID {category_id} is not valid."
            payload = {
                "alias": alias,
                "articletext": article_text,
                "catid": category_id,
                "language": "*",
                "metadesc": "",
                "metakey": "",
                "title": title,
                "state": 1 if published else 0,
            }
            async with httpx.AsyncClient() as client:
                response = await client.post(
                    JOOMLA_ARTICLES_API_URL, json=payload, headers=headers
                )
            if response.status_code in (200, 201):
                status = "published" if published else "unpublished"
                return f"Successfully created {status} article '{title}' in category ID {category_id}"
            else:
                return f"Failed to create article: HTTP {response.status_code} - {response.text}"
        except httpx.HTTPError as e:
            return f"Error creating article: {str(e)}"
        except Exception as e:
            return f"Unexpected error: {str(e)}"
  • main.py:26-57 (helper)
    Supporting function to convert plain text input to sanitized HTML, used by create_article when convert_plain_text is True.
    def convert_text_to_html(text: str) -> str:
        """
        Convert plain text to sanitized HTML using markdown and bleach.
    
        Args:
            text (str): The plain text to convert.
    
        Returns:
            str: Sanitized HTML content with allowed tags only.
        """
        html = markdown.markdown(text)
        allowed_tags = [
            "p",
            "br",
            "strong",
            "em",
            "ul",
            "ol",
            "li",
            "h1",
            "h2",
            "h3",
            "h4",
            "h5",
            "h6",
        ]
        allowed_attributes = {}
        sanitized_html = bleach.clean(
            html, tags=allowed_tags, attributes=allowed_attributes, strip=True
        )
        return sanitized_html
  • main.py:19-23 (helper)
    Utility function to generate a URL-friendly alias/slug from the article title, used in create_article payload.
    def generate_alias(title: str) -> str:
        """Convert a title to a slug alias (lowercase, hyphens, no special chars)."""
        alias = re.sub(r"[^a-z0-9\s-]", "", title.lower())
        alias = re.sub(r"\s+", "-", alias).strip("-")
        return alias
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 states the tool creates an article but fails to mention critical aspects like whether this is a write operation (implied but not explicit), what permissions are needed, how errors are handled, or the effect of default parameters like 'published: true'. This leaves significant gaps in understanding the tool's behavior.

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

Conciseness5/5

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

The description is a single, direct sentence with no wasted words, making it highly concise and front-loaded. It efficiently communicates the core action without unnecessary elaboration, which is appropriate for a basic tool description.

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 has 5 parameters with 0% schema coverage, no annotations, and an output schema (which reduces the need to describe return values), the description is incomplete. It covers the basic purpose but misses parameter explanations, usage context, and behavioral details, making it minimally adequate but with clear gaps for a creation tool in a CMS environment.

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

Parameters2/5

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

Schema description coverage is 0%, meaning parameter titles provide minimal semantic context. The description adds no information about parameters beyond the tool's name, such as explaining what 'convert_plain_text' does, how 'category_id' relates to existing categories, or the implications of 'published'. This fails to compensate for the low schema coverage, leaving parameters largely unexplained.

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 verb ('Create') and resource ('new article on the Joomla website'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'update_article' beyond the basic create vs. update difference, missing an opportunity to clarify scope or uniqueness.

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 'update_article' or 'manage_article_state'. It also lacks information about prerequisites, such as whether the category must exist or if authentication is required, leaving the agent without context for decision-making.

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/nasoma/joomla-mcp-server'

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