Metadata-Version: 2.3
Name: uxarray-mcp
Version: 0.2.1
Summary: MCP server for analyzing unstructured meshes with UXarray
Keywords: uxarray,mcp,unstructured grids,scientific computing,globus compute
Author: Rajeev Jain, Dayan Abdulla
Author-email: Rajeev Jain <rajeeja@gmail.com>, Dayan Abdulla <dayanabdulla000@gmail.com>
License: 
                                          Apache License
                                    Version 2.0, January 2004
                                 http://www.apache.org/licenses/
         
            TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
         
            1. Definitions.
         
               "License" shall mean the terms and conditions for use, reproduction,
               and distribution as defined by Sections 1 through 9 of this document.
         
               "Licensor" shall mean the copyright owner or entity authorized by
               the copyright owner that is granting the License.
         
               "Legal Entity" shall mean the union of the acting entity and all
               other entities that control, are controlled by, or are under common
               control with that entity. For the purposes of this definition,
               "control" means (i) the power, direct or indirect, to cause the
               direction or management of such entity, whether by contract or
               otherwise, or (ii) ownership of fifty percent (50%) or more of the
               outstanding shares, or (iii) beneficial ownership of such entity.
         
               "You" (or "Your") shall mean an individual or Legal Entity
               exercising permissions granted by this License.
         
               "Source" form shall mean the preferred form for making modifications,
               including but not limited to software source code, documentation
               source, and configuration files.
         
               "Object" form shall mean any form resulting from mechanical
               transformation or translation of a Source form, including but
               not limited to compiled object code, generated documentation,
               and conversions to other media types.
         
               "Work" shall mean the work of authorship, whether in Source or
               Object form, made available under the License, as indicated by a
               copyright notice that is included in or attached to the work
               (an example is provided in the Appendix below).
         
               "Derivative Works" shall mean any work, whether in Source or Object
               form, that is based on (or derived from) the Work and for which the
               editorial revisions, annotations, elaborations, or other modifications
               represent, as a whole, an original work of authorship. For the purposes
               of this License, Derivative Works shall not include works that remain
               separable from, or merely link (or bind by name) to the interfaces of,
               the Work and Derivative Works thereof.
         
               "Contribution" shall mean any work of authorship, including
               the original version of the Work and any modifications or additions
               to that Work or Derivative Works thereof, that is intentionally
               submitted to Licensor for inclusion in the Work by the copyright owner
               or by an individual or Legal Entity authorized to submit on behalf of
               the copyright owner. For the purposes of this definition, "submitted"
               means any form of electronic, verbal, or written communication sent
               to the Licensor or its representatives, including but not limited to
               communication on electronic mailing lists, source code control systems,
               and issue tracking systems that are managed by, or on behalf of, the
               Licensor for the purpose of discussing and improving the Work, but
               excluding communication that is conspicuously marked or otherwise
               designated in writing by the copyright owner as "Not a Contribution."
         
               "Contributor" shall mean Licensor and any individual or Legal Entity
               on behalf of whom a Contribution has been received by Licensor and
               subsequently incorporated within the Work.
         
            2. Grant of Copyright License. Subject to the terms and conditions of
               this License, each Contributor hereby grants to You a perpetual,
               worldwide, non-exclusive, no-charge, royalty-free, irrevocable
               copyright license to reproduce, prepare Derivative Works of,
               publicly display, publicly perform, sublicense, and distribute the
               Work and such Derivative Works in Source or Object form.
         
            3. Grant of Patent License. Subject to the terms and conditions of
               this License, each Contributor hereby grants to You a perpetual,
               worldwide, non-exclusive, no-charge, royalty-free, irrevocable
               (except as stated in this section) patent license to make, have made,
               use, offer to sell, sell, import, and otherwise transfer the Work,
               where such license applies only to those patent claims licensable
               by such Contributor that are necessarily infringed by their
               Contribution(s) alone or by combination of their Contribution(s)
               with the Work to which such Contribution(s) was submitted. If You
               institute patent litigation against any entity (including a
               cross-claim or counterclaim in a lawsuit) alleging that the Work
               or a Contribution incorporated within the Work constitutes direct
               or contributory patent infringement, then any patent licenses
               granted to You under this License for that Work shall terminate
               as of the date such litigation is filed.
         
            4. Redistribution. You may reproduce and distribute copies of the
               Work or Derivative Works thereof in any medium, with or without
               modifications, and in Source or Object form, provided that You
               meet the following conditions:
         
               (a) You must give any other recipients of the Work or
                   Derivative Works a copy of this License; and
         
               (b) You must cause any modified files to carry prominent notices
                   stating that You changed the files; and
         
               (c) You must retain, in the Source form of any Derivative Works
                   that You distribute, all copyright, patent, trademark, and
                   attribution notices from the Source form of the Work,
                   excluding those notices that do not pertain to any part of
                   the Derivative Works; and
         
               (d) If the Work includes a "NOTICE" text file as part of its
                   distribution, then any Derivative Works that You distribute must
                   include a readable copy of the attribution notices contained
                   within such NOTICE file, excluding those notices that do not
                   pertain to any part of the Derivative Works, in at least one
                   of the following places: within a NOTICE text file distributed
                   as part of the Derivative Works; within the Source form or
                   documentation, if provided along with the Derivative Works; or,
                   within a display generated by the Derivative Works, if and
                   wherever such third-party notices normally appear. The contents
                   of the NOTICE file are for informational purposes only and
                   do not modify the License. You may add Your own attribution
                   notices within Derivative Works that You distribute, alongside
                   or as an addendum to the NOTICE text from the Work, provided
                   that such additional attribution notices cannot be construed
                   as modifying the License.
         
               You may add Your own copyright statement to Your modifications and
               may provide additional or different license terms and conditions
               for use, reproduction, or distribution of Your modifications, or
               for any such Derivative Works as a whole, provided Your use,
               reproduction, and distribution of the Work otherwise complies with
               the conditions stated in this License.
         
            5. Submission of Contributions. Unless You explicitly state otherwise,
               any Contribution intentionally submitted for inclusion in the Work
               by You to the Licensor shall be under the terms and conditions of
               this License, without any additional terms or conditions.
               Notwithstanding the above, nothing herein shall supersede or modify
               the terms of any separate license agreement you may have executed
               with Licensor regarding such Contributions.
         
            6. Trademarks. This License does not grant permission to use the trade
               names, trademarks, service marks, or product names of the Licensor,
               except as required for reasonable and customary use in describing the
               origin of the Work and reproducing the content of the NOTICE file.
         
            7. Disclaimer of Warranty. Unless required by applicable law or
               agreed to in writing, Licensor provides the Work (and each
               Contributor provides its Contributions) on an "AS IS" BASIS,
               WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
               implied, including, without limitation, any warranties or conditions
               of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
               PARTICULAR PURPOSE. You are solely responsible for determining the
               appropriateness of using or redistributing the Work and assume any
               risks associated with Your exercise of permissions under this License.
         
            8. Limitation of Liability. In no event and under no legal theory,
               whether in tort (including negligence), contract, or otherwise,
               unless required by applicable law (such as deliberate and grossly
               negligent acts) or agreed to in writing, shall any Contributor be
               liable to You for damages, including any direct, indirect, special,
               incidental, or consequential damages of any character arising as a
               result of this License or out of the use or inability to use the
               Work (including but not limited to damages for loss of goodwill,
               work stoppage, computer failure or malfunction, or any and all
               other commercial damages or losses), even if such Contributor
               has been advised of the possibility of such damages.
         
            9. Accepting Warranty or Additional Liability. While redistributing
               the Work or Derivative Works thereof, You may choose to offer,
               and charge a fee for, acceptance of support, warranty, indemnity,
               or other liability obligations and/or rights consistent with this
               License. However, in accepting such obligations, You may act only
               on Your own behalf and on Your sole responsibility, not on behalf
               of any other Contributor, and only if You agree to indemnify,
               defend, and hold each Contributor harmless for any liability
               incurred by, or claims asserted against, such Contributor by reason
               of your accepting any such warranty or additional liability.
         
            END OF TERMS AND CONDITIONS
         
            APPENDIX: How to apply the Apache License to your work.
         
               To apply the Apache License to your work, attach the following
               boilerplate notice, with the fields enclosed by brackets "[]"
               replaced with your own identifying information. (Don't include
               the brackets!)  The text should be enclosed in the appropriate
               comment syntax for the file format. We also recommend that a
               file or class name and description of purpose be included on the
               same "printed page" as the copyright notice for easier
               identification within third-party archives.
         
            Copyright [yyyy] [name of copyright owner]
         
            Licensed under the Apache License, Version 2.0 (the "License");
            you may not use this file except in compliance with the License.
            You may obtain a copy of the License at
         
                http://www.apache.org/licenses/LICENSE-2.0
         
            Unless required by applicable law or agreed to in writing, software
            distributed under the License is distributed on an "AS IS" BASIS,
            WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            See the License for the specific language governing permissions and
            limitations under the License.
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: Apache Software License
Requires-Dist: toolregistry-server[mcp]>=0.4.0
Requires-Dist: mcp>=1.20,<2
Requires-Dist: holoviews>=1.19.0
Requires-Dist: matplotlib>=3.9.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: uxarray>=2026.7.0
Requires-Dist: sphinx>=7.0 ; extra == 'docs'
Requires-Dist: sphinx-book-theme>=1.1.0 ; extra == 'docs'
Requires-Dist: myst-parser>=3.0 ; extra == 'docs'
Requires-Dist: academy-py>=0.3.1 ; extra == 'hpc'
Requires-Dist: globus-compute-sdk>=4.5.0 ; extra == 'hpc'
Requires-Dist: toolregistry-server[openapi]>=0.4.0 ; extra == 'openapi'
Requires-Python: >=3.12, <3.13
Project-URL: Documentation, https://uxarray-mcp-server.readthedocs.io
Project-URL: Source, https://github.com/UXARRAY/uxarray-mcp-server
Project-URL: Tracker, https://github.com/UXARRAY/uxarray-mcp-server/issues
Provides-Extra: docs
Provides-Extra: hpc
Provides-Extra: openapi
Description-Content-Type: text/markdown

# UXarray MCP Server

An MCP server that lets an AI assistant (Claude Code, Claude Desktop, Cursor,
or any MCP client) analyze unstructured climate meshes with
[UXarray](https://uxarray.readthedocs.io/) — locally on your machine, or
remotely on an HPC system you have access to.

```text
┌─────────────┐  stdio  ┌──────────────┐                    ┌─────────────────┐
│  AI client  │ ◀─────▶ │ uxarray-mcp  │ ◀── Globus ──────▶ │  HPC endpoint   │
│  (Claude…)  │   pipe  │ (your laptop)│    Compute (opt)   │ (Slurm/PBS node)│
└─────────────┘         └──────────────┘                    └─────────────────┘
```

> **What the AI can do.** Open meshes and datasets, compute area / zonal mean
> / vorticity / divergence, subset, remap, plot, and run multi-step workflows.
> All as natural-language prompts.

> **Local by default; HPC is opt-in.** Everything runs on your machine unless
> you configure a [Globus Compute](https://www.globus.org/compute) endpoint.
> The remote option only becomes available once such an endpoint exists —
> running one requires an account and allocation on that HPC system, though a
> shared/service-account endpoint can let authorized users submit without their
> own login.

> **⚠️ What the AI can access.** Any file you (or your HPC account) can read.
> Any compute the configured endpoint can submit. Outputs are written to your
> disk. **See [SECURITY.md](SECURITY.md) before connecting any remote endpoint.**

---

## Pick your path

You are most likely one of:

1. **Local user** — laptop only, no HPC. → [Local install](#local-install).
2. **HPC user, endpoint already exists** — someone at your lab gave you a
   Globus Compute endpoint UUID. → [Local install](#local-install), then
   [docs/remote-hpc.md](docs/remote-hpc.md).
3. **HPC user, your own personal endpoint** — you have a Globus identity and
   shell access to an HPC machine, and want to stand up an endpoint just for
   yourself. → [Local install](#local-install), then
   [docs/operating-an-endpoint.md](docs/operating-an-endpoint.md#solo-personal-endpoint-quickstart).
4. **Group / shared endpoint operator** — you're standing one up for a team,
   project, or lab. → [Local install](#local-install), then the full
   [docs/operating-an-endpoint.md](docs/operating-an-endpoint.md) including
   service-account migration and the MEP allowlist.

---

## Local install

Five steps. Each is one command unless noted.

### Step 1 — Install the package

Pick one. `uv` is the easiest; `pip` works too.

```bash
# Recommended
uv tool install --python 3.12 uxarray-mcp

# Or from a fresh clone (developer path)
git clone https://github.com/UXARRAY/uxarray-mcp-server.git
cd uxarray-mcp-server && uv sync --python 3.12
# or: bash SETUP.sh   (does the sync + runs the local test suite in one step)
```

> **Why `--python 3.12`?** The server uses Globus Compute to submit work to
> HPC endpoints, and Globus Compute's serializer is fragile across Python
> minor versions — a 3.13 submitter against a 3.12 endpoint worker raises
> `WorkerLost` on non-trivial payloads. HPC sites broadly ship 3.12 conda
> stacks today, so we pin the install to match. Tracking removal of this pin
> at [globus/globus-compute#2139](https://github.com/globus/globus-compute/issues/2139).
> `uv` downloads 3.12 automatically if your system doesn't have it.

### Step 2 — Write a starter config

```bash
uxarray-mcp setup
```

Creates `~/.config/uxarray-mcp/config.yaml` with sensible defaults. Local mode
needs nothing more.

### Step 3 — Connect your AI client

**Claude Desktop**

```bash
uxarray-mcp install-claude        # merges the mcpServers block into your config
# or
uxarray-mcp install-claude --print-only   # prints the JSON to paste manually
```

Restart Claude Desktop. The `uxarray` server should appear in Settings →
Developer.

**Claude Code**

```bash
claude mcp add uxarray --transport stdio -- uxarray-mcp serve
```

Then `/mcp` in Claude Code; pick `uxarray`.

**Cursor / other MCP clients**

Add an MCP server entry pointing at `uxarray-mcp serve` over stdio. See your
client's MCP docs.

### Step 4 — Sanity check

```bash
uxarray-mcp doctor
```

Prints a JSON diagnostic report. With no endpoints configured it reports a
passing local setup and skips the remote checks; the process exits `0` when
`passed` is true.

### Step 5 — Ask the AI to do something

In your client, try:

> "Open `<path to a UGRID/MPAS/SCRIP grid file>` and plot the mesh."

That's it for local use.

**A few more things to try:**

- `Use run_analysis with operation="inspect_mesh" and grid_path="healpix:4"` —
  no sample file needed; HEALPix meshes are generated on the fly.
- `Run a complete scientific analysis on healpix:4` — the autonomous
  Analyze → Plan → Execute → Verify agent (see
  [docs/scientific-agent.md](docs/scientific-agent.md)).
- `Create a session called baseline-analysis, register <grid> and <data> in
  it, then run the workflow for <variable>` — persisted, resumable
  multi-step runs (see [docs/workflows.md](docs/workflows.md)).
- `Diagnose my configured endpoint status` — once you've added an endpoint
  below, this is the fastest way to check it's healthy.

---

## Going beyond your laptop

If you have an HPC account at a national lab or university cluster with
[Globus Compute](https://www.globus.org/compute) available:

| You want to … | Read this |
|---|---|
| Connect to an endpoint someone else set up | **[docs/remote-hpc.md](docs/remote-hpc.md)** |
| Stand up your own endpoint | **[docs/operating-an-endpoint.md](docs/operating-an-endpoint.md)** |
| Understand the security model first | **[SECURITY.md](SECURITY.md)** |

Both paths assume you've finished local install above.

---

## What the MCP exposes

Intent-shaped tools, not raw UXarray bindings — all local by default:

- `get_capabilities` — what can I do with this mesh?
- `analyze_dataset` — deterministic first-look: inspect, validate, area, zonal mean, plots.
- `run_analysis` — one operation at a time (gradient, curl, subset, remap, …).
- `plot_dataset` — mesh, geographic, variable, or zonal-mean plots.
- `run_workflow`, `resume_workflow`, `get_status`, `get_result`, `manage_session` —
  persisted sessions and multi-step workflows.

Full schema: [docs/tools.md](docs/tools.md).

**Once you've configured an HPC endpoint** (optional — see
[Going beyond your laptop](#going-beyond-your-laptop) below): most tools above
also take `use_remote: bool` and `endpoint: str`, falling back to local if the
endpoint is unhealthy. Two more tools exist purely for that case:
`diagnose_endpoint` and `probe_path_access` (endpoint health + file
readability). Ignore all of this until you actually have an endpoint to point
at.

---

## Transparency & correctness safeguards

Because agent-driven analysis needs to be *trustworthy*, every result is
auditable and the server actively flags common scientific pitfalls:

- **Provenance on everything.** Each result carries a `_provenance` block:
  the tool that ran, timestamp, input arguments, `execution_venue`
  (`local` or `hpc:<endpoint>`), and the UXarray/Python versions used.
- **Derivative unit convention is never hidden.** `gradient`, `curl`, and
  `divergence` echo `scale_by_radius` in both the result and provenance, so a
  unit-sphere result can never be mistaken for a physical (per-metre) one.
  Gradient and curl default to physical scaling, matching UXarray; pass
  `scale_by_radius=False` explicitly for unit-sphere output.
- **Vector-calculus sanity guard.** `curl`/`divergence` warn (without blocking)
  when the two inputs are the same field, or when neither carries a
  velocity/flux-like `units` attribute — the classic "vorticity from two random
  scalars" mistake now surfaces a warning in `_provenance.warnings` and a
  machine-actionable `scientific_status` with stable warning codes.
- **Applicability is not suitability.** `get_capabilities` reports whether
  vector operations are structurally computable separately from whether
  metadata supports physical interpretation.
- **Local/remote version drift is surfaced.** Remote results record the
  worker's *actual* UXarray version (`remote_uxarray_version`) and emit a
  warning when it differs from the local version, so silent numerical
  differences between venues can't slip through.
- **Validation gating.** `analyze_dataset` validates a dataset (NaN/Inf/fill
  checks) before computing statistics like the zonal mean.

---

## CLI reference

| Command | Purpose |
|---|---|
| `uxarray-mcp serve` | Run the MCP server (used by your AI client) |
| `uxarray-mcp setup` | Write a starter config |
| `uxarray-mcp endpoints add NAME UUID` | Register a Globus Compute endpoint |
| `uxarray-mcp endpoints list` | Show configured endpoints |
| `uxarray-mcp doctor` | Validate local + (optionally) remote setup |
| `uxarray-mcp install-claude` | Merge or print the Claude Desktop config block |

---

## Upgrading

```bash
uv tool upgrade --python 3.12 uxarray-mcp        # or your original install method
```

> **⚠️ Restart your AI client after upgrading.** MCP servers are launched once
> when your client (Claude Desktop, Claude Code, Cursor, …) starts and are **not
> hot-reloaded**. After upgrading the package, **fully quit and reopen your AI
> client** so it relaunches `uxarray-mcp serve` with the new code. Until you do,
> the running server keeps executing the *old* version — new tools and fixes
> won't appear, and you may see confusing errors (for example, a `use_remote`
> call on an HPC-only path failing with "file not found" because the old,
> local-only tool is still loaded). If in doubt, run `uxarray-mcp doctor` and
> check the reported version.

---

## Risks (read before relying on output)

AI agents can misread prompts, pick the wrong file, get units wrong (e.g.,
sphere-radius scaling on derivatives), or run long jobs on your HPC
allocation. uxarray-mcp does **not** guarantee correctness of agent-driven
analysis. You are responsible for:

- Verifying numerical results before publishing.
- Reviewing what files the agent opens.
- Monitoring HPC job submissions against your allocation.

For the security model (what the agent and the endpoint operator can access),
see **[SECURITY.md](SECURITY.md)**.

---

## Development

```bash
uv sync --extra hpc --extra docs --dev
uv run pre-commit run --all-files
uv run pytest tests/ --ignore=tests/test_remote_agent.py
uv run sphinx-build -b html docs docs/_build/html
```

Release process: [docs/release.md](docs/release.md).

## License

See [LICENSE](LICENSE).
