Skip to content
Open
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
25 changes: 25 additions & 0 deletions src/targets/__tests__/mcpRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,31 @@ describe('existing listing', () => {
]);
});

test('ignores empty values that the registry drops', async () => {
const pkg = {
...MANIFEST.packages[0],
environmentVariables: [
{ name: 'TOKEN', isRequired: false, isSecret: true, value: '' },
],
packageArguments: [],
};
writeManifest({ ...MANIFEST, packages: [pkg] });
const listedPackage = {
...MANIFEST.packages[0],
version: VERSION,
environmentVariables: [{ name: 'TOKEN', isSecret: true }],
};
const fetchMock = mockFetch({
[`GET ${LISTING_URL}`]: json(
listing({ ...EXPECTED_SERVER, packages: [listedPackage] }),
),
});

await createTarget().publish(VERSION, 'sha');

expect(requests(fetchMock)).toHaveLength(1);
});

test('fails when the listed version differs from the manifest', async () => {
const fetchMock = mockFetch({
[`GET ${LISTING_URL}`]: json(
Expand Down
45 changes: 39 additions & 6 deletions src/targets/mcpRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ export class McpRegistryTarget extends BaseTarget {
}

/**
* Checks that the listing equals the manifest (ignoring `$schema`) and is
* active. Throws `mismatchMessage` when the content differs.
* Checks that the listing equals the manifest (ignoring `$schema` and the
* empty values the registry drops) and is active. Throws `mismatchMessage`
* when the content differs.
*/
private verifyListing(
listing: RegistryListing,
Expand All @@ -300,8 +301,8 @@ export class McpRegistryTarget extends BaseTarget {
): void {
if (
!isDeepStrictEqual(
withoutSchema(listing.server ?? {}),
withoutSchema(manifest),
normalizeServer(listing.server ?? {}),
normalizeServer(manifest),
)
) {
throw new Error(mismatchMessage);
Expand Down Expand Up @@ -475,12 +476,44 @@ export class McpRegistryTarget extends BaseTarget {
}
}

function withoutSchema(
/**
* Returns the server data the registry stores for `server`, for comparison:
* without `$schema`, and without the empty values (`false`, `""`, `null`,
* `[]`, `{}`) that the registry drops from its listings (Go `omitempty`).
*/
function normalizeServer(
server: Record<string, unknown>,
): Record<string, unknown> {
const copy = { ...server };
delete copy.$schema;
return copy;
return withoutEmptyValues(copy) as Record<string, unknown>;
}

function withoutEmptyValues(value: unknown): unknown {
if (Array.isArray(value)) {
return value.map(withoutEmptyValues);
}
if (value === null || typeof value !== 'object') {
return value;
}
const result: Record<string, unknown> = {};
for (const [key, item] of Object.entries(value)) {
const normalized = withoutEmptyValues(item);
if (!isEmptyValue(normalized)) {
result[key] = normalized;
}
}
return result;
}

function isEmptyValue(value: unknown): boolean {
if (value === undefined || value === null || value === false) {
return true;
}
if (typeof value === 'string' || Array.isArray(value)) {
return value.length === 0;
}
return typeof value === 'object' && Object.keys(value).length === 0;
}

function errorMessage(err: unknown): string {
Expand Down
Loading