const require_chunk = require('../../chunk-DWy1uDak.cjs');
require('../../errors-BtJEw2Z-.cjs');
require('../../url-utils-Bn5EoScr.cjs');
require('../../logging-CkAJKyq2.cjs');
require('../../schema-DoWJbcHt.cjs');
require('../../errors-Bmqdg5Q6.cjs');
require('../../client-C2TwbSm-.cjs');
require('../../types-D10T4PdD.cjs');
require('../../api-client-BsHWi0-I.cjs');
const require_utils = require('../../utils-DUJcA3eH.cjs');
const zod = require_chunk.__toESM(require("zod"));

//#region src/tools/use-sentry/tool-wrapper.ts
/**
* Helper to inject constrained parameters into tool calls.
* This applies session-level constraints (org, project, region) to tool parameters.
*/
function injectConstrainedParams(params, constraints) {
	const result = { ...params };
	if (constraints.organizationSlug && !result.organizationSlug) result.organizationSlug = constraints.organizationSlug;
	if (constraints.projectSlug) {
		if (!result.projectSlug) result.projectSlug = constraints.projectSlug;
		if (!result.projectSlugOrId) result.projectSlugOrId = constraints.projectSlug;
	}
	if (constraints.regionUrl && !result.regionUrl) result.regionUrl = constraints.regionUrl;
	return result;
}
/**
* Wraps any MCP tool to work with the embedded agent pattern.
*
* This function:
* 1. Takes a tool definition with its handler
* 2. Creates an agentTool-wrapped version
* 3. Pre-binds ServerContext so the agent doesn't need it
* 4. Applies session constraints automatically
* 5. Handles errors via agentTool's error handling
*
* @param tool - The MCP tool to wrap (from defineTool)
* @param options - Context and configuration for the tool
* @returns An agentTool-wrapped version ready for use by the embedded agent
*
* @example
* ```typescript
* const whoami = wrapToolForAgent(whoamiTool, { context });
* const findOrgs = wrapToolForAgent(findOrganizationsTool, { context });
* ```
*/
function wrapToolForAgent(tool, options) {
	return require_utils.agentTool({
		description: tool.description,
		parameters: zod.z.object(tool.inputSchema),
		execute: async (params) => {
			const fullParams = injectConstrainedParams(params, options.context.constraints);
			const result = await tool.handler(fullParams, options.context);
			return result;
		}
	});
}

//#endregion
exports.wrapToolForAgent = wrapToolForAgent;
//# sourceMappingURL=tool-wrapper.cjs.map