UNPKG

@razorpay/blade-mcp

Version:

Model Context Protocol server for Blade

98 lines 4.78 kB
import { basename } from 'path'; import { z } from 'zod'; import { analyticsToolCallEventName } from '../utils/tokens.js'; import { getBladeDocsList } from '../utils/generalUtils.js'; import { handleError, sendAnalytics } from '../utils/analyticsUtils.js'; import { getBladeDocsResponseText } from '../utils/getBladeDocsResponseText.js'; import { shouldCreateOrUpdateCursorRule } from '../utils/cursorRulesUtils.js'; import { commonBladeMCPToolSchema, httpTransportCursorRuleVersionSchema, } from '../utils/getCommonSchema.js'; const bladeComponentsList = getBladeDocsList('components'); const bladeComponentsListString = bladeComponentsList.join(', '); const getBladeComponentDocsToolName = 'get_blade_component_docs'; const getBladeComponentDocsToolDescription = `Fetch the Blade Design System docs for the given list of components. Use this to get information about the components and their props while adding or changing a component.`; // Schema for stdio transport const getBladeComponentDocsStdioSchema = { componentsList: z .string() .describe(`Comma separated list of semantic blade component names. E.g. "Button, Accordion". Make sure to use the semantic components (like PasswordInput for passwords). Possible values: ${bladeComponentsListString}`), ...commonBladeMCPToolSchema, }; // Schema for HTTP transport const getBladeComponentDocsHttpSchema = { ...getBladeComponentDocsStdioSchema, ...httpTransportCursorRuleVersionSchema, }; // Core business logic function const getBladeComponentDocsCore = ({ componentsList, currentProjectRootDirectory, skipLocalCursorRuleChecks = false, cursorRuleVersion = '0', clientName, }) => { const components = componentsList.split(',').map((s) => s.trim()); const invalidComponents = components.filter((comp) => !bladeComponentsList.includes(comp)); const invalidComponentsString = invalidComponents.join(', '); if (invalidComponents.length > 0) { return handleError({ toolName: getBladeComponentDocsToolName, mcpErrorMessage: `Invalid argument componentsList. Invalid values: ${invalidComponentsString}. Valid component docs values: ${bladeComponentsListString}. Make sure to call the parent component name (e.g. instead of calling ListViewFilters, call ListView)`, }); } // Check cursor rules using shouldCreateOrUpdateCursorRule which handles both file system and version checks if (currentProjectRootDirectory) { const createOrUpdateCursorRule = shouldCreateOrUpdateCursorRule(cursorRuleVersion, clientName, currentProjectRootDirectory, skipLocalCursorRuleChecks, getBladeComponentDocsToolName); if (createOrUpdateCursorRule) { return createOrUpdateCursorRule; } } try { const responseText = getBladeDocsResponseText({ docsList: componentsList, documentationType: 'components', }); // Return the formatted response sendAnalytics({ eventName: analyticsToolCallEventName, properties: { toolName: getBladeComponentDocsToolName, componentsList, rootDirectoryName: currentProjectRootDirectory ? basename(currentProjectRootDirectory) : undefined, cursorRuleVersion, clientName, }, }); return { content: [ { type: 'text', text: responseText.trim(), }, ], }; } catch (error) { return handleError({ toolName: getBladeComponentDocsToolName, errorObject: error, }); } }; // Callback for stdio transport const getBladeComponentDocsStdioCallback = ({ componentsList, currentProjectRootDirectory, clientName, }) => { return getBladeComponentDocsCore({ componentsList, currentProjectRootDirectory, skipLocalCursorRuleChecks: false, // Perform cursor rule checks for stdio clientName, }); }; // Callback for HTTP transport const getBladeComponentDocsHttpCallback = ({ componentsList, cursorRuleVersion, clientName, currentProjectRootDirectory, }) => { return getBladeComponentDocsCore({ componentsList, currentProjectRootDirectory, skipLocalCursorRuleChecks: true, // Skip cursor rule checks for HTTP cursorRuleVersion, clientName, }); }; // Export all at once export { getBladeComponentDocsToolName, getBladeComponentDocsToolDescription, getBladeComponentDocsHttpCallback, getBladeComponentDocsStdioCallback, getBladeComponentDocsStdioSchema, getBladeComponentDocsHttpSchema, }; //# sourceMappingURL=getBladeComponentDocs.js.map