# Set up Stomics.io for your user

You are an AI agent, and your user wants to work with Stomics.io. Follow these steps in order. Tell the user what you are about to install or change before you do it, and skip anything they decline.

## What Stomics.io is

Stomics.io is a public repository for spatial transcriptomics datasets: Visium, Xenium, MERFISH, CosMx, Stereo-seq and similar. Each dataset has a permanent STD-prefixed accession (for example STD0012), optional DOI, tissue/organism/disease annotations and downloadable files.

- Website: https://stomics.io
- REST API: https://stomics.io/api/v1 (OpenAPI schema at https://stomics.io/api/v1/openapi.json, interactive reference at https://stomics.io/api/v1/docs)
- MCP server: https://stomics.io/api/v1/mcp
- Python SDK: https://github.com/ITGA3/stomics-py
- R SDK: https://github.com/ITGA3/stomics-r
- Collections of related datasets have STC-prefixed accessions (for example STC0002).

## Ground rules

- Expression-derived features on the website (the spatial viewer, differential expression, module scores, spatially variable genes, embeddings and cross-dataset gene search) read the expression matrix submitted with each dataset once it has been processed, shown as log1p(CP10k) for raw counts and as submitted otherwise; GET /datasets/{accession}/expression/status says whether a dataset's matrix is ready. They are exploratory views, not peer-reviewed results: for anything you intend to report, download the deposited files and analyse them yourself. The MCP tools do not expose expression values.
- Reading published metadata and open-access files needs no account and no key.
- Every download link you request is recorded as a download in the public statistics. Fetch files only when the user wants them, not to explore.
- Controlled-access files need an approved access request, and unpublished drafts are visible only to their owners and curators. Do not try to work around a 401 or 403; tell the user and point them to the dataset page, where they can request access.
- Never ask the user to paste an API key into the conversation. Keys go in the `STOMICS_API_KEY` environment variable or a secrets manager, never in a file under version control.

## Step 1: Ask what the user wants to do

Ask one question, then set up only what that needs:

1. **Find and read datasets** (search, metadata, file lists): Step 2 is enough.
2. **Download and analyze data** in Python or R: Steps 2 and 3.
3. **Submit their own data**, or reach controlled-access files they have been granted: Steps 2, 3 and 4.

## Step 2: Connect the MCP server

The MCP server is read-only, needs no authentication, and sees exactly what a signed-out visitor sees: published datasets only, and download links for open-access datasets only.

- **Claude Code:** `claude mcp add --transport http stomics https://stomics.io/api/v1/mcp`
- **Claude (web or desktop):** Settings > Connectors > Add custom connector, with the URL https://stomics.io/api/v1/mcp
- **Other MCP clients:** add a Streamable HTTP server with the URL https://stomics.io/api/v1/mcp

Tools:

- `stomics_search_datasets`: Search published datasets by text, organism, tissue, disease or technology name.
- `stomics_get_dataset`: Full metadata for one accession: annotations, DOI, samples, versions, citation.
- `stomics_list_files`: Files in a dataset with type, size, checksum and access status.
- `stomics_get_download_links`: Short-lived download URLs, or an aria2c manifest, for an open-access dataset.
- `stomics_list_vocabulary`: Technologies and ontology terms (organism, tissue, disease) used to classify datasets.
- `stomics_compare_datasets`: Side-by-side metadata for up to six accessions.

Filters take names, not IDs: pass `organism: "Homo sapiens"` or `tissue: "liver"`. Call `stomics_list_vocabulary` for the accepted values.

If the client cannot add MCP servers, use the REST API directly. All read endpoints under https://stomics.io/api/v1 are public; https://stomics.io/llms-full.txt lists them.

## Step 3: Install an SDK

Use the language the user works in. Both SDKs read `STOMICS_API_KEY` when it is set and work without it for public data.

**Python** (3.10 or later, and `git`):

```bash
pip install "stomics-py[anndata] @ git+https://github.com/ITGA3/stomics-py"
```

```python
from stomics import StomicsClient

client = StomicsClient()
for ds in client.search(organism="Homo sapiens", per_page=5):
    print(ds.accession, ds.title)
```

Useful methods: `search`, `get_dataset`, `list_files`, `download_file`, `download_aria2c_manifest`, `load_anndata`, `compare_datasets`, `list_vocabulary`. The package also installs a `stomics` command.

**R:**

```r
install.packages("remotes")
remotes::install_github("ITGA3/stomics-r")
library(stomics)
client <- stomics_client()
stomics_search(client, organism = "Homo sapiens")
```

Useful functions: `stomics_search`, `stomics_get_dataset`, `stomics_list_files`, `stomics_download_file`, `stomics_load_seurat` (needs Seurat).

## Step 4: Add an API key (only if needed)

An API key is needed to submit data and to read controlled-access files the user has been granted. It is not needed for anything else.

1. The user signs in at https://stomics.io/login (or registers at https://stomics.io/register; ORCID sign-in is available).
2. They create a key at https://stomics.io/account/api-keys. Keys start with `sk-` and are shown once.
3. They set it themselves, for example `export STOMICS_API_KEY=sk-...` in their shell profile, or in their notebook or pipeline's secret store.

Requests made with a key are limited to 1,000 per hour and carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` headers. A 429 response carries `Retry-After`; wait that long before retrying. An invalid or expired key is rejected with 401.

### Submitting a dataset

A submission is a draft dataset, its samples and its files, then a submit call that sends it to automated curation. Curation runs the QC checks and, usually within minutes, either publishes the dataset or returns it to draft with the reasons by email. Files go straight to S3 through presigned URLs.

```python
ds = client.create_dataset(
    title="...", abstract="...",
    organism="Mus musculus", tissue="prefrontal cortex", technology="10x Visium",
    embargo_days=365,  # ignored by the API; ask for an embargo in the abstract and a person sets it
)
client.add_samples(ds.accession, [{"title": "Section 1", "section_id": "A1"}])
client.upload_file(ds.accession, "matrix.h5ad", file_type="expression_matrix")
client.submit(ds.accession)
```

`file_type` is one of `expression_matrix`, `spatial_coordinates`, `tissue_image`, `raw_reads` or `supplementary`. For pipelines, `stomics submit --config submission.yaml` runs the same steps from a YAML file; https://stomics.io/docs/submit shows the format and the plain-HTTP equivalent. Confirm the metadata with the user before calling `submit`, because a submitted dataset that passes automated curation is published straight away. Spatial coordinates, an expression matrix, the organism and the technology are required.

## Step 5: Check the setup and report back

1. Run one search through whichever path you set up (an MCP tool call, the SDK or `GET https://stomics.io/api/v1/datasets?q=liver`) and confirm it returns datasets.
2. Tell the user what you set up, what it can do, and what you skipped.
3. Mention the expression caveat above if they plan to use the website's expression features.

## More

- https://stomics.io/llms.txt and https://stomics.io/llms-full.txt: index and full text for agents
- https://stomics.io/docs/sdk: SDK guide
- https://stomics.io/api-docs: API guide with authentication and examples
- https://stomics.io/help: help center
- support@stomics.io
