Labsco
entanglr logo

MediaWiki

β˜… 3

from entanglr

Interact with MediaWiki installations through the MediaWiki API as a bot user.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredAdvanced setup

MediaWiki API MCP Server

A Model Context Protocol (MCP) server that allows LLMs to interact with MediaWiki installations through the MediaWiki API as a bot user.

Features

Tools

The server provides various MCP tools with the wiki_ prefix:

Tool Description wiki_page_edit Edit or create MediaWiki pages with comprehensive editing options wiki_page_get Retrieve page information and content wiki_page_parse Parse page content with support for wikitext processing, HTML generation, metadata extraction, and advanced parsing features wiki_page_compare Compare two pages, revisions, or text content to show differences between them wiki_page_move Move pages with support for talk pages, subpages, and redirects wiki_page_delete Delete pages with support for talk pages, watchlist management, and logging wiki_page_undelete Undelete (restore) deleted MediaWiki pages with comprehensive restoration options wiki_search Search for pages using MediaWiki's search API with advanced filtering wiki_opensearch Search using OpenSearch protocol for quick suggestions and autocomplete wiki_meta_siteinfo Get overall site information including general info, namespaces, statistics, extensions, and more

Development

Technology Stack

  • MCP SDK: mcp >= 1.2.0 (using FastMCP pattern)

  • HTTP Client: httpx >= 0.27.0 for MediaWiki API calls

  • Data Validation: pydantic >= 2.0.0 for configuration models

  • Environment: python-dotenv >= 1.0.0 for configuration

  • Testing: pytest with pytest-asyncio for async testing

  • Code Quality: ruff for linting, mypy for type checking

Architecture

  • FastMCP server with @mcp.tool() decorators

  • Separation of concerns: server β†’ handler β†’ client β†’ MediaWiki API

  • AsyncIO throughout for non-blocking operations

  • Environment-based configuration for MediaWiki credentials

Client Layer (client.py and client_modules/)

  • Handles MediaWiki API authentication and requests

  • Manages CSRF tokens and session state

  • Provides typed methods for API operations

Tools Layer (tools/)

  • Defines MCP tool schemas using JSON Schema

  • Separated by functional area (edit, search)

  • Ensures all tools have wiki_ prefix

Handlers Layer (handlers/)

  • Implements actual tool logic

  • Handles argument validation and error handling

  • Returns properly formatted MCP responses

Server Layer (server.py and server_tools/)

  • Main MCP server orchestration

  • Routes tool calls to appropriate handlers

  • Manages configuration and client lifecycle

Project Structure

The project is organized into modular components for maintainability:

mediawiki-api-mcp/
β”œβ”€β”€ mediawiki_api_mcp/
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ server.py # FastMCP server with tool definitions
β”‚ β”œβ”€β”€ client.py # MediaWiki API client
β”‚ β”œβ”€β”€ client_modules/ # Client modules for API operations
β”‚ β”‚ β”œβ”€β”€ __init__.py # Client module exports
β”‚ β”‚ └── client_*.py # Individual client modules
β”‚ β”œβ”€β”€ handlers/ # Business logic handlers
β”‚ β”‚ β”œβ”€β”€ __init__.py # Handler exports
β”‚ β”‚ └── wiki_*.py # Individual tool handlers
β”‚ β”œβ”€β”€ tools/ # Tool schemas
β”‚ β”‚ β”œβ”€β”€ __init__.py # Tool schema exports
β”‚ β”‚ └── wiki_*.py # Individual tool schemas
β”‚ └── server_tools/ # Tool definitions
β”‚ β”œβ”€β”€ __init__.py # Tool definition exports
β”‚ └── wiki_*.py # Individual tool definitions
β”œβ”€β”€ tests/ # Test suite
β”‚ └── test_*.py # Test files matching handlers
β”œβ”€β”€ docs/ # Documentation
β”‚ └── tools/ # Tool-specific documentation
β”‚ └── wiki_*.md # Individual tool docs
β”œβ”€β”€ pyproject.toml # Project configuration
└── uv.lock # Dependency lock file

Running Tests

uv run pytest

Run specific test modules, e.g.:

uv run pytest tests/test_server.py uv run pytest tests/test_tools.py uv run pytest tests/test_wiki_page_edit.py uv run pytest tests/test_wiki_search.py uv run pytest tests/test_wiki_opensearch.py

Code Quality

Linting

uv run ruff check

Type checking

uv run mypy mediawiki_api_mcp

Error Handling

The server implements comprehensive error handling:

  • Configuration errors: Missing environment variables

  • Authentication errors: Invalid credentials or permissions

  • API errors: Network issues, invalid requests

  • Tool errors: Missing parameters, invalid arguments

All errors are returned as MCP TextContent responses for LLM visibility.

Security

  • Bot credentials are required for editing operations

  • All API requests include proper User-Agent headers

  • CSRF tokens are automatically managed

  • Input validation on all tool parameters