Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mcp-provider-metadata-enrichment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@modelcontextprotocol/sdk": "^1.18.0",
"@salesforce/mcp-provider-api": "^0.5.0",
"@salesforce/mcp-provider-dx-core": "^0.7.0",
"@salesforce/metadata-enrichment": "^0.0.4",
"@salesforce/metadata-enrichment": "^0.0.6",
"@salesforce/source-deploy-retrieve": "^12.31.10",
"zod": "^3.25.76"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
Toolset,
} from "@salesforce/mcp-provider-api";
import { ComponentSetBuilder } from "@salesforce/source-deploy-retrieve";
import { ComponentProcessor, EnrichmentHandler, EnrichmentRecords, EnrichmentStatus, FileProcessor } from "@salesforce/metadata-enrichment";
import { SourceComponentProcessor, EnrichmentHandler, EnrichmentRecords, EnrichmentStatus, FileProcessor } from "@salesforce/metadata-enrichment";

/*
* Enrich metadata in a Salesforce org.
Expand Down Expand Up @@ -164,7 +164,7 @@ export class EnrichMetadataMcpTool extends McpTool<InputArgsShape, OutputArgsSha
const projectSourceComponents = projectComponentSet.getSourceComponents().toArray();
const enrichmentRecords = new EnrichmentRecords(projectSourceComponents);

const componentsToSkip = ComponentProcessor.getComponentsToSkip(
const componentsToSkip = SourceComponentProcessor.getComponentsToSkip(
projectSourceComponents,
input.metadataEntries,
project.getPath()
Expand Down Expand Up @@ -193,10 +193,10 @@ export class EnrichMetadataMcpTool extends McpTool<InputArgsShape, OutputArgsSha
}
}

const enrichmentResults = await EnrichmentHandler.enrich(connection, componentsEligibleToProcess);
enrichmentRecords.updateWithResults(enrichmentResults);
const enrichmentResponse = await EnrichmentHandler.enrich(connection, componentsEligibleToProcess);
enrichmentRecords.updateWithResults(enrichmentResponse);

const fileUpdatedRecords = await FileProcessor.updateMetadataFiles(
const fileUpdatedRecords = await FileProcessor.updateMetadata(
componentsEligibleToProcess,
enrichmentRecords.recordSet
);
Expand All @@ -216,8 +216,9 @@ export class EnrichMetadataMcpTool extends McpTool<InputArgsShape, OutputArgsSha
if (successfulRecords.length === 0) {
summaryParts.push('No components were enriched.');
} else {
summaryParts.push('Metadata enrichment completed. Components enriched:');
summaryParts.push(...successfulRecords.map((r) => ` • ${r.componentName}`));
summaryParts.push('Metadata enrichment completed');
summaryParts.push('Components enriched:');
summaryParts.push(...successfulRecords.map((r) => ` • ${r.componentName}\n (Request ID: ${r.response?.metadata?.requestId ?? 'None'})`));
}
if (skippedRecords.length > 0) {
summaryParts.push('Skipped:');
Expand All @@ -228,9 +229,10 @@ export class EnrichMetadataMcpTool extends McpTool<InputArgsShape, OutputArgsSha
if (failedRecords.length > 0) {
summaryParts.push('Failed:');
summaryParts.push(
...failedRecords.map((r) => ` • ${r.componentName}: ${r.message ?? 'Failed'}`)
...failedRecords.map((r) => ` • ${r.componentName}: ${r.message ?? 'Failed'}\n (Request ID: ${r.response?.metadata?.requestId ?? 'None'})`)
);
}

const summary = summaryParts.join('\n');

// Only return error response IFF there were only failed records
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
import { Connection, SfProject } from "@salesforce/core";
import { ReleaseState, Toolset, Services } from "@salesforce/mcp-provider-api";
import { EnrichmentStatus } from "@salesforce/metadata-enrichment";
import { ComponentProcessor, EnrichmentHandler, FileProcessor } from "@salesforce/metadata-enrichment";
import { SourceComponentProcessor, EnrichmentHandler, FileProcessor } from "@salesforce/metadata-enrichment";
import type { EnrichmentRequestRecord } from "@salesforce/metadata-enrichment";
import { ComponentSetBuilder } from "@salesforce/source-deploy-retrieve";
import { EnrichMetadataMcpTool } from "../../src/tools/enrich_metadata.js";
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("EnrichMetadataMcpTool", () => {
getConnection: () => Promise.resolve(mockConnection),
}),
} as unknown as Services;
vi.spyOn(ComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
vi.spyOn(SourceComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
vi.spyOn(EnrichmentHandler, "enrich").mockResolvedValue([
{
componentName: "myLwc",
Expand All @@ -128,8 +128,8 @@ describe("EnrichMetadataMcpTool", () => {
status: EnrichmentStatus.SUCCESS,
},
] as unknown as EnrichmentRequestRecord[]);
vi.spyOn(FileProcessor, "updateMetadataFiles").mockResolvedValue(
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadataFiles>>
vi.spyOn(FileProcessor, "updateMetadata").mockResolvedValue(
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadata>>
);
});

Expand Down Expand Up @@ -192,7 +192,7 @@ describe("EnrichMetadataMcpTool", () => {
getConnection: () => Promise.resolve(mockConnection),
}),
} as unknown as Services;
vi.spyOn(ComponentProcessor, "getComponentsToSkip").mockReturnValue(
vi.spyOn(SourceComponentProcessor, "getComponentsToSkip").mockReturnValue(
new Set([
{ typeName: "LightningComponentBundle", componentName: "otherCmp" },
])
Expand All @@ -207,8 +207,8 @@ describe("EnrichMetadataMcpTool", () => {
status: EnrichmentStatus.SUCCESS,
},
] as unknown as EnrichmentRequestRecord[]);
vi.spyOn(FileProcessor, "updateMetadataFiles").mockResolvedValue(
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadataFiles>>
vi.spyOn(FileProcessor, "updateMetadata").mockResolvedValue(
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadata>>
);

const tool = new EnrichMetadataMcpTool(servicesWithConnection);
Expand All @@ -220,7 +220,7 @@ describe("EnrichMetadataMcpTool", () => {

expect(result.isError).toBe(false);
const text = result.content[0].type === "text" ? result.content[0].text : "";
expect(text).toContain("Metadata enrichment completed. Components enriched:");
expect(text).toContain("Metadata enrichment completed");
expect(text).toContain(" • myLwc");
expect(text).toContain("Skipped:");
expect(text).toContain(" • otherCmp: Skipped");
Expand Down Expand Up @@ -262,7 +262,7 @@ describe("EnrichMetadataMcpTool", () => {
getConnection: () => Promise.resolve(mockConnection),
}),
} as unknown as Services;
vi.spyOn(ComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
vi.spyOn(SourceComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
vi.spyOn(EnrichmentHandler, "enrich").mockResolvedValue([
{
componentName: "myLwc",
Expand All @@ -281,8 +281,8 @@ describe("EnrichMetadataMcpTool", () => {
status: EnrichmentStatus.FAIL,
},
] as unknown as EnrichmentRequestRecord[]);
vi.spyOn(FileProcessor, "updateMetadataFiles").mockResolvedValue(
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadataFiles>>
vi.spyOn(FileProcessor, "updateMetadata").mockResolvedValue(
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadata>>
);

const tool = new EnrichMetadataMcpTool(servicesWithConnection);
Expand All @@ -294,7 +294,7 @@ describe("EnrichMetadataMcpTool", () => {

expect(result.isError).toBe(false);
const text = result.content[0].type === "text" ? result.content[0].text : "";
expect(text).toContain("Metadata enrichment completed. Components enriched:");
expect(text).toContain("Metadata enrichment completed");
expect(text).toContain(" • myLwc");
expect(text).toContain("Failed:");
expect(text).toContain(" • failedCmp: Enrichment API error");
Expand All @@ -308,7 +308,7 @@ describe("EnrichMetadataMcpTool", () => {
getConnection: () => Promise.resolve(mockConnection),
}),
} as unknown as Services;
vi.spyOn(ComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
vi.spyOn(SourceComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
vi.spyOn(EnrichmentHandler, "enrich").mockResolvedValue([
{
componentName: "failedCmp",
Expand All @@ -319,8 +319,8 @@ describe("EnrichMetadataMcpTool", () => {
status: EnrichmentStatus.FAIL,
},
] as unknown as EnrichmentRequestRecord[]);
vi.spyOn(FileProcessor, "updateMetadataFiles").mockResolvedValue(
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadataFiles>>
vi.spyOn(FileProcessor, "updateMetadata").mockResolvedValue(
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadata>>
);

const tool = new EnrichMetadataMcpTool(servicesWithConnection);
Expand Down