Skip to main content
Glama
W1seGit

Typst Universe MCP Server

by W1seGit

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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: {},
        },
    },
  • 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}`,
                },
            ],
        };
    }
  • 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;
    }
  • 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}`;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/W1seGit/Typst-Universe-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server