Skip to main content
Glama
tealight-uk

U301 URL Shortener MCP Server

u301_shortening_urls_in_bulk

Batch shorten up to 200 long URLs in one request using custom domains, slugs, expiration dates, and optional passwords. Simplify URL management with the U301 URL Shortener MCP Server.

Instructions

Use U301's short link service API to batch shorten long URLs. Custom domains are supported, with up to 200 URLs per request. You should provide as "{ urls: []}" Current ShortLink domain is u301.co URLItem Supported Parameters areurl: required, the URL to be shortened slug: optional, a custom slug for the shortened URL, the final shortened URL will be https://u301.co/ if you leave it empty, random slug will create expiredAt: optional, the expiration date for the shortened URL, e.g. 2023-01-01T00:00:00Z password: optional, a password for the shortened URL comment: optional, a comment, displayed on the dashboard

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlsYes

Implementation Reference

  • The tool handler function registered with server.tool. It validates the input URLs array, limits to 200, makes a POST request to U301 bulk shorten endpoint, formats the results using helper functions, and returns success or error response.
    server.tool(toolName, toolDescription, { urls: inputSchema }, async(args) => {
        const urls = inputSchema.parse(args.urls);
        if (urls.length > 200) {
            throw new Error("Too many URLs provided");
        } else if (urls.length === 0) {
            throw new Error("No URLs provided");
        }
        try {
            const responseLinks = await U301Request<(ShortenedURL | ShortenedURLFailed)[]>(`/shorten/bulk?workspaceId=${workspaceId}`, {
                method: "POST",
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(urls.map((url) => ({
                    url: url.url,
                    slug: url.slug,
                    domain: shortenDomain,
                    expiredAt: url.expiredAt,
                    password: url.password,
                    comment: url.comment,
                }))),
            })
            if (!responseLinks) {
                throw new Error("No response from U301 API");
            }
            return {
                content: [{ type: "text", text: formatResults(responseLinks) }],
                isError: false,
            }
        } catch (e) {
            return {
                content: [{ type: "text", text: `Error: ${e}` }],
                isError: true,
            }
        }
    })
  • Zod schema defining the input structure: an array of URL shortening requests, each with required 'url' and optional 'slug', 'expiredAt', 'password', 'comment'.
    const inputSchema = z.array(z.object({
        url: z.string({
            description: "URL to shorten e.g. https://example.com/very/long/url"
        }),
        slug: z.string({
            description: "(optional) Custom slug for the shortened URL"
        }).optional(),
        expiredAt: z.string({
            description: "(optional) Expiration date for the shortened URL, e.g. 2023-01-01T00:00:00Z",
            coerce: true,
        }).optional(),
        password: z.string({
            description: "(optional) Password for the shortened URL"
        }).optional(),
        comment: z.string({
            description: "(optional) Comment, displayed on the dashboard"
        }).optional(),
    }))
  • src/index.ts:49-62 (registration)
    Tool name, detailed description, and registration call to server.tool with schema and handler.
    const toolName = "u301_shortening_urls_in_bulk"
    const toolDescription = `Use U301's short link service API to batch shorten long URLs. Custom domains are supported, with up to 200 URLs per request.
    You should provide as "{ urls: <URLItem>[]}"
    Current ShortLink domain is ${shortenDomain}
    URLItem Supported Parameters are` +
    [
        "url: required, the URL to be shortened",
        `slug: optional, a custom slug for the shortened URL, the final shortened URL will be https://${shortenDomain}/<slug>
        if you leave it empty, random slug will create`,
        "expiredAt: optional, the expiration date for the shortened URL, e.g. 2023-01-01T00:00:00Z",
        "password: optional, a password for the shortened URL",
        "comment: optional, a comment, displayed on the dashboard"
    ].join("\n");
    server.tool(toolName, toolDescription, { urls: inputSchema }, async(args) => {
  • Helper function for making authenticated HTTP requests to the U301 API, used by the handler for the bulk shorten call.
    async function U301Request<T>(url: string, options?: RequestInit): Promise<T | null> {
        options = options || {} as RequestInit;
        const originalHeaders = options?.headers || {};
        options.headers = {
            'User-Agent': USER_AGENT,
            'Authorization': `Bearer ${U301_API_KEY}`,
            'Accept-Encoding': 'gzip',
            'Accept': 'application/json',
            ...originalHeaders
        };
        const response = await fetch(U301_API_BASE + url, options);
        if (!response.ok) {
            throw new Error(`U301 API error: ${response.status} ${response.statusText}\n${await response.text()}`);
        }
        return (await response.json()) as T;
    }
  • Helper functions to check if a link shortening failed (type guard) and to format the results into a readable text output.
    function isFailedLink(link: ShortenedURL | ShortenedURLFailed): link is ShortenedURLFailed {
        return (link as ShortenedURLFailed).error !== undefined;
    }
    
    function formatResults(links: (ShortenedURL | ShortenedURLFailed)[]): string {
        return (links || []).map((link, i) => {
            if (isFailedLink(link)) {
                return `[${i}]: Failed to shorten ${link.url}: ${link.error} - ${link.message}`;
            }
    
            const items = [
                `Index: ${i}`,
                `Id: ${link.id}`,
                `Original URL: ${link.url}`,
                `Short Link: ${link.shortLink}`,
                `Domain: ${link.domain}`,
                `Reused: ${link.isReused ? 'Yes' : 'No'}`,
                `Comment: ${link.comment || 'N/A'}`,
            ];
            return items.join('\n')
        }).join('\n---\n');
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the batch limit (200 URLs) and custom domain support, which are useful behavioral traits. However, it lacks critical details like authentication requirements, rate limits, error handling, or what the response format looks like, leaving significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the core purpose. However, it includes minor redundancy (e.g., repeating 'optional' for parameters already labeled as such in the text) and could be more streamlined. Most sentences earn their place by adding value, but slight editing could improve efficiency.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (batch mutation with multiple optional parameters), no annotations, and no output schema, the description is moderately complete. It covers the purpose, batch limit, domain, and parameter semantics well, but lacks behavioral details like authentication, response format, or error handling, which are important for a mutation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must fully compensate. It provides detailed semantics for all parameters: the required 'urls' array structure, and for each URLItem, it explains 'url' (required), 'slug' (optional with default behavior), 'expiredAt' (format example), 'password', and 'comment' (dashboard display). This adds substantial meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('batch shorten long URLs'), resource ('U301's short link service API'), and scope ('up to 200 URLs per request'). It distinguishes this as a bulk operation tool with no siblings to differentiate from, making the purpose highly specific and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for batch URL shortening with custom domain support, but provides no explicit guidance on when to use this tool versus alternatives (e.g., single URL shortening), prerequisites, or exclusions. With no sibling tools, the context is limited to the implied batch scenario.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/tealight-uk/u301-mcp'

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