gp_suggest
Retrieves Google Play Store search suggestions and autocomplete results for specified terms, supporting country and language customization.
Instructions
[Google Play] Get search suggestions/autocomplete
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| term | Yes | Search term to get suggestions for | |
| country | No | Two-letter country code (default: us) | us |
| lang | No | Language code (default: en) | en |
Implementation Reference
- src/server.js:900-935 (handler)Main handler function for gp_suggest tool. Validates input, builds URL using buildGPSuggestUrl, fetches JSON from Google Play suggest API, parses with parseGPSuggest, and returns formatted response or error.async function handleGPSuggest(args) { try { const { term, country = 'us', lang = 'en' } = args; if (!term) { throw new Error('term is required'); } const url = buildGPSuggestUrl({ term, country, lang }); const data = await fetchJSON(url); const suggestions = parseGPSuggest(data); return { content: [ { type: 'text', text: JSON.stringify({ term, suggestions, count: suggestions.length, }, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: error.message }, null, 2), }, ], isError: true, }; } }
- src/server.js:1412-1435 (registration)Tool registration in ListToolsRequestHandler, including name, description, and input schema (term required, country/lang optional).{ name: 'gp_suggest', description: '[Google Play] Get search suggestions/autocomplete', inputSchema: { type: 'object', properties: { term: { type: 'string', description: 'Search term to get suggestions for', }, country: { type: 'string', description: 'Two-letter country code (default: us)', default: 'us', }, lang: { type: 'string', description: 'Language code (default: en)', default: 'en', }, }, required: ['term'], }, },
- src/server.js:1484-1485 (registration)Dispatch case in CallToolRequestHandler switch statement that routes gp_suggest calls to handleGPSuggest.case 'gp_suggest': return await handleGPSuggest(args);
- Parser helper that handles various response formats from Google Play suggest API, extracts terms and priorities, sorts by priority.export function parseSuggest(data) { if (!data) { return []; } const suggestions = []; try { let jsonData; if (typeof data === 'string') { jsonData = JSON.parse(data); } else { jsonData = data; } // Google Play suggest API returns suggestions in various formats if (Array.isArray(jsonData)) { jsonData.forEach(item => { if (typeof item === 'string') { suggestions.push({ term: item }); } else if (item.suggestion || item.term || item.q) { suggestions.push({ term: item.suggestion || item.term || item.q, priority: item.priority || 0, }); } }); } else if (jsonData.suggestions || jsonData.data) { const suggestList = jsonData.suggestions || jsonData.data || []; suggestList.forEach(item => { suggestions.push({ term: item.suggestion || item.term || item.q || item, priority: item.priority || 0, }); }); } else if (jsonData.q) { // Single suggestion suggestions.push({ term: jsonData.q, priority: jsonData.priority || 0, }); } return suggestions.sort((a, b) => (b.priority || 0) - (a.priority || 0)); } catch (error) { console.error('Error parsing Google Play suggestions:', error); return []; } }
- src/endpoints/googlePlay.js:189-198 (helper)URL builder helper that constructs the Google Play suggest API endpoint with query parameters for term, country (gl), and language (hl).export function buildSuggestUrl(params) { const { term, country = 'us', lang = 'en' } = params; if (!term) { throw new Error('term is required'); } // Google Play uses a different endpoint for suggestions return `https://market.android.com/suggest/SuggRequest?json=1&c=3&query=${encodeURIComponent(term)}&gl=${country}&hl=${lang}`; }