ttbkk-mcp-server
Version:
MCP server providing access to Korean tteokbokki restaurant database with search, location-based queries, and brand information
93 lines • 2.67 kB
JavaScript
import { supabase } from '../lib/supabase.js';
/**
* Get all brands with place count (실제 ttbkk-web useBrandList 기반)
* @returns Array of brands sorted by place count
*/
export async function getBrandList() {
try {
// ttbkk-web useBrandList와 동일한 구조로 조회
const { data, error } = await supabase
.from('brand')
.select(`
*,
place_count:place(count)
`);
if (error) {
console.error('Supabase error:', error);
throw new Error(`Failed to get brand list: ${error.message}`);
}
if (!data) {
return [];
}
// place_count 기준으로 정렬 (ttbkk-web과 동일)
return data.sort((a, b) => {
const aCount = a.place_count?.[0]?.count || 0;
const bCount = b.place_count?.[0]?.count || 0;
return bCount - aCount;
});
}
catch (error) {
console.error('Error getting brand list:', error);
throw error;
}
}
/**
* Get specific brand details with hashtags
* @param brandId - Brand ID
* @returns Brand details with hashtags
*/
export async function getBrandDetails(brandId) {
try {
const { data, error } = await supabase
.from('brand')
.select(`
*,
hashtags:brand_hashtags!brand_id (
hashtag_id
),
place_count:place(count)
`)
.eq('id', brandId)
.single();
if (error) {
console.error('Supabase error:', error);
throw new Error(`Failed to get brand details: ${error.message}`);
}
if (!data) {
throw new Error(`Brand with ID ${brandId} not found`);
}
return data;
}
catch (error) {
console.error('Error getting brand details:', error);
throw error;
}
}
/**
* Search brands by name
* @param query - Search query for brand name
* @param limit - Maximum number of results
* @returns Array of matching brands
*/
export async function searchBrands(query, limit = 10) {
try {
const { data, error } = await supabase
.from('brand')
.select(`
*,
place_count:place(count)
`)
.ilike('name', `%${query}%`)
.limit(limit);
if (error) {
console.error('Supabase error:', error);
throw new Error(`Failed to search brands: ${error.message}`);
}
return data || [];
}
catch (error) {
console.error('Error searching brands:', error);
throw error;
}
}
//# sourceMappingURL=brand-list.js.map