Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions Concordia_Design/USAGE_AND_INTEGRATION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Product scope, user guide and AI integration

Concordia is a proposed local research workbench; commands and screens in this guide are target interfaces, not already implemented functionality.
Concordia is a local research workbench. The web UI, Python SDK, CLI, and read-only MCP server call the same authenticated FastAPI contracts; the backend remains authoritative for scientific state and evidence.

## Three user journeys

Expand All @@ -10,7 +10,7 @@ Concordia is a proposed local research workbench; commands and screens in this g
| PhD student | a retrospective research question and eligible summary dataset | register assumptions, run versioned analysis, inspect limitations, compare permitted descriptive summaries, archive artifact | reproducible thesis/paper supplementary material |
| Student | supplied synthetic example and tutorial | follow guided workflow, inspect missingness and uncertainty, compare output to hand calculation | learn reproducibility and cautious interpretation |

## Guided local steps (target)
## Guided local steps

1. Install via release instructions and start the app on loopback. Start with included synthetic example.
2. Create a project, document question and license, select scope category and import a derived multi-omics CSV or Parquet table; aggregate tables remain supported where appropriate.
Expand All @@ -20,13 +20,48 @@ Concordia is a proposed local research workbench; commands and screens in this g
6. Review chart, denominator, uncertainty, findings, evidence IDs and provenance. Interpret only within stated assumptions.
7. Export report and bundle; keep manifest and input digest alongside research record. No causal or clinical conclusions.

## Python SDK and CLI

The SDK is available as `concordia_sdk.ConcordiaClient` and supports context-manager cleanup, bounded timeouts, typed contract responses, stable exception classes, and GET-only retries. A minimal read-only call is:

```python
from concordia_sdk import ConcordiaClient

with ConcordiaClient() as concordia:
for project in concordia.list_projects():
print(project.project_id, project.name)
```

The CLI uses the same client and local token environment:

```bash
export CONCORDIA_API_URL=http://127.0.0.1:8000
export CONCORDIA_LOCAL_TOKEN=local-dev-token
concordia projects list --json
concordia datasets quality DATASET_ID --json
concordia runs status RUN_ID --json
concordia evidence verify bundle.json --artifact-root .concordia/artifacts
```

State-changing commands require confirmation, or `--yes` in a deliberately noninteractive local workflow. No CLI command computes statistics or bypasses approval.

## Claude and ChatGPT

The same read-only MCP server exposes authorized summaries to both. A local Claude client launches `concordia-mcp` using stdio; use an installed SDK/client version and verify capability discovery. Claude Code can register a local MCP server using its documented `claude mcp add` interface; verify exact arguments against installed `claude mcp add --help`. Claude Desktop may be configured using its supported local MCP configuration. Supply scoped project access through a secure credential mechanism; never paste secrets into prompts. Test `get_run_status` and `get_report_summary` with synthetic runs before use.

For ChatGPT, a compatible hosted custom MCP connection requires HTTPS and configured authentication; eligibility depends on subscription and workspace settings. Follow [OpenAI’s custom MCP connection instructions](https://help.openai.com/en/articles/12584461-connecting-custom-mcp-servers-in-chatgpt). Do not claim that a Plus account or localhost connector necessarily supports this setup. Where native custom MCP is unavailable, export the permitted report for upload into chat, or use the separately authorized application/API integration. Never expose local data through a public unauthenticated tunnel.

MCP uses supported negotiated stdio/Streamable HTTP protocol versions; check [the protocol specification](https://modelcontextprotocol.io/specification/). Clients receive only evidence summaries and cannot start compute or change plans. Tool schemas are identical across client adapters. A tool error should be explained, not bypassed.
MCP uses the installed FastMCP stdio transport for local clients. The registered read-only tools are `get_capabilities`, `list_projects`, `list_datasets`, `get_dataset_quality`, `list_analysis_runs`, `get_run_status`, `get_run_results`, `get_run_findings`, `get_run_manifest`, `get_evidence_summary`, `search_evidence`, and `get_report_summary`. Clients receive only API-authorized evidence and cannot start compute or change plans. Tool schemas are tested locally; a tool error should be explained, not bypassed.

Run the local server with:

```bash
CONCORDIA_API_URL=http://127.0.0.1:8000 \
CONCORDIA_LOCAL_TOKEN=local-dev-token \
uv run python -m concordia_mcp.server
```

Claude Code/Desktop configuration is local-client specific and should use the installed client’s documented MCP registration command/configuration. ChatGPT custom MCP requires an HTTPS endpoint and account/workspace eligibility; Concordia does not claim localhost or Plus-plan support. If that connection is unavailable, use the deterministic report or SDK/CLI export instead.

### Example user prompts

Expand Down
5 changes: 5 additions & 0 deletions Concordia_Design/architecture/API_CONTRACTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ All identifiers are opaque UUIDs, timestamps UTC ISO-8601, byte digests SHA-256
| GET `/api/v1/capabilities` | none | supported schema/methods 200 | authenticated |
| POST `/api/v1/projects` | name, purpose, data policy | project 201 | owner create |
| GET `/api/v1/projects` | cursor, limit | permitted page 200 | membership |
| GET `/api/v1/projects/{id}/datasets` | none | permitted dataset manifests 200 | membership |
| GET `/api/v1/projects/{id}/runs` | none | permitted run summaries 200 | membership |
| POST `/api/v1/projects/{id}/datasets` | multipart, metadata | manifest 201 | editor |
| GET `/api/v1/datasets/{id}` | none | manifest 200 | member |
| GET `/api/v1/datasets/{id}/quality` | none | QC report 200 | member |
| POST `/api/v1/datasets/{id}/acknowledgements` | warning IDs, digest | `QualityAcknowledgement` 201 | human editor |
| POST `/api/v1/analysis-plans` | dataset ID, operation ID, approved options | plan preview 201 | editor |
| GET `/api/v1/analysis-plans/{id}` | none | immutable plan 200 | membership |
| POST `/api/v1/analysis-plans/{id}/approve` | digest, confirmation | approved plan 200 | human editor |
| POST `/api/v1/runs` | plan ID, idempotency key header | run 202 | human editor |
| GET `/api/v1/runs/{id}` | none | run status 200 | member |
Expand Down Expand Up @@ -53,6 +56,8 @@ All identifiers are opaque UUIDs, timestamps UTC ISO-8601, byte digests SHA-256

`RunManifest`: run and plan IDs, input artifact ID/hash, plan hash, registered method ID/version, source commit, lock digest, runtime, peak memory, terminal status, result/diagnostic artifact IDs and hashes, split/calibration/missing-modality manifests, limitations, manifest digest, and creation time. `RunManifest` is published only after result and diagnostic artifacts are written and verified.

Phase 6 clients use the same `/api/v1` routes and `X-Concordia-Token` local authentication header. GET/HEAD requests may be retried by clients after transport or 502/503/504 failures; mutations are never silently retried. `POST /api/v1/runs` accepts an optional `Idempotency-Key` header and the server returns the existing run for the same approved plan/key. Clients must treat `401`, `403`, `404`, `409`, `413`, and `422` as explicit failures and must not infer scientific state from HTTP success alone.

`ResultRow`: evidence ID, metric, value or null, unit, denominator or null, uncertainty bounds or null, uncertainty method or null, calibration status or null, modality mask or null, applicability status, evidence artifact ID. Never substitute zero for missing. `Finding`: stable finding ID, check ID/version, severity, reason, evidence references, limitation, and suggested review. Acknowledgement of a Phase 1 warning never changes a Phase 3 finding to a pass. `EvidenceBundle`: bundle ID, run ID, manifest digest, source and result refs, findings, provenance, calibration and missing-modality summaries, limitations, bundle digest, bundle/report artifact IDs and hashes. Evidence payloads are canonical JSON and are verified against every referenced artifact before export. `EvaluationResult`: frozen protocol ID/version, fixture set, precision/recall, false positives, missed blocking cases, runtime, memory, limitations, and result digest. `Explanation`: source bundle ID, provider/model version, claim array, verified evidence IDs, validation status, source status, and fallback status. Reports are deterministic and offline.

## Error envelope
Expand Down
2 changes: 2 additions & 0 deletions Concordia_Design/architecture/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Untrusted sources: uploaded tables, documents, user text, remote model output, M

Local single-user mode bound to loopback with explicit local token/session; do not mistake localhost access for multi-user auth. Hosted: user OIDC identity, project roles owner/editor/viewer, service identity limited by role and operation. Deny default, reauthorize every object even if UUID known, short-lived tokens, no secrets in URLs or logs. Use TLS and restricted private network; no unrestricted external fetch, credentials or shell in worker/model. Limit outbound model traffic to explicitly configured destinations; default offline. Revoke access and expire sessions; separate development and production.

Phase 6 SDK and CLI keep the token in process memory and use bounded HTTPX timeouts. Only idempotent reads may be retried. Mutations require explicit CLI confirmation unless `--yes` is supplied for a scripted local workflow; no client can approve or execute without the API state gate. The MCP facade is read-only and calls the API rather than the database. MCP output is bounded, evidence text is untrusted content, and no tool accepts filesystem paths, SQL, code, credentials, or model-execution requests.

## Privacy and biological scope

MVP accepts synthetic, public, appropriately licensed, de-identified or aggregate human noninfectious observational information with derived multi-omics feature blocks. Reject raw genomes, biological sequences, direct identifiers, pathogenic-agent information, experimental design or optimization, reidentification requests and sensitive individual-level clinical records; do not add unrestricted plugins, model tools or user-provided code. No wet-lab instructions, intervention recommendations, sequences, clinical actions or causal claims. Any new data category requires documented scope and independent review; no model can change policy or approvals. Suppress small groups on exports under defined policy (choose threshold with owner review; not a claim of differential privacy). Treat data-use terms and consent as prerequisites. Do not send confidential inputs to third parties by default.
Expand Down
40 changes: 37 additions & 3 deletions Concordia_Design/docs/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Concordia is a CPU-first observational multi-omics cohort analysis product for p
- Phase 2: implemented and audited on 2026-11-29. Phase 3 and later remain unadvanced.
- Phase 3: implemented and audited on 2026-11-29. Versioned checks gate publication and the operator-only evaluation endpoint uses frozen development and held-out synthetic fixtures.
- Phase 4: implemented and audited on 2026-12-02; optional external model execution remains disabled by design.
- Phase 5: not advanced; Phase 1 upload/project boundary was corrected in the existing static workflow.
- Phase 6: not audited or advanced in this Phase 1 change.
- Phase 5: implemented and merged in `1d11e5b`; the React/Vite scientist workbench uses the canonical API and generated OpenAPI client schema.
- Phase 6: implemented on `feat/phase-6-integration`; final verification evidence is recorded below. No Phase 7 work is included.
- Phase 7: not audited or advanced in this Phase 1 change.

## Phase 1 acceptance audit
Expand Down Expand Up @@ -147,4 +147,38 @@ Reports contain computed summaries only. Synthetic fixtures are not biological v

## Next ticket

P5-01 — guided UI and charts. Phase 5 was not started in this change.
P7-01 — release and research package after owner review of Phase 6 evidence.

## Phase 6 integration audit and acceptance

### Baseline audit

At the Phase 6 branch start, the API already owned all scientific state transitions, credibility gates, and evidence verification. The SDK had only capabilities, project creation/listing, upload, quality, acknowledgement, plan creation/approval, run start, and Markdown report methods with untyped `Any` responses and no exception taxonomy. The CLI exposed four flat commands. The MCP server exposed four direct `httpx` read tools and had no bounded collection, quality, result, manifest, evidence, or search tools. Existing MCP registration coverage asserted only tool names.

### Implemented

- Typed SDK transport with context-manager cleanup, bounded timeouts, GET-only retries, stable exception classes, typed contract parsing, safe idempotency-key run starts, report/artifact export, and evidence retrieval.
- Canonical API collection/read routes for project datasets, project runs, and analysis-plan retrieval.
- Hierarchical CLI commands for projects, datasets, plans, runs, evidence export, and offline bundle verification; JSON output and explicit mutation confirmation are supported.
- Read-only MCP tools for capabilities, projects, datasets, quality, runs, results, findings, manifests, evidence summaries, bounded search, and deterministic report summaries.
- Cross-client contract tests for authentication errors, mutation retry behavior, collection authorization, CLI discovery, and MCP tool registration.
- README, usage, API contract, security, phase, and status documentation updated without changing the scientific scope.

### Verification record

- `UV_CACHE_DIR="$PWD/.uv-cache" uv sync --locked`: passed.
- `uv run pytest -q`: 49 passed, 3 existing FastAPI/Starlette deprecation warnings.
- `uv run ruff check packages services tests scripts`: passed.
- `uv run mypy packages services`: passed with no issues in 21 source files.
- `git diff --check`: passed.
- `uv run alembic upgrade head && uv run alembic current`: passed; `0003_evidence_fts (head)`.
- `uv run pip-audit --strict`: passed; no known vulnerabilities. The first sandboxed attempt was DNS-blocked and was rerun with network permission.
- `docker build --tag concordia:phase6-local .`: passed on the local CPU container runtime.
- `cd apps/web && npm ci && npm test -- --run && npm run build`: passed; 2 frontend tests and production build passed. Existing jsdom canvas and Rollup bundle-size warnings remain non-failing.
- `uv run python -m concordia_cli.main --help`: passed and displayed the hierarchical Phase 6 command tree.
- `uv run python -m concordia_cli.main evidence verify /private/tmp/concordia-phase6-inprocess-bundle-2.json --json`: passed; 3 artifacts verified.
- MCP stdio protocol harness: initialized successfully with protocol `2025-11-25`, discovered 12 read-only tools.
- `CONCORDIA_INPROCESS=1 CONCORDIA_DATA_ROOT=/private/tmp/concordia-phase6-inprocess-2 CONCORDIA_PHASE6_OUTPUT=/private/tmp/concordia-phase6-inprocess-bundle-2.json uv run python scripts/run_phase6_integration.py`: passed against the real FastAPI application. One warning, published run, 2 SDK result rows, 2 MCP result rows, 3 SDK findings, 3 MCP findings, 2,071-character report, and independent bundle verification `verified: true` over 3 artifacts.
- A separate live Uvicorn/HTTPX replay was attempted, but this execution environment terminated or isolated loopback server processes after health probing. No live-network success is claimed; the recorded cross-client replay uses FastAPI TestClient against the actual routes and schemas.

Hosted Claude, ChatGPT, and remote MCP connections remain unverified and are not advertised as supported integrations.
8 changes: 5 additions & 3 deletions Concordia_Design/phases/06-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

**Entry:** published API contracts and evidence bundles. **Exit:** approved clients retrieve the same evidence without direct data-store access.

1. Implement `concordia` CLI for project owner local flows: capabilities, validate, plan preview, approved run, status, report, export. All actions pass canonical backend policies; CLI is not a privileged bypass.
2. Add read-only MCP facade using official Python MCP SDK or FastMCP after compatibility verification. Tools: `list_projects`, `get_dataset_quality`, `get_run_status`, `get_run_findings`, `search_evidence`, `get_report_summary`. Do not expose arbitrary query/SQL, file read, execution, write tools or run initiation to LLM clients.
1. Implement `concordia` CLI for project owner local flows: capabilities, projects, datasets, plans, runs, report, export and offline verification. All actions pass canonical backend policies; CLI is not a privileged bypass.
2. Add read-only MCP facade using the installed FastMCP SDK. Tools expose project, dataset quality, run, findings, evidence and report summaries. Do not expose arbitrary query/SQL, file read, execution, write tools or run initiation to LLM clients.
3. Implement server tool schemas with project-scoped access and output byte limits. For local Claude clients use stdio; hosted eligible clients use Streamable HTTP and negotiated protocol version with separately configured authentication.
4. Test tool discovery, invalid IDs, scope denial, revoked token, malformed arguments, untrusted evidence, output truncation, and client-version compatibility. All tools return stable IDs, units and limitations.
5. Document Claude Code, Claude Desktop, ChatGPT custom-MCP eligibility and API/export fallbacks. Do not assume every subscription permits custom MCP; test on actual target account before claiming support.
5. Document Claude Code, Claude Desktop, ChatGPT custom-MCP eligibility and API/export fallbacks. This repository verifies local protocol registration; hosted client eligibility remains account- and configuration-dependent.

**Stack:** Typer, HTTPX, Python MCP SDK/FastMCP, OAuth-compatible authorization gateway for remote, FastAPI API client. stdio JSON-RPC local; HTTPS Streamable HTTP remote; API is authoritative; no database port exposed. No public unauthenticated endpoint.

**Phase 6 status:** local SDK, CLI, and read-only MCP adapters are implemented against the canonical API. A local MCP protocol harness and synthetic cross-client evidence replay are required release evidence; remote hosted MCP clients are not claimed.

**Handoff:** Phase 7 validates local and tested remote adapters against identical evidence fixtures; unsupported client integrations remain clearly labeled.
Loading
Loading