UNPKG

@progress/telerik-blazor-mcp

Version:

Model Context Protocol for Blazor

20 lines (17 loc) 6.65 kB
#!/usr/bin/env node var L=Object.defineProperty;var N=(e,o,r)=>o in e?L(e,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[o]=r;var d=(e,o,r)=>N(e,typeof o!="symbol"?o+"":o,r);import{McpServer as F}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as V}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as k}from"zod";var S="Telerik UI for Blazor",g="blazor",y=["AIPrompt","AnimationContainer","AppBar","ArcGauge","AutoComplete","Avatar","Badge","Barcode","Breadcrumb","Button","ButtonGroup","Calendar","Card","Carousel","Charts","Checkbox","Chip","ChipList","ChunkProgressBar","CircularGauge","ColorGradient","ColorPalette","ColorPicker","ComboBox","ContextMenu","DateInput","DatePicker","DateRangePicker","DateTimePicker","Diagram","Dialog","DockManager","Drawer","DropDownButton","DropDownList","DropZone","Editor","FileManager","FileSelect","Filter","FlatColorPicker","FloatingActionButton","FloatingLabel","FontIcon","Form","Gantt","Grid","GridLayout","InlineAIPrompt","InstallerandVSExtensions","LinearGauge","ListBox","ListView","Loader","LoaderContainer","Map","MaskedTextBox","MediaQuery","Menu","MultiColumnComboBox","MultiSelect","Notification","NumericTextBox","PageTemplatesAndBuildingBlocks","Pager","PanelBar","PDFViewer","PivotGrid","Popover","Popup","ProgressBar","QRCode","RadialGauge","RadioGroup","RangeSlider","Rating","Sankey","Scheduler","Signature","Skeleton","Slider","SpeechToTextButton","SplitButton","Splitter","Spreadsheet","StackLayout","Stepper","StockChart","SvgIcon","Switch","TabStrip","TextArea","TextBox","TileLayout","TimePicker","ToggleButton","ToolBar","Tooltip","TreeList","TreeView","Upload","ValidationMessage","ValidationSummary","ValidationTooltip","VSCodeExtension","Window","Wizard","General"];import{dirname as R,join as B}from"path";import{fileURLToPath as b}from"url";import{readFileSync as w}from"node:fs";import a from"node:fs";import p from"node:path";import U from"@grpc/proto-loader";import c from"@grpc/grpc-js";var E=["TELERIK_LICENSE","KENDO_UI_LICENSE"],T="TELERIK_LICENSE_PATH",l=(e=>(e[e.UNAUTHENTICATED=16]="UNAUTHENTICATED",e[e.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",e[e.PERMISSION_DENIED=7]="PERMISSION_DENIED",e))(l||{}),f=!1,n=process.env.DEBUG_LOG_FILE,I=!!(n&&typeof n=="string");if(I){let e=p.resolve(n),o=p.dirname(e);if(o!=="."&&o!==process.cwd()&&!a.existsSync(o))try{a.mkdirSync(o,{recursive:!0})}catch(r){console.error("Error creating log directory:",r)}if(!a.existsSync(e))try{a.writeFileSync(e,"")}catch(r){console.error("Error creating log file:",r)}}else f=!1;f=I&&!!n&&a.existsSync(p.resolve(n));function i(...e){if(f&&n){let o=`${new Date().toISOString()}: ${e.join(" ")} `,r=p.resolve(n);a.appendFile(r,o,t=>{t&&console.error("Error writing to log file:",t)})}}var s=process.env[T],m=process.env[E[0]]||process.env[E[1]],u=class extends Error{constructor(e){super(e),this.name="LicenseError"}};function D(){if(!s&&!m)throw new u(`No license found. Please set one of the following environment variables: ${E.join(", ")} or ${T}`);let e;if(s)try{e=w(s,"utf8"),i("License key read from file: ",s)}catch{throw new u(`Error reading license file: ${s}. Please verify the file exists and is readable.`)}return m&&(e=m,i("License key read from environment variable.")),e}var _=class{constructor(e,o){d(this,"client");d(this,"isDev");this.contextApiUrl=e,this.protoPath=o;let r=U.loadSync(this.protoPath,{keepCase:!0,longs:String,enums:String,defaults:!0,oneofs:!0});this.isDev=this.contextApiUrl?.includes("localhost")||this.contextApiUrl?.includes("127.0.0.1"),i("Using ContextApi URl:",this.contextApiUrl);let t=c.loadPackageDefinition(r);this.client=new t.ContextQueryService(this.contextApiUrl||"contextapi.telerik.com:443",this.isDev?c.credentials.createInsecure():c.credentials.createSsl())}async query(e){let o=this.isDev?"fake_license":D(),r=new c.Metadata;if(o&&typeof o=="string"){o=o.replace(/^\uFEFF/,"");try{r.add("x-license-key",o)}catch(t){return i("Error adding license key to metadata:",t),Promise.reject(new Error(`Failed to use license key: ${t.message}`))}}return o&&typeof o=="string"&&r.add("x-license-key",o),new Promise((t,A)=>{this.client.query(e,r,(h,P)=>{h?A(h):t(P)})})}};var M=B(R(b(import.meta.url)),"../proto/service.proto"),O=new _("contextapi.telerik.com:443",M);async function C(e){return O.query(e)}import z from"fs";import x from"path";import{fileURLToPath as G}from"url";var H=G(import.meta.url),q=x.dirname(H),$=x.resolve(q,"../package.json"),J=JSON.parse(z.readFileSync($,"utf-8")),v=new F({name:"telerik-and-kendo-resources",version:J.version});v.tool("telerik_blazor_assistant",`Answers questions and retrieves documentation about Telerik UI for Blazor. Use this tool when the user asks about Telerik UI for Blazor features, specific components (e.g., Grid, Chart, Editor), implementation details, or general usage. Provide the user's detailed question as the 'query'. If the question pertains to a specific Telerik UI for Blazor component, specify its name in the 'component' parameter. This tool can be automatically triggered when the following phrases are detected in the user's input/prompt: - 'Telerik'; - '/telerik'; - '/telerikblazor' - '/ask_telerik'; - '/help_telerik'; - '@telerik'; - '@telerikblazor'; - '@ask_telerik'; - '@help_telerik'.`,{query:k.string().describe("The query to search for."),component:k.enum(y).describe("The component to search for. If not specified, you can use General.")},async({query:e,component:o})=>{i("Calling tool: ",JSON.stringify({query:e,component:o}));try{let r=await C({query:e,component:o.toLocaleLowerCase(),lib_name:g,text_matches_count:3,code_matches_count:0,allowed_types:["documentation"]});i("Response from context API: ",JSON.stringify(r));let t=[{type:"text",text:r.values.join(` `)}];return i("Response from tool: ",JSON.stringify(t)),{content:t}}catch(r){throw i("Error calling context API: ",JSON.stringify(r)),r?.code===l.UNAUTHENTICATED?new Error("Error: You are not authenticated. Please verify the Telerik License Key provided is valid."):r?.code===l.RESOURCE_EXHAUSTED?new Error(`Error: You have exceeded the extension quota. Upgrade to subscription licensing in order to unlock full access. Message: ${r.message}.`):r?.code===l.PERMISSION_DENIED?new Error(`Error: You do not have permission to access this resource. Please verify that you have a valid ${S} license key.`):r instanceof u?(i("License error: ",r.message),r):new Error(`Error: An error occurred while calling the service. Please try again later. Error Message: ${r.message}`)}});async function K(){let e=new V;i("Starting server..."),await v.connect(e)}K();