@sanity/cli 5.3.0-next.57 → 5.3.0-next.59
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/lib/_chunks-cjs/cli.js +223 -160
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/package.json +8 -7
package/lib/_chunks-cjs/cli.js
CHANGED
|
@@ -18,7 +18,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
18
18
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
19
19
|
mod
|
|
20
20
|
));
|
|
21
|
-
var os = require("node:os"), chalk = require("chalk"), loadEnv = require("./loadEnv.js"), require$$0$5 = require("path"), require$$1$2 = require("module"), require$$0$4 = require("fs"), semver = require("semver"), telemetry = require("@sanity/telemetry"), childProcess = require("node:child_process"), fs$1 = require("node:fs"), path$3 = require("node:path"), fs = require("node:fs/promises"), util$3 = require("node:util"), require$$0$6 = require("os"), getLatestVersion = require("get-latest-version"), pkgDir = require("pkg-dir"), client$1 = require("@sanity/client"), require$$0$7 = require("constants"), require$$0$8 = require("stream"), require$$0$9 = require("util"), require$$0$a = require("assert"), require$$0$b = require("events"), require$$3$1 = require("crypto"), require$$1$3 = require("child_process"), getCliConfig = require("./getCliConfig.js"), require$$0$c = require("fs/promises"), require$$0$d = require("buffer"), journeyConfig = require("./journeyConfig.js"), Stream = require("node:stream"), promises$1 = require("node:stream/promises"), templateValidator = require("@sanity/template-validator"), require$$2$1 = require("string_decoder"), require$$0$e = require("zlib"), require$$7$1 = require("process"), http = require("node:http"), traverse = require("@babel/traverse"), node_url = require("node:url"), node_events = require("node:events"), node_string_decoder = require("node:string_decoder"), process$2 = require("node:process"), require$$2$2 = require("readline"), require$$0$f = require("tty");
|
|
21
|
+
var os = require("node:os"), chalk = require("chalk"), loadEnv = require("./loadEnv.js"), require$$0$5 = require("path"), require$$1$2 = require("module"), require$$0$4 = require("fs"), semver = require("semver"), telemetry = require("@sanity/telemetry"), childProcess = require("node:child_process"), fs$1 = require("node:fs"), path$3 = require("node:path"), fs = require("node:fs/promises"), util$3 = require("node:util"), require$$0$6 = require("os"), getLatestVersion = require("get-latest-version"), pkgDir = require("pkg-dir"), client$1 = require("@sanity/client"), require$$0$7 = require("constants"), require$$0$8 = require("stream"), require$$0$9 = require("util"), require$$0$a = require("assert"), require$$0$b = require("events"), require$$3$1 = require("crypto"), require$$1$3 = require("child_process"), getCliConfig = require("./getCliConfig.js"), require$$0$c = require("fs/promises"), require$$0$d = require("buffer"), journeyConfig = require("./journeyConfig.js"), Stream = require("node:stream"), promises$1 = require("node:stream/promises"), templateValidator = require("@sanity/template-validator"), require$$2$1 = require("string_decoder"), require$$0$e = require("zlib"), require$$7$1 = require("process"), http = require("node:http"), jsoncParser = require("jsonc-parser"), traverse = require("@babel/traverse"), node_url = require("node:url"), node_events = require("node:events"), node_string_decoder = require("node:string_decoder"), process$2 = require("node:process"), require$$2$2 = require("readline"), require$$0$f = require("tty");
|
|
22
22
|
function _interopDefaultCompat(e) {
|
|
23
23
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
24
24
|
}
|
|
@@ -15818,7 +15818,7 @@ var cleanStack$2, hasRequiredCleanStack$1;
|
|
|
15818
15818
|
function requireCleanStack$1() {
|
|
15819
15819
|
if (hasRequiredCleanStack$1) return cleanStack$2;
|
|
15820
15820
|
hasRequiredCleanStack$1 = 1;
|
|
15821
|
-
const os2 = require$$0__default$2.default, extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/, pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/,
|
|
15821
|
+
const os2 = require$$0__default$2.default, extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/, pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/, homeDir2 = typeof os2.homedir > "u" ? "" : os2.homedir();
|
|
15822
15822
|
return cleanStack$2 = (stack2, options2) => (options2 = Object.assign({ pretty: !1 }, options2), stack2.replace(/\\/g, "/").split(`
|
|
15823
15823
|
`).filter((line3) => {
|
|
15824
15824
|
const pathMatches = line3.match(extractPathRegex);
|
|
@@ -15826,7 +15826,7 @@ function requireCleanStack$1() {
|
|
|
15826
15826
|
return !0;
|
|
15827
15827
|
const match2 = pathMatches[1];
|
|
15828
15828
|
return match2.includes(".app/Contents/Resources/electron.asar") || match2.includes(".app/Contents/Resources/default_app.asar") ? !1 : !pathRegex.test(match2);
|
|
15829
|
-
}).filter((line3) => line3.trim() !== "").map((line3) => options2.pretty ? line3.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(
|
|
15829
|
+
}).filter((line3) => line3.trim() !== "").map((line3) => options2.pretty ? line3.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir2, "~"))) : line3).join(`
|
|
15830
15830
|
`)), cleanStack$2;
|
|
15831
15831
|
}
|
|
15832
15832
|
var aggregateError, hasRequiredAggregateError;
|
|
@@ -23926,6 +23926,223 @@ function samlProviderToLoginProvider(saml) {
|
|
|
23926
23926
|
url: saml.loginUrl
|
|
23927
23927
|
};
|
|
23928
23928
|
}
|
|
23929
|
+
const MCP_SERVER_URL = "https://mcp.sanity.io", NO_EDITORS_DETECTED_MESSAGE = `Couldn't auto-configure Sanity MCP server for your editor. Visit ${MCP_SERVER_URL} for setup instructions.`, defaultHttpConfig = (token2) => ({
|
|
23930
|
+
type: "http",
|
|
23931
|
+
url: MCP_SERVER_URL,
|
|
23932
|
+
headers: { Authorization: `Bearer ${token2}` }
|
|
23933
|
+
}), homeDir = os__default.default.homedir(), EDITOR_CONFIGS = {
|
|
23934
|
+
Cursor: {
|
|
23935
|
+
configKey: "mcpServers",
|
|
23936
|
+
detect: async () => {
|
|
23937
|
+
const cursorDir = path__default.default.join(homeDir, ".cursor");
|
|
23938
|
+
return fs$1.existsSync(cursorDir) ? path__default.default.join(cursorDir, "mcp.json") : null;
|
|
23939
|
+
},
|
|
23940
|
+
buildServerConfig: defaultHttpConfig
|
|
23941
|
+
},
|
|
23942
|
+
"VS Code": {
|
|
23943
|
+
configKey: "servers",
|
|
23944
|
+
detect: async () => {
|
|
23945
|
+
let configDir = null;
|
|
23946
|
+
switch (process.platform) {
|
|
23947
|
+
case "darwin":
|
|
23948
|
+
configDir = path__default.default.join(homeDir, "Library/Application Support/Code/User");
|
|
23949
|
+
break;
|
|
23950
|
+
case "win32":
|
|
23951
|
+
process.env.APPDATA && (configDir = path__default.default.join(process.env.APPDATA, "Code/User"));
|
|
23952
|
+
break;
|
|
23953
|
+
default:
|
|
23954
|
+
configDir = path__default.default.join(homeDir, ".config/Code/User");
|
|
23955
|
+
}
|
|
23956
|
+
return configDir && fs$1.existsSync(configDir) ? path__default.default.join(configDir, "mcp.json") : null;
|
|
23957
|
+
},
|
|
23958
|
+
buildServerConfig: defaultHttpConfig
|
|
23959
|
+
},
|
|
23960
|
+
"VS Code Insiders": {
|
|
23961
|
+
configKey: "servers",
|
|
23962
|
+
detect: async () => {
|
|
23963
|
+
let configDir = null;
|
|
23964
|
+
switch (process.platform) {
|
|
23965
|
+
case "darwin":
|
|
23966
|
+
configDir = path__default.default.join(homeDir, "Library/Application Support/Code - Insiders/User");
|
|
23967
|
+
break;
|
|
23968
|
+
case "win32":
|
|
23969
|
+
process.env.APPDATA && (configDir = path__default.default.join(process.env.APPDATA, "Code - Insiders/User"));
|
|
23970
|
+
break;
|
|
23971
|
+
default:
|
|
23972
|
+
configDir = path__default.default.join(homeDir, ".config/Code - Insiders/User");
|
|
23973
|
+
}
|
|
23974
|
+
return configDir && fs$1.existsSync(configDir) ? path__default.default.join(configDir, "mcp.json") : null;
|
|
23975
|
+
},
|
|
23976
|
+
buildServerConfig: defaultHttpConfig
|
|
23977
|
+
},
|
|
23978
|
+
"Claude Code": {
|
|
23979
|
+
configKey: "mcpServers",
|
|
23980
|
+
detect: async () => {
|
|
23981
|
+
try {
|
|
23982
|
+
return await execa("claude", ["--version"], { stdio: "pipe", timeout: 5e3 }), path__default.default.join(homeDir, ".claude.json");
|
|
23983
|
+
} catch {
|
|
23984
|
+
return null;
|
|
23985
|
+
}
|
|
23986
|
+
},
|
|
23987
|
+
buildServerConfig: defaultHttpConfig
|
|
23988
|
+
},
|
|
23989
|
+
Zed: {
|
|
23990
|
+
configKey: "context_servers",
|
|
23991
|
+
detect: async () => {
|
|
23992
|
+
let configDir = null;
|
|
23993
|
+
return process.platform === "win32" ? process.env.APPDATA && (configDir = path__default.default.join(process.env.APPDATA, "Zed")) : configDir = path__default.default.join(homeDir, ".config/zed"), configDir && fs$1.existsSync(configDir) ? path__default.default.join(configDir, "settings.json") : null;
|
|
23994
|
+
},
|
|
23995
|
+
buildServerConfig: (token2) => ({
|
|
23996
|
+
url: MCP_SERVER_URL,
|
|
23997
|
+
headers: { Authorization: `Bearer ${token2}` },
|
|
23998
|
+
settings: {}
|
|
23999
|
+
})
|
|
24000
|
+
},
|
|
24001
|
+
OpenCode: {
|
|
24002
|
+
configKey: "mcp",
|
|
24003
|
+
detect: async () => {
|
|
24004
|
+
try {
|
|
24005
|
+
return await execa("opencode", ["--version"], { stdio: "pipe", timeout: 5e3 }), path__default.default.join(homeDir, ".config/opencode/opencode.json");
|
|
24006
|
+
} catch {
|
|
24007
|
+
return null;
|
|
24008
|
+
}
|
|
24009
|
+
},
|
|
24010
|
+
buildServerConfig: (token2) => ({
|
|
24011
|
+
type: "remote",
|
|
24012
|
+
url: MCP_SERVER_URL,
|
|
24013
|
+
headers: { Authorization: `Bearer ${token2}` }
|
|
24014
|
+
})
|
|
24015
|
+
}
|
|
24016
|
+
};
|
|
24017
|
+
function parseConfig(content) {
|
|
24018
|
+
if (content.trim() === "")
|
|
24019
|
+
return {};
|
|
24020
|
+
const errors = [], parsed = jsoncParser.parse(content, errors, { allowTrailingComma: !0 });
|
|
24021
|
+
return errors.length > 0 || typeof parsed != "object" || parsed === null || Array.isArray(parsed) ? null : parsed;
|
|
24022
|
+
}
|
|
24023
|
+
async function checkEditorConfig(name, configPath) {
|
|
24024
|
+
const { configKey } = EDITOR_CONFIGS[name];
|
|
24025
|
+
if (!fs$1.existsSync(configPath))
|
|
24026
|
+
return { name, configPath, configured: !1 };
|
|
24027
|
+
try {
|
|
24028
|
+
const content = await fs__default.default.readFile(configPath, "utf-8"), config2 = parseConfig(content);
|
|
24029
|
+
if (config2 === null)
|
|
24030
|
+
return getCliConfig.debug("Skipping %s: could not parse %s", name, configPath), null;
|
|
24031
|
+
const configured = !!config2[configKey]?.Sanity;
|
|
24032
|
+
return { name, configPath, configured };
|
|
24033
|
+
} catch (err) {
|
|
24034
|
+
return getCliConfig.debug("Skipping %s: could not read %s: %s", name, configPath, err), null;
|
|
24035
|
+
}
|
|
24036
|
+
}
|
|
24037
|
+
async function detectAvailableEditors() {
|
|
24038
|
+
const editors = [];
|
|
24039
|
+
for (const [name, config2] of Object.entries(EDITOR_CONFIGS)) {
|
|
24040
|
+
const configPath = await config2.detect();
|
|
24041
|
+
if (configPath) {
|
|
24042
|
+
const editor2 = await checkEditorConfig(name, configPath);
|
|
24043
|
+
editor2 && editors.push(editor2);
|
|
24044
|
+
}
|
|
24045
|
+
}
|
|
24046
|
+
return editors;
|
|
24047
|
+
}
|
|
24048
|
+
async function promptForMCPSetup(prompt2, editors) {
|
|
24049
|
+
const editorChoices = editors.map((e) => ({
|
|
24050
|
+
name: e.configured ? `${e.name} (already installed)` : e.name,
|
|
24051
|
+
value: e.name,
|
|
24052
|
+
checked: !e.configured
|
|
24053
|
+
// Only pre-select if NOT already configured
|
|
24054
|
+
})), selectedNames = (await prompt2([
|
|
24055
|
+
{
|
|
24056
|
+
type: "checkbox",
|
|
24057
|
+
name: "selectedEditors",
|
|
24058
|
+
message: "Configure Sanity MCP server?",
|
|
24059
|
+
choices: editorChoices
|
|
24060
|
+
}
|
|
24061
|
+
])).selectedEditors;
|
|
24062
|
+
return !selectedNames || selectedNames.length === 0 ? null : editors.filter((e) => selectedNames.includes(e.name));
|
|
24063
|
+
}
|
|
24064
|
+
async function createMCPToken(apiClient) {
|
|
24065
|
+
if (!getCliToken())
|
|
24066
|
+
throw new Error("Not authenticated. Please run `sanity login` first.");
|
|
24067
|
+
const client2 = apiClient({ requireUser: !0, requireProject: !1 }).clone().config({ apiVersion: "2025-12-09" }), sessionResponse = await client2.request({
|
|
24068
|
+
method: "POST",
|
|
24069
|
+
uri: "/auth/session/create",
|
|
24070
|
+
body: {
|
|
24071
|
+
sourceId: "sanity-mcp",
|
|
24072
|
+
withStamp: !1
|
|
24073
|
+
}
|
|
24074
|
+
});
|
|
24075
|
+
return (await client2.request({
|
|
24076
|
+
method: "GET",
|
|
24077
|
+
uri: "/auth/fetch",
|
|
24078
|
+
query: { sid: sessionResponse.sid }
|
|
24079
|
+
})).token;
|
|
24080
|
+
}
|
|
24081
|
+
async function writeMCPConfig(editor2, token2) {
|
|
24082
|
+
const configPath = editor2.configPath, { configKey, buildServerConfig } = EDITOR_CONFIGS[editor2.name];
|
|
24083
|
+
let content = "{}";
|
|
24084
|
+
if (fs$1.existsSync(configPath)) {
|
|
24085
|
+
const fileContent = await fs__default.default.readFile(configPath, "utf-8");
|
|
24086
|
+
fileContent.trim() && (content = fileContent);
|
|
24087
|
+
}
|
|
24088
|
+
const edits = jsoncParser.modify(content, [configKey, "Sanity"], buildServerConfig(token2), {
|
|
24089
|
+
formattingOptions: { tabSize: 2, insertSpaces: !0 }
|
|
24090
|
+
});
|
|
24091
|
+
content = jsoncParser.applyEdits(content, edits), await fs__default.default.mkdir(path__default.default.dirname(configPath), { recursive: !0 }), await fs__default.default.writeFile(configPath, content, "utf-8");
|
|
24092
|
+
}
|
|
24093
|
+
async function setupMCP(context, options2) {
|
|
24094
|
+
const { output, prompt: prompt2 } = context;
|
|
24095
|
+
if (options2.mcp === !1)
|
|
24096
|
+
return output.warn("Skipping MCP configuration due to --no-mcp flag"), {
|
|
24097
|
+
detectedEditors: [],
|
|
24098
|
+
configuredEditors: [],
|
|
24099
|
+
skipped: !0
|
|
24100
|
+
};
|
|
24101
|
+
const editors = await detectAvailableEditors(), detectedEditors = editors.map((e) => e.name);
|
|
24102
|
+
if (editors.length === 0)
|
|
24103
|
+
return output.warn(NO_EDITORS_DETECTED_MESSAGE), {
|
|
24104
|
+
detectedEditors,
|
|
24105
|
+
configuredEditors: [],
|
|
24106
|
+
skipped: !0
|
|
24107
|
+
};
|
|
24108
|
+
const selected = await promptForMCPSetup(prompt2, editors);
|
|
24109
|
+
if (!selected || selected.length === 0)
|
|
24110
|
+
return {
|
|
24111
|
+
detectedEditors,
|
|
24112
|
+
configuredEditors: [],
|
|
24113
|
+
skipped: !0
|
|
24114
|
+
};
|
|
24115
|
+
let token2;
|
|
24116
|
+
try {
|
|
24117
|
+
token2 = await createMCPToken(context.apiClient);
|
|
24118
|
+
} catch (error2) {
|
|
24119
|
+
const err = error2 instanceof Error ? error2 : new Error(String(error2));
|
|
24120
|
+
return output.warn(`Could not configure MCP: ${err.message}`), output.warn("You can set up MCP manually later using https://mcp.sanity.io"), {
|
|
24121
|
+
detectedEditors,
|
|
24122
|
+
configuredEditors: [],
|
|
24123
|
+
skipped: !1,
|
|
24124
|
+
error: err
|
|
24125
|
+
};
|
|
24126
|
+
}
|
|
24127
|
+
try {
|
|
24128
|
+
for (const editor2 of selected)
|
|
24129
|
+
await writeMCPConfig(editor2, token2);
|
|
24130
|
+
} catch (error2) {
|
|
24131
|
+
const err = error2 instanceof Error ? error2 : new Error(String(error2));
|
|
24132
|
+
return output.warn(`Could not configure MCP: ${err.message}`), output.warn("You can set up MCP manually later using https://mcp.sanity.io"), {
|
|
24133
|
+
detectedEditors,
|
|
24134
|
+
configuredEditors: [],
|
|
24135
|
+
skipped: !1,
|
|
24136
|
+
error: err
|
|
24137
|
+
};
|
|
24138
|
+
}
|
|
24139
|
+
const configuredEditors = selected.map((e) => e.name);
|
|
24140
|
+
return output.success(`MCP configured for ${configuredEditors.join(", ")}`), {
|
|
24141
|
+
detectedEditors,
|
|
24142
|
+
configuredEditors,
|
|
24143
|
+
skipped: !1
|
|
24144
|
+
};
|
|
24145
|
+
}
|
|
23929
24146
|
function createProject(apiClient, options2) {
|
|
23930
24147
|
return apiClient({
|
|
23931
24148
|
requireUser: !0,
|
|
@@ -39797,160 +40014,6 @@ function readPackageJson(filePath) {
|
|
|
39797
40014
|
return;
|
|
39798
40015
|
}
|
|
39799
40016
|
}
|
|
39800
|
-
const MCP_SERVER_URL = "https://mcp.sanity.io", NO_EDITORS_DETECTED_MESSAGE = `Couldn't auto-configure Sanity MCP server for your editor. Visit ${MCP_SERVER_URL} for setup instructions.`;
|
|
39801
|
-
async function detectAvailableEditors() {
|
|
39802
|
-
const editors = [], homeDir = os__default.default.homedir(), cursorDir = path__default.default.join(homeDir, ".cursor");
|
|
39803
|
-
fs$1.existsSync(cursorDir) && editors.push({
|
|
39804
|
-
name: "Cursor",
|
|
39805
|
-
configPath: path__default.default.join(cursorDir, "mcp.json"),
|
|
39806
|
-
configKey: "mcpServers"
|
|
39807
|
-
});
|
|
39808
|
-
let vscodeConfigDir = null;
|
|
39809
|
-
switch (process.platform) {
|
|
39810
|
-
case "darwin":
|
|
39811
|
-
vscodeConfigDir = path__default.default.join(homeDir, "Library/Application Support/Code/User");
|
|
39812
|
-
break;
|
|
39813
|
-
case "win32":
|
|
39814
|
-
process.env.APPDATA && (vscodeConfigDir = path__default.default.join(process.env.APPDATA, "Code/User"));
|
|
39815
|
-
break;
|
|
39816
|
-
default:
|
|
39817
|
-
vscodeConfigDir = path__default.default.join(homeDir, ".config/Code/User");
|
|
39818
|
-
}
|
|
39819
|
-
vscodeConfigDir && fs$1.existsSync(vscodeConfigDir) && editors.push({
|
|
39820
|
-
name: "VS Code",
|
|
39821
|
-
configPath: path__default.default.join(vscodeConfigDir, "mcp.json"),
|
|
39822
|
-
configKey: "servers"
|
|
39823
|
-
});
|
|
39824
|
-
try {
|
|
39825
|
-
await execa("claude", ["--version"], { stdio: "pipe", timeout: 5e3 }), editors.push({
|
|
39826
|
-
name: "Claude Code",
|
|
39827
|
-
configPath: path__default.default.join(homeDir, ".claude.json"),
|
|
39828
|
-
configKey: "mcpServers"
|
|
39829
|
-
});
|
|
39830
|
-
} catch {
|
|
39831
|
-
}
|
|
39832
|
-
return editors;
|
|
39833
|
-
}
|
|
39834
|
-
async function promptForMCPSetup(prompt2, detectedEditors, editorsWithExisting) {
|
|
39835
|
-
const editorChoices = detectedEditors.map((e) => {
|
|
39836
|
-
const isConfigured = editorsWithExisting.some((existing) => existing.name === e.name);
|
|
39837
|
-
return {
|
|
39838
|
-
name: isConfigured ? `${e.name} (already installed)` : e.name,
|
|
39839
|
-
value: e.name,
|
|
39840
|
-
checked: !isConfigured
|
|
39841
|
-
// Only pre-select if NOT already configured
|
|
39842
|
-
};
|
|
39843
|
-
}), selectedNames = (await prompt2([
|
|
39844
|
-
{
|
|
39845
|
-
type: "checkbox",
|
|
39846
|
-
name: "selectedEditors",
|
|
39847
|
-
message: "Configure Sanity MCP server?",
|
|
39848
|
-
choices: editorChoices
|
|
39849
|
-
}
|
|
39850
|
-
])).selectedEditors;
|
|
39851
|
-
return !selectedNames || selectedNames.length === 0 ? null : detectedEditors.filter((e) => selectedNames.includes(e.name));
|
|
39852
|
-
}
|
|
39853
|
-
async function createMCPToken(apiClient) {
|
|
39854
|
-
if (!getCliToken())
|
|
39855
|
-
throw new Error("Not authenticated. Please run `sanity login` first.");
|
|
39856
|
-
const client2 = apiClient({ requireUser: !0, requireProject: !1 }).clone().config({ apiVersion: "2025-12-09" }), sessionResponse = await client2.request({
|
|
39857
|
-
method: "POST",
|
|
39858
|
-
uri: "/auth/session/create",
|
|
39859
|
-
body: {
|
|
39860
|
-
sourceId: "sanity-mcp",
|
|
39861
|
-
withStamp: !1
|
|
39862
|
-
}
|
|
39863
|
-
});
|
|
39864
|
-
return (await client2.request({
|
|
39865
|
-
method: "GET",
|
|
39866
|
-
uri: "/auth/fetch",
|
|
39867
|
-
query: { sid: sessionResponse.sid }
|
|
39868
|
-
})).token;
|
|
39869
|
-
}
|
|
39870
|
-
async function getEditorsWithExistingConfig(editors) {
|
|
39871
|
-
const configured = [];
|
|
39872
|
-
for (const editor2 of editors)
|
|
39873
|
-
if (fs$1.existsSync(editor2.configPath))
|
|
39874
|
-
try {
|
|
39875
|
-
const content = await fs__default.default.readFile(editor2.configPath, "utf-8");
|
|
39876
|
-
JSON.parse(content)[editor2.configKey]?.Sanity && configured.push(editor2);
|
|
39877
|
-
} catch (err) {
|
|
39878
|
-
getCliConfig.debug("Could not read MCP config for %s: %s", editor2.name, err);
|
|
39879
|
-
}
|
|
39880
|
-
return configured;
|
|
39881
|
-
}
|
|
39882
|
-
async function writeMCPConfig(editor2, token2) {
|
|
39883
|
-
const configPath = editor2.configPath;
|
|
39884
|
-
let existingConfig = {};
|
|
39885
|
-
if (fs$1.existsSync(configPath))
|
|
39886
|
-
try {
|
|
39887
|
-
const content = await fs__default.default.readFile(configPath, "utf-8");
|
|
39888
|
-
existingConfig = JSON.parse(content);
|
|
39889
|
-
} catch {
|
|
39890
|
-
getCliConfig.debug(`Warning: Could not parse ${configPath}. Creating new config.`);
|
|
39891
|
-
}
|
|
39892
|
-
const serverKey = editor2.configKey;
|
|
39893
|
-
existingConfig[serverKey] || (existingConfig[serverKey] = {}), existingConfig[serverKey].Sanity = {
|
|
39894
|
-
type: "http",
|
|
39895
|
-
url: MCP_SERVER_URL,
|
|
39896
|
-
headers: {
|
|
39897
|
-
Authorization: `Bearer ${token2}`
|
|
39898
|
-
}
|
|
39899
|
-
}, await fs__default.default.mkdir(path__default.default.dirname(configPath), { recursive: !0 }), await fs__default.default.writeFile(configPath, JSON.stringify(existingConfig, null, 2), "utf-8");
|
|
39900
|
-
}
|
|
39901
|
-
async function setupMCP(context, options2) {
|
|
39902
|
-
const { output, prompt: prompt2 } = context;
|
|
39903
|
-
if (options2.mcp === !1)
|
|
39904
|
-
return output.warn("Skipping MCP configuration due to --no-mcp flag"), {
|
|
39905
|
-
detectedEditors: [],
|
|
39906
|
-
configuredEditors: [],
|
|
39907
|
-
skipped: !0
|
|
39908
|
-
};
|
|
39909
|
-
const detected = await detectAvailableEditors(), detectedEditors = detected.map((e) => e.name);
|
|
39910
|
-
if (detected.length === 0)
|
|
39911
|
-
return output.warn(NO_EDITORS_DETECTED_MESSAGE), {
|
|
39912
|
-
detectedEditors,
|
|
39913
|
-
configuredEditors: [],
|
|
39914
|
-
skipped: !0
|
|
39915
|
-
};
|
|
39916
|
-
const editorsWithExisting = await getEditorsWithExistingConfig(detected), selected = await promptForMCPSetup(prompt2, detected, editorsWithExisting);
|
|
39917
|
-
if (!selected || selected.length === 0)
|
|
39918
|
-
return {
|
|
39919
|
-
detectedEditors,
|
|
39920
|
-
configuredEditors: [],
|
|
39921
|
-
skipped: !0
|
|
39922
|
-
};
|
|
39923
|
-
let token2;
|
|
39924
|
-
try {
|
|
39925
|
-
token2 = await createMCPToken(context.apiClient);
|
|
39926
|
-
} catch (error2) {
|
|
39927
|
-
const err = error2 instanceof Error ? error2 : new Error(String(error2));
|
|
39928
|
-
return output.warn(`Could not configure MCP: ${err.message}`), output.warn("You can set up MCP manually later using https://mcp.sanity.io"), {
|
|
39929
|
-
detectedEditors,
|
|
39930
|
-
configuredEditors: [],
|
|
39931
|
-
skipped: !1,
|
|
39932
|
-
error: err
|
|
39933
|
-
};
|
|
39934
|
-
}
|
|
39935
|
-
try {
|
|
39936
|
-
for (const editor2 of selected)
|
|
39937
|
-
await writeMCPConfig(editor2, token2);
|
|
39938
|
-
} catch (error2) {
|
|
39939
|
-
const err = error2 instanceof Error ? error2 : new Error(String(error2));
|
|
39940
|
-
return output.warn(`Could not configure MCP: ${err.message}`), output.warn("You can set up MCP manually later using https://mcp.sanity.io"), {
|
|
39941
|
-
detectedEditors,
|
|
39942
|
-
configuredEditors: [],
|
|
39943
|
-
skipped: !1,
|
|
39944
|
-
error: err
|
|
39945
|
-
};
|
|
39946
|
-
}
|
|
39947
|
-
const configuredEditors = selected.map((e) => e.name);
|
|
39948
|
-
return output.success(`MCP configured for ${configuredEditors.join(", ")}`), {
|
|
39949
|
-
detectedEditors,
|
|
39950
|
-
configuredEditors,
|
|
39951
|
-
skipped: !1
|
|
39952
|
-
};
|
|
39953
|
-
}
|
|
39954
40017
|
const authorType = `import {UserIcon} from '@sanity/icons'
|
|
39955
40018
|
import {defineArrayMember, defineField, defineType} from 'sanity'
|
|
39956
40019
|
|
|
@@ -41466,7 +41529,7 @@ Examples
|
|
|
41466
41529
|
group: "mcp",
|
|
41467
41530
|
helpText: helpText$8,
|
|
41468
41531
|
signature: "",
|
|
41469
|
-
description: "Configure Sanity MCP server for AI editors
|
|
41532
|
+
description: "Configure Sanity MCP server for AI editors",
|
|
41470
41533
|
async action(args, context) {
|
|
41471
41534
|
const { output, telemetry: telemetry2 } = context, trace = telemetry2.trace(MCPConfigureTrace);
|
|
41472
41535
|
if ((await detectAvailableEditors()).length === 0) {
|
|
@@ -70156,7 +70219,7 @@ var cleanStack$1, hasRequiredCleanStack;
|
|
|
70156
70219
|
function requireCleanStack() {
|
|
70157
70220
|
if (hasRequiredCleanStack) return cleanStack$1;
|
|
70158
70221
|
hasRequiredCleanStack = 1;
|
|
70159
|
-
const os2 = require$$0__default$2.default, escapeStringRegexp2 = requireEscapeStringRegexp(), extractPathRegex = /\s+at.*[(\s](.*)\)?/, pathRegex = /^(?:(?:(?:node|(?:(?:node:)?internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)(?:\.js)?:\d+:\d+)|native)/,
|
|
70222
|
+
const os2 = require$$0__default$2.default, escapeStringRegexp2 = requireEscapeStringRegexp(), extractPathRegex = /\s+at.*[(\s](.*)\)?/, pathRegex = /^(?:(?:(?:node|(?:(?:node:)?internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)(?:\.js)?:\d+:\d+)|native)/, homeDir2 = typeof os2.homedir > "u" ? "" : os2.homedir();
|
|
70160
70223
|
return cleanStack$1 = (stack2, { pretty = !1, basePath } = {}) => {
|
|
70161
70224
|
const basePathRegex = basePath && new RegExp(`(at | \\()${escapeStringRegexp2(basePath)}`, "g");
|
|
70162
70225
|
return stack2.replace(/\\/g, "/").split(`
|
|
@@ -70166,7 +70229,7 @@ function requireCleanStack() {
|
|
|
70166
70229
|
return !0;
|
|
70167
70230
|
const match2 = pathMatches[1];
|
|
70168
70231
|
return match2.includes(".app/Contents/Resources/electron.asar") || match2.includes(".app/Contents/Resources/default_app.asar") ? !1 : !pathRegex.test(match2);
|
|
70169
|
-
}).filter((line3) => line3.trim() !== "").map((line3) => (basePathRegex && (line3 = line3.replace(basePathRegex, "$1")), pretty && (line3 = line3.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(
|
|
70232
|
+
}).filter((line3) => line3.trim() !== "").map((line3) => (basePathRegex && (line3 = line3.replace(basePathRegex, "$1")), pretty && (line3 = line3.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir2, "~")))), line3)).join(`
|
|
70170
70233
|
`);
|
|
70171
70234
|
}, cleanStack$1;
|
|
70172
70235
|
}
|