Skip to main content
Glama

help

Retrieve documentation and usage information for any Stata command. Understand syntax, options, and troubleshoot errors before running your analysis.

Instructions

Retrieve documentation and usage information for a Stata command. Use when you need to understand a command's syntax, options, or troubleshoot errors before running it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cmdYes
replaceNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'help' tool is registered in _TOOL_REGISTRY with description, func reference to the `help()` function, profiles, and unix_only constraint.
    "help": {
        "description": (
            "Retrieve documentation and usage information for a Stata command. "
            "Use when you need to understand a command's syntax, options, "
            "or troubleshoot errors before running it."
        ),
        "func": help,
        "profiles": {"core", "all"},
        "unix_only": True,
    },
  • register_tools() iterates _TOOL_REGISTRY and calls server.tool(name='help', ...) to register the help tool with FastMCP.
    def register_tools(server: FastMCP, profile: str = "all") -> None:
        """Register tools and resources based on a selected profile."""
        global _registered_profile
    
        if profile not in {"core", "all"}:
            raise ValueError(f"Unsupported profile: {profile}")
    
        if _registered_profile == profile:
            return
        if _registered_profile is not None and _registered_profile != profile:
            raise RuntimeError(
                "Tools are already registered with a different profile. "
                "Create a new process to switch profile."
            )
    
        for name, meta in _TOOL_REGISTRY.items():
            if meta.get("unix_only") and not config.IS_UNIX:
                continue
            if meta.get("deprecated") and not config.ENABLE_WRITE_DOFILE:
                continue
            if profile not in meta["profiles"]:
                continue
    
            tool_func: ToolFunc | None = meta.get("func")
            if tool_func is None:
                logging.warning("Skipping tool '%s' because its registry entry has no callable func.", name)
                continue
            server.tool(name=name, description=meta["description"])(tool_func)
    
        # # Keep help as both tool and resource on Unix platforms.
        # # NOTE: Temporarily disabled due to MCP resource URI parameter mismatch
        # if config.IS_UNIX and profile in {"core", "all"}:
        #     server.resource(
        #         uri="help://stata/{cmd}",
        #         name="help",
        #         description="Get help for a Stata command"
        #     )(help)
    
        _registered_profile = profile
  • The `help()` handler function retrieves documentation for a Stata command. It lazy-loads the StataHelp provider and delegates to StataHelp.help().
    def help(cmd: str, replace: bool = False) -> str:
        """
        Retrieve documentation and usage information for a Stata command.
    
        Args:
            cmd (str): The name of the Stata command to query, e.g., "regress" or "describe".
    
        Returns:
            str: The help text returned by Stata for the specified command,
                 or a message indicating that no help was found.
    
        Notes:
            If the returned content starts with 'Cached result for {cmd}', but the output shows the command
            does not exist or you believe the cached content is incorrect, and you are certain the command exists,
            set the environment variable STATA_MCP__CACHE_HELP to false. STATA_MCP__SAVE_HELP works similarly.
        """
        return _load_help_cls().help(cmd, replace=replace)
  • StataHelp class initializes with stata_cli, cache_dir, project_tmp_dir, and config. It creates a StataController for running Stata commands.
    class StataHelp:
        def __init__(
                self,
                stata_cli: str,
                project_tmp_dir: Path | None = None,
                cache_dir: Path | None = None,
                config: "Config | None" = None,
        ):
            self._config = config
            self.help_cache_dir = cache_dir or (
                config.HELP_CACHE_DIR if config else Path.home() / ".statamcp" / "help"
            )
            self.help_cache_dir.mkdir(parents=True, exist_ok=True)
  • StataHelp.help() method implements the core logic: checks saved/cached results first, then runs `help {cmd}` in Stata via StataController, and caches/saves the result.
    def help(self, cmd: str, replace: bool = False) -> str:
        if not replace:
            saved_help_result = self.load_from_project(cmd)
            cached_help_result = self.load_from_cache(cmd)
            if saved_help_result and self.IS_SAVE:
                return f"Saved result for {cmd}\n" + saved_help_result
            if cached_help_result and self.IS_CACHE:
                return f"Cached result for {cmd}\n" + cached_help_result
    
        # If no cached help found, get from Stata
        try:
            help_result = self.load_from_stata(cmd)
        except Exception as e:
            return str(e)
    
        self._cache_and_save(cmd, content=help_result, force=replace)
        return help_result
Behavior3/5

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

No annotations are provided, so the description must cover behavioral aspects. It states the tool 'retrieves documentation,' which implies a read-only operation, but it does not disclose the format of the output (e.g., text, pager) or any potential side effects. The description is adequate but minimal.

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 two sentences long, front-loads the purpose, and contains no redundant information. Every word earns its place.

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?

The tool is simple with an output schema, but the description lacks parameter documentation, which is essential for correct usage. It does not mention whether the command requires internet or works offline. It is minimally complete for a help tool but leaves gaps.

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

Parameters1/5

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

Schema coverage is 0%, meaning the description adds no explanation for the two parameters ('cmd' and 'replace'). The agent receives no guidance on what 'cmd' expects (e.g., a string of the command name) or the effect of 'replace' (e.g., overwriting existing help file). This is a critical gap.

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

Purpose5/5

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

The description clearly states the action ('Retrieve') and the resource ('documentation and usage information for a Stata command'). This distinguishes it well from siblings like 'stata_do' (execute code) and 'get_data_info' (data information).

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

Usage Guidelines4/5

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

The description provides explicit context for when to use the tool: 'Use when you need to understand a command's syntax, options, or troubleshoot errors before running it.' It does not specify when not to use it or mention alternatives, but the positive guidance is strong and clear.

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/SepineTam/stata-mcp'

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