> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usefusion.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Workflow Examples

> End-to-end examples for creating quests, generating jsPsych experiments, exporting datasets, and publishing interactive HTML artifacts with the Quest MCP Server.

These examples show how an MCP client (or custom integration) chains NeuroFusion MCP tools across common research workflows.

## 1. Create a Quest with an AI-Generated Experiment and Publish It

A typical study creation workflow discovers your organization, generates a jsPsych 8 experiment, saves a draft quest, and publishes it.

### Step 1: Discover your organization

**Tool call:** `list_organizations`

```json theme={null}
{}
```

**Response:**

```json theme={null}
{
  "organizations": [
    {
      "organizationGuid": "org_9f8e7d6c",
      "name": "Cognitive Systems Lab",
      "slug": "cognitive-systems-lab",
      "role": "owner",
      "permissions": ["quest.create", "quest.update", "quest.publish", "data.view", "data.download", "billing.view"],
      "creditBalance": 2500,
      "createdAt": "2026-01-15T10:00:00.000Z"
    }
  ],
  "count": 1
}
```

### Step 2: Generate a jsPsych 8 experiment

**Tool call:** `generate_experiment_code`

```json theme={null}
{
  "description": "Create a 20-trial visual Stroop task with 4 practice trials, keyboard responses (R, G, B, Y), and reaction time logging."
}
```

You can iteratively refine the generated HTML by calling `generate_experiment_code` again with `existingCode` set to the previous HTML output and a follow-up `description`.

### Step 3: Create the draft quest

**Tool call:** `create_quest`

```json theme={null}
{
  "organizationGuid": "org_9f8e7d6c",
  "title": "Visual Stroop Attention Study",
  "description": "Evaluating color-word interference reaction times across 20 trials.",
  "organizerName": "Cognitive Systems Lab",
  "config": {
    "experiments": [
      {
        "name": "Visual Stroop Task",
        "code": "<!DOCTYPE html>..."
      }
    ],
    "onboardingQuestions": [
      {
        "question": "Do you have normal or corrected-to-normal color vision?",
        "type": "customOptions",
        "options": ["Yes", "No"]
      }
    ]
  }
}
```

**Response:**

```json theme={null}
{
  "guid": "qst_4a3b2c1d",
  "title": "Visual Stroop Attention Study",
  "description": "Evaluating color-word interference reaction times across 20 trials.",
  "organizerName": "Cognitive Systems Lab",
  "organizationGuid": "org_9f8e7d6c",
  "projectGuid": null,
  "joinCode": "STROOP42",
  "isPublic": false,
  "config": { "...": "..." },
  "createdAt": "2026-12-01T09:15:00.000Z"
}
```

> [!NOTE]
>
> NeuroFusion automatically enforces the platform consent onboarding question and records version `1` in the quest's config history when `create_quest` runs.

### Step 4: Publish the quest

**Tool call:** `publish_quest`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d"
}
```

Publishing charges `quest_publish` credits to the organization on the **first publish only**; unpublishing and republishing later is free.

***

## 2. Inspect Collected Datasets and Run an Async Export

### Step 1: Check dataset summary

**Tool call:** `get_quest_dataset_summary`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d"
}
```

Use the summary to see dataset counts by type (`experiment_trials`, `brain_recordings`, `onboarding_responses`), experiment names, and captured URL parameters (such as `PROLIFIC_PID` or `condition`).

### Step 2: Filter and inspect datasets

**Tool call:** `list_quest_datasets`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d",
  "type": "experiment_trials",
  "urlParamKey": "condition",
  "urlParamValue": "treatment",
  "limit": 25,
  "offset": 0
}
```

To inspect an individual record's JSON or CSV payload:

**Tool call:** `get_dataset_content`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d",
  "datasetId": 1042,
  "maxChars": 50000
}
```

### Step 3: Trigger an async export and fetch the download URL

**Tool call:** `create_dataset_export`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d",
  "format": "combined_csv",
  "filter": {
    "mode": "by_type",
    "selectedTypes": ["experiment_trials"]
  }
}
```

Poll the returned `jobGuid` until `status` is `"completed"`, setting `includeDownloadUrl: true` to mint a 30-minute read-only Azure Blob SAS URL:

**Tool call:** `get_dataset_export`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d",
  "jobGuid": "exp_7c6d5e4f",
  "includeDownloadUrl": true
}
```

***

## 3. Create and Publish an Interactive HTML Research Artifact

AI assistants can analyze exported data and publish interactive HTML reports directly back to the quest.

### Step 1: Create an organization-visible draft artifact

**Tool call:** `create_quest_artifact`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d",
  "title": "Stroop Reaction Time Report (n=64)",
  "description": "Interactive congruency effect breakdown and accuracy distributions.",
  "htmlContent": "<!DOCTYPE html><html><head><title>Stroop Report</title></head><body><h1>Stroop Results</h1></body></html>",
  "visibility": "organization"
}
```

### Step 2: Publish the artifact publicly

Once your team reviews the artifact, update its visibility to `"public"` (requires `artifact.publish` permission):

**Tool call:** `update_quest_artifact`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d",
  "artifactGuid": "art_1a2b3c4d",
  "visibility": "public"
}
```

***

## 4. Audited Deletion & Config Rollback

### Delete test datasets with an audit reason

**Tool call:** `delete_quest_datasets`

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d",
  "datasetIds": [1001, 1002],
  "reason": "Remove internal QA pilot runs before Prolific launch"
}
```

Every deleted dataset is recorded in the [Data Audit Trail](https://docs.usefusion.ai/data/audit-trail.md) with your user ID, `source: "mcp"`, and the provided `reason`.

### Roll back a quest configuration

1. Call `get_quest_config_history` with `{ "questGuid": "qst_4a3b2c1d" }` to inspect prior version numbers.
2. Restore a previous snapshot with `rollback_quest_config`:

```json theme={null}
{
  "questGuid": "qst_4a3b2c1d",
  "version": 2
}
```

***

## 5. Direct HTTP JSON-RPC Requests (`curl`)

If you are building a custom client or testing with an OAuth 2.1 access token (`$MCP_ACCESS_TOKEN`), send JSON-RPC 2.0 requests directly to `POST /mcp`:

### Initialize and list tools

```bash theme={null}
curl -X POST https://neurofusionbackendprd.azurewebsites.net/mcp \
  -H "Authorization: Bearer $MCP_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list",
    "params": {}
  }'
```

### Invoke a tool

```bash theme={null}
curl -X POST https://neurofusionbackendprd.azurewebsites.net/mcp \
  -H "Authorization: Bearer $MCP_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "list_quests",
      "arguments": {
        "isPublic": true,
        "limit": 10
      }
    }
  }'
```

### Read an MCP resource

```bash theme={null}
curl -X POST https://neurofusionbackendprd.azurewebsites.net/mcp \
  -H "Authorization: Bearer $MCP_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 3,
    "method": "resources/read",
    "params": {
      "uri": "neurofusion://quests/qst_4a3b2c1d/datasets/summary"
    }
  }'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.