Back to Blog

URL Shortener API and MCP Server: Create Smart Links From Code or Your AI Assistant

Shorten links, read click analytics and make QR codes with a REST API, or ask Claude, Cursor or VS Code over MCP. Copy-paste examples included.

Smart Link Team
5 min read
Blog Post
APIMCPDevelopersAI AgentsAutomationSmart Link
Share:
URL Shortener API and MCP Server: Create Smart Links From Code or Your AI Assistant

Creating links by hand is fine for one launch. It breaks down when every product, campaign, release or customer needs its own tracked link. At that point you want a URL shortener API: something your code, your CMS or your automation tool can call.

And in 2026 there is a second consumer of that API: your AI assistant. With an MCP server, Claude, Cursor or VS Code can create links and answer "which link did best last week?" without you opening a dashboard.

This guide covers both. It walks through the Smart Link REST API with working examples, then shows how to connect the same account to an AI assistant over the Model Context Protocol.

What a URL shortener API should give you

Plenty of shorteners have an API. Before you build on one, check that it covers the whole lifecycle, not just "make a short URL":

  • Create links with your own code, title, expiry and password.
  • Look up and update links: rename, pause, change the expiry.
  • Delete links cleanly.
  • Analytics per link and across the account: clicks, unique visitors, countries, devices, referrers.
  • QR codes for any link, as PNG or SVG.
  • Clear limits and errors so your integration fails loudly instead of silently.

The Smart Link API does all of the above. Every link it creates is also a smart link, so a YouTube, Instagram, Spotify or Amazon URL opens in the right app on the visitor's phone. More on that in why opening the right app beats a browser tab.

Quickstart: shorten a URL with one request

Create an API key in Dashboard → API, then send it as a Bearer token:

curl https://smartlink.sh/api/v1/links \
  -H "Authorization: Bearer $SMARTLINK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"originalUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}'

The response includes the new shortUrl, the detected platform (here YOUTUBE) and the link's id for later calls.

The same thing from JavaScript:

const response = await fetch('https://smartlink.sh/api/v1/links', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SMARTLINK_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    originalUrl: 'https://open.spotify.com/album/...',
    customCode: 'new-album',
    title: 'New album',
  }),
});
const { data: link } = await response.json();
console.log(link.shortUrl);

The endpoints you will actually use

EndpointWhat it does
POST /api/v1/linksCreate a link (custom code, title, password, expiry, iOS/Android store URLs)
GET /api/v1/linksList and search links, with paging and filters
GET /api/v1/links/{id}Get one link
PATCH /api/v1/links/{id}Rename, pause or resume, change expiry or password
DELETE /api/v1/links/{id}Delete a link and its analytics
GET /api/v1/links/{id}/analyticsClicks, visitors, countries, devices, referrers for one link
GET /api/v1/analyticsThe same across your account, plus top links
GET /api/v1/links/{id}/qrA QR code as PNG or SVG

The full reference is in the API docs, and there is an OpenAPI 3.1 spec at /api/v1/openapi.json if you want to generate a client.

Pass both store URLs and the link sends each visitor to their own store:

{
  "originalUrl": "https://yourapp.com",
  "iosUrl": "https://apps.apple.com/app/id123456789",
  "androidUrl": "https://play.google.com/store/apps/details?id=com.yourapp"
}

See one link for iOS and Android app downloads for when this beats separate store badges.

Limits and errors

  • 60 requests per minute per key, shared between REST and MCP.
  • 1,000 new links per day per account.
  • Up to 5 active keys, so each integration can have its own and be revoked on its own.
  • Every response carries an X-Request-Id and rate-limit headers, and errors share one JSON shape, so retries and logging are simple.

Connect your AI assistant over MCP

MCP (Model Context Protocol) is an open standard that lets AI assistants call tools in other apps. Smart Link runs a remote MCP server at https://smartlink.sh/api/mcp. There is nothing to install: point your assistant at the URL and give it an API key.

In Claude Code, that is one command:

claude mcp add --transport http smartlink https://smartlink.sh/api/mcp \
  --header "Authorization: Bearer sl_live_YOUR_API_KEY"

Cursor, Claude Desktop, VS Code and Windsurf take a short JSON config. After you create a key, the dashboard shows each config with your key filled in, plus an Add to Cursor button. Details are in the MCP docs.

What you can ask

Once connected, your assistant gets tools for creating, listing, updating and deleting links, reading analytics, and making QR codes. In practice you just ask:

  • "Create a smart link for this YouTube video with the code launch, and give me a QR code for it."
  • "Which of my links got the most clicks from Germany in the last 7 days?"
  • "Make one link for my app that sends iPhones to the App Store and Android phones to Google Play."
  • "Pause every link whose title contains 'summer sale'."
  • "Compare mobile and desktop clicks across my account this month."

Automation ideas

  • E-commerce: create a tracked smart link for every new product and put it in the launch email.
  • Music releases: generate a link and QR code for each single the day it drops, and pull streaming-click reports a week later.
  • Agencies: one link per client campaign, with a weekly analytics pull into your reporting sheet.
  • Event check-ins: a password-protected link with an expiry that ends when the event does.
  • AI workflows: let an agent that writes social posts also create the link it shares, then report which post drove the most taps.

Frequently asked questions

Is the URL shortener API free?

The API and MCP server are included in Smart Link Pro, which also covers every dashboard feature. There is one plan, and you can cancel anytime.

Do API links get the same app routing as dashboard links?

Yes. Every link opens the right app on iPhone and Android, falls back to the web when the app is missing, and records the same analytics.

Which AI assistants work with the MCP server?

Any client that supports remote MCP over Streamable HTTP with a custom Authorization header, including Claude Code, Claude Desktop, Cursor, VS Code and Windsurf.

Can I use my own short codes?

Yes. Pass customCode when you create a link. If the code is taken, the API returns 409 so your code can pick another.

Start building

Get an API key from your dashboard, run the curl example above, and you will have a tracked, app-opening short link in under a minute. Then connect your assistant and ask it how your links did this week.

Read the API docs or set up the MCP server.

Published on October 18, 2026
Actionable Insights

Go beyond the click.

Transform your links into intelligence. Get started with our powerful analytics platform today.