@sentry/mcp-server 0.42.0 → 0.48.0
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 +54 -0
- package/dist/sentry-mcp.cjs +3436 -0
- package/package.json +22 -40
- package/LICENSE.md +0 -105
- package/dist/auth/constants.cjs +0 -9
- package/dist/auth/constants.d.cts +0 -31
- package/dist/auth/constants.d.cts.map +0 -1
- package/dist/auth/constants.d.ts +0 -31
- package/dist/auth/constants.d.ts.map +0 -1
- package/dist/auth/constants.js +0 -3
- package/dist/auth/device-code-flow.cjs +0 -10
- package/dist/auth/device-code-flow.d.cts +0 -34
- package/dist/auth/device-code-flow.d.cts.map +0 -1
- package/dist/auth/device-code-flow.d.ts +0 -34
- package/dist/auth/device-code-flow.d.ts.map +0 -1
- package/dist/auth/device-code-flow.js +0 -6
- package/dist/auth/resolve-token.cjs +0 -8
- package/dist/auth/resolve-token.d.cts +0 -17
- package/dist/auth/resolve-token.d.cts.map +0 -1
- package/dist/auth/resolve-token.d.ts +0 -17
- package/dist/auth/resolve-token.d.ts.map +0 -1
- package/dist/auth/resolve-token.js +0 -8
- package/dist/auth/token-cache.cjs +0 -5
- package/dist/auth/token-cache.d.cts +0 -11
- package/dist/auth/token-cache.d.cts.map +0 -1
- package/dist/auth/token-cache.d.ts +0 -11
- package/dist/auth/token-cache.d.ts.map +0 -1
- package/dist/auth/token-cache.js +0 -3
- package/dist/auth/types.cjs +0 -7
- package/dist/auth/types.d.cts +0 -2
- package/dist/auth/types.d.ts +0 -2
- package/dist/auth/types.js +0 -3
- package/dist/auth-B__Aec1m.cjs +0 -90
- package/dist/auth-B__Aec1m.cjs.map +0 -1
- package/dist/auth-BtRpItji.js +0 -79
- package/dist/auth-BtRpItji.js.map +0 -1
- package/dist/blob-utils-B0ae0K-m-BF8kTomr.cjs +0 -4724
- package/dist/blob-utils-B0ae0K-m-BF8kTomr.cjs.map +0 -1
- package/dist/blob-utils-B0ae0K-m-BhC2W04C.js +0 -4701
- package/dist/blob-utils-B0ae0K-m-BhC2W04C.js.map +0 -1
- package/dist/blob-utils-BM8EcgEO.js +0 -3
- package/dist/blob-utils-DBvCs9nw.cjs +0 -3
- package/dist/chunk-CunrlGP7.js +0 -37
- package/dist/chunk-Cv9WC9bY.cjs +0 -58
- package/dist/cli/commands/auth.cjs +0 -11
- package/dist/cli/commands/auth.d.cts +0 -8
- package/dist/cli/commands/auth.d.cts.map +0 -1
- package/dist/cli/commands/auth.d.ts +0 -8
- package/dist/cli/commands/auth.d.ts.map +0 -1
- package/dist/cli/commands/auth.js +0 -10
- package/dist/cli/output.cjs +0 -3
- package/dist/cli/output.d.cts +0 -7
- package/dist/cli/output.d.cts.map +0 -1
- package/dist/cli/output.d.ts +0 -7
- package/dist/cli/output.d.ts.map +0 -1
- package/dist/cli/output.js +0 -3
- package/dist/cli/parse.cjs +0 -5
- package/dist/cli/parse.d.cts +0 -11
- package/dist/cli/parse.d.cts.map +0 -1
- package/dist/cli/parse.d.ts +0 -11
- package/dist/cli/parse.d.ts.map +0 -1
- package/dist/cli/parse.js +0 -3
- package/dist/cli/resolve.cjs +0 -6
- package/dist/cli/resolve.d.cts +0 -16
- package/dist/cli/resolve.d.cts.map +0 -1
- package/dist/cli/resolve.d.ts +0 -16
- package/dist/cli/resolve.d.ts.map +0 -1
- package/dist/cli/resolve.js +0 -4
- package/dist/cli/types.cjs +0 -0
- package/dist/cli/types.d.cts +0 -2
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli/types.js +0 -0
- package/dist/cli/usage.cjs +0 -3
- package/dist/cli/usage.d.cts +0 -9
- package/dist/cli/usage.d.cts.map +0 -1
- package/dist/cli/usage.d.ts +0 -9
- package/dist/cli/usage.d.ts.map +0 -1
- package/dist/cli/usage.js +0 -3
- package/dist/config-40SaJWzQ-Bxau3bPR.cjs +0 -928
- package/dist/config-40SaJWzQ-Bxau3bPR.cjs.map +0 -1
- package/dist/config-40SaJWzQ-Dz27jdMQ.js +0 -886
- package/dist/config-40SaJWzQ-Dz27jdMQ.js.map +0 -1
- package/dist/config-DeGbV11k.cjs +0 -7
- package/dist/config-NGx6OsOU.js +0 -3
- package/dist/constants-CGu8w21D.js +0 -452
- package/dist/constants-CGu8w21D.js.map +0 -1
- package/dist/constants-Cw_BclsW.cjs +0 -644
- package/dist/constants-Cw_BclsW.cjs.map +0 -1
- package/dist/device-code-flow-afx1qvK6.cjs +0 -154
- package/dist/device-code-flow-afx1qvK6.cjs.map +0 -1
- package/dist/device-code-flow-mwBASRbi.js +0 -124
- package/dist/device-code-flow-mwBASRbi.js.map +0 -1
- package/dist/index.cjs +0 -61536
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -61537
- package/dist/index.js.map +0 -1
- package/dist/output-A_-7o7gV.js +0 -8
- package/dist/output-A_-7o7gV.js.map +0 -1
- package/dist/output-DEoNyYz7.cjs +0 -14
- package/dist/output-DEoNyYz7.cjs.map +0 -1
- package/dist/parse-CPY7-_2_.cjs +0 -130
- package/dist/parse-CPY7-_2_.cjs.map +0 -1
- package/dist/parse-Dd3OOgIq.js +0 -112
- package/dist/parse-Dd3OOgIq.js.map +0 -1
- package/dist/resolve-BvvBO-dw.cjs +0 -179
- package/dist/resolve-BvvBO-dw.cjs.map +0 -1
- package/dist/resolve-DOyeMm4X.js +0 -144
- package/dist/resolve-DOyeMm4X.js.map +0 -1
- package/dist/resolve-token-BHBj9ll0.js +0 -47
- package/dist/resolve-token-BHBj9ll0.js.map +0 -1
- package/dist/resolve-token-dsXzYI7-.cjs +0 -52
- package/dist/resolve-token-dsXzYI7-.cjs.map +0 -1
- package/dist/stdio-0Gl343e-.js +0 -59
- package/dist/stdio-0Gl343e-.js.map +0 -1
- package/dist/stdio-CZiqpRKP.cjs +0 -65
- package/dist/stdio-CZiqpRKP.cjs.map +0 -1
- package/dist/token-3xpHVxQo.js +0 -51
- package/dist/token-3xpHVxQo.js.map +0 -1
- package/dist/token-C7MavkKX.cjs +0 -55
- package/dist/token-C7MavkKX.cjs.map +0 -1
- package/dist/token-cache-ATUcs1cg.cjs +0 -84
- package/dist/token-cache-ATUcs1cg.cjs.map +0 -1
- package/dist/token-cache-DbZp4rvg.js +0 -66
- package/dist/token-cache-DbZp4rvg.js.map +0 -1
- package/dist/token-error-CBmJNKLY.js +0 -43
- package/dist/token-error-CBmJNKLY.js.map +0 -1
- package/dist/token-error-x_miDBP3.cjs +0 -48
- package/dist/token-error-x_miDBP3.cjs.map +0 -1
- package/dist/token-util-4bIYDTMS.js +0 -4
- package/dist/token-util-BRoQwIG6.cjs +0 -363
- package/dist/token-util-BRoQwIG6.cjs.map +0 -1
- package/dist/token-util-DurDL44i.cjs +0 -9
- package/dist/token-util-batRsXGA.js +0 -358
- package/dist/token-util-batRsXGA.js.map +0 -1
- package/dist/transports/stdio.cjs +0 -4
- package/dist/transports/stdio.d.cts +0 -40
- package/dist/transports/stdio.d.cts.map +0 -1
- package/dist/transports/stdio.d.ts +0 -40
- package/dist/transports/stdio.d.ts.map +0 -1
- package/dist/transports/stdio.js +0 -4
- package/dist/types-BCSxlxZI.js +0 -57
- package/dist/types-BCSxlxZI.js.map +0 -1
- package/dist/types-BGyk9F4G.d.ts +0 -61
- package/dist/types-BGyk9F4G.d.ts.map +0 -1
- package/dist/types-C9HgNyIE.d.cts +0 -61
- package/dist/types-C9HgNyIE.d.cts.map +0 -1
- package/dist/types-D-BIcaY4.d.ts +0 -91
- package/dist/types-D-BIcaY4.d.ts.map +0 -1
- package/dist/types-Dyacb-A8.d.cts +0 -91
- package/dist/types-Dyacb-A8.d.cts.map +0 -1
- package/dist/types-dghCRFW4.cjs +0 -87
- package/dist/types-dghCRFW4.cjs.map +0 -1
- package/dist/usage-DZ4QDygT.cjs +0 -74
- package/dist/usage-DZ4QDygT.cjs.map +0 -1
- package/dist/usage-Hi-6-LDr.js +0 -68
- package/dist/usage-Hi-6-LDr.js.map +0 -1
- package/dist/version-NjstoynH.js +0 -7
- package/dist/version-NjstoynH.js.map +0 -1
- package/dist/version-_1CmW0BF.cjs +0 -19
- package/dist/version-_1CmW0BF.cjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants-Cw_BclsW.cjs","names":[],"sources":["../../mcp-core/dist/events-datasets-bC65QyVa.js","../../mcp-core/dist/url-utils-8DkYoi3G.js","../../mcp-core/dist/scopes.js","../src/auth/constants.ts"],"sourcesContent":["//#region src/utils/events-datasets.ts\nconst PUBLIC_EVENTS_DATASETS = [\n\t\"spans\",\n\t\"errors\",\n\t\"logs\",\n\t\"metrics\",\n\t\"profiles\"\n];\nfunction isMetricsDataset(dataset) {\n\treturn dataset === \"metrics\" || dataset === \"tracemetrics\";\n}\nfunction isProfilesDataset(dataset) {\n\treturn dataset === \"profiles\";\n}\n/**\n* Sentry's product-facing Explore schemas already call this dataset \"metrics\",\n* but the current `/events/` and `/trace-items/attributes/` APIs still expect\n* the legacy `tracemetrics` identifier. Keep MCP aligned with the UI-facing\n* schema and swap only at the transport boundary until the upstream API name\n* catches up.\n*/\nfunction normalizeEventsDataset(dataset) {\n\treturn dataset === \"metrics\" ? \"tracemetrics\" : dataset;\n}\n\n//#endregion\nexport { PUBLIC_EVENTS_DATASETS, isMetricsDataset, isProfilesDataset, normalizeEventsDataset };\n//# sourceMappingURL=events-datasets-bC65QyVa.js.map","import { isMetricsDataset, isProfilesDataset } from \"./events-datasets-bC65QyVa.js\";\n\n//#region src/utils/url-utils.ts\n/**\n* Recognizes Sentry-owned hosts, including single-tenant deployments.\n*/\nfunction isSentryHost(host) {\n\treturn host === \"sentry.io\" || host.endsWith(\".sentry.io\");\n}\n/** Hosts that use the public SaaS control host and organization web subdomains. */\nfunction isPublicSentryHost(host) {\n\treturn isSentryHost(host) && !host.endsWith(\".my.sentry.io\");\n}\nfunction deriveSelectedFields(fields, aggregateFunctions, groupByFields) {\n\tif (fields && fields.length > 0) return fields;\n\treturn Array.from(new Set([...groupByFields ?? [], ...aggregateFunctions ?? []]));\n}\nfunction getSentryWebBaseUrl(host, organizationSlug, path, protocol = \"https\") {\n\tconst isSaas = isPublicSentryHost(host);\n\tconst webHost = isSaas ? \"sentry.io\" : host;\n\treturn isSaas ? `${protocol}://${organizationSlug}.${webHost}${path}` : `${protocol}://${host}/organizations/${organizationSlug}${path}`;\n}\nfunction normalizeTraceMetric(metric) {\n\tif (!metric?.name || !metric.type) return null;\n\treturn {\n\t\tname: metric.name,\n\t\ttype: metric.type,\n\t\tunit: metric.unit && metric.unit !== \"-\" ? metric.unit : void 0\n\t};\n}\nfunction extractTraceMetricFromAggregate(field) {\n\tconst match = field.match(/^[^(]+\\((.*)\\)$/);\n\tif (!match) return null;\n\tconst args = match[1].split(\",\").map((arg) => arg.trim()).filter((arg) => arg.length > 0);\n\tif (args.length < 4) return null;\n\treturn normalizeTraceMetric({\n\t\tname: args[1],\n\t\ttype: args[2],\n\t\tunit: args[3]\n\t});\n}\nfunction extractTraceMetricFromQuery(query) {\n\tconst extractValue = (field) => {\n\t\tconst quotedMatch = query.match(new RegExp(`${field}:\"([^\"]+)\"`, \"i\"));\n\t\tif (quotedMatch?.[1]) return quotedMatch[1];\n\t\tconst unquotedMatch = query.match(new RegExp(`${field}:([^\\\\s]+)`, \"i\"));\n\t\treturn unquotedMatch?.[1] ?? null;\n\t};\n\treturn normalizeTraceMetric({\n\t\tname: extractValue(\"metric\\\\.name\") ?? \"\",\n\t\ttype: extractValue(\"metric\\\\.type\") ?? \"\",\n\t\tunit: extractValue(\"metric\\\\.unit\") ?? void 0\n\t});\n}\nfunction dedupeTraceMetrics(metrics) {\n\tconst deduped = /* @__PURE__ */ new Map();\n\tfor (const metric of metrics) {\n\t\tconst normalizedMetric = normalizeTraceMetric(metric);\n\t\tif (!normalizedMetric) continue;\n\t\tconst key = `${normalizedMetric.name}|${normalizedMetric.type}|${normalizedMetric.unit ?? \"\"}`;\n\t\tdeduped.set(key, normalizedMetric);\n\t}\n\treturn [...deduped.values()];\n}\nfunction buildMetricQueryState(params) {\n\treturn JSON.stringify({\n\t\tmetric: params.metric,\n\t\tquery: params.query,\n\t\taggregateFields: [...params.yAxes.map((yAxis) => ({ yAxes: [yAxis] })), ...(params.groupByFields ?? []).map((field) => ({ groupBy: field }))],\n\t\taggregateSortBys: params.aggregateSortBys ?? [],\n\t\tmode: params.mode\n\t});\n}\nfunction getTraceMetricsExploreUrl(host, organizationSlug, options, protocol = \"https\") {\n\tconst { query, projectId, statsPeriod, start, end, sort, aggregateFunctions, groupByFields, traceMetrics } = options;\n\tconst urlParams = new URLSearchParams();\n\tif (projectId) urlParams.set(\"project\", projectId);\n\tif (start && end) {\n\t\turlParams.set(\"start\", start);\n\t\turlParams.set(\"end\", end);\n\t} else urlParams.set(\"statsPeriod\", statsPeriod || \"24h\");\n\tconst aggregateFields = aggregateFunctions ?? [];\n\tconst aggregateGroupByFields = groupByFields ?? [];\n\tconst isAggregateQuery = aggregateFields.length > 0;\n\tconst sortField = sort?.startsWith(\"-\") ? sort.slice(1) : sort;\n\tconst sortKind = sort?.startsWith(\"-\") ? \"desc\" : \"asc\";\n\tif (isAggregateQuery) {\n\t\tconst metricQueries = /* @__PURE__ */ new Map();\n\t\tfor (const aggregateField of aggregateFields) {\n\t\t\tconst metric = extractTraceMetricFromAggregate(aggregateField);\n\t\t\tif (!metric) continue;\n\t\t\tconst key = `${metric.name}|${metric.type}|${metric.unit ?? \"\"}`;\n\t\t\tconst existing = metricQueries.get(key);\n\t\t\tif (existing) existing.yAxes.push(aggregateField);\n\t\t\telse metricQueries.set(key, {\n\t\t\t\tmetric,\n\t\t\t\tyAxes: [aggregateField]\n\t\t\t});\n\t\t}\n\t\tfor (const { metric, yAxes } of metricQueries.values()) {\n\t\t\tconst aggregateSortBys = sortField && (yAxes.includes(sortField) || aggregateGroupByFields.includes(sortField)) ? [{\n\t\t\t\tfield: sortField,\n\t\t\t\tkind: sortKind\n\t\t\t}] : [];\n\t\t\turlParams.append(\"metric\", buildMetricQueryState({\n\t\t\t\tmetric,\n\t\t\t\tquery,\n\t\t\t\tmode: \"aggregate\",\n\t\t\t\tyAxes,\n\t\t\t\tgroupByFields: aggregateGroupByFields,\n\t\t\t\taggregateSortBys\n\t\t\t}));\n\t\t}\n\t} else {\n\t\tconst sampleMetrics = dedupeTraceMetrics([...traceMetrics ?? [], extractTraceMetricFromQuery(query)]);\n\t\tfor (const metric of sampleMetrics) urlParams.append(\"metric\", buildMetricQueryState({\n\t\t\tmetric,\n\t\t\tquery,\n\t\t\tmode: \"samples\",\n\t\t\tyAxes: [\"sum(value)\"],\n\t\t\taggregateSortBys: [{\n\t\t\t\tfield: \"sum(value)\",\n\t\t\t\tkind: \"desc\"\n\t\t\t}]\n\t\t}));\n\t}\n\treturn `${getSentryWebBaseUrl(host, organizationSlug, \"/explore/metrics/\", protocol)}?${urlParams.toString()}`;\n}\nfunction getProfilingExplorerUrl(host, organizationSlug, options, protocol = \"https\") {\n\tconst { query, projectId, statsPeriod, start, end, sort, fields, aggregateFunctions, groupByFields } = options;\n\tconst urlParams = new URLSearchParams();\n\tif (query) urlParams.set(\"query\", query);\n\tif (projectId) urlParams.set(\"project\", projectId);\n\tif (sort) urlParams.set(\"sort\", sort);\n\tfor (const field of deriveSelectedFields(fields, aggregateFunctions, groupByFields)) urlParams.append(\"field\", field);\n\tif (start && end) {\n\t\turlParams.set(\"start\", start);\n\t\turlParams.set(\"end\", end);\n\t} else urlParams.set(\"statsPeriod\", statsPeriod || \"24h\");\n\treturn `${getSentryWebBaseUrl(host, organizationSlug, \"/explore/profiling/\", protocol)}?${urlParams.toString()}`;\n}\n/**\n* Generates a Sentry issue URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param issueId Issue identifier (e.g., \"PROJECT-123\")\n* @returns The complete issue URL\n*/\nfunction getIssueUrl(host, organizationSlug, issueId, protocol = \"https\") {\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/issues/${issueId}`, protocol);\n}\n/**\n* Generates a Sentry dashboard URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param dashboardId Dashboard ID\n* @param options Optional dashboard view query parameters\n* @param protocol Protocol to use when building the web URL\n* @returns The complete dashboard URL\n*/\nfunction getDashboardUrl(host, organizationSlug, dashboardId, options = {}, protocol = \"https\") {\n\tconst encodedDashboardId = encodeURIComponent(dashboardId);\n\tconst params = new URLSearchParams();\n\tif (options.projectId !== null && options.projectId !== void 0) params.set(\"project\", String(options.projectId));\n\tif (options.statsPeriod) params.set(\"statsPeriod\", options.statsPeriod);\n\tconst queryString = params.toString();\n\treturn `${getSentryWebBaseUrl(host, organizationSlug, `/dashboard/${encodedDashboardId}/`, protocol)}${queryString ? `?${queryString}` : \"\"}`;\n}\n/**\n* Generates a Sentry preprod snapshot URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param snapshotId Preprod snapshot artifact ID\n* @returns The complete snapshot URL\n*/\nfunction getPreprodSnapshotUrl(host, organizationSlug, snapshotId, protocol = \"https\") {\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/preprod/snapshots/${snapshotId}/`, protocol);\n}\n/**\n* Generates a Sentry cron monitor URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param monitorSlug Monitor slug\n* @param projectSlug Optional project slug to disambiguate monitors with the same slug\n* @returns The complete monitor URL\n*/\nfunction getMonitorUrl(host, organizationSlug, monitorSlug, protocol = \"https\", projectSlug) {\n\tconst monitorPath = (projectSlug ? [projectSlug, monitorSlug] : [monitorSlug]).map((segment) => encodeURIComponent(segment)).join(\"/\");\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/crons/${monitorPath}/`, protocol);\n}\n/**\n* Generates a Sentry release URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param releaseVersion Release version identifier\n* @returns The complete release URL\n*/\n/**\n* Generates a Sentry uptime monitor URL.\n*\n* Uses the monitors UI path (`/monitors/{id}/`), which is the current home for\n* uptime detectors in Sentry.\n*/\nfunction getUptimeMonitorUrl(host, organizationSlug, uptimeMonitorId, protocol = \"https\") {\n\tconst encodedId = encodeURIComponent(String(uptimeMonitorId));\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/monitors/${encodedId}/`, protocol);\n}\nfunction getReleaseUrl(host, organizationSlug, releaseVersion, protocol = \"https\") {\n\tconst encodedReleaseVersion = encodeURIComponent(releaseVersion);\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/releases/${encodedReleaseVersion}/`, protocol);\n}\n/**\n* Generates a Sentry issues search URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param query Optional search query\n* @param projectSlugOrId Optional project slug or ID\n* @returns The complete issues search URL\n*/\nfunction getIssuesSearchUrl(host, organizationSlug, query, projectSlugOrId, protocol = \"https\") {\n\tlet url = getSentryWebBaseUrl(host, organizationSlug, \"/issues/\", protocol);\n\tconst params = new URLSearchParams();\n\tif (projectSlugOrId) params.append(\"project\", projectSlugOrId);\n\tif (query) params.append(\"query\", query);\n\tconst queryString = params.toString();\n\tif (queryString) url += `?${queryString}`;\n\treturn url;\n}\n/**\n* Generates a Sentry replay search URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param options Replay search options\n* @returns The complete replay search URL\n*/\nfunction getReplaysSearchUrl(host, organizationSlug, options = {}, protocol = \"https\") {\n\tconst { query, projectSlugOrId, environment, sort, statsPeriod, start, end } = options;\n\tlet url = getSentryWebBaseUrl(host, organizationSlug, \"/explore/replays/\", protocol);\n\tconst params = new URLSearchParams();\n\tif (projectSlugOrId) params.append(\"project\", projectSlugOrId);\n\tif (query) params.append(\"query\", query);\n\tif (environment) {\n\t\tconst environments = Array.isArray(environment) ? environment : [environment];\n\t\tfor (const value of environments) params.append(\"environment\", value);\n\t}\n\tif (sort) params.append(\"sort\", sort);\n\tif (start && end) {\n\t\tparams.append(\"start\", start);\n\t\tparams.append(\"end\", end);\n\t} else if (statsPeriod) params.append(\"statsPeriod\", statsPeriod);\n\tconst queryString = params.toString();\n\tif (queryString) url += `?${queryString}`;\n\treturn url;\n}\n/**\n* Generates a Sentry trace URL for performance investigation.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param traceId Trace identifier\n* @returns The complete trace URL\n*/\nfunction getTraceUrl(host, organizationSlug, traceId, protocol = \"https\") {\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/explore/traces/trace/${traceId}`, protocol);\n}\n/**\n* Generates a Sentry replay URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param replayId Replay identifier\n* @returns The complete replay URL\n*/\nfunction getReplayUrl(host, organizationSlug, replayId, protocol = \"https\") {\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/explore/replays/${replayId}/`, protocol);\n}\n/**\n* Generates a Sentry AI conversation URL.\n* @param host The Sentry host\n* @param organizationSlug Organization identifier\n* @param conversationId AI conversation identifier\n* @returns The complete AI conversation URL\n*/\nfunction getAIConversationUrl(host, organizationSlug, conversationId, protocol = \"https\") {\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/explore/conversations/${encodeURIComponent(conversationId)}/`, protocol);\n}\n/**\n* Extract a single non-negated AI conversation ID from a Sentry search query\n* that filters on `gen_ai.conversation.id`. Returns undefined when the query\n* does not contain exactly one such filter or contains a negated filter.\n*/\nfunction extractConversationIdFromSearchQuery(query) {\n\tif (!query) return void 0;\n\tif (/!gen_ai\\.conversation\\.id:|\\bNOT\\s+(?:\\(\\s*)?gen_ai\\.conversation\\.id:/i.test(query)) return void 0;\n\tconst pattern = /gen_ai\\.conversation\\.id:(?:\"([^\"]+)\"|([^\\s)]+))/g;\n\tconst matches = [...query.matchAll(pattern)];\n\tif (matches.length !== 1) return void 0;\n\tconst conversationId = matches[0][1] ?? matches[0][2];\n\tif (conversationId.startsWith(\"[\")) return void 0;\n\treturn conversationId;\n}\n/**\n* Generates a Sentry AI conversations list URL with optional search filters.\n*/\nfunction getAIConversationsUrl(host, organizationSlug, options = {}, protocol = \"https\") {\n\tconst urlParams = new URLSearchParams();\n\tif (options.query) urlParams.set(\"query\", options.query);\n\tfor (const projectId of options.project ?? []) urlParams.append(\"project\", projectId);\n\tconst environments = Array.isArray(options.environment) ? options.environment : options.environment ? [options.environment] : [];\n\tfor (const environmentName of environments) urlParams.append(\"environment\", environmentName);\n\tif (options.start && options.end) {\n\t\turlParams.set(\"start\", options.start);\n\t\turlParams.set(\"end\", options.end);\n\t} else if (options.statsPeriod) urlParams.set(\"statsPeriod\", options.statsPeriod);\n\tconst baseUrl = getSentryWebBaseUrl(host, organizationSlug, \"/explore/conversations/\", protocol);\n\tconst queryString = urlParams.toString();\n\treturn queryString ? `${baseUrl}?${queryString}` : baseUrl;\n}\nfunction getProfileUrl(host, organizationSlug, projectSlug, profileId, protocol = \"https\") {\n\treturn getSentryWebBaseUrl(host, organizationSlug, `/explore/profiling/profile/${projectSlug}/${profileId}/flamegraph/`, protocol);\n}\nfunction getContinuousProfileUrl(host, organizationSlug, projectSlug, options, protocol = \"https\") {\n\tconst url = new URL(getSentryWebBaseUrl(host, organizationSlug, `/explore/profiling/profile/${projectSlug}/flamegraph/`, protocol));\n\turl.searchParams.set(\"profilerId\", options.profilerId);\n\turl.searchParams.set(\"start\", options.start);\n\turl.searchParams.set(\"end\", options.end);\n\treturn url.toString();\n}\n/**\n* Generates a Sentry events explorer URL.\n* @param host The Sentry host (may include regional subdomain for API access)\n* @param organizationSlug Organization identifier\n* @param query Search query\n* @param dataset Dataset type\n* @param projectSlug Optional project slug\n* @param fields Optional fields to display\n* @returns The complete events explorer URL\n*/\nfunction getEventsExplorerUrl(host, organizationSlug, query, dataset = \"spans\", projectSlugOrId, fields, explorerOptions, protocol = \"https\") {\n\tif (isMetricsDataset(dataset)) {\n\t\tconst derivedAggregateFunctions = explorerOptions?.aggregateFunctions ?? fields?.filter((field) => field.includes(\"(\") && field.includes(\")\"));\n\t\tconst derivedGroupByFields = explorerOptions?.groupByFields ?? fields?.filter((field) => !field.includes(\"(\") && !field.includes(\")\"));\n\t\treturn getTraceMetricsExploreUrl(host, organizationSlug, {\n\t\t\t...explorerOptions,\n\t\t\tquery,\n\t\t\tprojectId: projectSlugOrId,\n\t\t\taggregateFunctions: derivedAggregateFunctions,\n\t\t\tgroupByFields: derivedGroupByFields\n\t\t}, protocol);\n\t}\n\tif (isProfilesDataset(dataset)) {\n\t\tconst derivedAggregateFunctions = explorerOptions?.aggregateFunctions ?? fields?.filter((field) => field.includes(\"(\") && field.includes(\")\"));\n\t\tconst derivedGroupByFields = explorerOptions?.groupByFields ?? fields?.filter((field) => !field.includes(\"(\") && !field.includes(\")\"));\n\t\treturn getProfilingExplorerUrl(host, organizationSlug, {\n\t\t\tquery,\n\t\t\tprojectId: projectSlugOrId,\n\t\t\tfields,\n\t\t\tsort: explorerOptions?.sort,\n\t\t\tstatsPeriod: explorerOptions?.statsPeriod,\n\t\t\tstart: explorerOptions?.start,\n\t\t\tend: explorerOptions?.end,\n\t\t\taggregateFunctions: derivedAggregateFunctions,\n\t\t\tgroupByFields: derivedGroupByFields\n\t\t}, protocol);\n\t}\n\tlet url = getSentryWebBaseUrl(host, organizationSlug, \"/explore/\", protocol);\n\tconst params = new URLSearchParams();\n\tparams.append(\"query\", query);\n\tparams.append(\"dataset\", dataset);\n\tparams.append(\"layout\", \"table\");\n\tif (projectSlugOrId) params.append(\"project\", projectSlugOrId);\n\tif (fields && fields.length > 0) for (const field of fields) params.append(\"field\", field);\n\turl += `?${params.toString()}`;\n\treturn url;\n}\n/**\n* Internal validation function that checks if a SENTRY_HOST value contains only hostname (no protocol).\n* Throws an error if validation fails instead of exiting the process.\n*\n* @param host The hostname to validate\n* @throws {Error} If the host contains a protocol\n*/\nfunction _validateSentryHostInternal(host) {\n\tif (host.startsWith(\"http://\") || host.startsWith(\"https://\")) throw new Error(\"SENTRY_HOST should only contain a hostname (e.g., sentry.example.com). Use SENTRY_URL if you want to provide a full URL.\");\n}\n/**\n* Internal validation function that checks if a SENTRY_URL value is a valid HTTPS URL and extracts the hostname.\n* Throws an error if validation fails instead of exiting the process.\n*\n* @param url The HTTPS URL to validate and parse\n* @returns The extracted hostname from the URL\n* @throws {Error} If the URL is invalid or not HTTPS\n*/\nfunction _validateAndParseSentryUrlInternal(url) {\n\tif (!url.startsWith(\"https://\")) throw new Error(\"SENTRY_URL must be a full HTTPS URL (e.g., https://sentry.example.com).\");\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.host;\n\t} catch (error) {\n\t\tthrow new Error(\"SENTRY_URL must be a valid HTTPS URL (e.g., https://sentry.example.com).\");\n\t}\n}\n/**\n* Validates that a SENTRY_HOST value contains only hostname (no protocol).\n* Exits the process with error code 1 if validation fails (CLI behavior).\n*\n* @param host The hostname to validate\n*/\nfunction validateSentryHost(host) {\n\ttry {\n\t\t_validateSentryHostInternal(host);\n\t} catch (error) {\n\t\tconsole.error(`Error: ${error.message}`);\n\t\tprocess.exit(1);\n\t}\n}\n/**\n* Validates that a SENTRY_URL value is a valid HTTPS URL and extracts the hostname.\n* Exits the process with error code 1 if validation fails (CLI behavior).\n*\n* @param url The HTTPS URL to validate and parse\n* @returns The extracted hostname from the URL\n*/\nfunction validateAndParseSentryUrl(url) {\n\ttry {\n\t\treturn _validateAndParseSentryUrlInternal(url);\n\t} catch (error) {\n\t\tconsole.error(`Error: ${error.message}`);\n\t\tprocess.exit(1);\n\t}\n}\n/**\n* Validates that a SENTRY_HOST value contains only hostname (no protocol).\n* Throws an error instead of exiting the process (for testing).\n*\n* @param host The hostname to validate\n* @throws {Error} If the host contains a protocol\n*/\nfunction validateSentryHostThrows(host) {\n\t_validateSentryHostInternal(host);\n}\n/**\n* Validates that a SENTRY_URL value is a valid HTTPS URL and extracts the hostname.\n* Throws an error instead of exiting the process (for testing).\n*\n* @param url The HTTPS URL to validate and parse\n* @returns The extracted hostname from the URL\n* @throws {Error} If the URL is invalid or not HTTPS\n*/\nfunction validateAndParseSentryUrlThrows(url) {\n\treturn _validateAndParseSentryUrlInternal(url);\n}\n/**\n* Validates that the provided OpenAI base URL is a valid HTTP(S) URL and returns a normalized string.\n*\n* @param url The URL to validate and normalize\n* @returns The normalized URL string\n* @throws {Error} If the URL is empty, invalid, or uses an unsupported protocol\n*/\nfunction validateOpenAiBaseUrlThrows(url) {\n\tconst trimmed = url.trim();\n\tif (trimmed.length === 0) throw new Error(\"OPENAI base URL must not be empty.\");\n\tlet parsed;\n\ttry {\n\t\tparsed = new URL(trimmed);\n\t} catch (error) {\n\t\tthrow new Error(\"OPENAI base URL must be a valid HTTP or HTTPS URL (e.g., https://example.com/v1).\", { cause: error });\n\t}\n\tif (parsed.protocol !== \"https:\" && parsed.protocol !== \"http:\") throw new Error(\"OPENAI base URL must use http or https scheme (e.g., https://example.com/v1).\");\n\treturn parsed.toString();\n}\n\n//#endregion\nexport { extractConversationIdFromSearchQuery, getAIConversationUrl, getAIConversationsUrl, getContinuousProfileUrl, getDashboardUrl, getEventsExplorerUrl, getIssueUrl, getIssuesSearchUrl, getMonitorUrl, getPreprodSnapshotUrl, getProfileUrl, getProfilingExplorerUrl, getReleaseUrl, getReplayUrl, getReplaysSearchUrl, getTraceMetricsExploreUrl, getTraceUrl, getUptimeMonitorUrl, isPublicSentryHost, isSentryHost, validateAndParseSentryUrl, validateAndParseSentryUrlThrows, validateOpenAiBaseUrlThrows, validateSentryHost, validateSentryHostThrows };\n//# sourceMappingURL=url-utils-8DkYoi3G.js.map","//#region src/scopes.ts\nconst SCOPES = {\n\t\"org:read\": \"Read organization data\",\n\t\"project:write\": \"Write project data\",\n\t\"team:write\": \"Write team data\",\n\t\"event:write\": \"Write event data\",\n\t\"alerts:write\": \"Write alert rules\"\n};\n\n//#endregion\nexport { SCOPES };\n//# sourceMappingURL=scopes.js.map","import { SCOPES } from \"@sentry/mcp-core/scopes\";\nimport { isSentryHost } from \"@sentry/mcp-core/utils/url-utils\";\n\n/**\n * Public OAuth app registered on sentry.io for the stdio device code flow.\n * No client secret — device code grant is a public client flow.\n * The Cloudflare transport uses a separate OAuth app with a secret.\n * Override via SENTRY_CLIENT_ID environment variable.\n * See docs/operations/stdio-auth.md for the full credential architecture.\n */\nexport const DEFAULT_SENTRY_CLIENT_ID =\n \"0acbeba7d07d58076dd7dbde8cea2fed8ab525ce3713bda604988009ab35d765\";\n\nexport const DEVICE_CODE_ENDPOINT = \"/oauth/device/code/\";\nexport const TOKEN_ENDPOINT = \"/oauth/token/\";\nexport const DEVICE_CODE_SCOPES = Object.keys(SCOPES).join(\" \");\n\n/** Interval increment on slow_down response (RFC 8628). */\nexport const SLOW_DOWN_INCREMENT_SEC = 5;\n\n/**\n * Whether device code auth is available for this host.\n * Supports sentry.io and regional subdomains (us.sentry.io, eu.sentry.io).\n */\nexport { isSentryHost as isSentryIo };\n\n/**\n * OAuth endpoints live on sentry.io regardless of regional host.\n * Always use this as the host for device code and token requests.\n */\nexport const OAUTH_HOST = \"sentry.io\";\n"],"mappings":";;AACA,MAAM,yBAAyB;CAC9B;CACA;CACA;CACA;CACA;AACA;AACD,SAAS,iBAAiB,SAAS;AAClC,QAAO,YAAY,aAAa,YAAY;AAC5C;AACD,SAAS,kBAAkB,SAAS;AACnC,QAAO,YAAY;AACnB;;;;;;;;AAQD,SAAS,uBAAuB,SAAS;AACxC,QAAO,YAAY,YAAY,iBAAiB;AAChD;;;;;;;ACjBD,SAAS,aAAa,MAAM;AAC3B,QAAO,SAAS,eAAe,KAAK,SAAS,aAAa;AAC1D;;AAED,SAAS,mBAAmB,MAAM;AACjC,QAAO,aAAa,KAAK,KAAK,KAAK,SAAS,gBAAgB;AAC5D;AACD,SAAS,qBAAqB,QAAQ,oBAAoB,eAAe;AACxE,KAAI,UAAU,OAAO,SAAS,EAAG,QAAO;AACxC,QAAO,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,iBAAiB,C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AW,EAAG,OAAM,IAAI,MAAM;CAC1C,IAAI;AACJ,KAAI;AACH,WAAS,IAAI,IAAI;CACjB,SAAQ,OAAO;AACf,QAAM,IAAI,MAAM,qFAAqF,EAAE,OAAO,MAAO;CACrH;AACD,KAAI,OAAO,aAAa,YAAY,OAAO,aAAa,QAAS,OAAM,IAAI,MAAM;AACjF,QAAO,OAAO,UAAU;AACxB;;;;ACndD,MAAM,SAAS;CACd,YAAY;CACZ,iBAAiB;CACjB,cAAc;CACd,eAAe;CACf,gBAAgB;AAChB;;;;;;;;;;;ACGD,MAAa,2BACX;AAEF,MAAa,uBAAuB;AACpC,MAAa,iBAAiB;AAC9B,MAAa,qBAAqB,OAAO,KAAK,OAAO,CAAC,KAAK,IAAI;;AAG/D,MAAa,0BAA0B;;;;;AAYvC,MAAa,aAAa"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-Cv9WC9bY.cjs');
|
|
2
|
-
const require_constants = require('./constants-Cw_BclsW.cjs');
|
|
3
|
-
const require_version = require('./version-_1CmW0BF.cjs');
|
|
4
|
-
const require_types = require('./types-dghCRFW4.cjs');
|
|
5
|
-
const node_child_process = require_chunk.__toESM(require("node:child_process"));
|
|
6
|
-
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
7
|
-
|
|
8
|
-
//#region src/auth/device-code-flow.ts
|
|
9
|
-
const USER_AGENT = `sentry-mcp-server/${require_version.LIB_VERSION}`;
|
|
10
|
-
var DeviceCodeError = class extends Error {
|
|
11
|
-
constructor(message, code) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.code = code;
|
|
14
|
-
this.name = "DeviceCodeError";
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
async function requestDeviceCode(clientId, host, scopes = require_constants.DEVICE_CODE_SCOPES) {
|
|
18
|
-
const url = `https://${host}${require_constants.DEVICE_CODE_ENDPOINT}`;
|
|
19
|
-
const resp = await fetch(url, {
|
|
20
|
-
method: "POST",
|
|
21
|
-
headers: {
|
|
22
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
23
|
-
"User-Agent": USER_AGENT
|
|
24
|
-
},
|
|
25
|
-
body: new URLSearchParams({
|
|
26
|
-
client_id: clientId,
|
|
27
|
-
scope: scopes
|
|
28
|
-
})
|
|
29
|
-
});
|
|
30
|
-
if (!resp.ok) {
|
|
31
|
-
const text = await resp.text();
|
|
32
|
-
throw new DeviceCodeError(`Failed to request device code (HTTP ${resp.status}): ${text}`);
|
|
33
|
-
}
|
|
34
|
-
const body = await resp.json();
|
|
35
|
-
return require_types.DeviceCodeResponseSchema.parse(body);
|
|
36
|
-
}
|
|
37
|
-
function sleep(ms) {
|
|
38
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
39
|
-
}
|
|
40
|
-
async function pollForToken({ deviceCode, clientId, host, interval, expiresIn }) {
|
|
41
|
-
const url = `https://${host}${require_constants.TOKEN_ENDPOINT}`;
|
|
42
|
-
const deadline = Date.now() + expiresIn * 1e3;
|
|
43
|
-
let pollInterval = interval;
|
|
44
|
-
while (Date.now() < deadline) {
|
|
45
|
-
await sleep(pollInterval * 1e3);
|
|
46
|
-
const resp = await fetch(url, {
|
|
47
|
-
method: "POST",
|
|
48
|
-
headers: {
|
|
49
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
50
|
-
"User-Agent": USER_AGENT
|
|
51
|
-
},
|
|
52
|
-
body: new URLSearchParams({
|
|
53
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
54
|
-
device_code: deviceCode,
|
|
55
|
-
client_id: clientId
|
|
56
|
-
})
|
|
57
|
-
});
|
|
58
|
-
if (resp.ok) {
|
|
59
|
-
const body = await resp.json();
|
|
60
|
-
return require_types.TokenResponseSchema.parse(body);
|
|
61
|
-
}
|
|
62
|
-
const errorBody = await resp.json().catch(() => null);
|
|
63
|
-
const parsed = require_types.DeviceCodeErrorSchema.safeParse(errorBody);
|
|
64
|
-
const errorCode = parsed.success ? parsed.data.error : void 0;
|
|
65
|
-
switch (errorCode) {
|
|
66
|
-
case "authorization_pending": continue;
|
|
67
|
-
case "slow_down":
|
|
68
|
-
pollInterval += require_constants.SLOW_DOWN_INCREMENT_SEC;
|
|
69
|
-
continue;
|
|
70
|
-
case "access_denied": throw new DeviceCodeError("Authorization was denied. Please try again or provide --access-token.", errorCode);
|
|
71
|
-
case "expired_token": throw new DeviceCodeError("Device code expired before authorization was completed.", errorCode);
|
|
72
|
-
default: throw new DeviceCodeError(`Unexpected error during device code polling: ${errorCode ?? resp.statusText}`, errorCode);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
throw new DeviceCodeError("Device code expired before authorization was completed.", "expired_token");
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Write directly to stderr, bypassing console.warn which may be
|
|
79
|
-
* intercepted by the MCP transport layer.
|
|
80
|
-
*/
|
|
81
|
-
function stderr(msg) {
|
|
82
|
-
process.stderr.write(`${msg}\n`);
|
|
83
|
-
}
|
|
84
|
-
function isWSL() {
|
|
85
|
-
try {
|
|
86
|
-
return node_fs.readFileSync("/proc/version", "utf-8").toLowerCase().includes("microsoft");
|
|
87
|
-
} catch {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function openBrowser(url) {
|
|
92
|
-
try {
|
|
93
|
-
const { platform } = process;
|
|
94
|
-
if (platform === "darwin") (0, node_child_process.exec)(`open ${JSON.stringify(url)}`);
|
|
95
|
-
else if (platform === "win32") (0, node_child_process.exec)(`start "" ${JSON.stringify(url)}`);
|
|
96
|
-
else if (isWSL()) (0, node_child_process.exec)(`cmd.exe /c start "" ${JSON.stringify(url)}`);
|
|
97
|
-
else (0, node_child_process.exec)(`xdg-open ${JSON.stringify(url)}`);
|
|
98
|
-
} catch {}
|
|
99
|
-
}
|
|
100
|
-
function displayDeviceCode(response) {
|
|
101
|
-
stderr("");
|
|
102
|
-
stderr(`To authorize, visit: ${response.verification_uri_complete}`);
|
|
103
|
-
stderr(` and enter code: ${response.user_code}`);
|
|
104
|
-
stderr("");
|
|
105
|
-
stderr("Waiting for authorization...");
|
|
106
|
-
openBrowser(response.verification_uri_complete);
|
|
107
|
-
}
|
|
108
|
-
async function authenticate({ clientId, host }) {
|
|
109
|
-
stderr("No access token provided. Starting device authorization...");
|
|
110
|
-
const deviceCodeResponse = await requestDeviceCode(clientId, host);
|
|
111
|
-
displayDeviceCode(deviceCodeResponse);
|
|
112
|
-
const tokenResponse = await pollForToken({
|
|
113
|
-
deviceCode: deviceCodeResponse.device_code,
|
|
114
|
-
clientId,
|
|
115
|
-
host,
|
|
116
|
-
interval: deviceCodeResponse.interval,
|
|
117
|
-
expiresIn: deviceCodeResponse.expires_in
|
|
118
|
-
});
|
|
119
|
-
stderr(`Successfully authenticated as ${require_types.getTokenUserLabel(tokenResponse)}`);
|
|
120
|
-
return tokenResponse;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
Object.defineProperty(exports, 'DeviceCodeError', {
|
|
125
|
-
enumerable: true,
|
|
126
|
-
get: function () {
|
|
127
|
-
return DeviceCodeError;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
Object.defineProperty(exports, 'authenticate', {
|
|
131
|
-
enumerable: true,
|
|
132
|
-
get: function () {
|
|
133
|
-
return authenticate;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
Object.defineProperty(exports, 'displayDeviceCode', {
|
|
137
|
-
enumerable: true,
|
|
138
|
-
get: function () {
|
|
139
|
-
return displayDeviceCode;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
Object.defineProperty(exports, 'pollForToken', {
|
|
143
|
-
enumerable: true,
|
|
144
|
-
get: function () {
|
|
145
|
-
return pollForToken;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
Object.defineProperty(exports, 'requestDeviceCode', {
|
|
149
|
-
enumerable: true,
|
|
150
|
-
get: function () {
|
|
151
|
-
return requestDeviceCode;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
//# sourceMappingURL=device-code-flow-afx1qvK6.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"device-code-flow-afx1qvK6.cjs","names":["LIB_VERSION","message: string","code?: string","clientId: string","host: string","scopes: string","DEVICE_CODE_SCOPES","DEVICE_CODE_ENDPOINT","ms: number","TOKEN_ENDPOINT","SLOW_DOWN_INCREMENT_SEC","msg: string","url: string","response: DeviceCodeResponse"],"sources":["../src/auth/device-code-flow.ts"],"sourcesContent":["import { exec } from \"node:child_process\";\nimport * as fs from \"node:fs\";\nimport { LIB_VERSION } from \"@sentry/mcp-core/version\";\nimport {\n DEVICE_CODE_ENDPOINT,\n DEVICE_CODE_SCOPES,\n SLOW_DOWN_INCREMENT_SEC,\n TOKEN_ENDPOINT,\n} from \"./constants\";\nimport {\n DeviceCodeResponseSchema,\n DeviceCodeErrorSchema,\n TokenResponseSchema,\n getTokenUserLabel,\n type DeviceCodeResponse,\n type TokenResponse,\n} from \"./types\";\n\nconst USER_AGENT = `sentry-mcp-server/${LIB_VERSION}`;\n\nexport class DeviceCodeError extends Error {\n constructor(\n message: string,\n public readonly code?: string,\n ) {\n super(message);\n this.name = \"DeviceCodeError\";\n }\n}\n\nexport async function requestDeviceCode(\n clientId: string,\n host: string,\n scopes: string = DEVICE_CODE_SCOPES,\n): Promise<DeviceCodeResponse> {\n const url = `https://${host}${DEVICE_CODE_ENDPOINT}`;\n const resp = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"User-Agent\": USER_AGENT,\n },\n body: new URLSearchParams({\n client_id: clientId,\n scope: scopes,\n }),\n });\n\n if (!resp.ok) {\n const text = await resp.text();\n throw new DeviceCodeError(\n `Failed to request device code (HTTP ${resp.status}): ${text}`,\n );\n }\n\n const body = await resp.json();\n return DeviceCodeResponseSchema.parse(body);\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport async function pollForToken({\n deviceCode,\n clientId,\n host,\n interval,\n expiresIn,\n}: {\n deviceCode: string;\n clientId: string;\n host: string;\n interval: number;\n expiresIn: number;\n}): Promise<TokenResponse> {\n const url = `https://${host}${TOKEN_ENDPOINT}`;\n const deadline = Date.now() + expiresIn * 1000;\n let pollInterval = interval;\n\n while (Date.now() < deadline) {\n await sleep(pollInterval * 1000);\n\n const resp = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"User-Agent\": USER_AGENT,\n },\n body: new URLSearchParams({\n grant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n device_code: deviceCode,\n client_id: clientId,\n }),\n });\n\n if (resp.ok) {\n const body = await resp.json();\n return TokenResponseSchema.parse(body);\n }\n\n const errorBody = await resp.json().catch(() => null);\n const parsed = DeviceCodeErrorSchema.safeParse(errorBody);\n const errorCode = parsed.success ? parsed.data.error : undefined;\n\n switch (errorCode) {\n case \"authorization_pending\":\n // Keep polling at current interval\n continue;\n case \"slow_down\":\n pollInterval += SLOW_DOWN_INCREMENT_SEC;\n continue;\n case \"access_denied\":\n throw new DeviceCodeError(\n \"Authorization was denied. Please try again or provide --access-token.\",\n errorCode,\n );\n case \"expired_token\":\n throw new DeviceCodeError(\n \"Device code expired before authorization was completed.\",\n errorCode,\n );\n default:\n throw new DeviceCodeError(\n `Unexpected error during device code polling: ${errorCode ?? resp.statusText}`,\n errorCode,\n );\n }\n }\n\n throw new DeviceCodeError(\n \"Device code expired before authorization was completed.\",\n \"expired_token\",\n );\n}\n\n/**\n * Write directly to stderr, bypassing console.warn which may be\n * intercepted by the MCP transport layer.\n */\nfunction stderr(msg: string): void {\n process.stderr.write(`${msg}\\n`);\n}\n\nfunction isWSL(): boolean {\n try {\n return fs\n .readFileSync(\"/proc/version\", \"utf-8\")\n .toLowerCase()\n .includes(\"microsoft\");\n } catch {\n return false;\n }\n}\n\nfunction openBrowser(url: string): void {\n try {\n const { platform } = process;\n if (platform === \"darwin\") {\n exec(`open ${JSON.stringify(url)}`);\n } else if (platform === \"win32\") {\n exec(`start \"\" ${JSON.stringify(url)}`);\n } else if (isWSL()) {\n // WSL: invoke cmd.exe to open the default browser.\n exec(`cmd.exe /c start \"\" ${JSON.stringify(url)}`);\n } else {\n exec(`xdg-open ${JSON.stringify(url)}`);\n }\n } catch {\n // Best-effort — ignore errors (headless, etc.)\n }\n}\n\nexport function displayDeviceCode(response: DeviceCodeResponse): void {\n stderr(\"\");\n stderr(`To authorize, visit: ${response.verification_uri_complete}`);\n stderr(` and enter code: ${response.user_code}`);\n stderr(\"\");\n stderr(\"Waiting for authorization...\");\n\n openBrowser(response.verification_uri_complete);\n}\n\nexport async function authenticate({\n clientId,\n host,\n}: {\n clientId: string;\n host: string;\n}): Promise<TokenResponse> {\n stderr(\"No access token provided. Starting device authorization...\");\n\n const deviceCodeResponse = await requestDeviceCode(clientId, host);\n displayDeviceCode(deviceCodeResponse);\n\n const tokenResponse = await pollForToken({\n deviceCode: deviceCodeResponse.device_code,\n clientId,\n host,\n interval: deviceCodeResponse.interval,\n expiresIn: deviceCodeResponse.expires_in,\n });\n\n stderr(`Successfully authenticated as ${getTokenUserLabel(tokenResponse)}`);\n return tokenResponse;\n}\n"],"mappings":";;;;;;;;AAkBA,MAAM,cAAc,oBAAoBA;AAExC,IAAa,kBAAb,cAAqC,MAAM;CACzC,YACEC,SACgBC,MAChB;AACA,QAAM,QAAQ;EAFE;AAGhB,OAAK,OAAO;CACb;AACF;AAED,eAAsB,kBACpBC,UACAC,MACAC,SAAiBC,sCACY;CAC7B,MAAM,OAAO,UAAU,OAAOC;CAC9B,MAAM,OAAO,MAAM,MAAM,KAAK;EAC5B,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,cAAc;EACf;EACD,MAAM,IAAI,gBAAgB;GACxB,WAAW;GACX,OAAO;EACR;CACF,EAAC;AAEF,MAAK,KAAK,IAAI;EACZ,MAAM,OA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ACF,SAAO,QACJ,aAAa,iBAAiB,QAAQ,CACtC,aAAa,CACb,SAAS,YAAY;CACzB,QAAO;AACN,SAAO;CACR;AACF;AAED,SAAS,YAAYC,KAAmB;AACtC,KAAI;EACF,MAAM,EAAE,UAAU,GAAG;AACrB,MAAI,aAAa,SACf,+BAAM,OAAO,KAAK,UAAU,IAAI,GAAG;WAC1B,aAAa,QACtB,+BAAM,WAAW,KAAK,UAAU,IAAI,GAAG;WAC9B,OAAO,CAEhB,+BAAM,sBAAsB,KAAK,UAAU,IAAI,GAAG;MAElD,+BAAM,WAAW,KAAK,UAAU,IAAI,GAAG;CAE1C,QAAO,CAEP;AACF;AAED,SAAgB,kBAAkBC,UAAoC;AACpE,QAAO,GAAG;AACV,SAAQ,uBAAuB,SAAS,4BAA4B;AACpE,SAAQ,oBAAoB,SAAS,YAAY;AACjD,QAAO,GAAG;AACV,QAAO,+BAA+B;AAEtC,aAAY,SAAS,0BAA0B;AAChD;AAED,eAAsB,aAAa,EACjC,UACA,MAID,EAA0B;AACzB,QAAO,6DAA6D;CAEpE,MAAM,qBAAqB,MAAM,kBAAkB,UAAU,KAAK;AAClE,mBAAkB,mBAAmB;CAErC,MAAM,gBAAgB,MAAM,aAAa;EACvC,YAAY,mBAAmB;EAC/B;EACA;EACA,UAAU,mBAAmB;EAC7B,WAAW,mBAAmB;CAC/B,EAAC;AAEF,SAAQ,gCAAgC,gCAAkB,cAAc,GAAG;AAC3E,QAAO;AACR"}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { DEVICE_CODE_ENDPOINT, DEVICE_CODE_SCOPES, SLOW_DOWN_INCREMENT_SEC, TOKEN_ENDPOINT } from "./constants-CGu8w21D.js";
|
|
2
|
-
import { LIB_VERSION } from "./version-NjstoynH.js";
|
|
3
|
-
import { DeviceCodeErrorSchema, DeviceCodeResponseSchema, TokenResponseSchema, getTokenUserLabel } from "./types-BCSxlxZI.js";
|
|
4
|
-
import { exec } from "node:child_process";
|
|
5
|
-
import * as fs from "node:fs";
|
|
6
|
-
|
|
7
|
-
//#region src/auth/device-code-flow.ts
|
|
8
|
-
const USER_AGENT = `sentry-mcp-server/${LIB_VERSION}`;
|
|
9
|
-
var DeviceCodeError = class extends Error {
|
|
10
|
-
constructor(message, code) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.code = code;
|
|
13
|
-
this.name = "DeviceCodeError";
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
async function requestDeviceCode(clientId, host, scopes = DEVICE_CODE_SCOPES) {
|
|
17
|
-
const url = `https://${host}${DEVICE_CODE_ENDPOINT}`;
|
|
18
|
-
const resp = await fetch(url, {
|
|
19
|
-
method: "POST",
|
|
20
|
-
headers: {
|
|
21
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
22
|
-
"User-Agent": USER_AGENT
|
|
23
|
-
},
|
|
24
|
-
body: new URLSearchParams({
|
|
25
|
-
client_id: clientId,
|
|
26
|
-
scope: scopes
|
|
27
|
-
})
|
|
28
|
-
});
|
|
29
|
-
if (!resp.ok) {
|
|
30
|
-
const text = await resp.text();
|
|
31
|
-
throw new DeviceCodeError(`Failed to request device code (HTTP ${resp.status}): ${text}`);
|
|
32
|
-
}
|
|
33
|
-
const body = await resp.json();
|
|
34
|
-
return DeviceCodeResponseSchema.parse(body);
|
|
35
|
-
}
|
|
36
|
-
function sleep(ms) {
|
|
37
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
38
|
-
}
|
|
39
|
-
async function pollForToken({ deviceCode, clientId, host, interval, expiresIn }) {
|
|
40
|
-
const url = `https://${host}${TOKEN_ENDPOINT}`;
|
|
41
|
-
const deadline = Date.now() + expiresIn * 1e3;
|
|
42
|
-
let pollInterval = interval;
|
|
43
|
-
while (Date.now() < deadline) {
|
|
44
|
-
await sleep(pollInterval * 1e3);
|
|
45
|
-
const resp = await fetch(url, {
|
|
46
|
-
method: "POST",
|
|
47
|
-
headers: {
|
|
48
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
49
|
-
"User-Agent": USER_AGENT
|
|
50
|
-
},
|
|
51
|
-
body: new URLSearchParams({
|
|
52
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
53
|
-
device_code: deviceCode,
|
|
54
|
-
client_id: clientId
|
|
55
|
-
})
|
|
56
|
-
});
|
|
57
|
-
if (resp.ok) {
|
|
58
|
-
const body = await resp.json();
|
|
59
|
-
return TokenResponseSchema.parse(body);
|
|
60
|
-
}
|
|
61
|
-
const errorBody = await resp.json().catch(() => null);
|
|
62
|
-
const parsed = DeviceCodeErrorSchema.safeParse(errorBody);
|
|
63
|
-
const errorCode = parsed.success ? parsed.data.error : void 0;
|
|
64
|
-
switch (errorCode) {
|
|
65
|
-
case "authorization_pending": continue;
|
|
66
|
-
case "slow_down":
|
|
67
|
-
pollInterval += SLOW_DOWN_INCREMENT_SEC;
|
|
68
|
-
continue;
|
|
69
|
-
case "access_denied": throw new DeviceCodeError("Authorization was denied. Please try again or provide --access-token.", errorCode);
|
|
70
|
-
case "expired_token": throw new DeviceCodeError("Device code expired before authorization was completed.", errorCode);
|
|
71
|
-
default: throw new DeviceCodeError(`Unexpected error during device code polling: ${errorCode ?? resp.statusText}`, errorCode);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
throw new DeviceCodeError("Device code expired before authorization was completed.", "expired_token");
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Write directly to stderr, bypassing console.warn which may be
|
|
78
|
-
* intercepted by the MCP transport layer.
|
|
79
|
-
*/
|
|
80
|
-
function stderr(msg) {
|
|
81
|
-
process.stderr.write(`${msg}\n`);
|
|
82
|
-
}
|
|
83
|
-
function isWSL() {
|
|
84
|
-
try {
|
|
85
|
-
return fs.readFileSync("/proc/version", "utf-8").toLowerCase().includes("microsoft");
|
|
86
|
-
} catch {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function openBrowser(url) {
|
|
91
|
-
try {
|
|
92
|
-
const { platform } = process;
|
|
93
|
-
if (platform === "darwin") exec(`open ${JSON.stringify(url)}`);
|
|
94
|
-
else if (platform === "win32") exec(`start "" ${JSON.stringify(url)}`);
|
|
95
|
-
else if (isWSL()) exec(`cmd.exe /c start "" ${JSON.stringify(url)}`);
|
|
96
|
-
else exec(`xdg-open ${JSON.stringify(url)}`);
|
|
97
|
-
} catch {}
|
|
98
|
-
}
|
|
99
|
-
function displayDeviceCode(response) {
|
|
100
|
-
stderr("");
|
|
101
|
-
stderr(`To authorize, visit: ${response.verification_uri_complete}`);
|
|
102
|
-
stderr(` and enter code: ${response.user_code}`);
|
|
103
|
-
stderr("");
|
|
104
|
-
stderr("Waiting for authorization...");
|
|
105
|
-
openBrowser(response.verification_uri_complete);
|
|
106
|
-
}
|
|
107
|
-
async function authenticate({ clientId, host }) {
|
|
108
|
-
stderr("No access token provided. Starting device authorization...");
|
|
109
|
-
const deviceCodeResponse = await requestDeviceCode(clientId, host);
|
|
110
|
-
displayDeviceCode(deviceCodeResponse);
|
|
111
|
-
const tokenResponse = await pollForToken({
|
|
112
|
-
deviceCode: deviceCodeResponse.device_code,
|
|
113
|
-
clientId,
|
|
114
|
-
host,
|
|
115
|
-
interval: deviceCodeResponse.interval,
|
|
116
|
-
expiresIn: deviceCodeResponse.expires_in
|
|
117
|
-
});
|
|
118
|
-
stderr(`Successfully authenticated as ${getTokenUserLabel(tokenResponse)}`);
|
|
119
|
-
return tokenResponse;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
//#endregion
|
|
123
|
-
export { DeviceCodeError, authenticate, displayDeviceCode, pollForToken, requestDeviceCode };
|
|
124
|
-
//# sourceMappingURL=device-code-flow-mwBASRbi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"device-code-flow-mwBASRbi.js","names":["message: string","code?: string","clientId: string","host: string","scopes: string","ms: number","msg: string","url: string","response: DeviceCodeResponse"],"sources":["../src/auth/device-code-flow.ts"],"sourcesContent":["import { exec } from \"node:child_process\";\nimport * as fs from \"node:fs\";\nimport { LIB_VERSION } from \"@sentry/mcp-core/version\";\nimport {\n DEVICE_CODE_ENDPOINT,\n DEVICE_CODE_SCOPES,\n SLOW_DOWN_INCREMENT_SEC,\n TOKEN_ENDPOINT,\n} from \"./constants\";\nimport {\n DeviceCodeResponseSchema,\n DeviceCodeErrorSchema,\n TokenResponseSchema,\n getTokenUserLabel,\n type DeviceCodeResponse,\n type TokenResponse,\n} from \"./types\";\n\nconst USER_AGENT = `sentry-mcp-server/${LIB_VERSION}`;\n\nexport class DeviceCodeError extends Error {\n constructor(\n message: string,\n public readonly code?: string,\n ) {\n super(message);\n this.name = \"DeviceCodeError\";\n }\n}\n\nexport async function requestDeviceCode(\n clientId: string,\n host: string,\n scopes: string = DEVICE_CODE_SCOPES,\n): Promise<DeviceCodeResponse> {\n const url = `https://${host}${DEVICE_CODE_ENDPOINT}`;\n const resp = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"User-Agent\": USER_AGENT,\n },\n body: new URLSearchParams({\n client_id: clientId,\n scope: scopes,\n }),\n });\n\n if (!resp.ok) {\n const text = await resp.text();\n throw new DeviceCodeError(\n `Failed to request device code (HTTP ${resp.status}): ${text}`,\n );\n }\n\n const body = await resp.json();\n return DeviceCodeResponseSchema.parse(body);\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport async function pollForToken({\n deviceCode,\n clientId,\n host,\n interval,\n expiresIn,\n}: {\n deviceCode: string;\n clientId: string;\n host: string;\n interval: number;\n expiresIn: number;\n}): Promise<TokenResponse> {\n const url = `https://${host}${TOKEN_ENDPOINT}`;\n const deadline = Date.now() + expiresIn * 1000;\n let pollInterval = interval;\n\n while (Date.now() < deadline) {\n await sleep(pollInterval * 1000);\n\n const resp = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"User-Agent\": USER_AGENT,\n },\n body: new URLSearchParams({\n grant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n device_code: deviceCode,\n client_id: clientId,\n }),\n });\n\n if (resp.ok) {\n const body = await resp.json();\n return TokenResponseSchema.parse(body);\n }\n\n const errorBody = await resp.json().catch(() => null);\n const parsed = DeviceCodeErrorSchema.safeParse(errorBody);\n const errorCode = parsed.success ? parsed.data.error : undefined;\n\n switch (errorCode) {\n case \"authorization_pending\":\n // Keep polling at current interval\n continue;\n case \"slow_down\":\n pollInterval += SLOW_DOWN_INCREMENT_SEC;\n continue;\n case \"access_denied\":\n throw new DeviceCodeError(\n \"Authorization was denied. Please try again or provide --access-token.\",\n errorCode,\n );\n case \"expired_token\":\n throw new DeviceCodeError(\n \"Device code expired before authorization was completed.\",\n errorCode,\n );\n default:\n throw new DeviceCodeError(\n `Unexpected error during device code polling: ${errorCode ?? resp.statusText}`,\n errorCode,\n );\n }\n }\n\n throw new DeviceCodeError(\n \"Device code expired before authorization was completed.\",\n \"expired_token\",\n );\n}\n\n/**\n * Write directly to stderr, bypassing console.warn which may be\n * intercepted by the MCP transport layer.\n */\nfunction stderr(msg: string): void {\n process.stderr.write(`${msg}\\n`);\n}\n\nfunction isWSL(): boolean {\n try {\n return fs\n .readFileSync(\"/proc/version\", \"utf-8\")\n .toLowerCase()\n .includes(\"microsoft\");\n } catch {\n return false;\n }\n}\n\nfunction openBrowser(url: string): void {\n try {\n const { platform } = process;\n if (platform === \"darwin\") {\n exec(`open ${JSON.stringify(url)}`);\n } else if (platform === \"win32\") {\n exec(`start \"\" ${JSON.stringify(url)}`);\n } else if (isWSL()) {\n // WSL: invoke cmd.exe to open the default browser.\n exec(`cmd.exe /c start \"\" ${JSON.stringify(url)}`);\n } else {\n exec(`xdg-open ${JSON.stringify(url)}`);\n }\n } catch {\n // Best-effort — ignore errors (headless, etc.)\n }\n}\n\nexport function displayDeviceCode(response: DeviceCodeResponse): void {\n stderr(\"\");\n stderr(`To authorize, visit: ${response.verification_uri_complete}`);\n stderr(` and enter code: ${response.user_code}`);\n stderr(\"\");\n stderr(\"Waiting for authorization...\");\n\n openBrowser(response.verification_uri_complete);\n}\n\nexport async function authenticate({\n clientId,\n host,\n}: {\n clientId: string;\n host: string;\n}): Promise<TokenResponse> {\n stderr(\"No access token provided. Starting device authorization...\");\n\n const deviceCodeResponse = await requestDeviceCode(clientId, host);\n displayDeviceCode(deviceCodeResponse);\n\n const tokenResponse = await pollForToken({\n deviceCode: deviceCodeResponse.device_code,\n clientId,\n host,\n interval: deviceCodeResponse.interval,\n expiresIn: deviceCodeResponse.expires_in,\n });\n\n stderr(`Successfully authenticated as ${getTokenUserLabel(tokenResponse)}`);\n return tokenResponse;\n}\n"],"mappings":";;;;;;;AAkBA,MAAM,cAAc,oBAAoB;AAExC,IAAa,kBAAb,cAAqC,MAAM;CACzC,YACEA,SACgBC,MAChB;AACA,QAAM,QAAQ;EAFE;AAGhB,OAAK,OAAO;CACb;AACF;AAED,eAAsB,kBACpBC,UACAC,MACAC,SAAiB,oBACY;CAC7B,MAAM,OAAO,UAAU,OAAO;CAC9B,MAAM,OAAO,MAAM,MAAM,KAAK;EAC5B,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,cAAc;EACf;EACD,MAAM,IAAI,gBAAgB;GACxB,WAAW;GACX,OAAO;EACR;CACF,EAAC;AAEF,MAAK,KAAK,IAAI;EACZ,MAAM,OAAO,MAAM,KAAK,MAAM;AAC9B,QAAM,IAAI,iBACP,sCAAsC,KAAK,OAAO,KAAK;CAE3D;CAED,MAAM,OAAO,MAAM,KAAK,MAAM;AAC9B,QAAO,yBAAyB,MAAM,KAAK;AAC5C;AAED,SAAS,MAAMC,IAA2B;AACxC,QAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;AACxD;AAED,eAAsB,aAAa,EACjC,YACA,UACA,MACA,UACA,WAOD,EAA0B;CACzB,MAAM,OAAO,UAAU,OAAO;CAC9B,MAAM,WAAW,KAAK,KAAK,G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