fix: support collection ID in MCP URL path (not just slug)

This commit is contained in:
Ajax Davis 2026-01-13 22:41:41 +10:00
parent 3fe93b58d7
commit 2b4526ba95

View file

@ -42,15 +42,18 @@ function withTimeout<T>(promise: Promise<T>, ms: number, errorMessage: string):
} }
/** /**
* Find a public collection by username and slug * Find a public collection by username and slug or ID
* Supports both human-readable slugs and collection IDs for flexibility
*/ */
async function getPublicCollectionByUsernameAndSlug(username: string, slug: string) { async function getPublicCollectionByUsernameAndSlugOrId(username: string, slugOrId: string) {
return withTimeout( return withTimeout(
prisma.collection.findFirst({ prisma.collection.findFirst({
where: { where: {
slug, OR: [
{ slug: slugOrId, user: { username } },
{ id: slugOrId, user: { username } },
],
isPublic: true, isPublic: true,
user: { username },
}, },
select: { id: true, name: true, description: true, userId: true }, select: { id: true, name: true, description: true, userId: true },
}), }),
@ -280,7 +283,7 @@ export async function POST(request: NextRequest, context: RouteContext): Promise
); );
} }
const collection = await getPublicCollectionByUsernameAndSlug(username, slug); const collection = await getPublicCollectionByUsernameAndSlugOrId(username, slug);
if (!collection) { if (!collection) {
return NextResponse.json( return NextResponse.json(
@ -385,7 +388,7 @@ export async function GET(_request: NextRequest, context: RouteContext): Promise
return NextResponse.json({ error: `Invalid transport: ${transport}` }, { status: 400 }); return NextResponse.json({ error: `Invalid transport: ${transport}` }, { status: 400 });
} }
const collection = await getPublicCollectionByUsernameAndSlug(username, slug); const collection = await getPublicCollectionByUsernameAndSlugOrId(username, slug);
if (!collection) { if (!collection) {
return NextResponse.json({ error: 'Collection not found' }, { status: 404 }); return NextResponse.json({ error: 'Collection not found' }, { status: 404 });