Skip to main content
Technical overview of the Arch MCP Server implementation following the Arch Way principles.

Design Philosophy

This server embodies the Arch Way principles in its implementation.

Minimalism

No unnecessary abstractions or bloat. Every function serves a clear purpose with clean, readable code.
The entire codebase is under 3,000 lines - easy to audit and understand.

Correctness

Comprehensive error handling at every layer, full type hints, and extensive logging for debugging.

Transparency

Every module is well-documented with clear function signatures, docstrings, and inline comments.
No magic - you can read the source and understand exactly what’s happening.

User-Centricity

Assumes competent users. Provides detailed information and warnings, but doesn’t prevent advanced usage.
AUR warnings inform users of risks but don’t block access - you decide.

Pragmatism

Hybrid local/remote approach: uses fast local queries on Arch, falls back to remote APIs elsewhere.

Simplicity

Standard library and minimal dependencies. No complex frameworks or heavy abstractions.Dependencies: httpx, beautifulsoup4, markdownify, mcp

System Architecture

Module Breakdown

Main Entry Point (__init__.py and server.py)

__init__.py Responsibilities:
  • Package initialization
  • Function exports
  • Async main() entry point
  • STDIO transport setup
server.py Responsibilities: Responsibilities:
  • MCP protocol implementation
  • Resource URI handling
  • Tool invocation routing
  • Prompt template management
  • STDIO transport setup
Key Features:
  • Async operation for all network calls
  • URI parsing for resources
  • JSON serialization of responses
  • Error propagation from modules

HTTP Server Module (http_server.py)

New in v3.1.0: HTTP/SSE transport support for containerized deployments. Purpose:
  • Alternative transport to STDIO for web-based clients
  • Server-Sent Events (SSE) for real-time communication
  • Containerized deployment support (Docker, Smithery)
  • Health check endpoint for monitoring
Entry Points:
  • arch-ops-server - STDIO transport (default)
  • arch-ops-server-http - HTTP/SSE transport
Configuration:
Dependencies:
  • starlette - ASGI framework for HTTP routing
  • uvicorn - ASGI server for production
  • mcp.server.sse - SSE transport implementation

Tool Metadata System (tool_metadata.py)

New in v3.1.0: Structured tool organization and relationships. Purpose:
  • Categorizes all 22 tools into 9 logical groups
  • Defines tool relationships and workflows
  • Provides discoverability metadata
  • Enables intelligent tool suggestions
Categories:
Metadata Fields:
  • category - Logical grouping
  • platform - “any”, “arch”, or “systemd”
  • permission - “read” or “write”
  • workflow - Usage context (research, installation, cleanup, etc.)
  • related_tools - Tools commonly used together
  • prerequisite_tools - Tools to run first
Helper Functions:
Use Cases:
  • Auto-suggest related tools to users
  • Build guided workflows
  • Filter by platform/permission
  • Generate documentation
  • Analyze tool coverage

Utilities (utils.py)

Core helper functions for platform detection, command execution, and error handling.
All functions use type hints and comprehensive docstrings following Google style.

Arch Wiki Interface (wiki.py)

Manages Arch Wiki searches and page retrieval:
API Endpoints:
  • https://wiki.archlinux.org/api.php
  • Direct page URLs for scraping fallback
Error Handling:
  • Timeouts (10s default)
  • HTTP errors with status codes
  • Missing pages (404)
  • API errors in response JSON

AUR RPC Interface (aur.py)

Handles AUR package operations and security analysis:
API Endpoints:
  • https://aur.archlinux.org/rpc
  • https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD

Official Repository Interface (pacman.py)

Hybrid local/remote access to official packages and comprehensive package management:
Hybrid Approach:
  • On Arch: Fast local queries, offline-capable
  • Remote: API-based, works anywhere

System Monitoring (system.py)

System health and diagnostics:

News Integration (news.py)

Arch Linux news feed parsing:

Transaction Logs (logs.py)

Pacman transaction history:

Mirror Management (mirrors.py)

Repository mirror testing and optimization:

Configuration Parsing (config.py)

System configuration analysis:

Data Flow Examples

Example 1: Reading an Arch Wiki Page

Example 2: Auditing an AUR Package

Error Handling Strategy

Graceful Degradation

Error Response Format

All errors follow consistent structure:
Error Types:
  • NotFound - Resource doesn’t exist
  • TimeoutError - Network timeout
  • HTTPError - HTTP status error
  • NotSupported - Feature unavailable on platform
  • CommandNotFound - Required command missing
  • RateLimitError - API rate limit exceeded

Concurrency Model

Async/Await Throughout

All network and subprocess operations are async for non-blocking I/O:
Benefits:
  • Non-blocking I/O
  • Concurrent tool calls possible
  • Responsive server
  • Timeout support built-in

HTTP Client Management

Uses httpx.AsyncClient with context managers:
Features:
  • Automatic connection pooling
  • Timeout enforcement
  • Proper cleanup
  • HTTP/2 support

Security Considerations

AUR Safety (Defense in Depth)

Multi-layered security approach for AUR package handling.
1

Warning Metadata

Every AUR response includes prominent warnings:
Warnings are added automatically by add_aur_warning() utility function.
2

PKGBUILD Analysis

Automated scanning for 50+ threat patterns:
  • 🔴 Critical: rm -rf /, fork bombs, kernel module loading
  • 🟠 Dangerous: dd, mkfs, direct /dev access
  • 🟡 Suspicious: curl|sh, eval, base64 pipes
Pattern matching has limitations - see below.
3

Metadata Evaluation

Display community trust indicators:
4

Manual Review Encouragement

Tools facilitate human review:
  • aur://package/pkgbuild - Easy PKGBUILD access
  • Formatted, syntax-highlighted display
  • Side-by-side with analysis results
The AI assistant can explain suspicious patterns in plain English.
5

Official First Policy

Check official repos before AUR:
Known Limitations:
  • ❌ Pattern matching can’t catch all malicious code
  • ❌ Obfuscation techniques can bypass detection
  • ❌ Zero-day exploits won’t be detected
  • ✅ User judgment is always required
Never blindly trust automated scans!

Command Execution

Only safe read-only commands:
  • pacman -Si - Query package info
  • checkupdates - Check for updates (no installation)
Protections:
  • Timeout enforcement (default 10s)
  • No shell=True (prevents shell injection)
  • Whitelist of allowed commands
  • Platform checks before execution

Network Safety

  • Timeout limits - All requests have timeouts
  • HTTPS only - No plaintext HTTP
  • Rate limiting - Handle 429 responses
  • Input validation - Sanitize user inputs

Performance Optimizations

Caching Strategy

Current: No caching (always live data) Rationale: Rolling release means data changes frequently Future: Consider time-based caching:
  • Wiki pages: 1 hour
  • Package info: 5 minutes
  • AUR metadata: 10 minutes

Request Efficiency

  • Single API calls - No unnecessary round trips
  • Async operations - Concurrent requests possible
  • Connection pooling - httpx manages connections
  • Timeout limits - Don’t wait forever

Testing Strategy

Functional Tests

Basic tests verify core functionality:
Tests cover:
  • Wiki search and page retrieval
  • AUR search and PKGBUILD fetch
  • Official package lookup
  • Platform detection

Integration Testing

Use MCP Inspector for interactive testing:

Manual Testing Checklist

  • Resources work on both Arch and non-Arch
  • Tools return proper error responses
  • Prompts guide users through workflows
  • AUR warnings always present
  • Timeouts enforced
  • Logging goes to stderr

Extension Points

Adding New Tools

  1. Create async function in appropriate module
  2. Export from __init__.py
  3. Add @server.tool() decorator in main file
  4. Update list_tools() with schema
  5. Add handler in call_tool()
  6. Document in README and examples

Adding New Resources

  1. Define URI scheme
  2. Add parsing in read_resource()
  3. Implement fetch logic in module
  4. Add example to list_resources()
  5. Document usage

Adding New Prompts

  1. Design workflow
  2. Add @server.prompt() decorator
  3. Implement in get_prompt()
  4. Add to list_prompts()
  5. Create example in documentation

Future Enhancements

Planned Features

  • Caching layer for performance
  • Arch News integration
  • Package dependency tree analysis
  • Security advisory integration (arch-audit)
  • Local pacman.conf parsing
  • File list queries for packages
  • Systemd unit analysis
  • Custom repository support

Potential Improvements

  • Metrics collection (response times, error rates)
  • More sophisticated PKGBUILD analysis
  • Wiki page diff tracking
  • AUR package popularity trends
  • Integration with Arch forums
  • Batch operations support

Contributing

Want to contribute? See the Contributing Guide for:
  • Development setup and testing
  • Code standards and best practices
  • Pull request process
  • Feature contribution guidelines

References


Built with ❤️ following the Arch Way.