UNPKG

@coretext-ai/qa-discord-77f3255a-cccf-4fab-b131-c7d49ae1be7c

Version:
1,433 lines 66.2 kB
import axios from 'axios';
import { Logger } from '../services/logger.js';
export class DiscordClient {
    constructor(config) {
        this.config = config;
        // Generate unique session ID for this client instance
        this.sessionId = `discord-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
        // Initialize logger (fallback to console if not provided)
        this.logger = config.logger || new Logger({
            logLevel: 'ERROR',
            component: 'client',
            enableConsole: true,
            enableShipping: false,
            serverName: 'discord-mcp-server'
        });
        this.logger.info('CLIENT_INIT', 'Client instance created', {
            baseUrl: this.resolveBaseUrl(),
            timeout: this.config.timeout || 30000,
            hasRateLimit: !!this.config.rateLimit,
            configKeys: Object.keys(config)
        });
        this.httpClient = axios.create({
            baseURL: this.resolveBaseUrl(),
            timeout: this.config.timeout || 30000,
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'User-Agent': 'discord-mcp-server/1.0.0',
                ...this.getAuthHeaders()
            },
        });
        // Add request interceptor for rate limiting
        if (this.config.rateLimit) {
            this.setupRateLimit(this.config.rateLimit);
        }
        // Add request interceptor for logging
        this.httpClient.interceptors.request.use((config) => {
            this.logger.logRequestStart(config.method?.toUpperCase() || 'GET', `${config.baseURL}${config.url}`, {
                hasData: !!config.data,
                hasParams: !!(config.params && Object.keys(config.params).length > 0),
                headers: Object.keys(config.headers || {})
            });
            if (config.data) {
                this.logger.debug('HTTP_REQUEST_BODY', 'Request body data', {
                    dataType: typeof config.data,
                    dataSize: JSON.stringify(config.data).length
                });
            }
            if (config.params && Object.keys(config.params).length > 0) {
                this.logger.debug('HTTP_REQUEST_PARAMS', 'Query parameters', {
                    paramCount: Object.keys(config.params).length,
                    paramKeys: Object.keys(config.params)
                });
            }
            return config;
        }, (error) => {
            this.logger.error('HTTP_REQUEST_ERROR', 'Request interceptor error', {
                error: error.message,
                code: error.code
            });
            return Promise.reject(error);
        });
        // Add response interceptor for logging and error handling
        this.httpClient.interceptors.response.use((response) => {
            this.logger.logRequestSuccess(response.config?.method?.toUpperCase() || 'GET', `${response.config?.baseURL}${response.config?.url}`, response.status, 0, // Duration will be calculated in endpoint methods
            {
                statusText: response.statusText,
                responseSize: JSON.stringify(response.data).length,
                headers: Object.keys(response.headers || {})
            });
            return response;
        }, (error) => {
            this.logger.logRequestError(error.config?.method?.toUpperCase() || 'GET', `${error.config?.baseURL}${error.config?.url}`, error, 0, // Duration will be calculated in endpoint methods
            {
                hasResponseData: !!error.response?.data
            });
            throw error;
        });
    }
    setupRateLimit(requestsPerMinute) {
        const interval = 60000 / requestsPerMinute; // ms between requests
        let lastRequestTime = 0;
        this.logger.info('RATE_LIMIT_SETUP', 'Rate limiting configured', {
            requestsPerMinute,
            intervalMs: interval
        });
        this.httpClient.interceptors.request.use(async (config) => {
            const now = Date.now();
            const timeSinceLastRequest = now - lastRequestTime;
            if (timeSinceLastRequest < interval) {
                const delayMs = interval - timeSinceLastRequest;
                this.logger.logRateLimit('HTTP_REQUEST', delayMs, {
                    timeSinceLastRequest,
                    requiredInterval: interval
                });
                await new Promise(resolve => setTimeout(resolve, delayMs));
            }
            lastRequestTime = Date.now();
            return config;
        });
    }
    resolveBaseUrl() {
        let baseUrl = 'https://discord.com/api/v10';
        // Handle dynamic domain replacement (e.g., YOUR_DOMAIN placeholder)
        if (baseUrl.includes('YOUR_DOMAIN')) {
            const domainEnvVar = `DISCORD_DOMAIN`;
            const domain = process.env[domainEnvVar];
            if (!domain) {
                throw new Error(`Missing domain configuration. Please set ${domainEnvVar} environment variable.`);
            }
            baseUrl = baseUrl.replace('YOUR_DOMAIN', domain);
            console.error(`[DISCORD] Resolved base URL: ${baseUrl}`);
        }
        return baseUrl;
    }
    getAuthHeaders() {
        // Bearer/API key authentication
        const token = this.config.authToken || this.config['dISCORDACCESSTOKEN'] || process.env.DISCORD_ACCESS_TOKEN;
        if (token) {
            this.logger.logAuthEvent('bearer_auth_setup', true, {
                authType: 'bearer',
                tokenPreview: token.substring(0, 8) + '...',
                header: 'Authorization'
            });
            return {
                'Authorization': `Bearer ${token}`
            };
        }
        this.logger.warn('AUTH_WARNING', 'No authentication token found', {
            authType: 'bearer',
            warning: 'API calls may be rate limited',
            checkedSources: ['config.authToken', 'environment variables']
        });
        return {};
    }
    /**
     * Initialize the client (for OAuth clients that need initialization)
     */
    async initialize() {
        this.logger.debug('CLIENT_INITIALIZE', 'No initialization required for this auth type');
    }
    /**
     * Get the session ID for this client instance
     */
    getSessionId() {
        return this.sessionId;
    }
    /**
     * Make an authenticated request with proper headers
     */
    async makeAuthenticatedRequest(config) {
        return this.httpClient.request(config);
    }
    buildPath(template, params) {
        let path = template;
        for (const [key, value] of Object.entries(params)) {
            path = path.replace(`{${key}}`, encodeURIComponent(String(value)));
        }
        this.logger.debug('PATH_BUILD', 'Built API path from template', {
            template,
            resultPath: path,
            paramCount: Object.keys(params).length,
            paramKeys: Object.keys(params)
        });
        return path;
    }
    async getCurrentUser(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_current_user',
            method: 'GET',
            path: '/users/@me',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/users/@me'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            const path = this.buildPath('/users/@me', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_current_user',
                method: 'GET',
                path: '/users/@me',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_current_user',
                method: 'GET',
                path: '/users/@me',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_current_user: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getUser(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_user',
            method: 'GET',
            path: '/users/{user_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/users/{user_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.user_id) {
                throw new Error(`Missing required parameter: user_id`);
            }
            const path = this.buildPath('/users/{user_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_user',
                method: 'GET',
                path: '/users/{user_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_user',
                method: 'GET',
                path: '/users/{user_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_user: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getCurrentUserGuilds(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_current_user_guilds',
            method: 'GET',
            path: '/users/@me/guilds',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/users/@me/guilds'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            const path = this.buildPath('/users/@me/guilds', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_current_user_guilds',
                method: 'GET',
                path: '/users/@me/guilds',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_current_user_guilds',
                method: 'GET',
                path: '/users/@me/guilds',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_current_user_guilds: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getGuild(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_guild',
            method: 'GET',
            path: '/guilds/{guild_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/guilds/{guild_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.guild_id) {
                throw new Error(`Missing required parameter: guild_id`);
            }
            const path = this.buildPath('/guilds/{guild_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_guild',
                method: 'GET',
                path: '/guilds/{guild_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_guild',
                method: 'GET',
                path: '/guilds/{guild_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_guild: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getGuildChannels(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_guild_channels',
            method: 'GET',
            path: '/guilds/{guild_id}/channels',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/guilds/{guild_id}/channels'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.guild_id) {
                throw new Error(`Missing required parameter: guild_id`);
            }
            const path = this.buildPath('/guilds/{guild_id}/channels', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_guild_channels',
                method: 'GET',
                path: '/guilds/{guild_id}/channels',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_guild_channels',
                method: 'GET',
                path: '/guilds/{guild_id}/channels',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_guild_channels: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async createGuildChannel(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'create_guild_channel',
            method: 'POST',
            path: '/guilds/{guild_id}/channels',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/guilds/{guild_id}/channels'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.guild_id) {
                throw new Error(`Missing required parameter: guild_id`);
            }
            if (!params.name) {
                throw new Error(`Missing required parameter: name`);
            }
            const path = this.buildPath('/guilds/{guild_id}/channels', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.post(path, remainingParams);
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'create_guild_channel',
                method: 'POST',
                path: '/guilds/{guild_id}/channels',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'create_guild_channel',
                method: 'POST',
                path: '/guilds/{guild_id}/channels',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute create_guild_channel: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getChannel(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_channel',
            method: 'GET',
            path: '/channels/{channel_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            const path = this.buildPath('/channels/{channel_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_channel',
                method: 'GET',
                path: '/channels/{channel_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_channel',
                method: 'GET',
                path: '/channels/{channel_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_channel: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async modifyChannel(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'modify_channel',
            method: 'PATCH',
            path: '/channels/{channel_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            const path = this.buildPath('/channels/{channel_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'modify_channel',
                method: 'PATCH',
                path: '/channels/{channel_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'modify_channel',
                method: 'PATCH',
                path: '/channels/{channel_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute modify_channel: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async deleteChannel(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'delete_channel',
            method: 'DELETE',
            path: '/channels/{channel_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            const path = this.buildPath('/channels/{channel_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.delete(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'delete_channel',
                method: 'DELETE',
                path: '/channels/{channel_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'delete_channel',
                method: 'DELETE',
                path: '/channels/{channel_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute delete_channel: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getChannelMessages(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_channel_messages',
            method: 'GET',
            path: '/channels/{channel_id}/messages',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/messages'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            const path = this.buildPath('/channels/{channel_id}/messages', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_channel_messages',
                method: 'GET',
                path: '/channels/{channel_id}/messages',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_channel_messages',
                method: 'GET',
                path: '/channels/{channel_id}/messages',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_channel_messages: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getChannelMessage(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_channel_message',
            method: 'GET',
            path: '/channels/{channel_id}/messages/{message_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/messages/{message_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            if (!params.message_id) {
                throw new Error(`Missing required parameter: message_id`);
            }
            const path = this.buildPath('/channels/{channel_id}/messages/{message_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_channel_message',
                method: 'GET',
                path: '/channels/{channel_id}/messages/{message_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_channel_message',
                method: 'GET',
                path: '/channels/{channel_id}/messages/{message_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_channel_message: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async createMessage(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'create_message',
            method: 'POST',
            path: '/channels/{channel_id}/messages',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/messages'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            const path = this.buildPath('/channels/{channel_id}/messages', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.post(path, remainingParams);
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'create_message',
                method: 'POST',
                path: '/channels/{channel_id}/messages',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'create_message',
                method: 'POST',
                path: '/channels/{channel_id}/messages',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute create_message: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async editMessage(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'edit_message',
            method: 'PATCH',
            path: '/channels/{channel_id}/messages/{message_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/messages/{message_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            if (!params.message_id) {
                throw new Error(`Missing required parameter: message_id`);
            }
            const path = this.buildPath('/channels/{channel_id}/messages/{message_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'edit_message',
                method: 'PATCH',
                path: '/channels/{channel_id}/messages/{message_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'edit_message',
                method: 'PATCH',
                path: '/channels/{channel_id}/messages/{message_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute edit_message: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async deleteMessage(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'delete_message',
            method: 'DELETE',
            path: '/channels/{channel_id}/messages/{message_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/messages/{message_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            if (!params.message_id) {
                throw new Error(`Missing required parameter: message_id`);
            }
            const path = this.buildPath('/channels/{channel_id}/messages/{message_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.delete(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'delete_message',
                method: 'DELETE',
                path: '/channels/{channel_id}/messages/{message_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'delete_message',
                method: 'DELETE',
                path: '/channels/{channel_id}/messages/{message_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute delete_message: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async addReaction(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'add_reaction',
            method: 'PUT',
            path: '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            if (!params.message_id) {
                throw new Error(`Missing required parameter: message_id`);
            }
            if (!params.emoji) {
                throw new Error(`Missing required parameter: emoji`);
            }
            const path = this.buildPath('/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.put(path, remainingParams);
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'add_reaction',
                method: 'PUT',
                path: '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'add_reaction',
                method: 'PUT',
                path: '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute add_reaction: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async removeReaction(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'remove_reaction',
            method: 'DELETE',
            path: '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            if (!params.message_id) {
                throw new Error(`Missing required parameter: message_id`);
            }
            if (!params.emoji) {
                throw new Error(`Missing required parameter: emoji`);
            }
            const path = this.buildPath('/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.delete(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'remove_reaction',
                method: 'DELETE',
                path: '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'remove_reaction',
                method: 'DELETE',
                path: '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute remove_reaction: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getGuildMembers(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_guild_members',
            method: 'GET',
            path: '/guilds/{guild_id}/members',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/guilds/{guild_id}/members'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.guild_id) {
                throw new Error(`Missing required parameter: guild_id`);
            }
            const path = this.buildPath('/guilds/{guild_id}/members', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_guild_members',
                method: 'GET',
                path: '/guilds/{guild_id}/members',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_guild_members',
                method: 'GET',
                path: '/guilds/{guild_id}/members',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_guild_members: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getGuildMember(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_guild_member',
            method: 'GET',
            path: '/guilds/{guild_id}/members/{user_id}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/guilds/{guild_id}/members/{user_id}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.guild_id) {
                throw new Error(`Missing required parameter: guild_id`);
            }
            if (!params.user_id) {
                throw new Error(`Missing required parameter: user_id`);
            }
            const path = this.buildPath('/guilds/{guild_id}/members/{user_id}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_guild_member',
                method: 'GET',
                path: '/guilds/{guild_id}/members/{user_id}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_guild_member',
                method: 'GET',
                path: '/guilds/{guild_id}/members/{user_id}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_guild_member: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async createWebhook(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'create_webhook',
            method: 'POST',
            path: '/channels/{channel_id}/webhooks',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/webhooks'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            if (!params.name) {
                throw new Error(`Missing required parameter: name`);
            }
            const path = this.buildPath('/channels/{channel_id}/webhooks', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.post(path, remainingParams);
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'create_webhook',
                method: 'POST',
                path: '/channels/{channel_id}/webhooks',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'create_webhook',
                method: 'POST',
                path: '/channels/{channel_id}/webhooks',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute create_webhook: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async getChannelWebhooks(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'get_channel_webhooks',
            method: 'GET',
            path: '/channels/{channel_id}/webhooks',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/channels/{channel_id}/webhooks'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.channel_id) {
                throw new Error(`Missing required parameter: channel_id`);
            }
            const path = this.buildPath('/channels/{channel_id}/webhooks', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.get(path, { params: remainingParams });
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'get_channel_webhooks',
                method: 'GET',
                path: '/channels/{channel_id}/webhooks',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'get_channel_webhooks',
                method: 'GET',
                path: '/channels/{channel_id}/webhooks',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute get_channel_webhooks: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
    async executeWebhook(params) {
        const startTime = Date.now();
        this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
            endpoint: 'execute_webhook',
            method: 'POST',
            path: '/webhooks/{webhook_id}/{webhook_token}',
            paramCount: Object.keys(params || {}).length,
            paramKeys: Object.keys(params || {})
        });
        try {
            // Extract path parameters from URL template and separate from query/body params
            const pathParamNames = '/webhooks/{webhook_id}/{webhook_token}'.match(/{([^}]+)}/g) || [];
            const pathParams = {};
            const remainingParams = { ...params };
            // Extract path parameters
            pathParamNames.forEach(paramTemplate => {
                const paramName = paramTemplate.slice(1, -1); // Remove { }
                if (params[paramName] !== undefined) {
                    pathParams[paramName] = params[paramName];
                    delete remainingParams[paramName];
                }
            });
            // Validate required parameters
            if (!params.webhook_id) {
                throw new Error(`Missing required parameter: webhook_id`);
            }
            if (!params.webhook_token) {
                throw new Error(`Missing required parameter: webhook_token`);
            }
            const path = this.buildPath('/webhooks/{webhook_id}/{webhook_token}', pathParams);
            // Use standard HTTP client for other auth types
            const response = await this.httpClient.post(path, remainingParams);
            const duration = Date.now() - startTime;
            this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
                endpoint: 'execute_webhook',
                method: 'POST',
                path: '/webhooks/{webhook_id}/{webhook_token}',
                duration_ms: duration,
                responseDataSize: JSON.stringify(response.data).length
            });
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(response.data, null, 2)
                    }
                ]
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
                endpoint: 'execute_webhook',
                method: 'POST',
                path: '/webhooks/{webhook_id}/{webhook_token}',
                duration_ms: duration,
                error: error instanceof Error ? error.message : String(error),
                errorType: error instanceof Error ? error.constructor.name : 'unknown'
            });
            throw new Error(`Failed to execute execute_webhook: ${error instanceof Error ? error.message : String(error)}`);
        }
    }
}
//# sourceMappingURL=discord-client.js.map