Skip to main content
Glama

get_package_docs

Retrieve version-specific package documentation with formatted metadata and optional query filtering to streamline dependency management in Python projects.

Instructions

Retrieve formatted documentation for a package with version-based caching.

Args: package_name: Name of the package to fetch documentation for version_constraint: Version constraint from dependency scanning query: Optional query to filter documentation sections

Returns: Formatted documentation with package metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
package_nameYes
queryNo
version_constraintNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'get_package_docs' MCP tool. Decorated with @mcp.tool for automatic registration and schema inference from type hints and docstring. Implements version resolution, caching, documentation fetching from PyPI, formatting, and comprehensive error handling.
    @mcp.tool
    async def get_package_docs(
        package_name: str, version_constraint: str | None = None, query: str | None = None
    ) -> dict[str, Any]:
        """
        Retrieve formatted documentation for a package with version-based caching.
    
        This is the legacy single-package documentation tool. For rich context with
        dependencies, use get_package_docs_with_context instead.
    
        Args:
            package_name: Name of the package to fetch documentation for
            version_constraint: Version constraint from dependency scanning
            query: Optional query to filter documentation sections
    
        Returns:
            Formatted documentation with package metadata
        """
        from .observability import get_metrics_collector, track_request
    
        async with track_request("get_package_docs") as metrics:
            if cache_manager is None or version_resolver is None:
                get_metrics_collector().finish_request(
                    metrics.request_id,
                    success=False,
                    error_type="ServiceNotInitialized",
                    package_name=package_name,
                )
                return {
                    "success": False,
                    "error": {
                        "message": "Services not initialized",
                        "suggestion": "Try again or restart the MCP server",
                        "severity": "critical",
                        "code": "service_not_initialized",
                        "recoverable": False,
                    },
                }
    
            try:
                # Validate inputs
                validated_package_name = InputValidator.validate_package_name(package_name)
                if version_constraint is not None:
                    validated_constraint = InputValidator.validate_version_constraint(
                        version_constraint
                    )
                else:
                    validated_constraint = None
    
                logger.info(
                    "Fetching package docs",
                    package=validated_package_name,
                    constraint=validated_constraint,
                    query=query,
                )
    
                # Step 1: Resolve to specific version
                resolved_version = await version_resolver.resolve_version(
                    validated_package_name, validated_constraint
                )
    
                # Step 2: Check version-specific cache
                cache_key = version_resolver.generate_cache_key(
                    validated_package_name, resolved_version
                )
                cached_entry = await cache_manager.get(cache_key)
    
                if cached_entry:
                    logger.info(
                        "Version-specific cache hit",
                        package=validated_package_name,
                        version=resolved_version,
                        constraint=version_constraint,
                    )
                    package_info = cached_entry.data
                    from_cache = True
                else:
                    logger.info(
                        "Fetching fresh package info",
                        package=validated_package_name,
                        version=resolved_version,
                    )
    
                    async with PyPIDocumentationFetcher() as fetcher:
                        package_info = await fetcher.fetch_package_info(
                            validated_package_name
                        )
                        await cache_manager.set(cache_key, package_info)
                    from_cache = False
    
                # Step 3: Format documentation
                async with PyPIDocumentationFetcher() as fetcher:
                    formatted_docs = fetcher.format_documentation(package_info, query)
    
                # Record successful metrics
                get_metrics_collector().finish_request(
                    metrics.request_id,
                    success=True,
                    cache_hit=from_cache,
                    package_name=validated_package_name,
                )
    
                return {
                    "success": True,
                    "package_name": package_info.name,
                    "version": package_info.version,
                    "resolved_version": resolved_version,
                    "version_constraint": version_constraint,
                    "documentation": formatted_docs,
                    "from_cache": from_cache,
                    "cache_key": cache_key,
                    "query_applied": query is not None,
                }
    
            except AutoDocsError as e:
                formatted_error = ErrorFormatter.format_exception(
                    e, {"package": validated_package_name}
                )
                logger.error(
                    "Documentation fetch failed",
                    package=validated_package_name,
                    error=str(e),
                    error_type=type(e).__name__,
                )
                get_metrics_collector().finish_request(
                    metrics.request_id,
                    success=False,
                    error_type="AutoDocsError",
                    package_name=package_name,
                )
                return {
                    "success": False,
                    "error": {
                        "message": formatted_error.message,
                        "suggestion": formatted_error.suggestion,
                        "severity": formatted_error.severity.value,
                        "code": formatted_error.error_code,
                        "recoverable": formatted_error.recoverable,
                    },
                }
            except Exception as e:
                formatted_error = ErrorFormatter.format_exception(
                    e, {"package": validated_package_name}
                )
                logger.error("Unexpected error during documentation fetch", error=str(e))
                get_metrics_collector().finish_request(
                    metrics.request_id,
                    success=False,
                    error_type=type(e).__name__,
                    package_name=package_name,
                )
                return {
                    "success": False,
                    "error": {
                        "message": formatted_error.message,
                        "suggestion": formatted_error.suggestion,
                        "severity": formatted_error.severity.value,
                        "code": formatted_error.error_code,
                        "recoverable": formatted_error.recoverable,
                    },
                }
Behavior3/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 adds value by mentioning 'version-based caching', which hints at performance optimization and data freshness considerations. However, it lacks details on error handling, rate limits, authentication needs, or what 'formatted documentation' entails structurally. For a tool with no annotations, this leaves significant gaps in understanding its operational 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 well-structured and front-loaded: the first sentence states the core purpose, followed by a clear 'Args' and 'Returns' section. Every sentence earns its place by providing essential information without redundancy. It's appropriately sized for a tool with three parameters and an output schema.

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

Completeness4/5

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

Given the tool's moderate complexity (3 parameters, no annotations, but with an output schema), the description is reasonably complete. The output schema handles return value details, so the description doesn't need to explain 'formatted documentation' further. It covers the tool's purpose and parameter semantics adequately, though usage guidelines and deeper behavioral context are lacking.

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

Parameters4/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 semantic context for all three parameters: 'package_name' is for fetching documentation, 'version_constraint' ties to dependency scanning, and 'query' filters documentation sections. This adds meaningful interpretation beyond the bare schema, though it doesn't specify format details (e.g., what a valid 'version_constraint' looks like).

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: 'Retrieve formatted documentation for a package with version-based caching.' It specifies the verb ('retrieve'), resource ('documentation'), and a key behavioral trait ('version-based caching'). However, it doesn't explicitly differentiate from sibling tools like 'scan_dependencies' or 'get_cache_stats', which could help an agent understand when to choose this tool over others.

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 mentions 'version-based caching' but doesn't explain how this relates to sibling tools like 'refresh_cache' or 'get_cache_stats'. There's no mention of prerequisites, typical use cases, or exclusions, leaving the agent with minimal context for tool selection.

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

Related 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/bradleyfay/autodoc-mcp'

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