Skip to main content
Glama
oborchers

mcp-server-pacman

docker_image_info

Retrieve detailed metadata about a Docker image, including version, repository, and tag, to manage and analyze containerized applications effectively.

Instructions

Get detailed information about a specific Docker image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesImage name (e.g., user/repo or library/repo)
tagNoSpecific image tag (default: latest)

Implementation Reference

  • MCP tool handler dispatch for 'docker_image_info' in @server.call_tool(), validates input with DockerImageInfo schema, calls appropriate provider function based on tag presence, and formats response.
    elif name == "docker_image_info":
        try:
            args = DockerImageInfo(**arguments)
            logger.debug(f"Validated docker image info args: {args}")
        except ValueError as e:
            logger.error(f"Invalid docker image info parameters: {str(e)}")
            raise McpError(ErrorData(code=INVALID_PARAMS, message=str(e)))
    
        logger.info(
            f"Getting Docker image info for {args.name}"
            + (f" (tag={args.tag})" if args.tag else "")
        )
    
        if args.tag:
            info = await get_docker_hub_tag_info(args.name, args.tag)
        else:
            info = await get_docker_hub_tags(args.name)
    
        logger.info(f"Successfully retrieved Docker image info for {args.name}")
        return [
            TextContent(
                type="text",
                text=f"Docker image information for {args.name}:\n{json.dumps(info, indent=2)}",
            )
        ]
  • Pydantic model defining input schema for docker_image_info tool: requires 'name', optional 'tag'.
    class DockerImageInfo(BaseModel):
        """Parameters for getting Docker image information."""
    
        name: Annotated[
            str, Field(description="Image name (e.g., user/repo or library/repo)")
        ]
        tag: Annotated[
            Optional[str],
            Field(
                default=None,
                description="Specific image tag (default: latest)",
            ),
        ]
  • Tool registration in @server.list_tools(): defines name, description, and input schema.
    Tool(
        name="docker_image_info",
        description="Get detailed information about a specific Docker image",
        inputSchema=DockerImageInfo.model_json_schema(),
    ),
  • Helper function to fetch all tags for a Docker image from Docker Hub API, including repo info; called when no specific tag provided.
    async def get_docker_hub_tags(name: str) -> Dict:
        """Get information about tags for a specific Docker image."""
        # Split the image name into namespace and repository
        if "/" in name:
            namespace, repository = name.split("/", 1)
        else:
            namespace, repository = "library", name
    
        async with httpx.AsyncClient() as client:
            response = await client.get(
                f"https://hub.docker.com/v2/repositories/{namespace}/{repository}/tags",
                params={"page_size": 25, "ordering": "last_updated"},
                headers={"Accept": "application/json", "User-Agent": DEFAULT_USER_AGENT},
                follow_redirects=True,
            )
    
            if response.status_code != 200:
                raise McpError(
                    ErrorData(
                        code=INTERNAL_ERROR,
                        message=f"Failed to get image tags from Docker Hub - status code {response.status_code}",
                    )
                )
    
            try:
                data = response.json()
                tags = [
                    {
                        "name": tag.get("name", ""),
                        "last_updated": tag.get("last_updated", ""),
                        "digest": tag.get("digest", ""),
                        "images": [
                            {
                                "architecture": img.get("architecture", ""),
                                "os": img.get("os", ""),
                                "size": img.get("size", 0),
                            }
                            for img in tag.get("images", [])
                        ],
                    }
                    for tag in data.get("results", [])
                ]
    
                # Get repo information
                repo_response = await client.get(
                    f"https://hub.docker.com/v2/repositories/{namespace}/{repository}",
                    headers={
                        "Accept": "application/json",
                        "User-Agent": DEFAULT_USER_AGENT,
                    },
                    follow_redirects=True,
                )
                repo_info = {}
                if repo_response.status_code == 200:
                    repo_data = repo_response.json()
                    repo_info = {
                        "description": repo_data.get("description", ""),
                        "star_count": repo_data.get("star_count", 0),
                        "pull_count": repo_data.get("pull_count", 0),
                        "is_official": repo_data.get("is_official", False),
                        "last_updated": repo_data.get("last_updated", ""),
                    }
    
                return {
                    "name": f"{namespace}/{repository}",
                    "tags": tags,
                    "tag_count": data.get("count", 0),
                    "repository": repo_info,
                }
            except Exception as e:
                raise McpError(
                    ErrorData(
                        code=INTERNAL_ERROR,
                        message=f"Failed to parse Docker Hub tags response: {str(e)}",
                    )
                )
  • Helper function to fetch specific tag info for a Docker image from Docker Hub API; called when tag is provided.
    async def get_docker_hub_tag_info(name: str, tag: str = "latest") -> Dict:
        """Get information about a specific tag of a Docker image."""
        # Split the image name into namespace and repository
        if "/" in name:
            namespace, repository = name.split("/", 1)
        else:
            namespace, repository = "library", name
    
        async with httpx.AsyncClient() as client:
            tag_url = f"https://hub.docker.com/v2/repositories/{namespace}/{repository}/tags/{tag}"
            response = await client.get(
                tag_url,
                headers={"Accept": "application/json", "User-Agent": DEFAULT_USER_AGENT},
                follow_redirects=True,
            )
    
            if response.status_code != 200:
                raise McpError(
                    ErrorData(
                        code=INTERNAL_ERROR,
                        message=f"Failed to get tag info for {name}:{tag} - status code {response.status_code}",
                    )
                )
    
            try:
                data = response.json()
                result = {
                    "name": f"{namespace}/{repository}",
                    "tag": tag,
                    "last_updated": data.get("last_updated", ""),
                    "full_size": data.get("full_size", 0),
                    "digest": data.get("digest", ""),
                    "images": [
                        {
                            "architecture": img.get("architecture", ""),
                            "os": img.get("os", ""),
                            "size": img.get("size", 0),
                        }
                        for img in data.get("images", [])
                    ],
                }
                return result
            except Exception as e:
                raise McpError(
                    ErrorData(
                        code=INTERNAL_ERROR,
                        message=f"Failed to parse Docker Hub tag info: {str(e)}",
                    )
                )

Tool Definition Quality

Score is being calculated. Check back soon.

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/oborchers/mcp-server-pacman'

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