Skip to main content
Glama

Quick Start

Python 3.11 or newer is required. Install uv to create the project environment and install the optional MCP server dependency.

cd ~/Projects/wikimedia
uv sync --extra mcp
.venv/bin/wikimedia --help
.venv/bin/wikimedia search "Discogs logo" --type svg --limit 5

If the shell command is already installed, run wikimedia "Discogs logo" to open the interactive result picker. Use an exact Commons file title for repeatable downloads and references.

cd ~/Projects/wikimedia
python3 -m venv .venv
.venv/bin/python -m pip install -e ".[mcp]"
IMPORTANT

Search results are ranked suggestions. Check the file page, license, attribution, and restrictions before reusing media.

Related MCP server: call-copilot

Features

Feature

What it does

Commons search

Search files by phrase and filter by SVG, image, audio, video, or PDF.

File details

Resolve an exact title to source page, original URL, size, dimensions, artist, license, and restrictions.

References

Format Markdown, HTML, a direct URL, or an attribution line.

Downloads

Save original media or a rendered preview with a JSON provenance sidecar. Existing files are protected unless --force is set.

Categories

List direct file members of a Commons category and continue through result pages.

Wikipedia

Retrieve an article introduction or full extract, revision link, optional wikitext, and image titles.

MCP tools

Expose Commons and Wikipedia lookups to MCP-compatible clients over local stdio.

Compatibility

Platform

CLI and MCP core

Clipboard and open

macOS

Python 3.11+

Text and file clipboard via pbcopy and AppleScript; opens with open.

Linux

Python 3.11+

Text clipboard via wl-copy, xclip, or xsel; opens with xdg-open. File-item clipboard is unavailable.

Windows

Not verified

Clipboard and open helpers are not implemented for Windows.

The HTTP client uses Python's standard library. MCP support adds the optional mcp package. The project is developed and verified on macOS; platform entries describe the integrations present in the code.

Workflow

Step

What happens

CLI example

Search

Find media by phrase, exact title, or Commons URL.

wikimedia "Discogs logo"

Review

Inspect creator, source, license, and restrictions.

wikimedia info "File:Discogs icon.svg"

Choose

Pick an original, rendered preview, or reference format.

wikimedia md "File:Discogs icon.svg"

Act

Download, copy, or open the file page.

wikimedia d c "File:Discogs icon.svg"

Retain

Keep the media and its provenance sidecar together.

wikimedia d --out ./assets "File:Discogs icon.svg"

Interactive terminals show a numbered picker and action menu. In a non-interactive shell, a plain search prints results; a search combined with an action uses the first ranked result. Use an exact File: title when a script must target a specific item.

Usage

Search And Select

# Interactive search and selection in a terminal
wikimedia "Discogs logo"

# Filter for vector files and print structured results
wikimedia search "Discogs logo" --type svg --limit 5 --json

# Search for images, audio, video, or PDF files
wikimedia search "field recording" --type audio --limit 10

search is optional for a Commons query. The first example uses the interactive selector when stdin is a terminal. --json disables interactive output.

Inspect A File

wikimedia info "File:Discogs icon.svg"
wikimedia "https://commons.wikimedia.org/wiki/File:Discogs_icon.svg" --json

The record includes the Commons source page and direct media URL, file dimensions and size, MIME type, upload timestamp, artist, license fields, and restrictions such as trademark notices.

Create References

# Print a Markdown image reference
wikimedia md "File:Discogs icon.svg"

# Print an HTML image element with a display height
wikimedia html "File:Discogs icon.svg" --height 32

# Print the direct media URL or an attribution line
wikimedia url "File:Discogs icon.svg"
wikimedia attr "File:Discogs icon.svg"

# Copy a Markdown reference to the text clipboard
wikimedia md -c "File:Discogs icon.svg"

When l or url is used without a style, an interactive terminal offers Markdown, HTML, URL, and attribution formats. md, html, and attr select a format directly. A width requests a Wikimedia thumbnail, which may change an SVG reference into a PNG preview URL.

Download Media

# Download the original file to ./downloads
wikimedia d --out ./downloads "File:Discogs icon.svg"

# Download a 120 px preview. SVG previews are raster PNGs.
wikimedia d --out ./downloads --width 120 "File:Discogs icon.svg"

# Download and copy the downloaded file to the system clipboard
wikimedia d c --out ./downloads "File:Discogs icon.svg"

# Download, print a Markdown reference, and force replacement if needed
wikimedia d l md -f --out ./downloads "File:Discogs icon.svg"

Each download writes a sibling .wikimedia.json file with the source record, representation, retrieval time, byte count, and SHA-256 hash. Downloads are staged before publication and do not overwrite existing media or sidecars by default.

TIP

Group short actions:d c downloads then copies the file; d l md downloads and prints Markdown. -O is the short output-directory flag. -o means open in a browser.

Browse Categories

wikimedia category "ITunes logos" --limit 10
wikimedia cat "Category:Discogs logos" --limit 20 --json

The category command lists direct file members, not recursive descendants. Use --cursor with the continuation token from JSON output to request another page.

Read Wikipedia

# Fetch an article introduction
wikimedia wiki "MediaWiki"

# Fetch the full plain-text extract or include revision wikitext
wikimedia wiki "MediaWiki" --full
wikimedia wiki "MediaWiki" --full --wikitext --language en

# Create a revision-specific Markdown citation
wikimedia wiki md "MediaWiki"

The CLI fetches a known article title. Wikipedia title search is available through the MCP wikipedia_search tool; the CLI does not currently expose a separate Wikipedia search command. wikipedia_list_images returns titles only. Some may be local Wikipedia files or non-free media, so a title alone does not establish that a Commons download is available.

Copy And Open

Action

Command

Behavior

Open

wikimedia -o "File:Discogs icon.svg"

Opens the Commons file page in the default browser.

Copy a reference

wikimedia md -c "File:Discogs icon.svg"

Copies the generated text reference.

Copy a file

wikimedia d c "File:Discogs icon.svg"

Downloads the original, then copies the file item where supported.

On macOS, file clipboard uses AppleScript and text clipboard uses pbcopy. On Linux, text clipboard tries wl-copy, xclip, then xsel; file clipboard falls back to copying the local path. Browser opening uses open on macOS and xdg-open on Linux.

Commands

Command

Purpose

Example

wikimedia [query]

Search Commons or resolve a supplied file, category, or supported Wikimedia URL.

wikimedia "Discogs logo"

search [query]

Search Commons media.

wikimedia search "Discogs" --type svg

info [file]

Print full metadata.

wikimedia info "File:Discogs icon.svg" --json

download / d

Download original media or a width-rendered preview.

wikimedia d --out ./assets "File:Discogs icon.svg"

md, html, url, attr

Generate a Markdown, HTML, URL, or attribution reference.

wikimedia html "File:Discogs icon.svg"

open / -o

Open the Commons file page.

wikimedia -o "File:Discogs icon.svg"

category / cat

List direct Commons category members.

wikimedia cat "ITunes logos"

wiki / w

Fetch a Wikipedia article.

wikimedia wiki "MediaWiki" --full

mcp

Start the MCP stdio server.

wikimedia mcp --download-dir ~/Downloads/Wikimedia

Option

Default

Meaning

-O, --out DIR

Current directory

Download destination.

-w, --width PX

0

Request a rendered thumbnail at this width. 0 uses the original.

--height PX

24

HTML reference display height.

-n, --limit N

10

Result count, from 1 to 50.

--offset N

0

Search offset, from 0 to 10,000.

-t, --type KIND

all

Commons filter: all, svg, image, audio, video, or pdf.

--name FILE

API filename

Choose a safe output filename.

--language CODE

en

Wikipedia language code. --lang is an alias.

--full

Off

Fetch a full Wikipedia text extract.

--wikitext

Off

Include the current revision wikitext.

--cursor TOKEN

Empty

Continue a Commons category listing.

-f, --force

Off

Replace an existing media file and sidecar.

-c, --copy

Off

Copy the downloaded file or generated reference to the clipboard.

-d, --download

Off

Download the selected file.

-l, --link

Off

Generate a reference; prompts for format in an interactive terminal.

--md, --html

Off

Select Markdown or HTML reference output.

--json

Off

Emit JSON rather than styled terminal output.

-h, --help

—

Show usage.

-v, --version

—

Print the CLI version.

Short actions can be separate words (d c) or grouped (-dcf). --out may appear before or after the query. The output-directory short flag is -O; -o is reserved for open.

MCP Server

Install the optional MCP dependency with uv sync --extra mcp. The server uses stdio and exposes nine tools for Commons search, file metadata, categories, references, downloads, Wikipedia articles, images, and citations.

# Start the standalone server with downloads disabled
.venv/bin/wikimedia-mcp

# Enable downloads under a fixed directory
.venv/bin/wikimedia-mcp --download-dir ~/Downloads/Wikimedia

# Or start it through the main CLI
.venv/bin/wikimedia mcp --download-dir ~/Downloads/Wikimedia

Add the executable to your MCP client's configuration. Use an absolute path to the checkout and choose a download directory the server may write to.

{
  "mcpServers": {
    "wikimedia": {
      "command": "/absolute/path/to/wikimedia/.venv/bin/wikimedia",
      "args": [
        "mcp",
        "--download-dir",
        "/absolute/path/to/wikimedia-downloads"
      ]
    }
  }
}

Tool

What it returns

wikimedia_search_media

Ranked Commons files with optional type filter, preview width, and continuation.

wikimedia_get_file

Exact file record and reuse metadata.

wikimedia_list_category

Direct file members and category continuation.

wikimedia_reference_file

URL, Markdown, HTML, or attribution text.

wikimedia_download_file

Downloaded file and provenance sidecar under the configured root.

wikipedia_search

Search results for an article query and language.

wikipedia_get_article

Article intro or full extract with revision metadata.

wikipedia_list_images

Image titles on a Wikipedia article.

wikipedia_reference_article

Citation text tied to a retrieved revision.

Downloads are disabled until a root is configured with --download-dir or WIKIMEDIA_DOWNLOAD_DIR. MCP downloads accept a relative subdir, validate path containment, and refuse to overwrite existing files.

Configuration

There is no configuration file or API key. The CLI reads these environment variables when present:

Variable

Default

Purpose

WIKIMEDIA_USER_AGENT

Iconography-Wikimedia/0.1 (https://github.com/deathrashed)

Override the HTTP User-Agent sent to Wikimedia. Include a contact URL in a custom value.

WIKIMEDIA_DOWNLOAD_DIR

Unset

Enable MCP downloads under this directory when no --download-dir is passed.

NO_COLOR

Unset

Disable ANSI colors when set.

FORCE_COLOR

0

Set to 1 to enable ANSI colors in non-TTY output.

The CLI defaults downloads to the current directory. --out changes that location for a command; it does not enable MCP downloads.

Reuse And Safety

Wikimedia records can contain license, author, source, and restriction metadata. The tool carries that data into references and download sidecars, but it does not determine whether a particular reuse is lawful or whether a mark may be used commercially.

WARNING

A public-domain copyright status does not remove trademark restrictions. Review the Commons file page and relevant rights before publishing or redistributing a file.

The header mark is Commons-logo.svg, by Reidab, Grunt, 3247, and Pumbaa. It is licensed under CC BY-SA 3.0 and is identified on Commons as a Wikimedia trademark. Its source record is preserved in assets/Commons-logo.svg.wikimedia.json; see the Commons file page.

The downloader only accepts HTTPS Wikimedia media hosts, follows redirects only to supported hosts, caps files at 100 MiB in the CLI, and checks the downloaded original size against the API record when available. --force replaces both the media file and sidecar.

How It Works

The CLI and MCP adapter share one Python core. Both query the same Wikimedia APIs and use the same reference formatter and downloader. The downloader writes a media file and a provenance sidecar. Network access uses Python's standard library; the MCP SDK is the only optional runtime dependency.

Component

Responsibility

client.py

API requests, title and URL parsing, response shaping, retry handling.

references.py

Escaped Markdown and HTML references plus attribution text.

downloads.py

Host validation, bounded transfer, no-clobber publication, SHA-256, sidecar metadata.

clipboard.py

Platform clipboard and default-app integration.

cli.py

Flexible action parser, search workflow, and terminal selection.

server.py

MCP stdio tools using the shared core.

Troubleshooting

Install the optional server dependency from the project root:

uv sync --extra mcp

Choose another destination or filename. Add --force only when replacing both the media and its metadata sidecar is intended.

Some files have no preview URL at the requested size. Remove --width to use the original file, or try a smaller width.

On macOS, check that pbcopy and osascript are available. On Linux, install one of wl-copy, xclip, or xsel for text. File-item clipboard integration is macOS-specific.

Check network access and retry later. The client retries temporary API or transport failures, but honors long Retry-After pauses by returning an error rather than sleeping for an extended period.

Structure

wikimedia/
├── assets/
│   ├── Commons-logo.svg          # Wikimedia Commons source mark
│   ├── Commons-logo.svg.wikimedia.json # License and source record
│   ├── wikimedia-header.svg       # Repository header banner
│   ├── workflow.svg              # Wide workflow graphic
│   └── workflow-mobile.svg       # Mobile workflow graphic
├── bin/
│   └── wikimedia                 # Symlink-friendly development launcher
├── src/wikimedia_tool/
│   ├── cli.py                    # Command-line entry point
│   ├── client.py                 # Shared Wikimedia API client
│   ├── clipboard.py              # Clipboard and system-open helpers
│   ├── downloads.py              # Safe media transfer and provenance
│   ├── references.py             # Markdown, HTML, URL, attribution output
│   ├── server.py                 # Optional MCP stdio server
│   └── ui.py                     # Terminal cards and selectors
├── tests/
│   └── test_wikimedia.py         # Unit tests
├── downloads/                    # Local download examples and output
├── pyproject.toml                # Package metadata and entry points
└── uv.lock                       # Locked development environment

Development

uv sync --extra mcp
uv run python -m unittest discover -s tests -v
uv run wikimedia --help
uv build

The test suite uses the standard-library unittest runner. Tests mock network transfers; live API and download behavior should be checked separately when changing the HTTP client or downloader.

License

𝗗𝗢 𝗪𝗛𝗔𝗧 𝗧𝗛𝗘 𝗙𝗨𝗖𝗞 𝗬𝗢𝗨 𝗪𝗔𝗡𝗧 𝗧𝗢 𝗣𝗨𝗕𝗟𝗜𝗖 𝗟𝗜𝗖𝗘𝗡𝗦𝗘

𝗖𝗢𝗣𝗬𝗥𝗜𝗚𝗛𝗧 © 𝟮𝟬𝟮𝟲 𝗗𝗘𝗔𝗧𝗛𝗥𝗔𝗦𝗛𝗘𝗗

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    MCP server providing web search, news search, and X/Twitter search capabilities via HTTP or stdio.
    -
  • A
    license
    Not graded
    quality
    A
    maintenance
    Search and read locally-recorded meeting transcripts over stdio. Read-only, no network. Exposes list_sessions, get_session, and search_transcripts to any MCP client.
    67 PyPI
    7
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    An MCP server that exposes a single tool to retrieve Wikipedia articles from local multistream dump files, offering fast offline access with redirect following and fuzzy matching.
    -
  • A
    license
    A
    quality
    B
    maintenance
    Enables any MCP-compatible agent to query a local OpenRhyme activity timeline, search history, and issue control commands over stdio while keeping all data on-machine.
    5
    MIT