Skip to content

Commit b9e3e66

Browse files
authored
♻️ refactor: clean mcp sitemap (#8596)
1 parent 403aebd commit b9e3e66

File tree

7 files changed

+2
-139
lines changed

7 files changed

+2
-139
lines changed

src/app/sitemap.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ export async function generateSitemaps() {
1717
const staticSitemaps = sitemapModule.sitemapIndexs;
1818

1919
// 获取需要分页的类型的页数
20-
const [pluginPages, assistantPages, mcpPages, modelPages] = await Promise.all([
20+
const [pluginPages, assistantPages, modelPages] = await Promise.all([
2121
sitemapModule.getPluginPageCount(),
2222
sitemapModule.getAssistantPageCount(),
23-
sitemapModule.getMcpPageCount(),
2423
sitemapModule.getModelPageCount(),
2524
]);
2625

@@ -30,7 +29,6 @@ export async function generateSitemaps() {
3029
...Array.from({ length: assistantPages }, (_, i) => ({
3130
id: `assistants-${i + 1}` as SitemapType,
3231
})),
33-
...Array.from({ length: mcpPages }, (_, i) => ({ id: `mcp-${i + 1}` as SitemapType })),
3432
...Array.from({ length: modelPages }, (_, i) => ({ id: `models-${i + 1}` as SitemapType })),
3533
];
3634

@@ -60,9 +58,6 @@ export default async function sitemap({ id }: { id: string }): Promise<MetadataR
6058
case SitemapType.Assistants: {
6159
return sitemapModule.getAssistants(page);
6260
}
63-
case SitemapType.Mcp: {
64-
return sitemapModule.getMcp(page);
65-
}
6661
case SitemapType.Plugins: {
6762
return sitemapModule.getPlugins(page);
6863
}
@@ -82,10 +77,6 @@ export default async function sitemap({ id }: { id: string }): Promise<MetadataR
8277
const pageNum = parseInt(id.split('-')[1], 10);
8378
return sitemapModule.getAssistants(pageNum);
8479
}
85-
if (id.startsWith('mcp-')) {
86-
const pageNum = parseInt(id.split('-')[1], 10);
87-
return sitemapModule.getMcp(pageNum);
88-
}
8980
if (id.startsWith('models-')) {
9081
const pageNum = parseInt(id.split('-')[1], 10);
9182
return sitemapModule.getModels(pageNum);

src/server/routers/lambda/market/index.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,6 @@ export const marketRouter = router({
173173
}
174174
}),
175175

176-
getMcpIdentifiers: marketProcedure.query(async ({ ctx }) => {
177-
log('getMcpIdentifiers called');
178-
179-
try {
180-
return await ctx.discoverService.getMcpIdentifiers();
181-
} catch (error) {
182-
log('Error fetching mcp identifiers: %O', error);
183-
throw new TRPCError({
184-
code: 'INTERNAL_SERVER_ERROR',
185-
message: 'Failed to fetch mcp identifiers',
186-
});
187-
}
188-
}),
189-
190176
getMcpList: marketProcedure
191177
.input(
192178
z

src/server/services/discover/index.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -462,19 +462,6 @@ export class DiscoverService {
462462
return result;
463463
};
464464

465-
getMcpIdentifiers = async (): Promise<IdentifiersResponse> => {
466-
log('getMcpIdentifiers: fetching identifiers');
467-
const result = await this.market.plugins.getPublishedIdentifiers({
468-
cache: 'force-cache',
469-
next: {
470-
revalidate: CacheRevalidate.List,
471-
tags: [CacheTag.Discover, CacheTag.MCP],
472-
},
473-
});
474-
log('getMcpIdentifiers: returning %d identifiers', result.length);
475-
return result;
476-
};
477-
478465
getMcpList = async (params: McpQueryParams = {}): Promise<McpListResponse> => {
479466
log('getMcpList: params=%O', params);
480467
const { locale } = params;

src/server/sitemap.test.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ describe('Sitemap', () => {
1313
// Mock the page count methods to return specific values for testing
1414
vi.spyOn(sitemap, 'getPluginPageCount').mockResolvedValue(2);
1515
vi.spyOn(sitemap, 'getAssistantPageCount').mockResolvedValue(3);
16-
vi.spyOn(sitemap, 'getMcpPageCount').mockResolvedValue(1);
1716
vi.spyOn(sitemap, 'getModelPageCount').mockResolvedValue(2);
1817

1918
const index = await sitemap.getIndex();
@@ -31,7 +30,6 @@ describe('Sitemap', () => {
3130
expect(index).toContain(`<loc>${getCanonicalUrl('/sitemap/assistants-1.xml')}</loc>`);
3231
expect(index).toContain(`<loc>${getCanonicalUrl('/sitemap/assistants-2.xml')}</loc>`);
3332
expect(index).toContain(`<loc>${getCanonicalUrl('/sitemap/assistants-3.xml')}</loc>`);
34-
expect(index).toContain(`<loc>${getCanonicalUrl('/sitemap/mcp-1.xml')}</loc>`);
3533
expect(index).toContain(`<loc>${getCanonicalUrl('/sitemap/models-1.xml')}</loc>`);
3634
expect(index).toContain(`<loc>${getCanonicalUrl('/sitemap/models-2.xml')}</loc>`);
3735

@@ -218,46 +216,6 @@ describe('Sitemap', () => {
218216
});
219217
});
220218

221-
describe('getMcp', () => {
222-
it('should return a valid mcp sitemap without pagination', async () => {
223-
vi.spyOn(sitemap['discoverService'], 'getMcpIdentifiers').mockResolvedValue([
224-
// @ts-ignore
225-
{ identifier: 'test-mcp', lastModified: '2023-01-01' },
226-
]);
227-
228-
const mcpSitemap = await sitemap.getMcp();
229-
expect(mcpSitemap.length).toBe(15);
230-
expect(mcpSitemap).toContainEqual(
231-
expect.objectContaining({
232-
url: getCanonicalUrl('/discover/mcp/test-mcp'),
233-
lastModified: '2023-01-01T00:00:00.000Z',
234-
}),
235-
);
236-
expect(mcpSitemap).toContainEqual(
237-
expect.objectContaining({
238-
url: getCanonicalUrl('/discover/mcp/test-mcp?hl=zh-CN'),
239-
lastModified: '2023-01-01T00:00:00.000Z',
240-
}),
241-
);
242-
});
243-
244-
it('should return a valid mcp sitemap with pagination', async () => {
245-
const mockMcps = Array.from({ length: 80 }, (_, i) => ({
246-
identifier: `test-mcp-${i}`,
247-
lastModified: '2023-01-01',
248-
}));
249-
250-
vi.spyOn(sitemap['discoverService'], 'getMcpIdentifiers').mockResolvedValue(
251-
// @ts-ignore
252-
mockMcps,
253-
);
254-
255-
// Test first page (should have 80 items, all on first page)
256-
const firstPageSitemap = await sitemap.getMcp(1);
257-
expect(firstPageSitemap.length).toBe(80 * 15); // 80 items * 15 locales
258-
});
259-
});
260-
261219
describe('getProviders', () => {
262220
it('should return a valid providers sitemap', async () => {
263221
vi.spyOn(sitemap['discoverService'], 'getProviderIdentifiers').mockResolvedValue([
@@ -303,16 +261,6 @@ describe('Sitemap', () => {
303261
expect(pageCount).toBe(3); // 250 items / 100 per page = ceil(2.5) = 3 pages
304262
});
305263

306-
it('should return correct mcp page count', async () => {
307-
vi.spyOn(sitemap['discoverService'], 'getMcpIdentifiers').mockResolvedValue(
308-
// @ts-ignore
309-
Array.from({ length: 50 }, (_, i) => ({ identifier: `mcp-${i}` })),
310-
);
311-
312-
const pageCount = await sitemap.getMcpPageCount();
313-
expect(pageCount).toBe(1); // 50 items / 100 per page = 1 page
314-
});
315-
316264
it('should return correct model page count', async () => {
317265
vi.spyOn(sitemap['discoverService'], 'getModelIdentifiers').mockResolvedValue(
318266
// @ts-ignore

src/server/sitemap.ts

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ export class Sitemap {
5252
return Math.ceil(list.length / ITEMS_PER_PAGE);
5353
}
5454

55-
// 获取MCP总页数
56-
async getMcpPageCount(): Promise<number> {
57-
const list = await this.discoverService.getMcpIdentifiers();
58-
return Math.ceil(list.length / ITEMS_PER_PAGE);
59-
}
60-
6155
// 获取模型总页数
6256
async getModelPageCount(): Promise<number> {
6357
const list = await this.discoverService.getModelIdentifiers();
@@ -171,10 +165,9 @@ export class Sitemap {
171165
);
172166

173167
// 获取需要分页的类型的页数
174-
const [pluginPages, assistantPages, mcpPages, modelPages] = await Promise.all([
168+
const [pluginPages, assistantPages, modelPages] = await Promise.all([
175169
this.getPluginPageCount(),
176170
this.getAssistantPageCount(),
177-
this.getMcpPageCount(),
178171
this.getModelPageCount(),
179172
]);
180173

@@ -193,11 +186,6 @@ export class Sitemap {
193186
),
194187
),
195188
),
196-
...Array.from({ length: mcpPages }, (_, i) =>
197-
this._generateSitemapLink(
198-
getCanonicalUrl(SITEMAP_BASE_URL, isDev ? `mcp-${i + 1}` : `mcp-${i + 1}.xml`),
199-
),
200-
),
201189
...Array.from({ length: modelPages }, (_, i) =>
202190
this._generateSitemapLink(
203191
getCanonicalUrl(SITEMAP_BASE_URL, isDev ? `models-${i + 1}` : `models-${i + 1}.xml`),
@@ -239,31 +227,6 @@ export class Sitemap {
239227
return flatten(sitmap);
240228
}
241229

242-
async getMcp(page?: number): Promise<MetadataRoute.Sitemap> {
243-
const list = await this.discoverService.getMcpIdentifiers();
244-
245-
if (page !== undefined) {
246-
const startIndex = (page - 1) * ITEMS_PER_PAGE;
247-
const endIndex = startIndex + ITEMS_PER_PAGE;
248-
const pageMcps = list.slice(startIndex, endIndex);
249-
250-
const sitmap = pageMcps.map((item) =>
251-
this._genSitemap(urlJoin('/discover/mcp', item.identifier), {
252-
lastModified: item?.lastModified || LAST_MODIFIED,
253-
}),
254-
);
255-
return flatten(sitmap);
256-
}
257-
258-
// 如果没有指定页数,返回所有(向后兼容)
259-
const sitmap = list.map((item) =>
260-
this._genSitemap(urlJoin('/discover/mcp', item.identifier), {
261-
lastModified: item?.lastModified || LAST_MODIFIED,
262-
}),
263-
);
264-
return flatten(sitmap);
265-
}
266-
267230
async getPlugins(page?: number): Promise<MetadataRoute.Sitemap> {
268231
const list = await this.discoverService.getPluginIdentifiers();
269232

src/services/discover.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ class DiscoverService {
8383
});
8484
};
8585

86-
getMcpIdentifiers = async (): Promise<IdentifiersResponse> => {
87-
return lambdaClient.market.getMcpIdentifiers.query();
88-
};
89-
9086
getMcpList = async (params: McpQueryParams = {}): Promise<McpListResponse> => {
9187
const locale = globalHelpers.getCurrentLanguage();
9288
return lambdaClient.market.getMcpList.query({

src/store/discover/slices/mcp/action.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { DiscoverStore } from '@/store/discover';
88
import { globalHelpers } from '@/store/global/helpers';
99
import {
1010
DiscoverMcpDetail,
11-
IdentifiersResponse,
1211
McpListResponse,
1312
McpQueryParams,
1413
} from '@/types/discover';
@@ -20,7 +19,6 @@ export interface MCPAction {
2019
}) => SWRResponse<DiscoverMcpDetail>;
2120
useFetchMcpList: (params: McpQueryParams) => SWRResponse<McpListResponse>;
2221
useMcpCategories: (params: CategoryListQuery) => SWRResponse<CategoryItem[]>;
23-
useMcpIdentifiers: () => SWRResponse<IdentifiersResponse>;
2422
}
2523

2624
export const createMCPSlice: StateCreator<
@@ -61,10 +59,4 @@ export const createMCPSlice: StateCreator<
6159
},
6260
);
6361
},
64-
65-
useMcpIdentifiers: () => {
66-
return useClientDataSWR('mcp-identifiers', async () => discoverService.getMcpIdentifiers(), {
67-
revalidateOnFocus: false,
68-
});
69-
},
7062
});

0 commit comments

Comments
 (0)