mcp-dataverse 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CAPABILITIES.md +92 -33
- package/README.md +35 -20
- package/dist/auth-provider.factory-IVYKBXVY.js +1 -0
- package/dist/chunk-FSM3J3WD.js +35 -0
- package/dist/chunk-KJ3HM2VM.js +1 -0
- package/dist/chunk-M5UROAVJ.js +4 -0
- package/dist/chunk-OQ46VPYS.js +3 -0
- package/dist/chunk-RYRO3QPE.js +29 -0
- package/dist/config.loader-YZJ7QTCV.js +1 -0
- package/dist/dataverse-client-advanced-EASNSX3M.js +1 -0
- package/dist/doctor.js +2 -2
- package/dist/entra-jwt-validator-DABIEBOV.js +2 -0
- package/dist/http-server.js +8 -4
- package/dist/install.js +17 -8
- package/dist/server.js +22 -11
- package/dist/setup-auth.js +1 -1
- package/package.json +3 -2
- package/server.json +3 -3
- package/dist/auth-provider.factory-MSMLSOX3.js +0 -1
- package/dist/chunk-24RDOMG4.js +0 -29
- package/dist/chunk-MPWVUZBX.js +0 -35
- package/dist/chunk-PAX4NW5B.js +0 -1
- package/dist/chunk-SUDI4JM6.js +0 -3
- package/dist/config.loader-VTIKUDN7.js +0 -1
- package/dist/dataverse-client-advanced-ZG4OPCGR.js +0 -1
package/dist/setup-auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as n}from"./chunk-
|
|
2
|
+
import{a as n}from"./chunk-OQ46VPYS.js";import{a as s}from"./chunk-RYRO3QPE.js";import"./chunk-KJ3HM2VM.js";async function t(){process.stderr.write(`MCP Dataverse \u2014 One-time Authentication Setup
|
|
3
3
|
`),process.stderr.write(`\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4
4
|
`);let e=process.argv[2];e&&(process.env.DATAVERSE_ENV_URL=e);let r;try{r=n()}catch{process.stderr.write(`Environment URL is required.
|
|
5
5
|
Usage: npx mcp-dataverse-auth https://yourorg.crm.dynamics.com
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-dataverse",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The most complete MCP server for Microsoft Dataverse.
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "The most complete MCP server for Microsoft Dataverse. 73 production-ready tools for AI agents: OData & FetchXML queries, CRUD, metadata, solutions, audit, batch operations and more. Device code, client credentials, and managed identity auth. Works with VS Code Copilot, Claude, Cursor, Windsurf and all MCP clients.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/server.js",
|
|
7
7
|
"bin": {
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@azure/msal-node": "^2.16.0",
|
|
77
77
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
78
|
+
"jose": "^6.1.3",
|
|
78
79
|
"zod": "^3.23.0"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
package/server.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.codeurali/dataverse",
|
|
4
4
|
"title": "MCP Dataverse",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "73 tools for Microsoft Dataverse: CRUD, FetchXML, metadata, audit, batch, role privileges and more.",
|
|
6
6
|
"icons": [
|
|
7
7
|
{
|
|
8
8
|
"src": "https://raw.githubusercontent.com/codeurali/mcp-dataverse/master/assets/logo.webp",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"source": "github",
|
|
19
19
|
"id": "1163599879"
|
|
20
20
|
},
|
|
21
|
-
"version": "0.
|
|
21
|
+
"version": "0.5.0",
|
|
22
22
|
"packages": [
|
|
23
23
|
{
|
|
24
24
|
"registryType": "npm",
|
|
25
25
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
26
26
|
"identifier": "mcp-dataverse",
|
|
27
|
-
"version": "0.
|
|
27
|
+
"version": "0.5.0",
|
|
28
28
|
"transport": {
|
|
29
29
|
"type": "stdio"
|
|
30
30
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"./chunk-PAX4NW5B.js";import"./chunk-24RDOMG4.js";export{a as createAuthProvider};
|
package/dist/chunk-24RDOMG4.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import{PublicClientApplication as p}from"@azure/msal-node";import{existsSync as d,mkdirSync as m,readFileSync as f,writeFileSync as g}from"fs";import{homedir as v}from"os";import{join as u}from"path";import{exec as y}from"child_process";import{platform as c}from"process";import{createCipheriv as w,createDecipheriv as C,createHash as k,randomBytes as T}from"crypto";function A(n){let e=c==="win32"?`echo|set /p="${n}"| clip`:c==="darwin"?`printf '%s' '${n}' | pbcopy`:`printf '%s' '${n}' | xclip -selection clipboard 2>/dev/null || printf '%s' '${n}' | xsel --clipboard 2>/dev/null`;y(e,()=>{})}var E="1950a258-227b-4e31-a9cf-717495945fc2",h=u(v(),".mcp-dataverse"),a=u(h,"msal-cache.json"),S=300*1e3;function l(){let n=[process.env.COMPUTERNAME??process.env.HOSTNAME??"",process.env.USERNAME??process.env.USER??"","mcp-dataverse-cache-v1"].join(".");return k("sha256").update(n).digest()}function P(n){let e=l(),t=T(16),r=w("aes-256-gcm",e,t),i=Buffer.concat([r.update(n,"utf-8"),r.final()]);return JSON.stringify({v:1,iv:t.toString("hex"),tag:r.getAuthTag().toString("hex"),d:i.toString("hex")})}function x(n){let e=JSON.parse(n);if(e.v!==1)throw new Error("Unknown cache format version");let t=Buffer.from(e.iv,"hex"),r=Buffer.from(e.tag,"hex"),i=Buffer.from(e.d,"hex"),o=C("aes-256-gcm",l(),t);return o.setAuthTag(r),o.update(i).toString("utf-8")+o.final("utf-8")}function b(){return{beforeCacheAccess:async n=>{if(d(a))try{let e=f(a,"utf-8"),t;try{t=x(e)}catch{t=e}n.tokenCache.deserialize(t)}catch{}},afterCacheAccess:async n=>{n.cacheHasChanged&&(m(h,{recursive:!0}),g(a,P(n.tokenCache.serialize()),{encoding:"utf-8",mode:384}))}}}var s=class{environmentUrl;pca;cachedToken=null;tokenExpiresAt=0;pendingAuth=null;constructor(e){this.environmentUrl=e.replace(/\/$/,""),this.pca=new p({auth:{clientId:E,authority:"https://login.microsoftonline.com/common"},cache:{cachePlugin:b()}})}async getToken(){let e=Date.now();return this.cachedToken!==null&&this.tokenExpiresAt>e+6e4?this.cachedToken:this.pendingAuth!==null?this.pendingAuth:(this.pendingAuth=this.refreshToken().finally(()=>{this.pendingAuth=null}),this.pendingAuth)}invalidateToken(){this.cachedToken=null,this.tokenExpiresAt=0}async isAuthenticated(){try{return await this.getToken(),!0}catch{return!1}}async setupViaDeviceCode(){await this.runDeviceCodeFlow()}async refreshToken(){if((await this.pca.getAllAccounts()).length===0){process.stderr.write(`
|
|
2
|
-
[mcp-dataverse] First-time authentication required.
|
|
3
|
-
Environment: ${this.environmentUrl}
|
|
4
|
-
Open the URL below in your browser to sign in.
|
|
5
|
-
|
|
6
|
-
`);try{return await this.runDeviceCodeFlow(),await this.acquireSilently()}catch(t){let r=t instanceof Error?t.message:String(t);throw new Error(`Authentication setup failed: ${r}
|
|
7
|
-
|
|
8
|
-
You can also authenticate manually:
|
|
9
|
-
npx mcp-dataverse-auth ${this.environmentUrl}
|
|
10
|
-
Then restart the MCP server in VS Code.`)}}try{return await this.acquireSilently()}catch{process.stderr.write(`
|
|
11
|
-
[mcp-dataverse] Session expired \u2014 re-authenticating.
|
|
12
|
-
Open the URL below in your browser to sign in again.
|
|
13
|
-
|
|
14
|
-
`);try{return await this.runDeviceCodeFlow(),await this.acquireSilently()}catch(t){this.cachedToken=null;let r=t instanceof Error?t.message:String(t);throw new Error(`Re-authentication failed: ${r}
|
|
15
|
-
|
|
16
|
-
To authenticate manually:
|
|
17
|
-
npx mcp-dataverse-auth ${this.environmentUrl}
|
|
18
|
-
Then restart the MCP server in VS Code.`)}}}async acquireSilently(){let e=await this.pca.getAllAccounts();if(e.length===0)throw new Error("No account found in cache after authentication.");let t=await this.pca.acquireTokenSilent({scopes:[`${this.environmentUrl}/.default`],account:e[0]});if(!t?.accessToken)throw new Error("Token acquisition returned an empty access token.");return this.cacheResult(t),t.accessToken}async runDeviceCodeFlow(){let e=await Promise.race([this.pca.acquireTokenByDeviceCode({scopes:[`${this.environmentUrl}/.default`],deviceCodeCallback:t=>{A(t.userCode),process.stderr.write(`
|
|
19
|
-
[mcp-dataverse] Sign in required
|
|
20
|
-
|
|
21
|
-
1. Open ${t.verificationUri} in your browser
|
|
22
|
-
(use the browser profile linked to your Power Platform account)
|
|
23
|
-
2. Paste the code: ${t.userCode} (already copied to your clipboard)
|
|
24
|
-
3. Sign in with your work account
|
|
25
|
-
|
|
26
|
-
`)}}),new Promise((t,r)=>setTimeout(()=>r(new Error("Authentication timed out after 5 minutes. Please try again.")),S))]);e&&(this.cacheResult(e),process.stderr.write(`
|
|
27
|
-
[mcp-dataverse] Authenticated \u2713 Token cached \u2014 no sign-in needed next time.
|
|
28
|
-
|
|
29
|
-
`))}cacheResult(e){this.cachedToken=e.accessToken,this.tokenExpiresAt=e.expiresOn?.getTime()??Date.now()+3300*1e3}};export{s as a};
|
package/dist/chunk-MPWVUZBX.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
var y=class extends Error{constructor(e,n,s,r,i={}){super(e);this.status=n;this.data=s;this.code=r;this.responseHeaders=i;this.name="HttpError"}},R=class{baseURL;timeoutMs;defaultHeaders;tokenProvider;constructor(t){this.baseURL=t.baseURL.endsWith("/")?t.baseURL:t.baseURL+"/",this.timeoutMs=t.timeout??3e4,this.defaultHeaders={...t.headers},this.tokenProvider=t.tokenProvider??void 0}async get(t,e){return this.request("GET",t,void 0,e)}async post(t,e,n){return this.request("POST",t,e,n)}async patch(t,e,n){return this.request("PATCH",t,e,n)}async put(t,e,n){return this.request("PUT",t,e,n)}async delete(t,e){return this.request("DELETE",t,void 0,e)}resolveUrl(t){if(!t.startsWith("http"))return this.baseURL+t;let e=new URL(t),n=new URL(this.baseURL);if(e.origin!==n.origin)throw new y(`SSRF protection: request to '${e.origin}' blocked; only '${n.origin}' is permitted`,0,void 0,"SSRF_BLOCKED");return t}async request(t,e,n,s){let r=this.resolveUrl(e),i={...this.defaultHeaders,...s?.headers};this.tokenProvider&&(i.Authorization=`Bearer ${await this.tokenProvider()}`);let a=s?.timeoutMs??this.timeoutMs,c=new AbortController,u=setTimeout(()=>c.abort(),a);try{let o={method:t,headers:i,signal:c.signal};n!==void 0&&(o.body=typeof n=="string"?n:JSON.stringify(n));let d=await fetch(r,o),p={};if(d.headers.forEach((g,f)=>{p[f]=g}),!d.ok){let g=await d.text(),f;try{f=JSON.parse(g)}catch{f=g||void 0}throw new y(`Request failed with status ${d.status}`,d.status,f,void 0,p)}let m;if(s?.responseType==="text")m=await d.text();else{let g=await d.text();m=g?JSON.parse(g):{}}return{data:m,status:d.status,headers:p}}catch(o){throw o instanceof y?o:o instanceof DOMException&&o.name==="AbortError"?new y("Request timed out",0,void 0,"ECONNABORTED"):o}finally{clearTimeout(u)}}};function O(h){let t=h.indexOf(`\r
|
|
2
|
-
\r
|
|
3
|
-
`),e=h.indexOf(`
|
|
4
|
-
|
|
5
|
-
`);return t!==-1&&(e===-1||t<=e)?t+4:e!==-1?e+2:-1}function q(h,t){let e=[],n=h.split(`--${t}`);for(let s of n){let r=s.trim();if(!r||r==="--")continue;let i=O(s);if(i===-1)continue;let a=s.slice(i),c=O(a);if(c===-1)continue;let o=(a.trimStart().split(/\r?\n/)[0]??"").match(/^HTTP\/\d+\.\d+\s+(\d{3})/),d=o?parseInt(o[1],10):0,p=d>=200&&d<300,m=a.slice(c).trim();if(!m){e.push(p?null:{error:"Empty response body",status:d});continue}try{let g=JSON.parse(m);e.push(p?g:{error:g,status:d})}catch{e.push({error:m,status:d})}}return e}function l(h){return h.replace(/'/g,"''")}var P="9.2",v={opportunities:"opportunityid",territories:"territoryid",categories:"categoryid",activityparties:"activitypartyid",activitymimeattachments:"activitymimeattachmentid",queues:"queueid",queueitems:"queueitemid"},$=class{http;authProvider;maxRetries;constructor(t,e=3,n=3e4){this.authProvider=t,this.maxRetries=e,this.http=new R({baseURL:`${t.environmentUrl}/api/data/v${P}/`,timeout:n,headers:{"OData-MaxVersion":"4.0","OData-Version":"4.0",Accept:"application/json","Content-Type":"application/json; charset=utf-8"},tokenProvider:()=>t.getToken()})}async requestWithRetry(t,e=0){try{return await t()}catch(n){if(n instanceof y){if(n.status===401&&e===0)return this.authProvider.invalidateToken(),this.requestWithRetry(t,e+1);if([429,503,504].includes(n.status)&&e<this.maxRetries){let r=n.responseHeaders["retry-after"],i=r?parseInt(r,10)*1e3:Math.pow(2,e)*1e3;return await new Promise(a=>setTimeout(a,i)),this.requestWithRetry(t,e+1)}if(n.status===400&&n.data?.error?.code==="0x80071151"&&e<5){let i=Math.pow(2,e)*5e3;return await new Promise(a=>setTimeout(a,i)),this.requestWithRetry(t,e+1)}}throw this.formatError(n)}}formatError(t){if(t instanceof y){let e=t.data?.error;return e?new Error(`Dataverse error ${e.code??""}: ${e.message??"Unknown error"}`):t.code==="ECONNABORTED"?new Error("Request timed out. Check your Dataverse environment URL."):t}return t instanceof Error?t:new Error(String(t))}async whoAmI(){return this.requestWithRetry(async()=>{let t=await this.http.get("WhoAmI"),{UserId:e,BusinessUnitId:n,OrganizationId:s}=t.data,r="";try{r=(await this.http.get(`organizations(${s})?$select=name`)).data.name??""}catch{r=""}let i=this.authProvider.environmentUrl;return{UserId:e,BusinessUnitId:n,OrganizationId:s,OrganizationName:r,EnvironmentUrl:i}})}async listTables(t=!1){let s=["$select=LogicalName,SchemaName,DisplayName,EntitySetName,PrimaryIdAttribute,PrimaryNameAttribute,IsCustomEntity",t?"$filter=IsCustomEntity eq true":""].filter(Boolean).join("&");return this.requestWithRetry(()=>this.http.get(`EntityDefinitions?${s}`).then(r=>r.data.value))}async getTableMetadata(t,e=!0){let n=e?"$expand=Attributes":"",s=`EntityDefinitions(LogicalName='${l(t)}')${n?"?"+n:""}`;return this.requestWithRetry(()=>this.http.get(s).then(r=>r.data))}async fetchAllPagesOData(t){let e=[],n=t;for(;n;){let s=await this.requestWithRetry(()=>this.http.get(n).then(r=>r.data));e.push(...s.value??[]),n=s["@odata.nextLink"]}return e}async getRelationships(t){let e=l(t),[n,s,r]=await Promise.all([this.fetchAllPagesOData(`EntityDefinitions(LogicalName='${e}')/OneToManyRelationships`),this.fetchAllPagesOData(`EntityDefinitions(LogicalName='${e}')/ManyToOneRelationships`),this.fetchAllPagesOData(`EntityDefinitions(LogicalName='${e}')/ManyToManyRelationships`)]);return[...n,...s,...r]}async query(t,e={}){let n=a=>encodeURIComponent(a).replace(/%28/g,"(").replace(/%29/g,")").replace(/%2C/g,",").replace(/%27/g,"'").replace(/%40/g,"@"),s=[];e.select?.length&&s.push(`$select=${e.select.join(",")}`),e.filter&&s.push(`$filter=${n(e.filter)}`),e.orderby&&s.push(`$orderby=${n(e.orderby)}`),e.top&&s.push(`$top=${e.top}`),e.expand&&s.push(`$expand=${e.expand}`),e.count&&s.push("$count=true"),e.apply&&s.push(`$apply=${n(e.apply)}`);let r=`${t}${s.length?"?"+s.join("&"):""}`,i=e.formattedValues?{headers:{Prefer:'odata.include-annotations="OData.Community.Display.V1.FormattedValue"'}}:void 0;return this.requestWithRetry(()=>this.http.get(r,i).then(a=>a.data))}async executeFetchXml(t,e,n){let s=encodeURIComponent(e),r=n?{headers:{Prefer:'odata.include-annotations="OData.Community.Display.V1.FormattedValue"'}}:void 0;return this.requestWithRetry(()=>this.http.get(`${t}?fetchXml=${s}`,r).then(i=>i.data))}async getRecord(t,e,n,s){let r=[];n?.length&&r.push(`$select=${n.join(",")}`),s&&r.push(`$expand=${s}`);let i=r.length?`?${r.join("&")}`:"";return this.requestWithRetry(async()=>{let a=await this.http.get(`${t}(${e})${i}`,{headers:{Prefer:'odata.include-annotations="*"'}}),c=a.headers["odata-etag"]??a.data["@odata.etag"]??null;return{record:a.data,etag:c}})}async createRecord(t,e){return this.requestWithRetry(async()=>{let n=await this.http.post(t,e,{headers:{Prefer:"return=representation"}}),r=n.headers["odata-entityid"]?.match(/\(([^)]+)\)/)?.[1];if(r)return r;let i=n.data,a=i["@odata.id"]?.match(/\(([^)]+)\)/)?.[1];if(a)return a;let c=v[t]??t.replace(/s$/,"")+"id",u=i[c];return u||(n.headers.location?.match(/\(([^)]+)\)/)?.[1]??"")})}async updateRecord(t,e,n,s){await this.requestWithRetry(()=>this.http.patch(`${t}(${e})`,n,{headers:{"If-Match":s??"*"}}))}async deleteRecord(t,e){await this.requestWithRetry(()=>this.http.delete(`${t}(${e})`))}async upsertRecord(t,e,n,s,r="upsert",i){return this.requestWithRetry(async()=>{let a=i?`${t}(${i})`:`${t}(${l(e)}='${l(n)}')`,c={Prefer:"return=representation"};r==="createOnly"&&(c["If-None-Match"]="*"),r==="updateOnly"&&(c["If-Match"]="*");try{let u=await this.http.put(a,s,{headers:c}),o=u.status===201?"created":"updated",p=u.headers["odata-entityid"]?.match(/\(([^)]+)\)/)?.[1],m=u.data,g=v[t]??t.replace(/s$/,"")+"id",f=p??m?.[g]??n;return{operation:o,id:f}}catch(u){if(u instanceof y&&u.status===412){if(r==="createOnly")throw new Error("Record already exists");if(r==="updateOnly")throw new Error("Record not found")}throw u}})}async associate(t,e,n,s,r){let i=`${this.authProvider.environmentUrl}/api/data/v${P}/${s}(${r})`;await this.requestWithRetry(()=>this.http.post(`${t}(${e})/${n}/$ref`,{"@odata.id":i}))}async disassociate(t,e,n,s,r){let i=s?`?$id=${this.authProvider.environmentUrl}/api/data/v${P}/${r??t}(${s})`:"";await this.requestWithRetry(()=>this.http.delete(`${t}(${e})/${n}/$ref${i}`))}};var w=class extends ${async executeAction(t,e={}){return this.requestWithRetry(()=>this.http.post(t,e).then(n=>n.data))}async executeFunction(t,e={}){let n=[],s=[];Object.entries(e).forEach(([a,c])=>{if(typeof c=="object"&&c!==null){let u=`@${a}`;s.push(`${l(a)}=${u}`),n.push(`${u}=${encodeURIComponent(JSON.stringify(c))}`)}else typeof c=="string"?s.push(`${l(a)}='${l(c)}'`):s.push(`${l(a)}=${String(c)}`)});let r=s.length?`${t}(${s.join(",")})`:`${t}()`,i=n.length?`${r}?${n.join("&")}`:r;return this.requestWithRetry(()=>this.http.get(i).then(a=>a.data))}async search(t){let n=`${this.http.baseURL.replace(/\/api\/data\/v[\d.]+\/?$/,"")}/api/search/v2.0/query`;return this.requestWithRetry(()=>this.http.post(n,t).then(s=>s.data))}async executeBoundAction(t,e,n,s={}){return this.requestWithRetry(()=>this.http.post(`${t}(${e})/Microsoft.Dynamics.CRM.${n}`,s).then(r=>r.data))}};var b=class extends w{async listDependencies(t,e){return this.requestWithRetry(()=>this.http.get(`RetrieveDependenciesForDelete(ComponentType=${t},ObjectId=${e})`).then(n=>n.data.value))}async listTableDependencies(t,e){let n={0:"Workflow",1:"Dialog",2:"BusinessRule",3:"Action",4:"BusinessProcessFlow",5:"Flow"},s={0:"Draft",1:"Active",2:"Inactive"},i=(await this.requestWithRetry(()=>this.http.get(`workflows?$filter=primaryentity eq '${l(t)}' and statecode ne 2&$select=name,workflowid,statecode,category,triggeroncreate,triggerondelete,triggeronupdateattributelist`).then(o=>o.data))).value.map(o=>{let d=[];return o.triggeroncreate&&d.push("Create"),o.triggerondelete&&d.push("Delete"),o.triggeronupdateattributelist&&d.push("Update"),{componentType:n[o.category]??`Category${o.category}`,name:o.name,id:o.workflowid,state:s[o.statecode]??`State${o.statecode}`,triggerEvent:d.length?d.join(","):null,solutionName:null}}),a=e?.length?i.filter(o=>e.includes(o.componentType)):i,u=e?.some(o=>o==="Plugin"||o==="CustomAPI")?"Plugin and CustomAPI types require additional SDK message queries and are not yet implemented. Results show Workflow/BusinessRule/Flow/Action dependencies only.":null;return{tableName:t,dependencies:a,count:a.length,warning:u}}async listGlobalOptionSets(){return this.requestWithRetry(()=>this.http.get("GlobalOptionSetDefinitions").then(t=>t.data.value))}async getOptionSet(t){return this.requestWithRetry(()=>this.http.get(`GlobalOptionSetDefinitions(Name='${l(t)}')`).then(e=>e.data))}async getAttributeOptionSet(t,e){let n=["PicklistAttributeMetadata","MultiSelectPicklistAttributeMetadata","StatusAttributeMetadata","StateAttributeMetadata"];for(let s of n)try{let r=`EntityDefinitions(LogicalName='${l(t)}')/Attributes(LogicalName='${l(e)}')/Microsoft.Dynamics.CRM.${s}?$select=LogicalName,DisplayName&$expand=OptionSet`,u=((await this.requestWithRetry(()=>this.http.get(r).then(o=>o.data))).OptionSet?.Options??[]).map(o=>({label:o.Label?.UserLocalizedLabel?.Label??"",value:o.Value}));return{entityLogicalName:t,attributeLogicalName:e,attributeType:s.replace("AttributeMetadata",""),options:u}}catch{continue}throw new Error(`Attribute '${e}' on entity '${t}' is not a Picklist, MultiSelectPicklist, Status, or State attribute, or does not exist.`)}async getEntityKeys(t){return this.requestWithRetry(async()=>(await this.http.get(`EntityDefinitions(LogicalName='${l(t)}')/Keys?$select=SchemaName,LogicalName,KeyAttributes,IsCustomizable,EntityKeyIndexStatus`)).data.value.map(n=>({schemaName:n.SchemaName,logicalName:n.LogicalName,keyAttributes:n.KeyAttributes,isCustomizable:n.IsCustomizable?.Value??!1,indexStatus:n.EntityKeyIndexStatus})))}async updateEntityDefinition(t,e){await this.requestWithRetry(()=>this.http.patch(`EntityDefinitions(LogicalName='${l(t)}')`,e,{headers:{"MSCRM.MergeLabels":"true"}}))}async createAttribute(t,e){return this.requestWithRetry(async()=>(await this.http.post(`EntityDefinitions(LogicalName='${l(t)}')/Attributes`,e,{headers:{Prefer:"return=representation"}})).data.MetadataId??"")}async updateAttribute(t,e,n){await this.requestWithRetry(()=>this.http.put(`EntityDefinitions(LogicalName='${l(t)}')/Attributes(LogicalName='${l(e)}')`,n,{headers:{"MSCRM.MergeLabels":"true"}}))}async deleteAttribute(t,e){await this.requestWithRetry(()=>this.http.delete(`EntityDefinitions(LogicalName='${l(t)}')/Attributes(LogicalName='${l(e)}')`))}async createRelationship(t){return this.requestWithRetry(async()=>(await this.http.post("RelationshipDefinitions",t)).headers["odata-entityid"]?.match(/\(([^)]+)\)$/)?.[1]??"")}};var T=class extends b{async batchExecute(t,e=!1){let n=`batch_${Date.now()}`,s="";if(e){let i=`changeset_${Date.now()+1}`,a=t.filter(u=>u.method==="GET"),c=t.filter(u=>u.method!=="GET");for(let u of a)s+=`--${n}\r
|
|
6
|
-
`,s+=`Content-Type: application/http\r
|
|
7
|
-
`,s+=`Content-Transfer-Encoding: binary\r
|
|
8
|
-
\r
|
|
9
|
-
`,s+=`${u.method} ${this.http.baseURL}${u.url} HTTP/1.1\r
|
|
10
|
-
`,s+=`Accept: application/json\r
|
|
11
|
-
\r
|
|
12
|
-
`;if(c.length>0){s+=`--${n}\r
|
|
13
|
-
`,s+=`Content-Type: multipart/mixed; boundary=${i}\r
|
|
14
|
-
\r
|
|
15
|
-
`;let u=1;for(let o of c)s+=`--${i}\r
|
|
16
|
-
`,s+=`Content-Type: application/http\r
|
|
17
|
-
`,s+=`Content-Transfer-Encoding: binary\r
|
|
18
|
-
`,s+=`Content-ID: ${o.contentId??u++}\r
|
|
19
|
-
\r
|
|
20
|
-
`,s+=`${o.method} ${this.http.baseURL}${o.url} HTTP/1.1\r
|
|
21
|
-
`,s+=`Content-Type: application/json\r
|
|
22
|
-
\r
|
|
23
|
-
`,o.body&&(s+=JSON.stringify(o.body)),s+=`\r
|
|
24
|
-
`;s+=`--${i}--\r
|
|
25
|
-
`}}else t.forEach(i=>{s+=`--${n}\r
|
|
26
|
-
`,s+=`Content-Type: application/http\r
|
|
27
|
-
`,s+=`Content-Transfer-Encoding: binary\r
|
|
28
|
-
\r
|
|
29
|
-
`,s+=`${i.method} ${this.http.baseURL}${i.url} HTTP/1.1\r
|
|
30
|
-
`,s+=`Content-Type: application/json\r
|
|
31
|
-
\r
|
|
32
|
-
`,i.body&&(s+=JSON.stringify(i.body)),s+=`\r
|
|
33
|
-
`});s+=`--${n}--`;let r=await this.requestWithRetry(()=>this.http.post("$batch",s,{headers:{"Content-Type":`multipart/mixed;boundary=${n}`},responseType:"text"}));try{let a=(r.headers["content-type"]??"").match(/boundary=(?:"([^"]+)"|([^;"\s]+))/),c=a?.[1]??a?.[2];return c?q(r.data,c):(process.stderr.write(`[batchExecute] No multipart boundary in response Content-Type; returning raw data.
|
|
34
|
-
`),[r.data])}catch(i){return process.stderr.write(`[batchExecute] Failed to parse multipart response; returning raw data. ${String(i)}
|
|
35
|
-
`),[r.data]}}};var x={1:"Entity",2:"Attribute",3:"Relationship",9:"OptionSet",29:"Workflow",61:"SystemForm",71:"SiteMap",90:"PluginAssembly",92:"PluginType",97:"WebResource",95:"ServiceEndpoint",79:"ConnectionRole"};function k(h){return h.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var E=class extends T{async executeBoundFunction(t,e,n,s={}){let r=[],i=[];Object.entries(s).forEach(([o,d])=>{if(typeof d=="object"&&d!==null){let p=`@${o}`;i.push(`${l(o)}=${p}`),r.push(`${p}=${encodeURIComponent(JSON.stringify(d))}`)}else typeof d=="string"?i.push(`${l(o)}='${l(d)}'`):i.push(`${l(o)}=${String(d)}`)});let a=i.join(","),c=`${t}(${e})/Microsoft.Dynamics.CRM.${n}(${a})`,u=r.length?`${c}?${r.join("&")}`:c;return this.requestWithRetry(()=>this.http.get(u).then(o=>o.data))}async queryWithPaging(t,e={}){let n=Math.min(e.maxTotal??5e3,5e4),s=[],r=0,i={};e.select!==void 0&&(i.select=e.select),e.filter!==void 0&&(i.filter=e.filter),e.orderby!==void 0&&(i.orderby=e.orderby),e.expand!==void 0&&(i.expand=e.expand);let a=await this.query(t,i);for(s.push(...a.value),r++;a["@odata.nextLink"]&&s.length<n;){let u=a["@odata.nextLink"];a=await this.requestWithRetry(()=>this.http.get(u).then(o=>o.data)),s.push(...a.value),r++}let c=s.slice(0,n);return{records:c,totalRetrieved:c.length,pageCount:r}}async getChangedRecords(t,e,n){let s,r={};if(e===null){let p=n?.length?`?$select=${n.join(",")}`:"";s=`${t}${p}`,r.Prefer="odata.track-changes"}else{let p=n?.length?`&$select=${n.join(",")}`:"";s=`${t}?$deltatoken=${e}${p}`}let i=await this.requestWithRetry(()=>this.http.get(s,{headers:r}).then(p=>p.data)),a=i.value??[],c=[],u=[];for(let p of a)if("@removed"in p){let m=String(p["@id"]??""),g=m.match(/\(([^)]+)\)$/);u.push({id:g?g[1]:m})}else c.push(p);let o=i["@odata.deltaLink"],d=null;if(o){let p=o.match(/\$deltatoken=([^&]+)/);d=p?decodeURIComponent(p[1]):null}return{newAndModified:c,deleted:u,nextDeltaToken:d}}async getSolutionComponents(t,e,n=200){return this.requestWithRetry(async()=>{let r=(await this.http.get(`solutions?$filter=uniquename eq '${l(t)}'&$select=solutionid,uniquename,friendlyname,version&$top=1`)).data.value;if(!r.length)throw new Error(`Solution '${t}' not found`);let i=r[0],a=i.solutionid,c=`_solutionid_value eq ${a}`;e!==void 0&&(c+=` and componenttype eq ${e}`);let o=(await this.http.get(`solutioncomponents?$filter=${c}&$select=componenttype,objectid&$top=${n}&$orderby=componenttype`)).data.value.map(d=>({componentType:d.componenttype,componentTypeName:x[d.componenttype]??`Type${d.componenttype}`,objectId:d.objectid}));return{solutionName:i.uniquename,solutionId:a,friendlyName:i.friendlyname,version:i.version,components:o,count:o.length}})}async publishCustomizations(t){return this.requestWithRetry(async()=>{if(!(t&&((t.entities?.length??0)>0||(t.webResources?.length??0)>0||(t.optionSets?.length??0)>0)))return await this.http.post("PublishAllXml",{},{timeoutMs:12e4}),{published:!0,message:"All customizations published successfully"};let n="<importexportxml>";return t.entities?.length&&(n+="<entities>"+t.entities.map(s=>`<entity>${k(s)}</entity>`).join("")+"</entities>"),t.webResources?.length&&(n+="<webresources>"+t.webResources.map(s=>`<webresource>${k(s)}</webresource>`).join("")+"</webresources>"),t.optionSets?.length&&(n+="<optionsets>"+t.optionSets.map(s=>`<optionset>${k(s)}</optionset>`).join("")+"</optionsets>"),n+="</importexportxml>",await this.http.post("PublishXml",{ParameterXml:n},{timeoutMs:12e4}),{published:!0,message:"Selected customizations published successfully"}})}async listDataverseWorkflows(t){return this.requestWithRetry(async()=>{let e=[];t.category!==void 0&&e.push(`category eq ${t.category}`),t.nameContains&&e.push(`contains(name,'${l(t.nameContains)}')`);let n=`workflows?$select=workflowid,name,description,category,statecode,statuscode,type,modifiedon&$orderby=name asc&$top=${t.top??50}`;return e.length>0&&(n+=`&$filter=${e.join(" and ")}`),(await this.http.get(n)).data.value??[]})}async getDataverseWorkflow(t){return this.requestWithRetry(()=>this.http.get(`workflows(${t})?$select=workflowid,name,description,category,statecode,statuscode,type,modifiedon`).then(e=>e.data))}};export{l as a,E as b};
|
package/dist/chunk-PAX4NW5B.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as r}from"./chunk-24RDOMG4.js";function i(e){return new r(e.environmentUrl)}export{i as a};
|
package/dist/chunk-SUDI4JM6.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{readFileSync as v,existsSync as f}from"fs";import{join as u}from"path";import{homedir as g}from"os";import{z as t}from"zod";var c=t.object({environmentUrl:t.string().url("Must be a valid Dataverse environment URL").refine(e=>e.startsWith("https://"),{message:"Dataverse environment URL must use HTTPS"}).refine(e=>{try{return new URL(e).hostname.toLowerCase().endsWith(".dynamics.com")}catch{return!1}},{message:"environmentUrl must be a *.dynamics.com host"}),requestTimeoutMs:t.number().positive().default(3e4),maxRetries:t.number().min(0).max(10).default(3)});var p="config.json";function S(){let e=u(g(),".mcp-dataverse",p),o=process.env.MCP_CONFIG_PATH??(f(e)?e:u(process.cwd(),p)),n={};if(f(o)){let r=v(o,"utf-8");try{n=JSON.parse(r)}catch{throw new Error(`Invalid JSON in ${o}. Check for syntax errors (trailing commas, missing quotes).`)}}let i=process.env.DATAVERSE_ENV_URL??process.env.environmentUrl;i&&(n.environmentUrl=i);let a=process.env.REQUEST_TIMEOUT_MS??process.env.requestTimeoutMs;a&&(n.requestTimeoutMs=Number(a));let m=process.env.MAX_RETRIES??process.env.maxRetries;m&&(n.maxRetries=Number(m));let s=c.safeParse(n);if(!s.success)throw new Error(`Invalid configuration:
|
|
2
|
-
${s.error.issues.map(r=>` - ${r.path.join(".")}: ${r.message}`).join(`
|
|
3
|
-
`)}`);return s.data}export{S as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"./chunk-SUDI4JM6.js";export{a as loadConfig};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as a}from"./chunk-MPWVUZBX.js";export{a as DataverseAdvancedClient};
|