Metadata-Version: 2.1
Name: matrix-compute-mcp
Version: 0.1.2
Summary: Official Model Context Protocol (MCP) server and high-level verifiable AI primitives for distributed GPU matrix multiplication
Author: Distributed Matrix Multiply Team
License: Apache-2.0
Project-URL: Homepage, https://matrix-compute.net
Project-URL: Repository, https://github.com/matrixmultiplyconsortium/matrix-compute-mcp
Project-URL: Documentation, https://matrix-compute.net
Project-URL: Issues, https://github.com/matrixmultiplyconsortium/matrix-compute-mcp/issues
Project-URL: Hosted MCP Endpoint, https://mcp.matrix-compute.net/mcp
Keywords: mcp,mcp-server,model-context-protocol,distributed-computing,matrix-multiplication,gpu,freivalds,l402,nostr,pytorch,lora,cosine-similarity,pca,svd
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: matrix-compute-sdk
Requires-Dist: mcp>=1.0.0
Requires-Dist: torch>=2.0.0
Requires-Dist: safetensors>=0.4.0
Requires-Dist: numpy>=1.22.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: httpx>=0.24.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"

# `matrix-compute-mcp`: Official MCP Server & High-Level Verifiable AI Primitives

<!-- mcp-name: net.matrix-compute/matrix-compute-mcp -->
<!-- mcp-name: io.github.matrixmultiplyconsortium/matrix-compute-mcp -->

[![PyPI version](https://img.shields.io/pypi/v/matrix-compute-mcp.svg)](https://pypi.org/project/matrix-compute-mcp/)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/matrixmultiplyconsortium/matrix-compute-colab/blob/main/01_quickstart_distributed_matmul.ipynb)

`matrix-compute-mcp` is an official Model Context Protocol (MCP) server and high-level AI primitives package built on top of [`matrix-compute-sdk`](https://github.com/matrixmultiplyconsortium/matrix-compute-sdk) that provides:
1. **High-Level Verifiable AI Primitives (`matrix_compute_mcp.ai`):** Drop-in PyTorch layers (`DistributedLinear`, `DistributedLoRALinear`), massive exact cosine similarity search (`distributed_cosine_similarity`), and distributed spectral PCA/SVD (`distributed_pca_svd`) — all verified in $O(n^2)$ via Freivalds' algorithm.
2. **Official Model Context Protocol Server (`matrix-compute-mcp`):** Exposes decentralized GPU TFLOPS to autonomous AI agents (Claude Desktop, Cursor, Windsurf, Antigravity, LangChain, OpenClaw) over `stdio` (`uvx matrix-compute-mcp`) or remote Streamable HTTP (`https://mcp.matrix-compute.net/mcp`) with L402 Macaroon, NWC (`nostr+walletconnect://`), or zero-drain trial sandbox support.

---

## Quick Start

### 1A. Local `stdio` MCP Client Configuration (Claude Desktop / Cursor / Antigravity)

```json
{
  "mcpServers": {
    "matrix-compute": {
      "command": "uvx",
      "args": ["matrix-compute-mcp"],
      "env": {
        "MATRIX_NOSTR_RELAYS": "wss://relay.matrix-compute.net",
        "MATRIX_SETTLEMENT_API_URL": "https://settlement.matrix-compute.net"
      }
    }
  }
}
```

### 1B. Hosted Remote MCP Endpoint (Zero Install)

Point any Streamable HTTP MCP client directly to:
```
https://mcp.matrix-compute.net/mcp
```

### 2. Exposed MCP Tools
| Tool Name | Description |
|---|---|
| `get_network_status` | Queries the discovery relay for live GPU worker count, total VRAM, TEE enclaves, and `sats_per_gflop` pricing. |
| `estimate_job_cost` | Computes exact upload/download bandwidth (MB), task count, GFLOPs, and satoshi cost estimates via `BandwidthProfiler`. |
| `execute_distributed_matmul` | Executes verified distributed matrix multiplication $C = A \times B$ from `.npy`, `.npz`, `.safetensors`, or inline tensors. |
| `batch_similarity_search` | Runs massive exact $K$-NN cosine similarity search using `OUTPUT_GRID_2D` zero-reduction tiling. |
| `compute_pca_svd` | Runs verified top-$k$ randomized SVD or stateful remote-VRAM power-iteration PCA/SVD. |

### 3. High-Level Verifiable AI Primitives (`matrix_compute_mcp.ai`)

```python
import numpy as np
from matrix_compute_mcp.ai import (
    DistributedLinear,
    DistributedLoRALinear,
    distributed_cosine_similarity,
    distributed_pca_svd,
)

# 1. Exact K-NN Cosine Similarity with OUTPUT_GRID_2D zero download redundancy
scores, indices = distributed_cosine_similarity(queries, corpus_embeddings, top_k=10)

# 2. Drop-in PyTorch Linear & LoRA Linear layers with verified forward & backward passes
layer = DistributedLinear(in_features=4096, out_features=4096)
lora_layer = DistributedLoRALinear(in_features=4096, out_features=4096, r=16, lora_alpha=32.0)

# 3. Distributed Randomized SVD / Stateful Power-Iteration PCA
U, S, Vt = distributed_pca_svd(embeddings, k=32, method="randomized")
```
