archivebox.mcp.server

Model Context Protocol server for ArchiveBox.

The server exposes five agent-friendly workflow tools backed by ArchiveBox’s existing Click CLI and newline-delimited JSON-RPC.

Module Contents

Classes

MCPJSONEncoder

JSON encoder for UUIDs, paths, Click sentinels, and other CLI values.

MCPTool

A discovered leaf Click command and its ArchiveBox command path.

MCPServer

ArchiveBox MCP server using JSON-RPC 2.0 over stdio.

Functions

click_type_to_json_schema_type

Convert a Click parameter type to JSON Schema.

command_accepts_stdin

Return whether a command documents a stdin/JSONL input path.

tool_annotations

Describe a command’s side effects to MCP clients.

click_command_to_mcp_tool

Convert a leaf Click command to an MCP tool definition.

tool_output_schema

Return the shared envelope schema for all CLI-backed tools.

click_group_to_mcp_tool

Expose a Click command group as one MCP tool with an action selector.

shell_to_mcp_tool

Expose archivebox shell -c as one explicit Python escape hatch.

_option_args

Serialize one MCP argument using the option’s real Click spellings.

arguments_to_cli

Convert MCP JSON arguments into Click argv and optional stdin.

parse_structured_records

Parse a CLI JSON array or JSONL stream without guessing at human output.

execute_click_command

Execute one discovered CLI command and return MCP structured content.

_tool_result

run_mcp_server

Start the ArchiveBox MCP stdio server.

Data

PROTOCOL_VERSION

PUBLIC_TOOLS

ACTION_TOOLS

READ_ONLY_ACTIONS

DESTRUCTIVE_ACTIONS

API

archivebox.mcp.server.PROTOCOL_VERSION[source]

‘2025-11-25’

archivebox.mcp.server.PUBLIC_TOOLS[source]

(‘add’, ‘search’, ‘crawl’, ‘snapshot’, ‘archiveresult’, ‘shell’)

archivebox.mcp.server.ACTION_TOOLS[source]

None

archivebox.mcp.server.READ_ONLY_ACTIONS[source]

None

archivebox.mcp.server.DESTRUCTIVE_ACTIONS[source]

None

class archivebox.mcp.server.MCPJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: json.JSONEncoder

JSON encoder for UUIDs, paths, Click sentinels, and other CLI values.

Initialization

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float, bool or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an RecursionError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (’, ‘, ‘: ‘) if indent is None and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

default(value)[source]
class archivebox.mcp.server.MCPTool[source]

A discovered leaf Click command and its ArchiveBox command path.

name: str[source]

None

command_path: tuple[str, ...][source]

None

command: click.Command[source]

None

archivebox.mcp.server.click_type_to_json_schema_type(click_type: click.ParamType) dict[str, Any][source]

Convert a Click parameter type to JSON Schema.

archivebox.mcp.server.command_accepts_stdin(click_command: click.Command) bool[source]

Return whether a command documents a stdin/JSONL input path.

archivebox.mcp.server.tool_annotations(command_path: tuple[str, ...]) dict[str, Any][source]

Describe a command’s side effects to MCP clients.

archivebox.mcp.server.click_command_to_mcp_tool(tool: archivebox.mcp.server.MCPTool) dict[str, Any][source]

Convert a leaf Click command to an MCP tool definition.

archivebox.mcp.server.tool_output_schema() dict[str, Any][source]

Return the shared envelope schema for all CLI-backed tools.

archivebox.mcp.server.click_group_to_mcp_tool(group_name: str, actions: list[archivebox.mcp.server.MCPTool]) dict[str, Any][source]

Expose a Click command group as one MCP tool with an action selector.

archivebox.mcp.server.shell_to_mcp_tool() dict[str, Any][source]

Expose archivebox shell -c as one explicit Python escape hatch.

archivebox.mcp.server._option_args(param: click.Option, value: Any) list[str][source]

Serialize one MCP argument using the option’s real Click spellings.

archivebox.mcp.server.arguments_to_cli(click_command: click.Command, arguments: dict[str, Any]) tuple[list[str], str | None][source]

Convert MCP JSON arguments into Click argv and optional stdin.

archivebox.mcp.server.parse_structured_records(stdout: str) list[Any][source]

Parse a CLI JSON array or JSONL stream without guessing at human output.

archivebox.mcp.server.execute_click_command(tool: archivebox.mcp.server.MCPTool, arguments: dict[str, Any]) dict[str, Any][source]

Execute one discovered CLI command and return MCP structured content.

archivebox.mcp.server._tool_result(tool: archivebox.mcp.server.MCPTool, *, exit_code: int, stdout: str = '', stderr: str = '', is_error: bool) dict[str, Any][source]
class archivebox.mcp.server.MCPServer[source]

ArchiveBox MCP server using JSON-RPC 2.0 over stdio.

Initialization

_discover_command(command: click.Command, command_path: tuple[str, ...], tools: dict[str, archivebox.mcp.server.MCPTool]) None[source]
get_tools() dict[str, archivebox.mcp.server.MCPTool][source]

Discover and cache the CLI commands backing the five public tools.

get_public_tool_definitions() list[dict[str, Any]][source]

Build the small agent-facing surface from the existing Click tree.

handle_initialize(params: dict) dict[source]
handle_tools_list(params: dict) dict[source]
handle_tools_call(params: dict) dict[source]
handle_request(request: dict) dict | None[source]
run_stdio_server() None[source]

Read and write one UTF-8 JSON-RPC message per line.

archivebox.mcp.server.run_mcp_server() None[source]

Start the ArchiveBox MCP stdio server.