html-meta-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/api.js +71 -0
- package/dist/index.js +4 -0
- package/dist/server.js +24 -0
- package/package.json +44 -0
- package/server.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# HTML Meta MCP
|
|
2
|
+
|
|
3
|
+
Fetch title, description, and open graph tags from a web page. No key required.
|
|
4
|
+
|
|
5
|
+
This file is self contained. It reads public data only and never writes to the machine. All output is bounded and honest about what could not be fetched.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
* `meta` Meta and open graph tags.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install
|
|
16
|
+
npm run build
|
|
17
|
+
node dist/index.js
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Link preview products charge for this. The page is fetched, bounded, and only the meta tags are returned.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const UA = "mrfentmen-html-meta-mcp/1.0 (https://github.com/mrfentmen)";
|
|
2
|
+
export class HtmlmetaError extends Error {
|
|
3
|
+
}
|
|
4
|
+
function attr(html, name) {
|
|
5
|
+
const re = new RegExp(`(?:name|property)="${name}"[^>]*content="([^"]*)"`, "i");
|
|
6
|
+
const m = html.match(re);
|
|
7
|
+
if (m)
|
|
8
|
+
return decodeEntities(m[1]).trim();
|
|
9
|
+
const re2 = new RegExp(`content="([^"]*)"[^>]*(?:name|property)="${name}"`, "i");
|
|
10
|
+
const m2 = html.match(re2);
|
|
11
|
+
return m2 ? decodeEntities(m2[1]).trim() : null;
|
|
12
|
+
}
|
|
13
|
+
function decodeEntities(s) {
|
|
14
|
+
return s
|
|
15
|
+
.replace(/'/g, "'")
|
|
16
|
+
.replace(/"/g, '"')
|
|
17
|
+
.replace(/&/g, "&")
|
|
18
|
+
.replace(/</g, "<")
|
|
19
|
+
.replace(/>/g, ">")
|
|
20
|
+
.replace(/ /g, " ");
|
|
21
|
+
}
|
|
22
|
+
function first(html, regex) {
|
|
23
|
+
const m = html.match(regex);
|
|
24
|
+
return m ? decodeEntities(m[1]).replace(/\s+/g, " ").trim() : null;
|
|
25
|
+
}
|
|
26
|
+
export async function meta(args) {
|
|
27
|
+
const raw = (args.url ?? "").trim();
|
|
28
|
+
if (!raw)
|
|
29
|
+
throw new HtmlmetaError("Provide a URL");
|
|
30
|
+
const url = /^https?:\/\//i.test(raw) ? raw : `https://${raw}`;
|
|
31
|
+
let res;
|
|
32
|
+
try {
|
|
33
|
+
res = await fetch(url, {
|
|
34
|
+
headers: { "User-Agent": UA, Accept: "text/html" },
|
|
35
|
+
redirect: "follow",
|
|
36
|
+
signal: AbortSignal.timeout(15000),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
throw new HtmlmetaError(`Could not fetch ${url}: ${e instanceof Error ? e.message : String(e)}`);
|
|
41
|
+
}
|
|
42
|
+
if (!res.ok)
|
|
43
|
+
throw new HtmlmetaError(`HTTP ${res.status} from ${url}`);
|
|
44
|
+
const html = (await res.text()).slice(0, 400000);
|
|
45
|
+
const title = attr(html, "og:title") ?? first(html, /<title[^>]*>([^<]*)<\/title>/i) ?? "no title";
|
|
46
|
+
const description = attr(html, "og:description") ?? attr(html, "description") ?? "no description";
|
|
47
|
+
const image = attr(html, "og:image");
|
|
48
|
+
const site = attr(html, "og:site_name");
|
|
49
|
+
const type = attr(html, "og:type");
|
|
50
|
+
const canonical = first(html, /<link[^>]*rel="canonical"[^>]*href="([^"]*)"/i);
|
|
51
|
+
const author = attr(html, "author");
|
|
52
|
+
const published = attr(html, "article:published_time");
|
|
53
|
+
const lines = [
|
|
54
|
+
`URL: ${url}`,
|
|
55
|
+
`Title: ${title.slice(0, 200)}`,
|
|
56
|
+
`Description: ${description.slice(0, 300)}`,
|
|
57
|
+
];
|
|
58
|
+
if (site)
|
|
59
|
+
lines.push(`Site: ${site}`);
|
|
60
|
+
if (type)
|
|
61
|
+
lines.push(`Type: ${type}`);
|
|
62
|
+
if (image)
|
|
63
|
+
lines.push(`Image: ${image}`);
|
|
64
|
+
if (canonical)
|
|
65
|
+
lines.push(`Canonical: ${canonical}`);
|
|
66
|
+
if (author)
|
|
67
|
+
lines.push(`Author: ${author}`);
|
|
68
|
+
if (published)
|
|
69
|
+
lines.push(`Published: ${published.slice(0, 10)}`);
|
|
70
|
+
return lines.join("\n");
|
|
71
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2
|
+
import { createServer } from "./server.js";
|
|
3
|
+
const main = async () => { const server = createServer(); await server.connect(new StdioServerTransport()); };
|
|
4
|
+
main().catch((error) => { console.error("Fatal error:", error); process.exit(1); });
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { meta } from "./api.js";
|
|
4
|
+
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
5
|
+
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
6
|
+
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
7
|
+
const error = (e) => `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
8
|
+
export function createServer() {
|
|
9
|
+
const server = new McpServer({ name: "html-meta-mcp", version: "1.0.0" });
|
|
10
|
+
server.registerTool("meta", {
|
|
11
|
+
title: "Meta",
|
|
12
|
+
description: "Meta and open graph tags for a URL.",
|
|
13
|
+
inputSchema: z.object({ url: z.string().describe("URL to inspect.") }),
|
|
14
|
+
annotations: READ_ONLY,
|
|
15
|
+
}, async (args) => {
|
|
16
|
+
try {
|
|
17
|
+
return text(await meta(args));
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
return textError(error(e));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return server;
|
|
24
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/mrfentmen/html-meta-mcp.git"
|
|
7
|
+
},
|
|
8
|
+
"bin": {
|
|
9
|
+
"html-meta-mcp": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"server.json",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"start": "node dist/index.js",
|
|
20
|
+
"dev": "npm run build && node dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
25
|
+
"zod": "^3.23.8"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
29
|
+
"typescript": "^5.6.0"
|
|
30
|
+
},
|
|
31
|
+
"name": "html-meta-mcp",
|
|
32
|
+
"description": "Fetch title, description, and open graph tags from a web page. No key required.",
|
|
33
|
+
"mcpName": "io.github.mrfentmen/html-meta-mcp",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"mcp",
|
|
36
|
+
"metadata",
|
|
37
|
+
"opengraph",
|
|
38
|
+
"preview",
|
|
39
|
+
"web"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.mrfentmen/html-meta-mcp",
|
|
4
|
+
"description": "Fetch title, description, and open graph tags from a web page. No key required.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/mrfentmen/html-meta-mcp",
|
|
7
|
+
"source": "github"
|
|
8
|
+
},
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"packages": [
|
|
11
|
+
{
|
|
12
|
+
"registryType": "npm",
|
|
13
|
+
"identifier": "html-meta-mcp",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"transport": {
|
|
16
|
+
"type": "stdio"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|