Skip to main content
Glama
Talismanic

URL Shortener MCP

shorten

Convert long URLs into shorter, shareable links using the CleanURI API for easier distribution and management.

Instructions

Shorten a URL using the cleanuri API.

Args:
    original_url: The URL to shorten.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
original_urlYes

Implementation Reference

  • main.py:24-34 (handler)
    The main handler for the 'shorten' tool, registered via @mcp.tool() decorator. It invokes the helper to shorten the URL and returns the result or error message.
    @mcp.tool()
    async def shorten(original_url: str) -> str | None:
        """Shorten a URL using the cleanuri API.
    
        Args:
            original_url: The URL to shorten.
        """
        shortened_url = await shorten_url(original_url)
        if not shortened_url:
            return "Unable to shorten the URL."
        return shortened_url
  • main.py:9-21 (helper)
    Supporting helper function that performs the actual HTTP request to the cleanuri API to obtain the shortened URL.
    async def shorten_url(original_url: str) -> str | None:
        headers = {"Content-Type": "application/x-www-form-urlencoded"}
        data = {"url": original_url}
    
        async with httpx.AsyncClient() as client:
            try:
                response = await client.post(CLEANURI_API_URL, data=data, headers=headers, timeout=30.0)
                response.raise_for_status()
                result: dict[str, Any] = response.json()
                return result.get("result_url")
            except Exception as e:
                print(f"An error occurred: {e}")
                return None
Install Server

Other 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/Talismanic/cleanuri-url-shortener-mcp'

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