Skip to content

Commit 2bb2c69

Browse files
feat: Surface request ID in agent response (#402)
* fix: emitting request ID * feat: surfacing request id to agent * fix: enrich_metadata utest * bump metadata-enrichment library version
1 parent fb0a14b commit 2bb2c69

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

packages/mcp-provider-metadata-enrichment/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@modelcontextprotocol/sdk": "^1.18.0",
1717
"@salesforce/mcp-provider-api": "^0.5.0",
1818
"@salesforce/mcp-provider-dx-core": "^0.7.0",
19-
"@salesforce/metadata-enrichment": "^0.0.4",
19+
"@salesforce/metadata-enrichment": "^0.0.6",
2020
"@salesforce/source-deploy-retrieve": "^12.31.10",
2121
"zod": "^3.25.76"
2222
},

packages/mcp-provider-metadata-enrichment/src/tools/enrich_metadata.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
Toolset,
3030
} from "@salesforce/mcp-provider-api";
3131
import { ComponentSetBuilder } from "@salesforce/source-deploy-retrieve";
32-
import { ComponentProcessor, EnrichmentHandler, EnrichmentRecords, EnrichmentStatus, FileProcessor } from "@salesforce/metadata-enrichment";
32+
import { SourceComponentProcessor, EnrichmentHandler, EnrichmentRecords, EnrichmentStatus, FileProcessor } from "@salesforce/metadata-enrichment";
3333

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

167-
const componentsToSkip = ComponentProcessor.getComponentsToSkip(
167+
const componentsToSkip = SourceComponentProcessor.getComponentsToSkip(
168168
projectSourceComponents,
169169
input.metadataEntries,
170170
project.getPath()
@@ -193,10 +193,10 @@ export class EnrichMetadataMcpTool extends McpTool<InputArgsShape, OutputArgsSha
193193
}
194194
}
195195

196-
const enrichmentResults = await EnrichmentHandler.enrich(connection, componentsEligibleToProcess);
197-
enrichmentRecords.updateWithResults(enrichmentResults);
196+
const enrichmentResponse = await EnrichmentHandler.enrich(connection, componentsEligibleToProcess);
197+
enrichmentRecords.updateWithResults(enrichmentResponse);
198198

199-
const fileUpdatedRecords = await FileProcessor.updateMetadataFiles(
199+
const fileUpdatedRecords = await FileProcessor.updateMetadata(
200200
componentsEligibleToProcess,
201201
enrichmentRecords.recordSet
202202
);
@@ -216,8 +216,9 @@ export class EnrichMetadataMcpTool extends McpTool<InputArgsShape, OutputArgsSha
216216
if (successfulRecords.length === 0) {
217217
summaryParts.push('No components were enriched.');
218218
} else {
219-
summaryParts.push('Metadata enrichment completed. Components enriched:');
220-
summaryParts.push(...successfulRecords.map((r) => ` • ${r.componentName}`));
219+
summaryParts.push('Metadata enrichment completed');
220+
summaryParts.push('Components enriched:');
221+
summaryParts.push(...successfulRecords.map((r) => ` • ${r.componentName}\n (Request ID: ${r.response?.metadata?.requestId ?? 'None'})`));
221222
}
222223
if (skippedRecords.length > 0) {
223224
summaryParts.push('Skipped:');
@@ -228,9 +229,10 @@ export class EnrichMetadataMcpTool extends McpTool<InputArgsShape, OutputArgsSha
228229
if (failedRecords.length > 0) {
229230
summaryParts.push('Failed:');
230231
summaryParts.push(
231-
...failedRecords.map((r) => ` • ${r.componentName}: ${r.message ?? 'Failed'}`)
232+
...failedRecords.map((r) => ` • ${r.componentName}: ${r.message ?? 'Failed'}\n (Request ID: ${r.response?.metadata?.requestId ?? 'None'})`)
232233
);
233234
}
235+
234236
const summary = summaryParts.join('\n');
235237

236238
// Only return error response IFF there were only failed records

packages/mcp-provider-metadata-enrichment/test/unit/enrich_metadata.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
1919
import { Connection, SfProject } from "@salesforce/core";
2020
import { ReleaseState, Toolset, Services } from "@salesforce/mcp-provider-api";
2121
import { EnrichmentStatus } from "@salesforce/metadata-enrichment";
22-
import { ComponentProcessor, EnrichmentHandler, FileProcessor } from "@salesforce/metadata-enrichment";
22+
import { SourceComponentProcessor, EnrichmentHandler, FileProcessor } from "@salesforce/metadata-enrichment";
2323
import type { EnrichmentRequestRecord } from "@salesforce/metadata-enrichment";
2424
import { ComponentSetBuilder } from "@salesforce/source-deploy-retrieve";
2525
import { EnrichMetadataMcpTool } from "../../src/tools/enrich_metadata.js";
@@ -117,7 +117,7 @@ describe("EnrichMetadataMcpTool", () => {
117117
getConnection: () => Promise.resolve(mockConnection),
118118
}),
119119
} as unknown as Services;
120-
vi.spyOn(ComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
120+
vi.spyOn(SourceComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
121121
vi.spyOn(EnrichmentHandler, "enrich").mockResolvedValue([
122122
{
123123
componentName: "myLwc",
@@ -128,8 +128,8 @@ describe("EnrichMetadataMcpTool", () => {
128128
status: EnrichmentStatus.SUCCESS,
129129
},
130130
] as unknown as EnrichmentRequestRecord[]);
131-
vi.spyOn(FileProcessor, "updateMetadataFiles").mockResolvedValue(
132-
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadataFiles>>
131+
vi.spyOn(FileProcessor, "updateMetadata").mockResolvedValue(
132+
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadata>>
133133
);
134134
});
135135

@@ -192,7 +192,7 @@ describe("EnrichMetadataMcpTool", () => {
192192
getConnection: () => Promise.resolve(mockConnection),
193193
}),
194194
} as unknown as Services;
195-
vi.spyOn(ComponentProcessor, "getComponentsToSkip").mockReturnValue(
195+
vi.spyOn(SourceComponentProcessor, "getComponentsToSkip").mockReturnValue(
196196
new Set([
197197
{ typeName: "LightningComponentBundle", componentName: "otherCmp" },
198198
])
@@ -207,8 +207,8 @@ describe("EnrichMetadataMcpTool", () => {
207207
status: EnrichmentStatus.SUCCESS,
208208
},
209209
] as unknown as EnrichmentRequestRecord[]);
210-
vi.spyOn(FileProcessor, "updateMetadataFiles").mockResolvedValue(
211-
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadataFiles>>
210+
vi.spyOn(FileProcessor, "updateMetadata").mockResolvedValue(
211+
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadata>>
212212
);
213213

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

221221
expect(result.isError).toBe(false);
222222
const text = result.content[0].type === "text" ? result.content[0].text : "";
223-
expect(text).toContain("Metadata enrichment completed. Components enriched:");
223+
expect(text).toContain("Metadata enrichment completed");
224224
expect(text).toContain(" • myLwc");
225225
expect(text).toContain("Skipped:");
226226
expect(text).toContain(" • otherCmp: Skipped");
@@ -262,7 +262,7 @@ describe("EnrichMetadataMcpTool", () => {
262262
getConnection: () => Promise.resolve(mockConnection),
263263
}),
264264
} as unknown as Services;
265-
vi.spyOn(ComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
265+
vi.spyOn(SourceComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
266266
vi.spyOn(EnrichmentHandler, "enrich").mockResolvedValue([
267267
{
268268
componentName: "myLwc",
@@ -281,8 +281,8 @@ describe("EnrichMetadataMcpTool", () => {
281281
status: EnrichmentStatus.FAIL,
282282
},
283283
] as unknown as EnrichmentRequestRecord[]);
284-
vi.spyOn(FileProcessor, "updateMetadataFiles").mockResolvedValue(
285-
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadataFiles>>
284+
vi.spyOn(FileProcessor, "updateMetadata").mockResolvedValue(
285+
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadata>>
286286
);
287287

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

295295
expect(result.isError).toBe(false);
296296
const text = result.content[0].type === "text" ? result.content[0].text : "";
297-
expect(text).toContain("Metadata enrichment completed. Components enriched:");
297+
expect(text).toContain("Metadata enrichment completed");
298298
expect(text).toContain(" • myLwc");
299299
expect(text).toContain("Failed:");
300300
expect(text).toContain(" • failedCmp: Enrichment API error");
@@ -308,7 +308,7 @@ describe("EnrichMetadataMcpTool", () => {
308308
getConnection: () => Promise.resolve(mockConnection),
309309
}),
310310
} as unknown as Services;
311-
vi.spyOn(ComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
311+
vi.spyOn(SourceComponentProcessor, "getComponentsToSkip").mockReturnValue(new Set());
312312
vi.spyOn(EnrichmentHandler, "enrich").mockResolvedValue([
313313
{
314314
componentName: "failedCmp",
@@ -319,8 +319,8 @@ describe("EnrichMetadataMcpTool", () => {
319319
status: EnrichmentStatus.FAIL,
320320
},
321321
] as unknown as EnrichmentRequestRecord[]);
322-
vi.spyOn(FileProcessor, "updateMetadataFiles").mockResolvedValue(
323-
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadataFiles>>
322+
vi.spyOn(FileProcessor, "updateMetadata").mockResolvedValue(
323+
[] as unknown as Awaited<ReturnType<typeof FileProcessor.updateMetadata>>
324324
);
325325

326326
const tool = new EnrichMetadataMcpTool(servicesWithConnection);

0 commit comments

Comments
 (0)