UNPKG

mcp-think-tank

Version:

Structured thinking and knowledge management tool for Model Context Protocol

62 lines (61 loc) 1.83 kB
import { contentCache } from './ContentCache.js'; import * as querystring from 'querystring'; /** * NetworkAdapter provides cached versions of network operations * This implements Story 3-G: Execution cache for file/URL reads */ export class NetworkAdapter { /** * Fetch URL content with caching * @param url URL to fetch * @returns Response data as Buffer */ async fetchUrl(url) { return await contentCache.fetchUrl(url); } /** * Fetch URL content as text with caching * @param url URL to fetch * @param encoding Text encoding (defaults to utf8) * @returns Response data as string */ async fetchText(url, encoding = 'utf8') { const buffer = await contentCache.fetchUrl(url); return buffer.toString(encoding); } /** * Fetch JSON from URL with caching and parsing * @param url URL to fetch * @returns Parsed JSON object */ async fetchJson(url) { return await contentCache.getJson(url, true); } /** * Fetch API endpoint with query parameters * Properly builds URL with query parameters and fetches with caching * @param baseUrl Base API URL * @param params Query parameters * @returns Parsed JSON response */ async fetchApiWithParams(baseUrl, params) { // Build URL with parameters const query = querystring.stringify(params); const fullUrl = query ? `${baseUrl}?${query}` : baseUrl; return await this.fetchJson(fullUrl); } /** * Clear the content cache */ clearCache() { contentCache.clear(); } /** * Get cache statistics */ getCacheStats() { return contentCache.getStats(); } } // Export a singleton instance export const networkAdapter = new NetworkAdapter();