Skip to main content
Glama

shorten

Simplify lengthy URLs for easy sharing by transforming them into concise links using the CleanURI API. Ideal for integration into agent or tool-based systems.

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 'shorten' tool handler, decorated with @mcp.tool() for registration. It invokes the helper function to shorten the URL via CleanURI API and returns the result or an 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)
    Helper function that makes the asynchronous HTTP POST 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

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

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