d365fo-mcp 1.26.0 → 1.26.2
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/dist/bridge/bridgeClient.d.ts +50 -0
- package/dist/bridge/bridgeClient.js +131 -0
- package/dist/bridge/udeLaunchPaths.d.ts +20 -0
- package/dist/bridge/udeLaunchPaths.js +34 -0
- package/dist/config/settings.js +22 -0
- package/dist/index.js +23 -10
- package/dist/metadata/symbolIndex.d.ts +7 -0
- package/dist/metadata/symbolIndex.js +36 -1
- package/dist/middleware/httpPipeline.d.ts +14 -0
- package/dist/middleware/httpPipeline.js +23 -0
- package/dist/scripts/build-database.js +52 -3
- package/dist/scripts/build-fts.js +52 -3
- package/dist/scripts/extract-binary-models.js +20 -0
- package/dist/scripts/extract-metadata.js +20 -0
- package/dist/scripts/startupIndexWorker.js +52 -3
- package/dist/server/transport.js +5 -0
- package/dist/tools/readers/classInfo.js +29 -5
- package/dist/tools/readers/diskFallback.d.ts +30 -0
- package/dist/tools/readers/diskFallback.js +61 -0
- package/dist/tools/readers/edtInfo.js +7 -0
- package/dist/tools/readers/formInfo.js +14 -0
- package/dist/tools/readers/getWorkspaceInfo.js +15 -1
- package/dist/tools/sdlc/modelReindex.d.ts +30 -1
- package/dist/tools/sdlc/modelReindex.js +98 -6
- package/dist/tools/sdlc/runBpCheck.d.ts +28 -0
- package/dist/tools/sdlc/runBpCheck.js +82 -16
- package/dist/tools/sdlc/updateSymbolIndex.d.ts +17 -0
- package/dist/tools/sdlc/updateSymbolIndex.js +21 -0
- package/dist/tools/smart/generateSmartForm.js +9 -5
- package/dist/tools/smart/generateSmartReport.js +9 -5
- package/dist/tools/smart/generateSmartTable.js +9 -5
- package/dist/tools/toolHandler.js +6 -2
- package/dist/tools/write/createD365File.js +19 -12
- package/dist/tools/write/deleteD365File.js +7 -2
- package/dist/utils/modelClassifier.d.ts +2 -0
- package/dist/utils/modelClassifier.js +4 -0
- package/dist/utils/nameArguments.d.ts +22 -0
- package/dist/utils/nameArguments.js +59 -0
- package/dist/utils/objectFileLookup.js +5 -2
- package/package.json +1 -1
|
@@ -1085,6 +1085,13 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
1085
1085
|
logPrefix: '[create_d365fo_file]',
|
|
1086
1086
|
});
|
|
1087
1087
|
const { basePath, modelPath, normalizedFullPath } = target;
|
|
1088
|
+
// normalizedFullPath is what the user and the .rnrproj see: backslashes, as
|
|
1089
|
+
// on the VM. The disk is reached through the native path. On Windows the two
|
|
1090
|
+
// are the same string (path.join already uses backslashes there). On any
|
|
1091
|
+
// other OS a backslash is an ordinary file-name character, so writing to
|
|
1092
|
+
// normalizedFullPath made one file in the current directory, named after the
|
|
1093
|
+
// whole path, instead of the file under the metadata root.
|
|
1094
|
+
const diskPath = target.fullPath;
|
|
1088
1095
|
// A package name passed as modelName resolves to the package's one model:
|
|
1089
1096
|
// every step from here (bridge, project, index) works on that model.
|
|
1090
1097
|
actualModelName = target.modelName;
|
|
@@ -1092,7 +1099,7 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
1092
1099
|
if (outcome)
|
|
1093
1100
|
outcome.filePath = normalizedFullPath;
|
|
1094
1101
|
// Ensure directory exists (create if needed)
|
|
1095
|
-
const directory = path.dirname(
|
|
1102
|
+
const directory = path.dirname(diskPath);
|
|
1096
1103
|
// Verify drive/root exists before attempting recursive mkdir.
|
|
1097
1104
|
// path.parse().root works on Windows but returns '' for Windows-style paths on POSIX,
|
|
1098
1105
|
// so we extract the drive letter with a regex as a fallback.
|
|
@@ -1132,7 +1139,7 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
1132
1139
|
// Check if file already exists
|
|
1133
1140
|
let fileExisted = false;
|
|
1134
1141
|
try {
|
|
1135
|
-
await fs.access(
|
|
1142
|
+
await fs.access(diskPath);
|
|
1136
1143
|
fileExisted = true;
|
|
1137
1144
|
}
|
|
1138
1145
|
catch {
|
|
@@ -1147,7 +1154,7 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
1147
1154
|
// returned only "already exists", forcing repeated read_file calls.
|
|
1148
1155
|
let existingContent = '';
|
|
1149
1156
|
try {
|
|
1150
|
-
existingContent = await fs.readFile(
|
|
1157
|
+
existingContent = await fs.readFile(diskPath, 'utf-8');
|
|
1151
1158
|
}
|
|
1152
1159
|
catch { /* unreadable — fall through with no summary */ }
|
|
1153
1160
|
let existingSummary = '';
|
|
@@ -1857,7 +1864,7 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
1857
1864
|
// classes, is refused. A bare name passes an incremental build and fails the pipeline's full
|
|
1858
1865
|
// one (formDataMethodGate.ts).
|
|
1859
1866
|
if (args.objectType === 'form' || args.objectType === 'form-extension') {
|
|
1860
|
-
const existing = args.overwrite ? await fs.readFile(
|
|
1867
|
+
const existing = args.overwrite ? await fs.readFile(diskPath, 'utf-8').catch(() => null) : null;
|
|
1861
1868
|
const dm = await gateFormDataMethods(xmlContent, args.objectType, finalObjectName, context?.symbolIndex, existing);
|
|
1862
1869
|
if (dm.blocking.length > 0) {
|
|
1863
1870
|
return {
|
|
@@ -1888,7 +1895,7 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
1888
1895
|
}
|
|
1889
1896
|
// Write file matching D365FO convention: no BOM, CRLF, no trailing newline
|
|
1890
1897
|
try {
|
|
1891
|
-
await timer.time('xml write', () => writeFileAtomic(
|
|
1898
|
+
await timer.time('xml write', () => writeFileAtomic(diskPath, normalizeD365Xml(xmlContent)));
|
|
1892
1899
|
}
|
|
1893
1900
|
catch (writeError) {
|
|
1894
1901
|
console.error(`[create_d365fo_file] Failed to write file:`, writeError);
|
|
@@ -1898,17 +1905,17 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
1898
1905
|
throw new Error(`Failed to write file to ${normalizedFullPath}.\n\n` +
|
|
1899
1906
|
`Possible causes:\n` +
|
|
1900
1907
|
`1. Drive K:\\ does not exist (running on Linux/Mac? Use packagePath parameter to override)\n` +
|
|
1901
|
-
`2. Directory ${
|
|
1908
|
+
`2. Directory ${directory} is not accessible\n` +
|
|
1902
1909
|
`3. Insufficient permissions\n\n` +
|
|
1903
1910
|
`Original error: ${errorMessage}`);
|
|
1904
1911
|
}
|
|
1905
1912
|
throw writeError;
|
|
1906
1913
|
}
|
|
1907
1914
|
// Verify file was written
|
|
1908
|
-
const stats = await fs.stat(
|
|
1915
|
+
const stats = await fs.stat(diskPath);
|
|
1909
1916
|
const fileSizeKb = (stats.size / 1024).toFixed(1);
|
|
1910
1917
|
console.error(`[create_d365fo_file] ✅ Written: ${normalizedFullPath} (${fileSizeKb} KB)`);
|
|
1911
|
-
const createTagsNote = await applyCreateTags(
|
|
1918
|
+
const createTagsNote = await applyCreateTags(diskPath, args.properties);
|
|
1912
1919
|
// This path paid for the rebuild TWICE: once here on the response path, and
|
|
1913
1920
|
// again inside the fire-and-forget bridgeValidateAfterWrite() below, which
|
|
1914
1921
|
// already goes through the same coalescer before reading the object back.
|
|
@@ -2032,9 +2039,9 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
2032
2039
|
}
|
|
2033
2040
|
// Index the new object in-process — see the bridge paths above. Timed like
|
|
2034
2041
|
// the bridge path's, which has named its phases since the same audit.
|
|
2035
|
-
const indexNote = await timer.time('symbol index upsert', () => upsertWrittenFileIntoIndex(
|
|
2042
|
+
const indexNote = await timer.time('symbol index upsert', () => upsertWrittenFileIntoIndex(diskPath, context));
|
|
2036
2043
|
// Verify the write — see the bridge paths above.
|
|
2037
|
-
const verifyNote = renderWriteVerification(await timer.time('write verification', () => verifyWrittenFile(
|
|
2044
|
+
const verifyNote = renderWriteVerification(await timer.time('write verification', () => verifyWrittenFile(diskPath, args.addToProject ? projectPathToUse : undefined, membershipOf(args.objectType, finalObjectName, actualModelName))));
|
|
2038
2045
|
const bpNote = await timer.time('inline BP check', () => runInlineBpCheck(args.bpCheck, args.objectType, finalObjectName, context));
|
|
2039
2046
|
// Offline X++ rules on the source as written. A create hands over the whole
|
|
2040
2047
|
// class, so the class-scoped rules (COC004, COC005) apply here — the cheap
|
|
@@ -2042,13 +2049,13 @@ export async function handleCreateD365File(request, context, outcome) {
|
|
|
2042
2049
|
const xppRuleNote = validateWrittenXpp(sourceAsWritten(args.sourceCode, finalObjectName));
|
|
2043
2050
|
// The scalar properties the caller passed, against the file (see the bridge
|
|
2044
2051
|
// path). Keys the data-entity note below already names are left to that note.
|
|
2045
|
-
const readBackNote = await timer.time('read-back comparison', () => verifyWriteIntent(
|
|
2052
|
+
const readBackNote = await timer.time('read-back comparison', () => verifyWriteIntent(diskPath, createIntentFor(args.objectType, args.properties, args.objectType === 'data-entity'
|
|
2046
2053
|
? findIgnoredEntityProperties(args.properties)
|
|
2047
2054
|
: [])));
|
|
2048
2055
|
// An entity with data management enabled names a staging table: create it now,
|
|
2049
2056
|
// through this same handler, so the next build finds it (stagingTableProvisioning.ts).
|
|
2050
2057
|
const stagingNote = args.objectType === 'data-entity'
|
|
2051
|
-
? await timer.time('staging table', () => provisionStagingTable({ entityName: finalObjectName, entityPath:
|
|
2058
|
+
? await timer.time('staging table', () => provisionStagingTable({ entityName: finalObjectName, entityPath: diskPath, modelName: actualModelName, args }, context, handleCreateD365File))
|
|
2052
2059
|
: '';
|
|
2053
2060
|
// Return success message with file path
|
|
2054
2061
|
return {
|
|
@@ -292,7 +292,12 @@ export async function handleDeleteD365File(request, context) {
|
|
|
292
292
|
// The folder is derived from the deleted object's own path — it is the
|
|
293
293
|
// sibling of its Ax<Type> folder — which also gets the <Package> segment
|
|
294
294
|
// right for a package != model layout without re-resolving anything.
|
|
295
|
-
|
|
295
|
+
// path.win32.dirname slices and keeps the path's own separators, which is
|
|
296
|
+
// what reads a K:\ path on any host. path.win32.join would turn a native
|
|
297
|
+
// POSIX path into backslashes, and off Windows readdir would then find no
|
|
298
|
+
// folder and skip the cleanup without a word: join with the path's own.
|
|
299
|
+
const sep = filePath.includes('\\') ? '\\' : '/';
|
|
300
|
+
const listsFolder = `${path.win32.dirname(path.win32.dirname(filePath))}${sep}AxIgnoreDiagnosticList`;
|
|
296
301
|
const prefixes = suppressionPathSegmentsForObjectType(objectType, axFolder)
|
|
297
302
|
.map(segment => `dynamics://${segment}/${resolvedName}`);
|
|
298
303
|
const listFiles = (await fs.readdir(listsFolder).catch(() => []))
|
|
@@ -300,7 +305,7 @@ export async function handleDeleteD365File(request, context) {
|
|
|
300
305
|
const removedMonikers = [];
|
|
301
306
|
const cleanedFiles = [];
|
|
302
307
|
for (const entry of listFiles) {
|
|
303
|
-
const listPath =
|
|
308
|
+
const listPath = `${listsFolder}${sep}${entry}`;
|
|
304
309
|
const raw = await fs.readFile(listPath, 'utf-8');
|
|
305
310
|
const content = raw.replace(/^/, '').replace(/\r\n/g, '\n');
|
|
306
311
|
const { xml, removed } = removeDiagnosticSuppressionsByPathPrefix(content, prefixes);
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
* This allows dynamically detected models to be treated as custom
|
|
16
16
|
*/
|
|
17
17
|
export declare function registerCustomModel(modelName: string): void;
|
|
18
|
+
/** The models registered as custom at run time (workspace and custom packages root). */
|
|
19
|
+
export declare function getAutoDetectedCustomModels(): string[];
|
|
18
20
|
/**
|
|
19
21
|
* Clear all auto-detected custom models (for test isolation)
|
|
20
22
|
*/
|
|
@@ -24,6 +24,10 @@ export function registerCustomModel(modelName) {
|
|
|
24
24
|
autoDetectedCustomModels.add(modelName);
|
|
25
25
|
console.error(`[ModelClassifier] Registered "${modelName}" as custom model (auto-detected)`);
|
|
26
26
|
}
|
|
27
|
+
/** The models registered as custom at run time (workspace and custom packages root). */
|
|
28
|
+
export function getAutoDetectedCustomModels() {
|
|
29
|
+
return [...autoDetectedCustomModels];
|
|
30
|
+
}
|
|
27
31
|
/**
|
|
28
32
|
* Clear all auto-detected custom models (for test isolation)
|
|
29
33
|
*/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool arguments that name a thing: a model, a package, an object, a label file, a
|
|
3
|
+
* language. The server builds file paths from them, so each must be one path segment.
|
|
4
|
+
* Arguments that take a path (`filePath`, `projectPath`, `packagePath`, …) are checked
|
|
5
|
+
* where they are used and are not listed here.
|
|
6
|
+
*/
|
|
7
|
+
/** True when `value` cannot be one segment of a file path. */
|
|
8
|
+
export declare function isPathLikeName(value: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Where the first name argument holding a path is (`labels[0].translations[1].language`),
|
|
11
|
+
* or null when every name is a name.
|
|
12
|
+
*/
|
|
13
|
+
export declare function findPathLikeName(toolName: string, args: unknown): string | null;
|
|
14
|
+
/** The error result for a call with a path where a name goes, or null when there is none. */
|
|
15
|
+
export declare function refusePathAsName(toolName: string, args: unknown): {
|
|
16
|
+
content: {
|
|
17
|
+
type: 'text';
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
20
|
+
isError: boolean;
|
|
21
|
+
} | null;
|
|
22
|
+
//# sourceMappingURL=nameArguments.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool arguments that name a thing: a model, a package, an object, a label file, a
|
|
3
|
+
* language. The server builds file paths from them, so each must be one path segment.
|
|
4
|
+
* Arguments that take a path (`filePath`, `projectPath`, `packagePath`, …) are checked
|
|
5
|
+
* where they are used and are not listed here.
|
|
6
|
+
*/
|
|
7
|
+
const NAME_KEYS = new Set([
|
|
8
|
+
'baseFormName', 'baseName', 'baseObjectName', 'className', 'dutyName', 'edtName',
|
|
9
|
+
'entityName', 'enumName', 'formName', 'labelFileId', 'language', 'languages', 'macroName',
|
|
10
|
+
'mapName', 'model', 'modelName', 'objectName', 'packageName', 'policyName', 'privilegeName',
|
|
11
|
+
'projectName', 'queryName', 'reportName', 'serviceName', 'tableName', 'viewName',
|
|
12
|
+
]);
|
|
13
|
+
/** `name` is the name of an object only as a top-level argument of these tools. */
|
|
14
|
+
const TOOLS_NAMING_AN_OBJECT_AS_NAME = new Set(['get_object_info', 'generate_object']);
|
|
15
|
+
/** True when `value` cannot be one segment of a file path. */
|
|
16
|
+
export function isPathLikeName(value) {
|
|
17
|
+
const trimmed = value.trim();
|
|
18
|
+
return /[\\/\0]/.test(trimmed) || trimmed === '.' || trimmed === '..';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Where the first name argument holding a path is (`labels[0].translations[1].language`),
|
|
22
|
+
* or null when every name is a name.
|
|
23
|
+
*/
|
|
24
|
+
export function findPathLikeName(toolName, args) {
|
|
25
|
+
const visit = (value, at, isName) => {
|
|
26
|
+
if (typeof value === 'string')
|
|
27
|
+
return isName && isPathLikeName(value) ? at : null;
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
for (const [i, item] of value.entries()) {
|
|
30
|
+
const found = visit(item, `${at}[${i}]`, isName);
|
|
31
|
+
if (found)
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (!value || typeof value !== 'object')
|
|
37
|
+
return null;
|
|
38
|
+
for (const [key, item] of Object.entries(value)) {
|
|
39
|
+
const named = NAME_KEYS.has(key)
|
|
40
|
+
|| (at === '' && key === 'name' && TOOLS_NAMING_AN_OBJECT_AS_NAME.has(toolName));
|
|
41
|
+
const found = visit(item, at ? `${at}.${key}` : key, named);
|
|
42
|
+
if (found)
|
|
43
|
+
return found;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
return visit(args, '', false);
|
|
48
|
+
}
|
|
49
|
+
/** The error result for a call with a path where a name goes, or null when there is none. */
|
|
50
|
+
export function refusePathAsName(toolName, args) {
|
|
51
|
+
const at = findPathLikeName(toolName, args);
|
|
52
|
+
if (at === null)
|
|
53
|
+
return null;
|
|
54
|
+
const text = `❌ \`${at}\` takes a name, not a path: it cannot contain "/" or "\\", or be "." or "..". ` +
|
|
55
|
+
'Nothing was read or written. Pass the name alone; a file or folder goes in an argument ' +
|
|
56
|
+
'that takes a path (filePath, projectPath, packagePath).';
|
|
57
|
+
return { content: [{ type: 'text', text }], isError: true };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=nameArguments.js.map
|
|
@@ -12,6 +12,7 @@ import { getConfigManager, fallbackPackagePath } from './configManager.js';
|
|
|
12
12
|
import { PackageResolver } from './packageResolver.js';
|
|
13
13
|
import { findDescriptorPath } from '../metadata/modelDescriptor.js';
|
|
14
14
|
import { aotFolderFor } from '../metadata/aotFolders.js';
|
|
15
|
+
import { isPathLikeName } from './nameArguments.js';
|
|
15
16
|
// objectType → Ax* folder: metadata/aotFolders.ts, the same map the create tool writes with.
|
|
16
17
|
/**
|
|
17
18
|
* Resolve a MODEL DESCRIPTOR's path: <root>/<Package>/Descriptor/<Model>.xml.
|
|
@@ -40,7 +41,7 @@ export async function findModelDescriptorPath(modelName, explicitPackagePath) {
|
|
|
40
41
|
(await configManager.getAutoDetectedModelName()) ||
|
|
41
42
|
process.env.D365FO_MODEL_NAME ||
|
|
42
43
|
null;
|
|
43
|
-
if (!resolvedModel)
|
|
44
|
+
if (!resolvedModel || isPathLikeName(resolvedModel))
|
|
44
45
|
return null;
|
|
45
46
|
const roots = [
|
|
46
47
|
explicitPackagePath,
|
|
@@ -103,7 +104,7 @@ export async function moduleExistenceNote(moduleName, explicitPackagePath) {
|
|
|
103
104
|
*/
|
|
104
105
|
export async function findD365FileOnDisk(objectType, objectName, modelName, explicitPackagePath) {
|
|
105
106
|
const objectFolder = aotFolderFor(objectType);
|
|
106
|
-
if (!objectFolder)
|
|
107
|
+
if (!objectFolder || isPathLikeName(objectName))
|
|
107
108
|
return null;
|
|
108
109
|
const configManager = getConfigManager();
|
|
109
110
|
// Ensure .mcp.json is loaded — lazy init so this works even when
|
|
@@ -124,6 +125,8 @@ export async function findD365FileOnDisk(objectType, objectName, modelName, expl
|
|
|
124
125
|
'Provide modelName parameter, configure .mcp.json with modelName/projectPath, or set D365FO_MODEL_NAME env var.');
|
|
125
126
|
return null;
|
|
126
127
|
}
|
|
128
|
+
if (isPathLikeName(resolvedModel))
|
|
129
|
+
return null;
|
|
127
130
|
const configPackagePath = configManager.getPackagePath() || fallbackPackagePath();
|
|
128
131
|
// Resolve the custom write root (D365FO_CUSTOM_PACKAGES_PATH).
|
|
129
132
|
// Try this before the MS PLD so we find repo-tracked objects first.
|
package/package.json
CHANGED