mcp-dataverse 0.1.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/.env.example +15 -0
- package/CAPABILITIES.md +992 -0
- package/LICENSE +21 -0
- package/README.md +277 -0
- package/config.example.json +11 -0
- package/dist/auth/auth-provider.factory.d.ts +4 -0
- package/dist/auth/auth-provider.factory.d.ts.map +1 -0
- package/dist/auth/auth-provider.factory.js +15 -0
- package/dist/auth/auth-provider.factory.js.map +1 -0
- package/dist/auth/auth-provider.interface.d.ts +21 -0
- package/dist/auth/auth-provider.interface.d.ts.map +1 -0
- package/dist/auth/auth-provider.interface.js +2 -0
- package/dist/auth/auth-provider.interface.js.map +1 -0
- package/dist/auth/msal-auth-provider.d.ts +14 -0
- package/dist/auth/msal-auth-provider.d.ts.map +1 -0
- package/dist/auth/msal-auth-provider.js +62 -0
- package/dist/auth/msal-auth-provider.js.map +1 -0
- package/dist/auth/pac-auth-provider.d.ts +19 -0
- package/dist/auth/pac-auth-provider.d.ts.map +1 -0
- package/dist/auth/pac-auth-provider.js +153 -0
- package/dist/auth/pac-auth-provider.js.map +1 -0
- package/dist/config/config.loader.d.ts +3 -0
- package/dist/config/config.loader.d.ts.map +1 -0
- package/dist/config/config.loader.js +52 -0
- package/dist/config/config.loader.js.map +1 -0
- package/dist/config/config.schema.d.ts +34 -0
- package/dist/config/config.schema.d.ts.map +1 -0
- package/dist/config/config.schema.js +25 -0
- package/dist/config/config.schema.js.map +1 -0
- package/dist/dataverse/dataverse-client-advanced.d.ts +47 -0
- package/dist/dataverse/dataverse-client-advanced.d.ts.map +1 -0
- package/dist/dataverse/dataverse-client-advanced.js +147 -0
- package/dist/dataverse/dataverse-client-advanced.js.map +1 -0
- package/dist/dataverse/dataverse-client.d.ts +49 -0
- package/dist/dataverse/dataverse-client.d.ts.map +1 -0
- package/dist/dataverse/dataverse-client.js +313 -0
- package/dist/dataverse/dataverse-client.js.map +1 -0
- package/dist/dataverse/dataverse-client.metadata.d.ts +40 -0
- package/dist/dataverse/dataverse-client.metadata.d.ts.map +1 -0
- package/dist/dataverse/dataverse-client.metadata.js +121 -0
- package/dist/dataverse/dataverse-client.metadata.js.map +1 -0
- package/dist/dataverse/dataverse-client.utils.d.ts +14 -0
- package/dist/dataverse/dataverse-client.utils.d.ts.map +1 -0
- package/dist/dataverse/dataverse-client.utils.js +65 -0
- package/dist/dataverse/dataverse-client.utils.js.map +1 -0
- package/dist/dataverse/http-client.d.ts +36 -0
- package/dist/dataverse/http-client.d.ts.map +1 -0
- package/dist/dataverse/http-client.js +103 -0
- package/dist/dataverse/http-client.js.map +1 -0
- package/dist/dataverse/types.d.ts +68 -0
- package/dist/dataverse/types.d.ts.map +1 -0
- package/dist/dataverse/types.js +2 -0
- package/dist/dataverse/types.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +165 -0
- package/dist/server.js.map +1 -0
- package/dist/setup-auth.d.ts +2 -0
- package/dist/setup-auth.d.ts.map +1 -0
- package/dist/setup-auth.js +29 -0
- package/dist/setup-auth.js.map +1 -0
- package/dist/tools/actions.tools.d.ts +170 -0
- package/dist/tools/actions.tools.d.ts.map +1 -0
- package/dist/tools/actions.tools.js +179 -0
- package/dist/tools/actions.tools.js.map +1 -0
- package/dist/tools/annotations.tools.d.ts +82 -0
- package/dist/tools/annotations.tools.d.ts.map +1 -0
- package/dist/tools/annotations.tools.js +180 -0
- package/dist/tools/annotations.tools.js.map +1 -0
- package/dist/tools/audit.tools.d.ts +45 -0
- package/dist/tools/audit.tools.d.ts.map +1 -0
- package/dist/tools/audit.tools.js +163 -0
- package/dist/tools/audit.tools.js.map +1 -0
- package/dist/tools/auth.tools.d.ts +17 -0
- package/dist/tools/auth.tools.d.ts.map +1 -0
- package/dist/tools/auth.tools.js +30 -0
- package/dist/tools/auth.tools.js.map +1 -0
- package/dist/tools/batch.tools.d.ts +45 -0
- package/dist/tools/batch.tools.d.ts.map +1 -0
- package/dist/tools/batch.tools.js +71 -0
- package/dist/tools/batch.tools.js.map +1 -0
- package/dist/tools/crud.tools.d.ts +206 -0
- package/dist/tools/crud.tools.d.ts.map +1 -0
- package/dist/tools/crud.tools.js +213 -0
- package/dist/tools/crud.tools.js.map +1 -0
- package/dist/tools/customization.tools.d.ts +75 -0
- package/dist/tools/customization.tools.d.ts.map +1 -0
- package/dist/tools/customization.tools.js +187 -0
- package/dist/tools/customization.tools.js.map +1 -0
- package/dist/tools/environment.tools.d.ts +40 -0
- package/dist/tools/environment.tools.d.ts.map +1 -0
- package/dist/tools/environment.tools.js +145 -0
- package/dist/tools/environment.tools.js.map +1 -0
- package/dist/tools/file.tools.d.ts +61 -0
- package/dist/tools/file.tools.d.ts.map +1 -0
- package/dist/tools/file.tools.js +142 -0
- package/dist/tools/file.tools.js.map +1 -0
- package/dist/tools/impersonate.tools.d.ts +37 -0
- package/dist/tools/impersonate.tools.d.ts.map +1 -0
- package/dist/tools/impersonate.tools.js +85 -0
- package/dist/tools/impersonate.tools.js.map +1 -0
- package/dist/tools/metadata.tools.d.ts +156 -0
- package/dist/tools/metadata.tools.d.ts.map +1 -0
- package/dist/tools/metadata.tools.js +200 -0
- package/dist/tools/metadata.tools.js.map +1 -0
- package/dist/tools/org.tools.d.ts +26 -0
- package/dist/tools/org.tools.d.ts.map +1 -0
- package/dist/tools/org.tools.js +57 -0
- package/dist/tools/org.tools.js.map +1 -0
- package/dist/tools/quality.tools.d.ts +30 -0
- package/dist/tools/quality.tools.d.ts.map +1 -0
- package/dist/tools/quality.tools.js +69 -0
- package/dist/tools/quality.tools.js.map +1 -0
- package/dist/tools/query.tools.d.ts +120 -0
- package/dist/tools/query.tools.d.ts.map +1 -0
- package/dist/tools/query.tools.js +182 -0
- package/dist/tools/query.tools.js.map +1 -0
- package/dist/tools/relations.tools.d.ts +65 -0
- package/dist/tools/relations.tools.d.ts.map +1 -0
- package/dist/tools/relations.tools.js +64 -0
- package/dist/tools/relations.tools.js.map +1 -0
- package/dist/tools/search.tools.d.ts +68 -0
- package/dist/tools/search.tools.d.ts.map +1 -0
- package/dist/tools/search.tools.js +134 -0
- package/dist/tools/search.tools.js.map +1 -0
- package/dist/tools/solution.tools.d.ts +95 -0
- package/dist/tools/solution.tools.d.ts.map +1 -0
- package/dist/tools/solution.tools.js +130 -0
- package/dist/tools/solution.tools.js.map +1 -0
- package/dist/tools/teams.tools.d.ts +27 -0
- package/dist/tools/teams.tools.d.ts.map +1 -0
- package/dist/tools/teams.tools.js +67 -0
- package/dist/tools/teams.tools.js.map +1 -0
- package/dist/tools/trace.tools.d.ts +63 -0
- package/dist/tools/trace.tools.d.ts.map +1 -0
- package/dist/tools/trace.tools.js +218 -0
- package/dist/tools/trace.tools.js.map +1 -0
- package/dist/tools/tracking.tools.d.ts +35 -0
- package/dist/tools/tracking.tools.d.ts.map +1 -0
- package/dist/tools/tracking.tools.js +40 -0
- package/dist/tools/tracking.tools.js.map +1 -0
- package/dist/tools/users.tools.d.ts +57 -0
- package/dist/tools/users.tools.d.ts.map +1 -0
- package/dist/tools/users.tools.js +146 -0
- package/dist/tools/users.tools.js.map +1 -0
- package/dist/tools/views.tools.d.ts +30 -0
- package/dist/tools/views.tools.d.ts.map +1 -0
- package/dist/tools/views.tools.js +84 -0
- package/dist/tools/views.tools.js.map +1 -0
- package/package.json +81 -0
- package/server.json +30 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { esc } from '../dataverse/dataverse-client.utils.js';
|
|
3
|
+
const ENV_VAR_TYPE_NAMES = {
|
|
4
|
+
100000000: 'String',
|
|
5
|
+
100000001: 'Number',
|
|
6
|
+
100000002: 'Boolean',
|
|
7
|
+
100000003: 'JSON',
|
|
8
|
+
100000004: 'DataSource',
|
|
9
|
+
};
|
|
10
|
+
export const environmentTools = [
|
|
11
|
+
{
|
|
12
|
+
name: 'dataverse_get_environment_variable',
|
|
13
|
+
description: "Retrieves an environment variable's definition and current value from Dataverse. Returns the schema name, display name, type, default value, and the current override value (if set). Useful for reading feature flags, configuration values, and integration settings stored in Dataverse environment variables.",
|
|
14
|
+
inputSchema: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
schemaName: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
description: "The schema name of the environment variable (e.g. 'new_MyConfig')",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
required: ['schemaName'],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'dataverse_set_environment_variable',
|
|
27
|
+
description: 'Sets or updates an environment variable value in Dataverse. If a value record already exists for the variable, it is updated; otherwise a new value record is created. The schemaName must match an existing environment variable definition.',
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
schemaName: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'The schema name of the environment variable',
|
|
34
|
+
},
|
|
35
|
+
value: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
description: 'The new value to set',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
required: ['schemaName', 'value'],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
const GetEnvVarInput = z.object({ schemaName: z.string().min(1) });
|
|
45
|
+
const SetEnvVarInput = z.object({ schemaName: z.string().min(1), value: z.string() });
|
|
46
|
+
async function handleGetEnvironmentVariable(args, client) {
|
|
47
|
+
const { schemaName } = GetEnvVarInput.parse(args);
|
|
48
|
+
const defResult = await client.query('environmentvariabledefinitions', {
|
|
49
|
+
filter: `schemaname eq '${esc(schemaName)}'`,
|
|
50
|
+
select: [
|
|
51
|
+
'environmentvariabledefinitionid',
|
|
52
|
+
'schemaname',
|
|
53
|
+
'displayname',
|
|
54
|
+
'description',
|
|
55
|
+
'type',
|
|
56
|
+
'defaultvalue',
|
|
57
|
+
'isrequired',
|
|
58
|
+
],
|
|
59
|
+
top: 1,
|
|
60
|
+
});
|
|
61
|
+
const defRecords = defResult.value;
|
|
62
|
+
if (defRecords.length === 0) {
|
|
63
|
+
throw new Error(`Environment variable '${schemaName}' not found`);
|
|
64
|
+
}
|
|
65
|
+
const def = defRecords[0];
|
|
66
|
+
const defId = def['environmentvariabledefinitionid'];
|
|
67
|
+
const valResult = await client.query('environmentvariablevalues', {
|
|
68
|
+
filter: `_environmentvariabledefinitionid_value eq ${defId}`,
|
|
69
|
+
select: ['environmentvariablevalueid', 'value'],
|
|
70
|
+
top: 1,
|
|
71
|
+
});
|
|
72
|
+
const valRecords = valResult.value;
|
|
73
|
+
const valRecord = valRecords.length > 0 ? valRecords[0] : null;
|
|
74
|
+
const typeNum = def['type'];
|
|
75
|
+
const currentValue = valRecord ? valRecord['value'] ?? null : null;
|
|
76
|
+
const defaultValue = def['defaultvalue'] ?? null;
|
|
77
|
+
const response = {
|
|
78
|
+
schemaName: def['schemaname'],
|
|
79
|
+
displayName: def['displayname'] ?? '',
|
|
80
|
+
description: def['description'] ?? '',
|
|
81
|
+
type: typeNum,
|
|
82
|
+
typeName: ENV_VAR_TYPE_NAMES[typeNum] ?? 'Unknown',
|
|
83
|
+
defaultValue,
|
|
84
|
+
currentValue,
|
|
85
|
+
valueId: valRecord ? valRecord['environmentvariablevalueid'] : null,
|
|
86
|
+
isRequired: def['isrequired'] ?? false,
|
|
87
|
+
effectiveValue: currentValue ?? defaultValue,
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async function handleSetEnvironmentVariable(args, client) {
|
|
94
|
+
const { schemaName, value } = SetEnvVarInput.parse(args);
|
|
95
|
+
const defResult = await client.query('environmentvariabledefinitions', {
|
|
96
|
+
filter: `schemaname eq '${esc(schemaName)}'`,
|
|
97
|
+
select: ['environmentvariabledefinitionid', 'schemaname'],
|
|
98
|
+
top: 1,
|
|
99
|
+
});
|
|
100
|
+
const defRecords = defResult.value;
|
|
101
|
+
if (defRecords.length === 0) {
|
|
102
|
+
throw new Error(`Environment variable '${schemaName}' not found`);
|
|
103
|
+
}
|
|
104
|
+
const defId = defRecords[0]['environmentvariabledefinitionid'];
|
|
105
|
+
const valResult = await client.query('environmentvariablevalues', {
|
|
106
|
+
filter: `_environmentvariabledefinitionid_value eq ${defId}`,
|
|
107
|
+
select: ['environmentvariablevalueid', 'value'],
|
|
108
|
+
top: 1,
|
|
109
|
+
});
|
|
110
|
+
const valRecords = valResult.value;
|
|
111
|
+
let operation;
|
|
112
|
+
let valueId;
|
|
113
|
+
if (valRecords.length > 0) {
|
|
114
|
+
valueId = valRecords[0]['environmentvariablevalueid'];
|
|
115
|
+
await client.updateRecord('environmentvariablevalues', valueId, { value });
|
|
116
|
+
operation = 'updated';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
valueId = await client.createRecord('environmentvariablevalues', {
|
|
120
|
+
value,
|
|
121
|
+
'EnvironmentVariableDefinitionId@odata.bind': `/environmentvariabledefinitions(${defId})`,
|
|
122
|
+
});
|
|
123
|
+
operation = 'created';
|
|
124
|
+
}
|
|
125
|
+
const response = {
|
|
126
|
+
schemaName,
|
|
127
|
+
operation,
|
|
128
|
+
valueId,
|
|
129
|
+
value,
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export async function handleEnvironmentTool(name, args, client) {
|
|
136
|
+
switch (name) {
|
|
137
|
+
case 'dataverse_get_environment_variable':
|
|
138
|
+
return handleGetEnvironmentVariable(args, client);
|
|
139
|
+
case 'dataverse_set_environment_variable':
|
|
140
|
+
return handleSetEnvironmentVariable(args, client);
|
|
141
|
+
default:
|
|
142
|
+
throw new Error(`Unknown environment tool: ${name}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=environment.tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.tools.js","sourceRoot":"","sources":["../../src/tools/environment.tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,GAAG,EAAE,MAAM,wCAAwC,CAAC;AAE7D,MAAM,kBAAkB,GAA2B;IACjD,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,MAAM;IACjB,SAAS,EAAE,YAAY;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B;QACE,IAAI,EAAE,oCAAoC;QAC1C,WAAW,EACT,mTAAmT;QACrT,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,mEAAmE;iBACjF;aACF;YACD,QAAQ,EAAE,CAAC,YAAY,CAAC;SACzB;KACF;IACD;QACE,IAAI,EAAE,oCAAoC;QAC1C,WAAW,EACT,+OAA+O;QACjP,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6CAA6C;iBAC3D;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,sBAAsB;iBACpC;aACF;YACD,QAAQ,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC;SAClC;KACF;CACF,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACnE,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAA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zC,IAAY,EACZ,IAAa,EACb,MAA+B;IAE/B,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,oCAAoC;YACvC,OAAO,4BAA4B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpD,KAAK,oCAAoC;YACvC,OAAO,4BAA4B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpD;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { DataverseAdvancedClient } from '../dataverse/dataverse-client-advanced.js';
|
|
2
|
+
export declare const fileTools: ({
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {
|
|
8
|
+
entitySetName: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
recordId: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
columnName: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
fileContent: {
|
|
21
|
+
type: string;
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
fileName: {
|
|
25
|
+
type: string;
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
required: string[];
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: "object";
|
|
36
|
+
properties: {
|
|
37
|
+
entitySetName: {
|
|
38
|
+
type: string;
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
recordId: {
|
|
42
|
+
type: string;
|
|
43
|
+
description: string;
|
|
44
|
+
};
|
|
45
|
+
columnName: {
|
|
46
|
+
type: string;
|
|
47
|
+
description: string;
|
|
48
|
+
};
|
|
49
|
+
fileContent?: never;
|
|
50
|
+
fileName?: never;
|
|
51
|
+
};
|
|
52
|
+
required: string[];
|
|
53
|
+
};
|
|
54
|
+
})[];
|
|
55
|
+
export declare function handleFileTool(name: string, args: unknown, client: DataverseAdvancedClient): Promise<{
|
|
56
|
+
content: Array<{
|
|
57
|
+
type: 'text';
|
|
58
|
+
text: string;
|
|
59
|
+
}>;
|
|
60
|
+
}>;
|
|
61
|
+
//# sourceMappingURL=file.tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.tools.d.ts","sourceRoot":"","sources":["../../src/tools/file.tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AA2BzF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAuDrB,CAAC;AAEF,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA6E7D"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const SAFE_NAME_REGEX = /^[a-zA-Z0-9_]+$/;
|
|
3
|
+
const PATH_TRAVERSAL_REGEX = /\.\.|[/\\]/;
|
|
4
|
+
const UploadFileColumnInput = z.object({
|
|
5
|
+
entitySetName: z.string().min(1).refine(v => !PATH_TRAVERSAL_REGEX.test(v), {
|
|
6
|
+
message: 'entitySetName must not contain path traversal characters',
|
|
7
|
+
}),
|
|
8
|
+
recordId: z.string().uuid(),
|
|
9
|
+
columnName: z.string().min(1).refine(v => SAFE_NAME_REGEX.test(v), {
|
|
10
|
+
message: 'columnName must be alphanumeric/underscore only',
|
|
11
|
+
}),
|
|
12
|
+
fileContent: z.string().min(1).describe('Base64-encoded file content'),
|
|
13
|
+
fileName: z.string().min(1),
|
|
14
|
+
});
|
|
15
|
+
const DownloadFileColumnInput = z.object({
|
|
16
|
+
entitySetName: z.string().min(1).refine(v => !PATH_TRAVERSAL_REGEX.test(v), {
|
|
17
|
+
message: 'entitySetName must not contain path traversal characters',
|
|
18
|
+
}),
|
|
19
|
+
recordId: z.string().uuid(),
|
|
20
|
+
columnName: z.string().min(1).refine(v => SAFE_NAME_REGEX.test(v), {
|
|
21
|
+
message: 'columnName must be alphanumeric/underscore only',
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
export const fileTools = [
|
|
25
|
+
{
|
|
26
|
+
name: 'dataverse_upload_file_column',
|
|
27
|
+
description: 'Uploads a file to a Dataverse file column. Provide the entity set name, record GUID, column name, base64-encoded file content, and file name. The file is stored in the specified file-type column on the record.',
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
entitySetName: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'OData entity set name (e.g., "accounts")',
|
|
34
|
+
},
|
|
35
|
+
recordId: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
description: 'Record GUID',
|
|
38
|
+
},
|
|
39
|
+
columnName: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: 'File column logical name',
|
|
42
|
+
},
|
|
43
|
+
fileContent: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
description: 'Base64-encoded file content',
|
|
46
|
+
},
|
|
47
|
+
fileName: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
description: 'File name including extension (e.g., "report.pdf")',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
required: ['entitySetName', 'recordId', 'columnName', 'fileContent', 'fileName'],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'dataverse_download_file_column',
|
|
57
|
+
description: 'Downloads a file from a Dataverse file column. Returns the file content as a base64-encoded string along with the file name and size.',
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
entitySetName: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
description: 'OData entity set name (e.g., "accounts")',
|
|
64
|
+
},
|
|
65
|
+
recordId: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
description: 'Record GUID',
|
|
68
|
+
},
|
|
69
|
+
columnName: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
description: 'File column logical name',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
required: ['entitySetName', 'recordId', 'columnName'],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
export async function handleFileTool(name, args, client) {
|
|
79
|
+
// Access the protected HttpClient for raw binary requests (file column API).
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
const http = client.http;
|
|
82
|
+
switch (name) {
|
|
83
|
+
case 'dataverse_upload_file_column': {
|
|
84
|
+
const { entitySetName, recordId, columnName, fileContent, fileName } = UploadFileColumnInput.parse(args);
|
|
85
|
+
const buffer = Buffer.from(fileContent, 'base64');
|
|
86
|
+
const url = `${entitySetName}(${recordId})/${columnName}`;
|
|
87
|
+
await http.patch(url, buffer, {
|
|
88
|
+
headers: {
|
|
89
|
+
'Content-Type': 'application/octet-stream',
|
|
90
|
+
'x-ms-file-name': fileName,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: 'text',
|
|
97
|
+
text: JSON.stringify({
|
|
98
|
+
success: true,
|
|
99
|
+
entitySetName,
|
|
100
|
+
recordId,
|
|
101
|
+
columnName,
|
|
102
|
+
fileName,
|
|
103
|
+
sizeBytes: buffer.length,
|
|
104
|
+
}, null, 2),
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
case 'dataverse_download_file_column': {
|
|
110
|
+
const { entitySetName, recordId, columnName } = DownloadFileColumnInput.parse(args);
|
|
111
|
+
const url = `${entitySetName}(${recordId})/${columnName}/$value`;
|
|
112
|
+
const response = await http.get(url, {
|
|
113
|
+
responseType: 'text',
|
|
114
|
+
});
|
|
115
|
+
const data = response.data;
|
|
116
|
+
// The response may be binary data returned as a string; encode to base64
|
|
117
|
+
const base64 = Buffer.from(data, 'binary').toString('base64');
|
|
118
|
+
const fileName = response.headers['x-ms-file-name'] ??
|
|
119
|
+
(response.headers['content-disposition']?.match(/filename="?([^";\n]+)"?/)?.[1]) ??
|
|
120
|
+
'download';
|
|
121
|
+
const fileSize = parseInt(response.headers['content-length'] ?? '0', 10) || base64.length;
|
|
122
|
+
return {
|
|
123
|
+
content: [
|
|
124
|
+
{
|
|
125
|
+
type: 'text',
|
|
126
|
+
text: JSON.stringify({
|
|
127
|
+
entitySetName,
|
|
128
|
+
recordId,
|
|
129
|
+
columnName,
|
|
130
|
+
fileName,
|
|
131
|
+
sizeBytes: fileSize,
|
|
132
|
+
contentBase64: base64,
|
|
133
|
+
}, null, 2),
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
default:
|
|
139
|
+
throw new Error(`Unknown file tool: ${name}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=file.tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.tools.js","sourceRoot":"","sources":["../../src/tools/file.tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAC1C,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAE1C,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,aAAa,EAAE,CAAC,CAAC,M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;YAE9D,MAAM,QAAQ,GACX,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAwB;gBAC1D,CAAC,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,KAAK,CAAC,yBAAyB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAChF,UAAU,CAAC;YAEb,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC;YAE1F,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;4BACnB,aAAa;4BACb,QAAQ;4BACR,UAAU;4BACV,QAAQ;4BACR,SAAS,EAAE,QAAQ;4BACnB,aAAa,EAAE,MAAM;yBACtB,EAAE,IAAI,EAAE,CAAC,CAAC;qBACZ;iBACF;aACF,CAAC;QACJ,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DataverseAdvancedClient } from '../dataverse/dataverse-client-advanced.js';
|
|
2
|
+
type DispatchFn = (toolName: string, args: unknown, client: DataverseAdvancedClient) => Promise<{
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: 'text';
|
|
5
|
+
text: string;
|
|
6
|
+
}>;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const impersonateTools: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
inputSchema: {
|
|
12
|
+
type: "object";
|
|
13
|
+
properties: {
|
|
14
|
+
callerId: {
|
|
15
|
+
type: string;
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
toolName: {
|
|
19
|
+
type: string;
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
toolArgs: {
|
|
23
|
+
type: string;
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
required: string[];
|
|
28
|
+
};
|
|
29
|
+
}[];
|
|
30
|
+
export declare function handleImpersonateTool(name: string, args: unknown, client: DataverseAdvancedClient, dispatch: DispatchFn): Promise<{
|
|
31
|
+
content: Array<{
|
|
32
|
+
type: 'text';
|
|
33
|
+
text: string;
|
|
34
|
+
}>;
|
|
35
|
+
}>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=impersonate.tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impersonate.tools.d.ts","sourceRoot":"","sources":["../../src/tools/impersonate.tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAiBzF,KAAK,UAAU,GAAG,CAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,uBAAuB,KAC5B,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAKjE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;GAwB5B,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE,UAAU,GACnB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAuD7D"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { esc } from '../dataverse/dataverse-client.utils.js';
|
|
3
|
+
const ImpersonateInput = z.object({
|
|
4
|
+
callerId: z
|
|
5
|
+
.string()
|
|
6
|
+
.uuid()
|
|
7
|
+
.describe('Azure AD Object ID (GUID) of the Dataverse system user to impersonate. Requires the executing account to have the "Act on behalf of another user" privilege in Dataverse.'),
|
|
8
|
+
toolName: z
|
|
9
|
+
.string()
|
|
10
|
+
.min(1)
|
|
11
|
+
.describe('Name of the MCP tool to execute on behalf of the user (e.g., "dataverse_create", "dataverse_query")'),
|
|
12
|
+
toolArgs: z.record(z.unknown()).describe('Arguments for the wrapped tool, as an object'),
|
|
13
|
+
});
|
|
14
|
+
export const impersonateTools = [
|
|
15
|
+
{
|
|
16
|
+
name: 'dataverse_impersonate',
|
|
17
|
+
description: 'Executes another Dataverse tool on behalf of a different system user by injecting the MSCRMCallerId header. Requires the executing account to have the "Act on behalf of another user" privilege in Dataverse. The impersonation applies ONLY to the single tool call specified. Use for auditing workflows that must create or update records under a specific user identity.',
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
callerId: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'GUID (Azure AD Object ID) of the Dataverse system user to impersonate',
|
|
24
|
+
},
|
|
25
|
+
toolName: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'MCP tool to execute while impersonating (e.g., "dataverse_create")',
|
|
28
|
+
},
|
|
29
|
+
toolArgs: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
description: 'Arguments for the wrapped tool',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
required: ['callerId', 'toolName', 'toolArgs'],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
export async function handleImpersonateTool(name, args, client, dispatch) {
|
|
39
|
+
if (name !== 'dataverse_impersonate') {
|
|
40
|
+
throw new Error(`Unknown impersonate tool: ${name}`);
|
|
41
|
+
}
|
|
42
|
+
const { callerId, toolName, toolArgs } = ImpersonateInput.parse(args);
|
|
43
|
+
// Security guard: prevent privilege escalation via System Administrator impersonation.
|
|
44
|
+
// Best-effort check — if it fails for non-security reasons, log and proceed.
|
|
45
|
+
try {
|
|
46
|
+
const roleCheck = await client.query(`systemusers(${esc(callerId)})/systemuserroles_association`, { select: ['name'], filter: `name eq 'System Administrator'`, top: 1 });
|
|
47
|
+
if ((roleCheck.value?.length ?? 0) > 0) {
|
|
48
|
+
throw new Error('Security policy: impersonation of users with System Administrator role is prohibited to prevent privilege escalation.');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (err instanceof Error && err.message.includes('Security policy'))
|
|
53
|
+
throw err;
|
|
54
|
+
// Fail-closed: any failure verifying roles means we cannot confirm safety — deny impersonation.
|
|
55
|
+
throw new Error(`Security policy: cannot verify callerId roles — impersonation denied. Cause: ${String(err)}`);
|
|
56
|
+
}
|
|
57
|
+
// Access the HttpClient defaultHeaders via type cast — the http property is protected
|
|
58
|
+
const http = client.http;
|
|
59
|
+
const prev = http.defaultHeaders['MSCRMCallerId'];
|
|
60
|
+
try {
|
|
61
|
+
http.defaultHeaders['MSCRMCallerId'] = callerId;
|
|
62
|
+
const result = await dispatch(toolName, toolArgs, client);
|
|
63
|
+
return {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: 'text',
|
|
67
|
+
text: JSON.stringify({
|
|
68
|
+
impersonatedAs: callerId,
|
|
69
|
+
tool: toolName,
|
|
70
|
+
result: JSON.parse(result.content[0].text),
|
|
71
|
+
}, null, 2),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
if (prev === undefined) {
|
|
78
|
+
delete http.defaultHeaders['MSCRMCallerId'];
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
http.defaultHeaders['MSCRMCallerId'] = prev;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=impersonate.tools.js.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QAAQ;wBACxB,IAAI,EAAE,QAAQ;wBACd,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,IAAI,CAAY;qBACvD,EACD,IAAI,EACJ,CAAC,CACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;QAC9C,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { DataverseMetadataClient } from '../dataverse/dataverse-client.metadata.js';
|
|
2
|
+
export declare const metadataTools: ({
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {
|
|
8
|
+
includeSystemTables: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
logicalName?: never;
|
|
13
|
+
includeAttributes?: never;
|
|
14
|
+
relationshipType?: never;
|
|
15
|
+
name?: never;
|
|
16
|
+
tableName?: never;
|
|
17
|
+
entityLogicalName?: never;
|
|
18
|
+
attributeLogicalName?: never;
|
|
19
|
+
};
|
|
20
|
+
required: never[];
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: "object";
|
|
27
|
+
properties: {
|
|
28
|
+
logicalName: {
|
|
29
|
+
type: string;
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
includeAttributes: {
|
|
33
|
+
type: string;
|
|
34
|
+
description: string;
|
|
35
|
+
};
|
|
36
|
+
includeSystemTables?: never;
|
|
37
|
+
relationshipType?: never;
|
|
38
|
+
name?: never;
|
|
39
|
+
tableName?: never;
|
|
40
|
+
entityLogicalName?: never;
|
|
41
|
+
attributeLogicalName?: never;
|
|
42
|
+
};
|
|
43
|
+
required: string[];
|
|
44
|
+
};
|
|
45
|
+
} | {
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
inputSchema: {
|
|
49
|
+
type: "object";
|
|
50
|
+
properties: {
|
|
51
|
+
logicalName: {
|
|
52
|
+
type: string;
|
|
53
|
+
description: string;
|
|
54
|
+
};
|
|
55
|
+
relationshipType: {
|
|
56
|
+
type: string;
|
|
57
|
+
enum: string[];
|
|
58
|
+
description: string;
|
|
59
|
+
};
|
|
60
|
+
includeSystemTables?: never;
|
|
61
|
+
includeAttributes?: never;
|
|
62
|
+
name?: never;
|
|
63
|
+
tableName?: never;
|
|
64
|
+
entityLogicalName?: never;
|
|
65
|
+
attributeLogicalName?: never;
|
|
66
|
+
};
|
|
67
|
+
required: string[];
|
|
68
|
+
};
|
|
69
|
+
} | {
|
|
70
|
+
name: string;
|
|
71
|
+
description: string;
|
|
72
|
+
inputSchema: {
|
|
73
|
+
type: "object";
|
|
74
|
+
properties: {
|
|
75
|
+
includeSystemTables?: never;
|
|
76
|
+
logicalName?: never;
|
|
77
|
+
includeAttributes?: never;
|
|
78
|
+
relationshipType?: never;
|
|
79
|
+
name?: never;
|
|
80
|
+
tableName?: never;
|
|
81
|
+
entityLogicalName?: never;
|
|
82
|
+
attributeLogicalName?: never;
|
|
83
|
+
};
|
|
84
|
+
required: never[];
|
|
85
|
+
};
|
|
86
|
+
} | {
|
|
87
|
+
name: string;
|
|
88
|
+
description: string;
|
|
89
|
+
inputSchema: {
|
|
90
|
+
type: "object";
|
|
91
|
+
properties: {
|
|
92
|
+
name: {
|
|
93
|
+
type: string;
|
|
94
|
+
description: string;
|
|
95
|
+
};
|
|
96
|
+
includeSystemTables?: never;
|
|
97
|
+
logicalName?: never;
|
|
98
|
+
includeAttributes?: never;
|
|
99
|
+
relationshipType?: never;
|
|
100
|
+
tableName?: never;
|
|
101
|
+
entityLogicalName?: never;
|
|
102
|
+
attributeLogicalName?: never;
|
|
103
|
+
};
|
|
104
|
+
required: string[];
|
|
105
|
+
};
|
|
106
|
+
} | {
|
|
107
|
+
name: string;
|
|
108
|
+
description: string;
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: "object";
|
|
111
|
+
properties: {
|
|
112
|
+
tableName: {
|
|
113
|
+
type: string;
|
|
114
|
+
description: string;
|
|
115
|
+
};
|
|
116
|
+
includeSystemTables?: never;
|
|
117
|
+
logicalName?: never;
|
|
118
|
+
includeAttributes?: never;
|
|
119
|
+
relationshipType?: never;
|
|
120
|
+
name?: never;
|
|
121
|
+
entityLogicalName?: never;
|
|
122
|
+
attributeLogicalName?: never;
|
|
123
|
+
};
|
|
124
|
+
required: string[];
|
|
125
|
+
};
|
|
126
|
+
} | {
|
|
127
|
+
name: string;
|
|
128
|
+
description: string;
|
|
129
|
+
inputSchema: {
|
|
130
|
+
type: "object";
|
|
131
|
+
properties: {
|
|
132
|
+
entityLogicalName: {
|
|
133
|
+
type: string;
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
attributeLogicalName: {
|
|
137
|
+
type: string;
|
|
138
|
+
description: string;
|
|
139
|
+
};
|
|
140
|
+
includeSystemTables?: never;
|
|
141
|
+
logicalName?: never;
|
|
142
|
+
includeAttributes?: never;
|
|
143
|
+
relationshipType?: never;
|
|
144
|
+
name?: never;
|
|
145
|
+
tableName?: never;
|
|
146
|
+
};
|
|
147
|
+
required: string[];
|
|
148
|
+
};
|
|
149
|
+
})[];
|
|
150
|
+
export declare function handleMetadataTool(name: string, args: unknown, client: DataverseMetadataClient): Promise<{
|
|
151
|
+
content: Array<{
|
|
152
|
+
type: 'text';
|
|
153
|
+
text: string;
|
|
154
|
+
}>;
|
|
155
|
+
}>;
|
|
156
|
+
//# sourceMappingURL=metadata.tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.tools.d.ts","sourceRoot":"","sources":["../../src/tools/metadata.tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAEzF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2GzB,CAAC;AA+BF,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA+E7D"}
|