@specstory/tnydev-mcp
Version:
MCP server for tny.dev URL shortening service - AI agent integration for link management
80 lines ⢠2.95 kB
JavaScript
import { z } from 'zod';
const ListLinksSchema = z.object({
page: z.number()
.int()
.positive()
.optional()
.default(1)
.describe('Page number (default: 1)'),
limit: z.number()
.int()
.min(1)
.max(100)
.optional()
.default(20)
.describe('Number of links per page (1-100, default: 20)')
});
export async function handleListLinks(params, client) {
const parsed = ListLinksSchema.parse(params);
try {
const result = await client.listLinks(parsed.page, parsed.limit);
const rateLimitInfo = client.getRateLimitInfo();
// Format the links list
let linksText = `š **Your Shortened Links** (Page ${result.pagination.page}/${result.pagination.total_pages}):\n\n`;
if (result.links.length === 0) {
linksText += 'No links found.';
}
else {
result.links.forEach((link, index) => {
const num = (parsed.page - 1) * parsed.limit + index + 1;
linksText += `**${num}. ${link.short_url}**\n`;
linksText += ` ā ${link.long_url}\n`;
linksText += ` š Clicks: ${link.click_count} | š
Created: ${new Date(link.created_at).toLocaleDateString()}\n`;
linksText += ` š Slug: \`${link.id}\`\n\n`;
});
}
// Add pagination info
linksText += `\nš **Pagination**:\n`;
linksText += `- Total links: ${result.pagination.total}\n`;
linksText += `- Page ${result.pagination.page} of ${result.pagination.total_pages}\n`;
linksText += `- Showing ${result.links.length} links`;
if (result.pagination.page < result.pagination.total_pages) {
linksText += `\n- To see next page, use: page: ${result.pagination.page + 1}`;
}
if (rateLimitInfo) {
linksText += `\n\nā” Rate Limit: ${rateLimitInfo.remaining}/${rateLimitInfo.limit} requests remaining (${rateLimitInfo.tier} tier)`;
}
return {
content: [
{
type: "text",
text: linksText
}
]
};
}
catch (error) {
throw new Error(`Failed to list links: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}
export const listLinksTool = {
name: "list_links",
description: "List all shortened links created with your API key",
inputSchema: {
type: "object",
properties: {
page: {
type: "number",
minimum: 1,
description: "Page number (default: 1)"
},
limit: {
type: "number",
minimum: 1,
maximum: 100,
description: "Number of links per page (1-100, default: 20)"
}
}
}
};
//# sourceMappingURL=links.js.map