url_metadata
Extract metadata from URLs to analyze web content for security research and intelligence gathering.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to scrape metadata from |
Implementation Reference
- src/tools/social.ts:12-49 (handler)The scrapeMetadata method in SocialScraperClient implements the scraping logic used by the url_metadata tool.
async scrapeMetadata(url: string): Promise<any> { try { const response = await fetch(url); const html = await response.text(); const metadata: any = { title: "", description: "", ogTitle: "", ogDescription: "", ogImage: "", twitterCard: "", generator: "", }; // Simple regex-based extraction to avoid heavy dependencies like cheerio const titleMatch = html.match(/<title>(.*?)<\/title>/i); if (titleMatch) metadata.title = titleMatch[1]; const metaMatches = html.matchAll(/<meta\s+(?:name|property)="([^"]+)"\s+content="([^"]+)"/gi); for (const match of metaMatches) { const prop = match[1].toLowerCase(); const content = match[2]; if (prop === "description") metadata.description = content; if (prop === "og:title") metadata.ogTitle = content; if (prop === "og:description") metadata.ogDescription = content; if (prop === "og:image") metadata.ogImage = content; if (prop === "twitter:card") metadata.twitterCard = content; if (prop === "generator") metadata.generator = content; } return metadata; } catch (error) { throw new McpError(ErrorCode.InternalError, `Social Scraper error: ${(error as Error).message}`); } } } - src/index.ts:501-509 (registration)Registration of the url_metadata tool within the server instance.
server.tool( "url_metadata", { url: z.string().url().describe("URL to scrape metadata from") }, async ({ url }) => { const result = await socialClient.scrapeMetadata(url); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }