UNPKG

purchase-mcp-server

Version:

Purchase and budget management server handling requisitions, purchase orders, expenses, budgets, and vendor management with ERP access for data extraction

45 lines 1.67 kB
import { config } from "../utils/config.js"; import { logger } from "../utils/logger.js"; import axios from "axios"; export class SearchToolHandler { constructor() { this.GOOGLE_SEARCH_API_KEY = config.googleApiKey || ''; this.GOOGLE_SEARCH_ENGINE_ID = config.googleSearchEngineId || ''; } async googleSearch(arguments_) { const { query, num_results } = arguments_; if (!query) { throw new Error("Search query is required"); } try { const response = await axios.get('https://www.googleapis.com/customsearch/v1', { params: { key: this.GOOGLE_SEARCH_API_KEY, cx: this.GOOGLE_SEARCH_ENGINE_ID, q: query, num: num_results || 10 } }); const searchResults = response.data.items || []; const formattedResults = searchResults.map((result) => ({ title: result.title, link: result.link, snippet: result.snippet })); return [{ type: "text", text: JSON.stringify(formattedResults, null, 2), title: `Search results for: ${query}` }]; } catch (error) { logger.error(`Error performing Google search for query "${query}":`, error); return [{ type: "text", text: `Error performing search: ${error.message}`, title: "Search Error" }]; } } } //# sourceMappingURL=searchTools.js.map