url-shortener-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@url-shortener-mcpShorten https://example.com/article to a short link with tag 'blog'"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
url-shortener-mcp
A URL shortener exposed as an MCP server. Built with Express, Prisma, TypeScript, and SQLite.
Shorten URLs, set expiry times, tag them with a purpose note, and manage your links directly from any MCP-compatible LLM client.
This server is designed to be deployed remotely. Short URLs are only useful if they resolve publicly, and MCP clients connect over HTTP — so the server should run on a machine with a public hostname (e.g. a VPS, cloud VM, or PaaS). Set
HOSTNAMEto your public domain andHTTPS=truein production. Running it onlocalhostis fine for development, but short links won't be shareable outside your machine.
Table of Contents
Quick Start (npx)
The fastest way to get running — no cloning required:
npx url-shortener-mcp --port 3000 --hostname your-domain.com --https trueOn first run the server will:
Create a fresh SQLite database and apply all migrations automatically
Generate an API key and print it once — save it, it will not be shown again
Start listening
All environment variables can be passed as CLI flags:
npx url-shortener-mcp \
--port 3000 \
--database-url file:/data/urls.db \
--hostname your-domain.com \
--https true \
--enable-api true \
--enable-mcp trueFlag | Env var |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Flags take precedence over values set in a .env file.
Creating a user
To create a user without starting the server, pass --create-user:
npx url-shortener-mcp --create-userThis prints a user ID and API key, then exits. Store the key securely — it will not be shown again.
Getting Started (from source)
1. Install dependencies
pnpm install2. Set up environment
pnpm init-envThis copies .env.example to .env. Edit .env to configure your hostname, port, and other settings.
3. Run database migrations
pnpm db:migrate4. Create a user
pnpm user:createThis outputs a user ID and API key. Store the key securely — it will not be shown again.
User created successfully.
ID: clxyz...
Key: a1b2c3d4...
Store this key securely — it will not be shown again.5. Start the server
Development (with hot reload):
pnpm devProduction:
pnpm build && pnpm startThe server runs on http://localhost:3000 by default.
Docker
Setup
pnpm init-envEdit .env to configure your hostname, port, and other settings.
Development
Hot reload via nodemon + ts-node:
docker compose upProduction
Compiles TypeScript and runs the built output:
docker compose -f docker-compose.prod.yaml upThe database is persisted in a named Docker volume (db_data).
MCP Configuration
Add this server to your MCP client (e.g. Claude Desktop, Cursor):
{
"mcpServers": {
"url-shortener": {
"url": "https://your-domain.com/mcp",
"headers": {
"Authorization": "Bearer <your-api-key>"
}
}
}
}Replace https://your-domain.com with the public URL of your deployed server.
MCP Capabilities
Tools
Tool | Description |
| Create a shortened URL and return the short URL. Accepts an optional |
| Shorten up to 20 URLs in a single call. Each item accepts a |
| Search your URLs by |
| Get the full record and click count for a URL you own. |
| List all your shortened URLs. |
| Return aggregate stats for your active URLs: total count and total |
| Delete a shortened URL by slug. |
| Delete all your shortened URLs. |
The tag field
shorten_url and bulk_shorten_urls accept an optional tag — a short, agent-written note describing a URL's purpose (e.g. "stripe webhook docs", "PR #99", "staging deploy"). Tags are stored alongside the URL and are searchable via search_urls. Setting a tag at creation time means you can retrieve any URL later by purpose without keeping the full URL in context.
The estimatedTokensSaved field
Each URL record includes estimatedTokensSaved — an estimate of how many tokens are saved per substitution when using the slug instead of the full URL (computed using a ~4 chars/token heuristic). This is a per-use delta, not a cumulative total. Token savings only materialise when the slug is reused across multiple turns; single-use URLs will cost more context overall than pasting the original URL inline. get_stats returns the sum across all active URLs.
Resources
URI | Description |
| All your shortened URLs as JSON |
| A single shortened URL by slug |
Prompts
Prompt | Args | Description |
|
| Injects a user+assistant message pair into the conversation suggesting the user shorten the given URL. Designed to be invoked automatically by clients when a long URL appears in context. |
Sampling
When a client supports the MCP sampling capability and either slug or tag is missing from a shorten_url call, the server asks the connected LLM to suggest both in a single round-trip — returning a JSON object with a short, memorable slug and a brief purpose tag. If sampling is not supported or fails, a random slug is generated and tag is left unset.
AI Agent Rules
Add the following rule to your CLAUDE.md, system prompt, or any file your AI client loads as instructions. It tells the agent to automatically load URLs into the shortener during research so they can be retrieved later without bloating the context window.
## URL Shortener
This MCP server is available for shortening and tracking URLs.
When you encounter or are given a URL during research, browsing, or tool use:
1. Shorten it immediately using the `shorten_url` tool.
2. Always set a `tag` — a short phrase describing the URL's purpose
(e.g. "auth API reference", "PR #42", "deployment guide").
3. Use the returned short URL in all subsequent messages and tool calls
instead of the full URL.
When you need to refer back to a URL:
- Use `search_urls` with a partial `tag` or `longUrl` fragment to find it.
- Do not keep full URLs in your context when a slug exists for them.
Tag examples:
"stripe webhook docs" — for https://stripe.com/docs/webhooks
"main repo" — for the project's GitHub URL
"PR #99" — for a specific pull request
"staging deploy" — for a deployment URL you need to revisitThis rule is particularly effective in long research sessions where many URLs appear — tagging at creation time means you can retrieve any link later with a natural-language search rather than scrolling back through the conversation.
REST API
The server exposes a REST API under /urls using the same Bearer token auth. Short URLs resolve via public redirects at /:slug.
Method | Path | Description |
|
| List all your shortened URLs. Supports |
|
| Create a shortened URL. Body: |
|
| Shorten up to 20 URLs in one request. Body: |
|
| Search your URLs by |
|
| Get the full record for a URL you own. |
|
| Delete a URL you own. |
|
| Delete all your URLs. |
|
| Redirect to the original URL (public, increments click count). |
Environment Variables
Variable | Default | Description |
|
| Server port |
|
| Node environment. Set to |
|
| SQLite database path |
|
| Hostname used when building short URLs |
|
| Use |
|
| Maximum allowed TTL (default: 24 hours) |
|
| Cron schedule for cleaning up expired URLs |
|
| Automatically delete users inactive longer than this (default: 1 week) |
|
| Cron schedule for cleaning up inactive users (default: hourly) |
|
| Enable the REST API ( |
|
| Enable the MCP server ( |
Example Use Cases
Once configured, you can ask your LLM assistant:
"Shorten https://github.com/anthropics/anthropic-sdk-python/blob/main/README.md with a custom slug
anthropic-pythat expires in 12 hours, then list all my active URLs."
The assistant will call shorten_url with longUrl, slug, and ttl set appropriately, then call list_urls to show you the results — returning something like http://localhost:3000/anthropic-py.
If no slug or tag is provided and sampling is supported, the assistant will automatically suggest both:
"Shorten https://github.com/anthropics/anthropic-sdk-python/blob/main/README.md"
→ The server asks the LLM to suggest a slug (e.g. anthropic-sdk-py) and a tag (e.g. anthropic python SDK readme), then creates the short URL with both set.
You can retrieve a URL later by the tag you set at creation time:
"Find the URL I saved for the Anthropic SDK docs."
→ The assistant calls search_urls with tag: "anthropic" and returns the matching short URL — no need to keep the full URL in context.
You can also check your overall usage:
"How many URLs have I shortened and what's my total estimated token savings?"
→ The assistant calls get_stats and reports the aggregate count and totalEstimatedTokensSaved across all active URLs.
You can also read your URLs as resources:
"Show me everything at
urls://all"
→ The client fetches the urls://all resource and the assistant summarises your active links.
Development
pnpm test # run tests
pnpm test:coverage # coverage report
pnpm check # lint + format
pnpm db:studio # open Prisma StudioThis server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
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/michaelshumshum/url-shortener-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server