#!/usr/bin/env node
import { DEFAULT_SCOPES } from "./constants-BPM_OWt0.js";
import "./errors-D_R568zP.js";
import "./define-2Lj8Lm1t.js";
import "./url-utils-d9bPTnOl.js";
import "./logging-DqqDTe02.js";
import "./schema-CuB-30t5.js";
import "./errors-CQZ-QlOB.js";
import "./client-CWgvrDHH.js";
import "./types-Bx1EKe0v.js";
import "./api-client-BR5WolLe.js";
import "./validate-region-url-CaR6XWB_.js";
import "./api-CkLTFexT.js";
import "./whoami-Bh_uOPqO.js";
import "./slug-validation-58wajHeL.js";
import "./schema-rwexXWFL.js";
import "./find-organizations-DxH9SS3w.js";
import "./find-teams-D5770X0I.js";
import "./find-projects-DOMBBYAP.js";
import "./find-releases-CfZRMBvh.js";
import "./issue-helpers-8Bubch8E.js";
import "./seer-CderEQ-X.js";
import "./formatting-DytLf-hH.js";
import "./issue-BLm6gohl.js";
import "./enhance-error-D3QfZOhm.js";
import "./get-issue-details-CucQ2nf7.js";
import "./get-trace-details-BL5_jvgs.js";
import "./get-event-attachment-B_BzSfcE.js";
import "./formatting-CAQbf0su.js";
import "./update-issue-CoAkoO66.js";
import { configureOpenAIProvider } from "./openai-provider-CqpHDwSr.js";
import "./callEmbeddedAgent-BSnzLPfW.js";
import "./utils-iC0Uutcf.js";
import "./otel-semantics-CArUzarp.js";
import "./whoami-D8-XCgVJ.js";
import "./utils-CwvZS30K.js";
import "./config-DlhHLHjD.js";
import "./agent-FoPk5psd.js";
import "./formatters-B9XiCNZ_.js";
import "./handler-B3-dKrMX.js";
import "./search-events-Bo5bAsOv.js";
import "./create-team-BQIns3VD.js";
import "./create-project-C0pm6zUK.js";
import "./update-project-CuZlyBPN.js";
import "./create-dsn-Bx2s8Bik.js";
import "./find-dsns-BPN8wnUr.js";
import "./fetch-utils-BetJhSli.js";
import "./analyze-issue-with-seer-DvuKEcbu.js";
import "./search-docs-B9qNTw49.js";
import "./get-doc-D9Xq7et9.js";
import "./dataset-fields-C1o_cZrM.js";
import "./config-BMC-126h.js";
import "./agent-CRc61dcC.js";
import "./formatters-MEWHZ83Y.js";
import "./handler-JBRPTNfu.js";
import "./search-issues-DVHuKDdB.js";
import "./config-CTRUv0J3.js";
import "./agent-tLRcGXXr.js";
import { buildServer } from "./server-CDG3HfVV.js";
import "./error-handling-D_4c-JgK.js";
import { LIB_VERSION } from "./version-BaA5pxTW.js";
import { ALL_SCOPES } from "./permissions-xBjHy6Qx.js";
import "./constraint-helpers-0jgp7p3K.js";
import { startStdio } from "./stdio-BfZ7eu3Q.js";
import { buildUsage } from "./usage-DLck8shg.js";
import { merge, parseArgv, parseEnv } from "./parse-Da0oa8W8.js";
import { finalize } from "./resolve-C95FW12c.js";
import { sentryBeforeSend } from "./sentry-BhTMff8f.js";
import { agent_tools_default } from "./agent-tools-DodmjvZn.js";
import * as Sentry from "@sentry/node";

//#region src/index.ts
const packageName = "@sentry/mcp-server";
const usageText = buildUsage(packageName, DEFAULT_SCOPES, ALL_SCOPES);
function die(message) {
	console.error(message);
	console.error(usageText);
	process.exit(1);
}
const cli = parseArgv(process.argv.slice(2));
if (cli.help) {
	console.log(usageText);
	process.exit(0);
}
if (cli.version) {
	console.log(`${packageName} ${LIB_VERSION}`);
	process.exit(0);
}
if (cli.unknownArgs.length > 0) {
	console.error("Error: Invalid argument(s):", cli.unknownArgs.join(", "));
	console.error(usageText);
	process.exit(1);
}
const env = parseEnv(process.env);
const cfg = (() => {
	try {
		return finalize(merge(cli, env));
	} catch (err) {
		die(err instanceof Error ? err.message : String(err));
	}
})();
if (!process.env.OPENAI_API_KEY) {
	console.warn("Warning: OPENAI_API_KEY environment variable is not set.");
	console.warn("The following AI-powered search tools will be unavailable:");
	console.warn("  - search_events (natural language event search)");
	console.warn("  - search_issues (natural language issue search)");
	console.warn("All other tools will function normally. To enable AI-powered search, set OPENAI_API_KEY.");
	console.warn("");
}
configureOpenAIProvider({ baseUrl: cfg.openaiBaseUrl });
Sentry.init({
	dsn: cfg.sentryDsn,
	sendDefaultPii: true,
	tracesSampleRate: 1,
	beforeSend: sentryBeforeSend,
	initialScope: { tags: {
		"mcp.server_version": LIB_VERSION,
		"mcp.transport": "stdio",
		"mcp.agent_mode": cli.agent ? "true" : "false",
		"sentry.host": cfg.sentryHost,
		"mcp.mcp-url": cfg.mcpUrl
	} },
	release: "0.20.0",
	integrations: [
		Sentry.consoleLoggingIntegration(),
		Sentry.zodErrorsIntegration(),
		Sentry.vercelAIIntegration({
			recordInputs: true,
			recordOutputs: true
		})
	],
	environment: "stdio"
});
if (cli.agent) {
	console.warn("Agent mode enabled: Only use_sentry tool is available.");
	console.warn("The use_sentry tool provides access to all Sentry operations through natural language.");
	console.warn("");
}
const SENTRY_TIMEOUT = 5e3;
const context = {
	accessToken: cfg.accessToken,
	grantedScopes: cfg.finalScopes,
	constraints: {
		organizationSlug: cfg.organizationSlug ?? null,
		projectSlug: cfg.projectSlug ?? null
	},
	sentryHost: cfg.sentryHost,
	mcpUrl: cfg.mcpUrl,
	openaiBaseUrl: cfg.openaiBaseUrl
};
const server = buildServer({
	context,
	tools: cli.agent ? agent_tools_default : void 0
});
startStdio(server, context).catch((err) => {
	console.error("Server error:", err);
	Sentry.flush(SENTRY_TIMEOUT);
	process.exit(1);
});
Sentry.flush(SENTRY_TIMEOUT);

//#endregion
//# sourceMappingURL=index.js.map