#!/usr/bin/env python3
"""
Generated test file for MCP Tool Error Test
Framework: fastmcp
Execution mode: async
Streaming: no"""

import os
import sentry_sdk
import asyncio

from sentry_sdk.integrations.mcp import MCPIntegration
from fastmcp import FastMCP, Client


sentry_sdk.init(
    dsn=os.environ.get("SENTRY_DSN"),
    traces_sample_rate=1.0,
    send_default_pii=True,
    integrations=[MCPIntegration()],
)

mcp_server = FastMCP("test-server")

# Define MCP tools
@mcp_server.tool()
def failing_tool(input: str) -> str:
    """A tool that always fails"""
    raise Exception("Something went wrong in the tool")


async def main():
    async with Client(mcp_server) as client:
        try:
            result = await client.call_tool("failing_tool", {"input":"test"})
            print(f"Tool result: {result}")
        except Exception as e:
            print(f"Tool error (expected): {type(e).__name__}: {e}")

if __name__ == "__main__":
    with sentry_sdk.start_transaction(op="test", name="MCP Tool Error Test"):
        asyncio.run(main())
    sentry_sdk.flush(timeout=5)
