autots.mcp package

Subpackages

Submodules

autots.mcp.cache module

State management & global caches for the AutoTS MCP server.

autots.mcp.cache.cache_object(obj: Any, cache_type: str, metadata: dict = None) str

Cache an object and return a unique ID.

autots.mcp.cache.clear_cache(obj_id: str | None = None, cache_type: str | None = None)

Clear cache - specific ID, specific type, or all if both None.

autots.mcp.cache.get_cached_object(obj_id: str, cache_type: str) Dict[str, Any]

Retrieve a cached object by ID and type.

autots.mcp.cache.list_all_cached_objects() dict

List all cached objects across all cache types.

autots.mcp.core module

Transport-neutral dispatch for AutoTS tools.

run_tool is the single entry point shared by the MCP server, the Pyodide worker, and any general-purpose Python API. Handlers return plain, JSON-serializable data (dicts / lists); transport layers wrap the result as needed (the MCP server wraps it in TextContent / ImageContent, the Pyodide worker serializes it to JSON, etc.).

This module deliberately avoids importing mcp so it can run in environments (such as Pyodide) where the MCP SDK is not installed.

autots.mcp.core.available_tools()

Return the sorted list of registered tool names.

async autots.mcp.core.run_tool(name, arguments=None, progress_cb=None)

Dispatch a tool call and return plain, JSON-serializable data.

Parameters:
  • name – Registered tool name (see available_tools()).

  • arguments – Dict of tool arguments.

  • progress_cb – Optional None, sync, or async callable taking a single progress-message string.

Returns:

The handler’s plain-data result (a dict or list). Image-producing tools return {"image_base64": ..., "mime_type": ...}. Unknown tool names return {"error": ...} rather than raising.

autots.mcp.core.run_tool_sync(name, arguments=None, progress_cb=None)

Synchronous wrapper around run_tool() for non-async callers.

autots.mcp.data_utils module

DataFrame loading and CSV formatting utilities for the AutoTS MCP server.

autots.mcp.data_utils.build_csv_metadata(filepath: str, df: DataFrame, is_long: bool = False) dict

Build metadata dict for a CSV export with loading instructions.

autots.mcp.data_utils.dataframe_to_output(df: DataFrame, output_format: str = 'json_wide', save_path: str | None = None) dict | str

Convert DataFrame to requested output format.

Parameters:
  • df – DataFrame with DatetimeIndex.

  • output_format – “json_wide”, “json_long”, “csv_wide”, or “csv_long”.

  • save_path – Optional path to save CSV (returns path).

Returns:

Dictionary (JSON) or string (CSV path).

autots.mcp.data_utils.load_to_dataframe(data: dict | str | None = None, data_format: str = 'wide', data_id: str | None = None) DataFrame

Load data to pandas DataFrame from multiple sources.

Parameters:
  • data – JSON dict, CSV file path, or URL. If None, must provide data_id.

  • data_format – “wide” or “long” (for JSON dict input).

  • data_id – Optional cached data ID to load from cache.

Returns:

DataFrame with DatetimeIndex.

autots.mcp.data_utils.sanitize_json_values(obj)

Replace dataframe missing and non-finite scalar values with JSON null.

autots.mcp.data_utils.save_temp_csv(df: DataFrame, is_long: bool = False) str

Save DataFrame to a temporary CSV file and return the path.

autots.mcp.data_utils.serialize_timestamps(obj)

Recursively convert pandas Timestamp objects to strings for JSON serialization.

autots.mcp.ingest module

Smart data ingestion for the AutoTS PWA / MCP server.

smart_load is the beginner-friendly entry point for getting messy, human-authored spreadsheets into a clean wide DataFrame ready for forecasting. It is transport-neutral (no MCP / Pyodide dependency) so it is shared by the MCP server, the Pyodide worker, and any general-purpose API.

The hardest part of the beginner flow is the upload: non-technical users export spreadsheets that contain stray calculations, off-center tables, and empty padding rows/columns. smart_load reproduces the cleanup described in the PWA design doc:

  1. Parse pasted text (CSV/TSV), uploaded bytes (CSV/XLSX), or a URL.

  2. Drop fully-empty rows/columns, then rows/columns that are >=95% empty.

  3. Auto-detect orientation (single-series, wide, or long) and return a clean wide DataFrame plus a human/LLM-readable report of what happened.

autots.mcp.ingest.smart_load(*, text=None, csv_bytes=None, url=None, filename=None, data_format='auto', long_cols=None)

Load messy user data into a clean wide DataFrame.

Parameters:
  • text – Pasted CSV/TSV text.

  • csv_bytes – Raw uploaded bytes (CSV or XLSX; XLSX detected via filename).

  • url – A CSV URL (e.g. a published Google Sheet).

  • filename – Optional original filename, used to detect Excel uploads.

  • data_format – “auto” (default), “wide”, or “long”.

  • long_cols – For long data, an optional dict {"date": ..., "value": ..., "id": ...} naming the columns. When omitted (or “auto”), columns are auto-detected.

Returns:

(df_wide, report) where df_wide has a DatetimeIndex and one column per series, and report is a JSON-serializable dict describing the cleanup and detection decisions.

autots.mcp.prompts module

MCP Prompt & Resource definitions for the AutoTS MCP server.

async autots.mcp.prompts.get_prompt(name: str, arguments: dict | None = None) GetPromptResult

Return a multi-step workflow prompt by name.

autots.mcp.prompts.get_resources(mcp_file_path: str) list[Resource]

Return list of available documentation resources.

async autots.mcp.prompts.read_resource(uri: str) str

Read a documentation resource by URI.

autots.mcp.pyodide_api module

Pyodide-facing API for the AutoTS PWA.

This is the thin layer the in-browser Web Worker calls. It:

  • Restricts forecasting to a Pyodide-safe set of pure-Python models (no tensorflow / torch / prophet / xgboost / lightgbm / arch, all of which are unavailable or impractical in WASM), and forces n_jobs=1 since Pyodide has no process parallelism.

  • Maps the PWA’s three buttons (“make forecast”, “search for best forecast”, “search all night”) to concrete tool calls, keeping that business logic in Python so the Rust/Leptos (or any) frontend stays a thin view layer.

  • Exposes a single JSON-in / JSON-out boundary (run_command_json()) the worker can call, routing progress_cb to postMessage.

It deliberately avoids importing mcp so it runs where the MCP SDK is absent.

async autots.mcp.pyodide_api.dispatch(command, arguments=None, progress_cb=None)

Route a PWA command to a preset or directly to a core tool.

command is either a preset (“make_forecast”, “search_forecast”, “search_all_night”) or any registered tool name (see list_commands()).

autots.mcp.pyodide_api.list_commands()

All commands the PWA may call: presets plus every core tool.

async autots.mcp.pyodide_api.run_command_json(command, arguments_json='{}', progress_cb=None)

JSON-in / JSON-out boundary for the Pyodide Web Worker.

Parameters:
  • command – Preset or tool name.

  • arguments_json – JSON string (or dict) of arguments.

  • progress_cb – Optional callable taking a progress-message string. JS functions passed from the worker are invoked synchronously to postMessage progress updates.

Returns:

A JSON string of the result.

autots.mcp.schemas module

MCP Tool definitions for the AutoTS MCP server.

Combines tool schemas from:
  • schemas_data.py — cache management + data loading/conversion tools

  • schemas_forecast.py — forecasting and prediction manipulation tools

  • schemas_features.py — event risk and feature detection tools

autots.mcp.schemas_data module

MCP Tool schemas for cache management and data loading/conversion tools.

autots.mcp.schemas_features module

MCP Tool schemas for event risk forecasting and feature detection tools.

autots.mcp.schemas_forecast module

MCP Tool schemas for forecasting, prediction, event risk, and feature detection tools.

autots.mcp.server module

MCP Server for AutoTS Time Series Forecasting

Main entry point and request routing. Delegates to:
  • autots.mcp.schemas — Tool definitions

  • autots.mcp.prompts — Prompt & Resource definitions

  • autots.mcp.handlers — Tool execution logic

  • autots.mcp.cache — State management

Re-exports of sub-module symbols are provided at the bottom of this file for backwards compatibility (tests and other code that imports from autots.mcp.server).

async autots.mcp.server.call_tool(name: str, arguments: Any) list[TextContent | ImageContent]

Dispatch tool calls to the shared core and wrap the result for MCP.

async autots.mcp.server.get_prompt_handler(name: str, arguments: dict | None = None)
async autots.mcp.server.list_prompts()
async autots.mcp.server.list_resources()
async autots.mcp.server.list_tools()
async autots.mcp.server.read_resource_handler(uri: str) str
autots.mcp.server.serve()

Start the MCP server.

Module contents

Model Context Protocol (MCP) Server for AutoTS

This package provides an MCP server interface for AutoTS forecasting capabilities, enabling LLM integration for time series forecasting tasks.

autots.mcp.serve()

Start the MCP server.