|
|
2 months ago | |
|---|---|---|
| .. | ||
| README.md | 2 months ago | |
| TEST_RESULTS.md | 2 months ago | |
| __init__.py | 2 months ago | |
| apps.py | 2 months ago | |
| server.py | 2 months ago | |
Model Context Protocol (MCP) server for ArchiveBox that exposes all CLI commands as tools for AI agents.
This is a lightweight, stateless MCP server that dynamically introspects ArchiveBox's Click CLI commands and exposes them as MCP tools. It requires zero manual schema definitions - everything is auto-generated from the existing CLI metadata.
archivebox mcp
The server runs in stdio mode, reading JSON-RPC 2.0 requests from stdin and writing responses to stdout.
import subprocess
import json
# Start MCP server
proc = subprocess.Popen(
['archivebox', 'mcp'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
text=True
)
# Send initialize request
request = {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}
proc.stdin.write(json.dumps(request) + '\n')
proc.stdin.flush()
# Read response
response = json.loads(proc.stdout.readline())
print(response)
Initialize:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}
List all available tools:
{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
Call a tool:
{
"jsonrpc":"2.0",
"id":3,
"method":"tools/call",
"params":{
"name":"version",
"arguments":{"quiet":true}
}
}
initialize - Handshake and capability negotiationtools/list - List all available CLI commands as MCP toolstools/call - Execute a CLI command with argumentsThe server exposes all ArchiveBox CLI commands:
Meta: help, version, mcp
Setup: init, install
Archive: add, remove, update, search, status, config
Workers: orchestrator, worker
Tasks: crawl, snapshot, extract
Server: server, schedule
Utilities: shell, manage
Instead of manually defining schemas, the server uses Click's introspection API to automatically generate MCP tool definitions:
# Auto-discover commands
from archivebox.cli import ArchiveBoxGroup
cli_group = ArchiveBoxGroup()
all_commands = cli_group.all_subcommands
# Auto-generate schemas from Click metadata
for cmd_name in all_commands:
click_cmd = cli_group.get_command(None, cmd_name)
# Extract params, types, help text, etc.
tool_schema = click_command_to_mcp_tool(cmd_name, click_cmd)
Commands are executed using Click's CliRunner:
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(click_command, args)
server.py (~350 lines) - Core MCP server with Click introspectionarchivebox/cli/archivebox_mcp.py (~50 lines) - CLI entry pointapps.py, __init__.py - Django app boilerplateImplements the MCP 2025-11-25 specification.