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
JSON encoder for UUIDs, paths, Click sentinels, and other CLI values. |
|
A discovered leaf Click command and its ArchiveBox command path. |
|
ArchiveBox MCP server using JSON-RPC 2.0 over stdio. |
Functions
Convert a Click parameter type to JSON Schema. |
|
Return whether a command documents a stdin/JSONL input path. |
|
Describe a command’s side effects to MCP clients. |
|
Convert a leaf Click command to an MCP tool definition. |
|
Return the shared envelope schema for all CLI-backed tools. |
|
Expose a Click command group as one MCP tool with an action selector. |
|
Expose |
|
Serialize one MCP argument using the option’s real Click spellings. |
|
Convert MCP JSON arguments into Click argv and optional stdin. |
|
Parse a CLI JSON array or JSONL stream without guessing at human output. |
|
Execute one discovered CLI command and return MCP structured content. |
|
Start the ArchiveBox MCP stdio server. |
Data
API
- archivebox.mcp.server.PUBLIC_TOOLS[source]
(‘add’, ‘search’, ‘crawl’, ‘snapshot’, ‘archiveresult’, ‘shell’)
- 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.JSONEncoderJSON 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
Noneand (‘,’, ‘: ‘) 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.
- class archivebox.mcp.server.MCPTool[source]
A discovered leaf Click command and its ArchiveBox command path.
- 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 -cas 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.