UNPKG

templui-mcp-server

Version:

A Model Context Protocol (MCP) server for TemplUI components, providing AI assistants with access to component source code, documentation, demos, and metadata.

39 lines 1.48 kB
import { cache } from '../utils/cache.js'; import { logError, logInfo } from '../utils/logger.js'; let githubClient; export function setGitHubClient(client) { githubClient = client; } export async function handleGetComponent({ componentName }) { try { logInfo(`Getting source code for component: ${componentName}`); // Check cache first const cacheKey = `component-source:${componentName}`; const cached = await cache.get(cacheKey); if (cached) { logInfo(`Returning cached source for component: ${componentName}`); return { content: [{ type: "text", text: cached }] }; } // Fetch from GitHub const sourceCode = await githubClient.getComponentSource(componentName); // Cache the result await cache.set(cacheKey, sourceCode); logInfo(`Successfully fetched source code for component: ${componentName}`); return { content: [{ type: "text", text: sourceCode }] }; } catch (error) { logError(`Failed to get component "${componentName}"`, error); throw new Error(`Failed to get component "${componentName}": ${error instanceof Error ? error.message : String(error)}`); } } export const schema = { componentName: { type: 'string', description: 'Name of the TemplUI component (e.g., "button", "accordion", "modal")' } }; //# sourceMappingURL=get-component.js.map