import "../../errors-D_R568zP.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 { agentTool } from "../../utils-iC0Uutcf.js";
import { z } from "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 agentTool({
		description: tool.description,
		parameters: 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
export { wrapToolForAgent };
//# sourceMappingURL=tool-wrapper.js.map