Skip to content

Development

Setup and checks

Use Python 3.11.5 or newer. The CI matrix covers Python 3.11–3.14. Install the development dependencies from the lockfile:

uv sync --frozen

Run the non-live suite with coverage, lint, formatting, types, and release checks:

uv run --frozen pytest
uv run --frozen ruff check .
uv run --frozen ruff format --check .
uv run --frozen pyright --pythonpath .venv/bin/python src
uv run --frozen python scripts/check_release.py

Live checks require network access and working upstream providers:

uv run --frozen pytest -m live -o addopts=""

Build the documentation and verify the wheel in an isolated environment:

uv run --frozen --group docs mkdocs build --strict
uv build
uv run --no-project python scripts/check_install.py dist/*.whl

The wheel check covers the default installation, provider/profile selections, and combined selections. Use provider-shaped fixtures and independent numerical expectations to verify values, dates, errors, resource ownership, and public schemas. Workflow tool sets have an independent contract in tests/fixtures/tool_profiles.json; tests/core/test_profiles.py checks exact selections and UTF-8 catalog-size budgets. Review budget changes explicitly; they measure serialized definitions, not client context usage or result sizes.

Code organization

  • core/profiles.py owns immutable module/provider metadata and workflow tool allowlists. Selection applies the profile, explicit module override, then provider filtering. Provider capabilities are separate from module/workflow metadata; shared tools may support more than one enabled source. full is the default; overview opts into a curated 12-tool catalog.
  • core/mcpserver.py constructs servers, validates selected names before publication, and passes their runtime to services. core/mcp_compat.py owns SDK-specific generated argument-model adaptation; schemas and dispatch share strict fields and enabled-source constraints. Unsupported manager/model structures fail startup rather than weakening validation.
  • services/ exposes explicit MCP tools and research aggregation. Repositories are fixed at construction; create a new service to replace them. ServiceAdapter handles resources and caching; ToolRegistrationMixin publishes @tool methods.
  • repositories/ owns provider I/O and decoding. Use decode_model and require_dataframe at data boundaries; let programming errors propagate. SEC taxonomy and concept decoders validate nested containers and every supplied observation; malformed facts must not become successful empty histories. The industry catalog getter returns an independent collection without acquiring the Yahoo gate. repositories/history.py normalizes prices; core/indicators.py computes source-independent indicators. Source/adjustment metadata must survive every calculation. Keep provider-native behavior explicit and never silently fall back. Technical calculations compose a HistoryReader; inject normalized histories without a transport interface. Omitted sources follow the reader's enabled-source policy, preferring Yahoo when both Yahoo and WSJ are enabled. Yahoo single-symbol history requests share explicit adjustment, gap-retention, and error flags. Legacy stock/crypto projections retain dividend-adjusted prices and their existing omission of empty bars. Portfolio acquisition preserves gaps for the quantitative core to align. Crypto sentiment shares acquisition policy while retaining a seven-calendar-day request. Internal Yahoo durations do not expand the public tool period enums.
  • core/quant.py owns numerical algorithms and observation policy without I/O. Its pandas RSI adapter uses the shared kernel in core/indicators.py; portfolio preparation and indicator gap handling retain their own observation policies.
  • Each TTLCache owns its bounded reentrant miss-coordination stripes; independent runtime caches never share those locks. cached owns argument-key construction.
  • schemas/ defines typed input and result contracts. CuratedStockInfo is the purpose-based model name; StockInfo_v2 remains an alias and the existing schema title is retained for wire compatibility. SectorEnum in core/constants.py owns sector names and is re-exported from the original schema module. Catalogs reference its values, preserving their existing presentation order. Independent tests check exports and wire enums. Accounting dates use real ISO calendar dates; required SEC values are finite numbers, not booleans or numeric strings. Price observation dates accept actual dates or ISO timestamps, never numeric epochs. Explicit Unix-time fields retain their documented conversion rules.

Do not share concrete provider adapters across independent runtimes. Borrowed sessions remain caller-owned. Construct injected provider adapters with their runtime/session; services validate explicit resource arguments without rebinding the adapter. For example, use StockService(repository=YFinanceStockRepository(session=session), session=session). An existing session inherited from the repository's runtime is also accepted; validation never creates a lazy session to compare transports. Conflicting resources raise ValueError; custom duck-typed repositories need no resource interface. See API contracts for error semantics, financial assumptions, and resource lifecycle.

Reproducible live audits

Record one explicit argument set for every tool with optional parameters:

uv run --frozen python scripts/audit_optional_parameters.py --report /tmp/optional-audit.json

The full-server audit discovers parameters from MCP schemas and records server identity, timestamps, arguments, responses, failures, and schema checks. It distinguishes explicit defaults from non-default values. Selected assertions check observation ordering, limit bounds, option moneyness, SEC form filtering, and field projection. Overview comparisons record US and GB snapshots without interpreting identical global data as country-specific coverage. One argument set per tool does not establish exhaustive semantic or numerical correctness.

For independent numerical checks on captured live observations:

uv run --frozen pytest tests/live/test_portfolio_independent_values_live.py tests/live/test_indicator_values_live.py -m live -o addopts=""

Portfolio checks save the input price CSV under pytest's temporary directory and replay that snapshot through MCP. Separate formulas and ledgers check risk, correlation, factor loadings, allocations, and backtests. Indicator checks compare actual source observations with pandas calculations. These validate calculations on Yahoo/WSJ data, not agreement with an independent market-data source.

Dependencies

Keep installations reproducible with uv.lock; update dependencies explicitly. Audit the lockfile with uv audit --locked. CI also uses uv's preview malware check, which can be run locally with:

UV_MALWARE_CHECK=1 uv --preview-features malware-check sync --locked --all-groups