get_featured_packages
Retrieve featured Typst Universe packages to discover useful tools and templates for document creation.
Instructions
Get a list of featured/popular packages from Typst Universe.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/scraper.ts:237-268 (handler)The core handler function that scrapes the Typst Universe homepage using Cheerio to extract featured packages, parses name, version, description from links, removes duplicates, and returns TypstPackage[].export async function getFeaturedPackages(): Promise<TypstPackage[]> { const html = await fetchPage(UNIVERSE_URL); const $ = cheerio.load(html); const packages: TypstPackage[] = []; // Featured packages are typically at the top of the main page $('a[href^="/universe/package/"]').slice(0, 20).each((_, element) => { const $el = $(element); const href = $el.attr('href'); if (!href) return; const text = $el.text().trim(); const match = text.match(/^([a-z0-9_-]+)(\d+\.\d+\.\d+)(.*)$/i); if (match) { const [, name, version, description] = match; packages.push({ name: name.trim(), version: version.trim(), description: description.trim(), url: `${BASE_URL}${href}`, }); } }); // Remove duplicates return packages.filter((pkg, index, self) => index === self.findIndex(p => p.name === pkg.name) ); }
- src/index.ts:72-79 (registration)Tool registration in the TOOLS array: defines name, description, and empty inputSchema (no parameters). This is returned by listTools.{ name: 'get_featured_packages', description: 'Get a list of featured/popular packages from Typst Universe.', inputSchema: { type: 'object', properties: {}, }, },
- src/index.ts:254-277 (handler)MCP server request handler for tool calls: specifically the switch case that executes getFeaturedPackages(), handles empty results, formats output with formatPackage, and constructs the response content.case 'get_featured_packages': { const packages = await getFeaturedPackages(); if (packages.length === 0) { return { content: [ { type: 'text', text: 'No featured packages found.', }, ], }; } const formattedResults = packages.map(formatPackage).join('\n\n'); return { content: [ { type: 'text', text: `Featured packages (${packages.length}):\n\n${formattedResults}`, }, ], }; }
- src/scraper.ts:6-11 (schema)TypeScript interface defining the structure of a TypstPackage, used as input to formatPackage and output type of getFeaturedPackages.export interface TypstPackage { name: string; version: string; description: string; url: string; }
- src/index.ts:97-99 (helper)Utility function to format a single TypstPackage into a readable string for inclusion in the tool response.function formatPackage(pkg: TypstPackage): string { return `📦 ${pkg.name} v${pkg.version}\n ${pkg.description}\n URL: ${pkg.url}`; }