UNPKG

@progress/kendo-angular-mcp

Version:

Model Context Protocol for Kendo UI for Angular

20 lines (17 loc) 6.6 kB
#!/usr/bin/env node var _=Object.defineProperty;var D=(e,r,o)=>r in e?_(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o;var d=(e,r,o)=>D(e,typeof r!="symbol"?r+"":r,o);import{McpServer as M}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as O}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as C}from"zod";var h="Kendo UI for Angular",g="angular",S=["AIPrompt","ActionSheet","AppBar","ArcGauge","AutoComplete","Avatar","Badge","Barcode","BottomNavigation","BreadCrumb","Button","ButtonGroup","Calendar","Card","ChartWizard","Charts","CheckBox","Chip","ChipList","ChunkProgressBar","CircularGauge","CircularProgressBar","ColorGradient","ColorPalette","ColorPicker","ComboBox","ContextMenu","ConversationalUI","DataQuery","DateInput","DateMath","DatePicker","DateRange","DateTimePicker","Dialog","DragandDrop","Drawer","Drawing","DropDownButton","DropDownList","DropDownTree","Editor","ExcelExport","ExpansionPanel","FileSaver","FileSelect","Filter","FlatColorPicker","FloatingActionButton","FloatingLabel","Forms","FormField","Gantt","Gauges","General","Grid","GridLayout","Icon","Label","LinearGauge","ListBox","ListView","Loader","Map","MaskedTextBox","Menu","MultiColumnComboBox","MultiSelect","MultiSelectTree","MultiViewCalendar","Notification","NumericTextBox","OTPInput","Pager","PanelBar","PDFExport","PDFViewer","PivotGrid","Popover","Popup","ProgressBar","QRCode","RadialGauge","RadioButton","RangeSlider","Rating","Ripple","Sankey","Scheduler","ScrollView","Signature","Skeleton","Slider","Sortable","StockChart","Sparkline","SplitButton","Splitter","Spreadsheet","StackLayout","Stepper","SVGIcon","Switch","TabStrip","TextArea","TextBox","TileLayout","Timeline","TimePicker","ToolBar","Tooltip","TreeList","TreeView","Typography","Upload","Window"];import{dirname as R,join as B}from"path";import{fileURLToPath as G}from"url";import{readFileSync as L}from"node:fs";import a from"node:fs";import p from"node:path";import N from"@grpc/proto-loader";import l from"@grpc/grpc-js";var E=["TELERIK_LICENSE","KENDO_UI_LICENSE"],y="TELERIK_LICENSE_PATH",c=(e=>(e[e.UNAUTHENTICATED=16]="UNAUTHENTICATED",e[e.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",e[e.PERMISSION_DENIED=7]="PERMISSION_DENIED",e))(c||{}),v=!1,i=process.env.DEBUG_LOG_FILE,x=!!(i&&typeof i=="string");if(x){let e=p.resolve(i),r=p.dirname(e);if(r!=="."&&r!==process.cwd()&&!a.existsSync(r))try{a.mkdirSync(r,{recursive:!0})}catch(o){console.error("Error creating log directory:",o)}if(!a.existsSync(e))try{a.writeFileSync(e,"")}catch(o){console.error("Error creating log file:",o)}}v=x&&!!i&&a.existsSync(p.resolve(i));function n(...e){if(v&&i){let r=`${new Date().toISOString()}: ${e.join(" ")} `,o=p.resolve(i);a.appendFile(o,r,t=>{t&&console.error("Error writing to log file:",t)})}}var s=process.env[y],m=process.env[E[0]]||process.env[E[1]],u=class extends Error{constructor(e){super(e),this.name="LicenseError"}};function U(){if(!s&&!m)throw new u(`No license found. Please set one of the following environment variables: ${E.join(", ")} or ${y}`);let e;if(s)try{e=L(s,"utf8"),n("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,n("License key read from environment variable.")),e}var A=class{constructor(e,r){d(this,"client");d(this,"isDev");this.contextApiUrl=e,this.protoPath=r;let o=N.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"),n("Using ContextApi URl:",this.contextApiUrl);let t=l.loadPackageDefinition(o);this.client=new t.ContextQueryService(this.contextApiUrl||"contextapi.telerik.com:443",this.isDev?l.credentials.createInsecure():l.credentials.createSsl())}async query(e){let r=this.isDev?"fake_license":U(),o=new l.Metadata;if(r&&typeof r=="string"){r=r.replace(/^\uFEFF/,"");try{o.add("x-license-key",r)}catch(t){return n("Error adding license key to metadata:",t),Promise.reject(new Error(`Failed to use license key: ${t.message}`))}}return r&&typeof r=="string"&&o.add("x-license-key",r),new Promise((t,P)=>{this.client.query(e,o,(f,I)=>{f?P(f):t(I)})})}};var F=B(R(G(import.meta.url)),"../proto/service.proto"),b=new A("staging.contextapi.telerik.com:443",F);async function w(e){return b.query(e)}import q from"fs";import k from"path";import{fileURLToPath as V}from"url";var $=V(import.meta.url),H=k.dirname($),K=k.resolve(H,"../package.json"),j=JSON.parse(q.readFileSync(K,"utf-8")),T=new M({name:"kendo-and-kendo-resources",version:j.version});T.tool("kendo_angular_assistant",`Answers questions and retrieves documentation about Kendo UI for Angular. Use this tool when the user asks about Kendo UI for Angular features, specific components (e.g., Grid, Charts, Editor), implementation details, or general usage. Provide the user's detailed question as the 'query'. If the question pertains to a specific Kendo UI for Angular 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: - 'kendo'; - '/kendo'; - '/kendoangular' - '/ask_kendo'; - '/help_kendo'; - '@kendo'; - '@kendoangular'; - '@ask_kendo'; - '@help_kendo'.`,{query:C.string().describe("The query to search for."),component:C.enum(S).describe("The component to search for. If not specified, you can use General.")},async({query:e,component:r})=>{n("Calling tool: ",JSON.stringify({query:e,component:r}));try{let t=[{type:"text",text:(await w({query:e,component:r.toLocaleLowerCase(),lib_name:g,text_matches_count:3,code_matches_count:0,allowed_types:["documentation"]})).values.join(` `)}];return n("Response from tool: ",JSON.stringify(t)),{content:t}}catch(o){throw n("Error calling context API: ",JSON.stringify(o)),o?.code===c.UNAUTHENTICATED?new Error("Error: You are not authenticated. Please verify the Telerik License Key provided is valid."):o?.code===c.RESOURCE_EXHAUSTED?new Error(`Error: You have exceeded the extension quota. Upgrade to subscription licensing in order to unlock full access. Message: ${o.message}.`):o?.code===c.PERMISSION_DENIED?new Error(`Error: You do not have permission to access this resource. Please verify that you have a valid ${h} license key.`):o instanceof u?(n("License error: ",o.message),o):new Error(`Error: An error occurred while calling the service. Please try again later. Error Message: ${o.message}`)}});async function J(){let e=new O;n("Starting server..."),await T.connect(e)}J();