splera-mcp 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,7 +45,7 @@ Go to [splera.app/settings](https://splera.app/settings), click **Generate new k
45
45
  #### Claude Code
46
46
 
47
47
  ```bash
48
- claude mcp add splera npx -y splera-mcp --env SPLERA_API_KEY=splera_live_your_key_here
48
+ claude mcp add splera npx -y splera-mcp@latest --env SPLERA_API_KEY=splera_live_your_key_here
49
49
  ```
50
50
 
51
51
  Then restart Claude Code.
@@ -59,7 +59,7 @@ Same JSON shape for both, just different file paths.
59
59
  "mcpServers": {
60
60
  "splera": {
61
61
  "command": "npx",
62
- "args": ["-y", "splera-mcp"],
62
+ "args": ["-y", "splera-mcp@latest"],
63
63
  "env": {
64
64
  "SPLERA_API_KEY": "splera_live_your_key_here"
65
65
  }
@@ -80,7 +80,7 @@ Add to `~/.config/zed/settings.json`:
80
80
  "splera": {
81
81
  "command": {
82
82
  "path": "npx",
83
- "args": ["-y", "splera-mcp"],
83
+ "args": ["-y", "splera-mcp@latest"],
84
84
  "env": { "SPLERA_API_KEY": "splera_live_your_key_here" }
85
85
  }
86
86
  }
@@ -138,9 +138,13 @@ You've hit your plan's monthly experiment cap. Options: [upgrade](https://splera
138
138
  The SDK isn't reaching the page being tested. Verify the script tag is in place:
139
139
 
140
140
  ```html
141
- <script src="https://splera.app/sdk/splera.js" data-experiment-id="YOUR-EXPERIMENT-UUID" async></script>
141
+ <script src="https://splera.app/sdk/splera.js"
142
+ data-experiment="YOUR-EXPERIMENT-UUID"
143
+ data-api-url="https://splera.app"></script>
142
144
  ```
143
145
 
146
+ `data-api-url` is required: without it the SDK tracks nothing. If your experiment was created with splera-mcp 0.1.1, its install code was missing this attribute and used a callback form of `getVariant` that never runs. Re-copy the snippet from the experiment page on the dashboard.
147
+
144
148
  Also confirm the page is receiving real traffic. The dashboard shows live exposure counts at [splera.app/experiments/:id](https://splera.app).
145
149
 
146
150
  ### Agent doesn't use the Splera tool even when I ask
package/dist/config.d.ts CHANGED
@@ -17,4 +17,4 @@ export declare function loadConfig(): Config;
17
17
  * Pre-release / build metadata is NOT supported — we don't ship those for MCP.
18
18
  */
19
19
  export declare function isBelow(current: string, minimum: string): boolean;
20
- export declare const CURRENT_MCP_VERSION = "0.1.0";
20
+ export declare const CURRENT_MCP_VERSION = "0.1.2";
package/dist/config.js CHANGED
@@ -11,7 +11,7 @@ export function loadConfig() {
11
11
  console.error('splera-mcp: SPLERA_API_KEY not set.\n' +
12
12
  'Generate a key at https://splera.app/settings.\n' +
13
13
  'Your MCP config env block should look like:\n' +
14
- ' { "splera": { "command": "npx", "args": ["-y", "splera-mcp"], ' +
14
+ ' { "splera": { "command": "npx", "args": ["-y", "splera-mcp@latest"], ' +
15
15
  '"env": { "SPLERA_API_KEY": "splera_live_..." } } }');
16
16
  process.exit(1);
17
17
  }
@@ -51,4 +51,4 @@ export function isBelow(current, minimum) {
51
51
  }
52
52
  return false;
53
53
  }
54
- export const CURRENT_MCP_VERSION = '0.1.0';
54
+ export const CURRENT_MCP_VERSION = '0.1.2';
package/dist/index.js CHANGED
File without changes
@@ -0,0 +1,4 @@
1
+ export declare function buildInstallSnippet(experimentId: string, variants: {
2
+ id: string;
3
+ name: string;
4
+ }[], primaryEventName: string, decisionMode: string): string;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The install snippet create_experiment hands the agent. MUST match the web
3
+ * dashboard's `buildScriptTag` (packages/web/src/pages/experiments/lib/
4
+ * installPrompts.ts) — the SDK reads `data-experiment` + `data-api-url` from
5
+ * the tag and `getVariant(id, variantIds)` returns the variant synchronously.
6
+ * 0.1.1 shipped a callback form + no data-api-url, so nothing was tracked.
7
+ * Guarded by __tests__/installSnippet.test.ts.
8
+ */
9
+ const SDK_URL = 'https://splera.app/sdk/splera.js';
10
+ const API_URL = 'https://splera.app';
11
+ // Same rule as the web builder (Codex #23): code literals JSON-encoded, prose one line.
12
+ const inline = (s) => s.replace(/[\u0000-\u001f\u007f]+/g, ' ').trim();
13
+ export function buildInstallSnippet(experimentId, variants, primaryEventName, decisionMode) {
14
+ const branches = variants
15
+ .map((v, i) => {
16
+ const keyword = i === 0 ? 'if' : '} else if';
17
+ return ` ${keyword} (variant === ${JSON.stringify(v.id)}) {\n // Show ${inline(v.name)}`;
18
+ })
19
+ .join('\n');
20
+ return `<script src="${SDK_URL}"
21
+ data-experiment="${experimentId}"
22
+ data-api-url="${API_URL}"${decisionMode === 'bandit' ? '\n data-decision-mode="bandit"' : ''}></script>
23
+
24
+ <script>
25
+ const variant = Splera.getVariant("${experimentId}", ${JSON.stringify(variants.map((v) => v.id))});
26
+ ${branches}
27
+ }
28
+
29
+ // Call this when the conversion event happens:
30
+ Splera.track(${JSON.stringify(primaryEventName)});
31
+ </script>`;
32
+ }
@@ -1,4 +1,5 @@
1
1
  import { apiFetch, apiUrl } from '../apiClient.js';
2
+ import { buildInstallSnippet } from '../installSnippet.js';
2
3
  /**
3
4
  * Mirror of `packages/web/src/pages/experiments/lib/createExperiment.ts#variantId`.
4
5
  * Duplicated rather than imported because @splera/shared doesn't export it and
@@ -126,14 +127,10 @@ export const createExperimentTool = {
126
127
  `ID: ${exp.id}\n` +
127
128
  `Variants:\n${variantLines}\n` +
128
129
  `Primary metric: ${primaryMetric.event_name} (goal: ${primaryMetric.goal})\n\n` +
129
- `To activate, add this to your site's <head>:\n` +
130
- `<script src="https://splera.app/sdk/splera.js" data-experiment-id="${exp.id}" async></script>\n\n` +
131
- `Then wrap the element you want to vary:\n` +
132
- `Splera.getVariant('${exp.id}', (variant) => {\n` +
133
- ` if (variant === 'variant_b') document.querySelector('#cta').textContent = '${variants[1]?.name ?? 'Variant B'}';\n` +
134
- `});\n\n` +
135
- `Track conversions:\n` +
136
- `Splera.track('${primaryMetric.event_name}');\n\n` +
130
+ `Add this to the page (the first <script> in <head>, the second where the element renders),\n` +
131
+ `then put each variant's UI in its branch and move Splera.track() to the moment the conversion happens:\n\n` +
132
+ buildInstallSnippet(exp.id, variants, primaryMetric.event_name, body.decision_mode) +
133
+ `\n\nThe SDK is permanent: keep it installed after the test ends.\n\n` +
137
134
  `View live results: ${resultsUrl}`;
138
135
  // Structured JSON block. CRITICAL: agents parse this, not the prose.
139
136
  // `apiUrl` from config isn't substituted into results_url because the
@@ -152,6 +149,7 @@ export const createExperimentTool = {
152
149
  goal: primaryMetric.goal,
153
150
  },
154
151
  sdk_script_url: 'https://splera.app/sdk/splera.js',
152
+ install_snippet: buildInstallSnippet(exp.id, variants, primaryMetric.event_name, body.decision_mode),
155
153
  results_url: resultsUrl,
156
154
  api_url: apiUrl,
157
155
  };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "splera-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
+ "mcpName": "io.github.sohaibt/splera",
4
5
  "description": "Model Context Protocol (MCP) server for Splera — A/B testing for vibe coders. Create experiments, check results, and ship winners directly from your AI coding agent.",
5
6
  "type": "module",
6
7
  "bin": {