Skip to main content
Glama
chatbot.tools.ts7.7 kB
/** * Chatbot Tools for MCP Server */ import { z } from 'zod'; import { ChatbotService } from '../services/chatbot.service.js'; import { logger } from '../utils/logger.js'; import { validateNotEmpty } from '../utils/validation.js'; export function createChatbotTools(chatbotService: ChatbotService) { return { ask_support: { description: 'Ask a support question and get helpful responses with related FAQs and suggested actions', parameters: z.object({ query: z.string().describe('The user\'s question or support query') }), execute: async (args: { query: string }) => { try { logger.info('Processing support query', args); validateNotEmpty(args.query, 'Query'); const response = await chatbotService.getChatbotResponse(args.query); return { content: [ { type: 'text', text: JSON.stringify( { success: true, response: { message: response.message, relatedFAQs: response.relatedFAQs?.map(faq => ({ question: faq.question, answer: faq.answer, category: faq.category })), suggestedActions: response.suggestedActions } }, null, 2 ) } ] }; } catch (error) { logger.error('Failed to process support query', error); return { content: [ { type: 'text', text: JSON.stringify( { success: false, error: error instanceof Error ? error.message : 'Unknown error' }, null, 2 ) } ], isError: true }; } } }, search_faqs: { description: 'Search for FAQs based on keywords or questions', parameters: z.object({ query: z.string().describe('Search query for FAQs'), limit: z.number().optional().default(5).describe('Maximum number of results to return') }), execute: async (args: { query: string; limit?: number }) => { try { logger.info('Searching FAQs', args); validateNotEmpty(args.query, 'Query'); const faqs = chatbotService.searchFAQs(args.query, args.limit || 5); return { content: [ { type: 'text', text: JSON.stringify( { success: true, count: faqs.length, faqs: faqs.map(faq => ({ question: faq.question, answer: faq.answer, category: faq.category })) }, null, 2 ) } ] }; } catch (error) { logger.error('Failed to search FAQs', error); return { content: [ { type: 'text', text: JSON.stringify( { success: false, error: error instanceof Error ? error.message : 'Unknown error' }, null, 2 ) } ], isError: true }; } } }, get_faq_categories: { description: 'Get all available FAQ categories', parameters: z.object({}), execute: async () => { try { logger.info('Getting FAQ categories'); const categories = chatbotService.getCategories(); return { content: [ { type: 'text', text: JSON.stringify( { success: true, categories }, null, 2 ) } ] }; } catch (error) { logger.error('Failed to get FAQ categories', error); return { content: [ { type: 'text', text: JSON.stringify( { success: false, error: error instanceof Error ? error.message : 'Unknown error' }, null, 2 ) } ], isError: true }; } } }, get_faqs_by_category: { description: 'Get all FAQs for a specific category', parameters: z.object({ category: z.string().describe('Category name to filter FAQs') }), execute: async (args: { category: string }) => { try { logger.info('Getting FAQs by category', args); validateNotEmpty(args.category, 'Category'); const faqs = chatbotService.getFAQsByCategory(args.category); return { content: [ { type: 'text', text: JSON.stringify( { success: true, category: args.category, count: faqs.length, faqs: faqs.map(faq => ({ question: faq.question, answer: faq.answer })) }, null, 2 ) } ] }; } catch (error) { logger.error('Failed to get FAQs by category', error); return { content: [ { type: 'text', text: JSON.stringify( { success: false, error: error instanceof Error ? error.message : 'Unknown error' }, null, 2 ) } ], isError: true }; } } }, get_all_faqs: { description: 'Get all available FAQs across all categories', parameters: z.object({}), execute: async () => { try { logger.info('Getting all FAQs'); const faqs = chatbotService.getAllFAQs(); return { content: [ { type: 'text', text: JSON.stringify( { success: true, count: faqs.length, faqs: faqs.map(faq => ({ question: faq.question, answer: faq.answer, category: faq.category })) }, null, 2 ) } ] }; } catch (error) { logger.error('Failed to get all FAQs', error); return { content: [ { type: 'text', text: JSON.stringify( { success: false, error: error instanceof Error ? error.message : 'Unknown error' }, null, 2 ) } ], isError: true }; } } } }; }

Implementation Reference

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/osmarsant/fitslot-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server