digitalnz-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 +21 -0
- package/dist/api.js +45 -0
- package/dist/index.js +4 -0
- package/dist/server.js +38 -0
- package/package.json +44 -0
- package/server.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# DigitalNZ MCP
|
|
2
|
+
|
|
3
|
+
New Zealand cultural records from the public DigitalNZ API. 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
|
+
* `search` Search records.
|
|
11
|
+
* `record` Get a record.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install
|
|
17
|
+
npm run build
|
|
18
|
+
node dist/index.js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Data comes from the public DigitalNZ API.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const BASE = 'https://api.digitalnz.org/v3/records.json';
|
|
2
|
+
const UA = 'mrfentmen-digitalnz-mcp/1.0';
|
|
3
|
+
export async function search(args) {
|
|
4
|
+
const query = (args.query ?? '').trim();
|
|
5
|
+
if (!query)
|
|
6
|
+
return 'Provide search terms.';
|
|
7
|
+
const limit = Math.min(Math.max(Number(args.limit ?? 10) || 10, 1), 25);
|
|
8
|
+
const url = `${BASE}?text=${encodeURIComponent(query)}&per_page=${limit}`;
|
|
9
|
+
const res = await fetch(url, {
|
|
10
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
11
|
+
signal: AbortSignal.timeout(25000),
|
|
12
|
+
});
|
|
13
|
+
if (!res.ok)
|
|
14
|
+
throw new Error(`DigitalNZ returned ${res.status}`);
|
|
15
|
+
const d = (await res.json());
|
|
16
|
+
const results = d.search?.results ?? [];
|
|
17
|
+
if (!results.length)
|
|
18
|
+
return `No DigitalNZ results for "${query}".`;
|
|
19
|
+
return `DigitalNZ results for "${query}" (total ${d.search?.result_count ?? results.length}):\n` +
|
|
20
|
+
results.slice(0, limit).map((r, i) => `${i + 1}. ${r.title ?? '?'} [${r.display_content_partner ?? '?'}] id=${r.id ?? '?'}`).join('\n');
|
|
21
|
+
}
|
|
22
|
+
export async function record(args) {
|
|
23
|
+
const id = (args.id ?? '').trim();
|
|
24
|
+
if (!id)
|
|
25
|
+
return 'Provide a record id.';
|
|
26
|
+
const url = `${BASE}?id=${encodeURIComponent(id)}`;
|
|
27
|
+
const res = await fetch(url, {
|
|
28
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
29
|
+
signal: AbortSignal.timeout(25000),
|
|
30
|
+
});
|
|
31
|
+
if (!res.ok)
|
|
32
|
+
throw new Error(`DigitalNZ returned ${res.status}`);
|
|
33
|
+
const d = (await res.json());
|
|
34
|
+
const r = d.record ?? {};
|
|
35
|
+
return [
|
|
36
|
+
`DigitalNZ record ${id}`,
|
|
37
|
+
`Title: ${r.title ?? '?'}`,
|
|
38
|
+
r.description ? `Description: ${r.description.slice(0, 400)}` : null,
|
|
39
|
+
`Partner: ${r.display_content_partner ?? '?'}`,
|
|
40
|
+
r.category?.length ? `Categories: ${r.category.join(', ')}` : null,
|
|
41
|
+
r.date?.length ? `Dates: ${r.date.join(', ')}` : null,
|
|
42
|
+
r.thumbnail_url ? `Thumbnail: ${r.thumbnail_url}` : null,
|
|
43
|
+
r.landing_url ? `Link: ${r.landing_url}` : null,
|
|
44
|
+
].filter(Boolean).join('\n');
|
|
45
|
+
}
|
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,38 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { record } from "./api.js";
|
|
4
|
+
import { search } from "./api.js";
|
|
5
|
+
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
6
|
+
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
7
|
+
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
8
|
+
const error = (e) => `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
9
|
+
export function createServer() {
|
|
10
|
+
const server = new McpServer({ name: "digitalnz-mcp", version: "1.0.0" });
|
|
11
|
+
server.registerTool("search", {
|
|
12
|
+
title: "Search",
|
|
13
|
+
description: "Search records.",
|
|
14
|
+
inputSchema: z.object({ query: z.string().describe("Search terms."), limit: z.number().describe("Max results.").optional() }),
|
|
15
|
+
annotations: READ_ONLY,
|
|
16
|
+
}, async (args) => {
|
|
17
|
+
try {
|
|
18
|
+
return text(await search(args));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
return textError(error(e));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
server.registerTool("record", {
|
|
25
|
+
title: "Record",
|
|
26
|
+
description: "Get a record by id.",
|
|
27
|
+
inputSchema: z.object({ id: z.string().describe("Record id.") }),
|
|
28
|
+
annotations: READ_ONLY,
|
|
29
|
+
}, async (args) => {
|
|
30
|
+
try {
|
|
31
|
+
return text(await record(args));
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return textError(error(e));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return server;
|
|
38
|
+
}
|
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/digitalnz-mcp.git"
|
|
7
|
+
},
|
|
8
|
+
"bin": {
|
|
9
|
+
"digitalnz-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": "digitalnz-mcp",
|
|
32
|
+
"description": "New Zealand cultural records from DigitalNZ. No key required.",
|
|
33
|
+
"mcpName": "io.github.mrfentmen/digitalnz-mcp",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"mcp",
|
|
36
|
+
"digitalnz",
|
|
37
|
+
"new-zealand",
|
|
38
|
+
"culture",
|
|
39
|
+
"archives"
|
|
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/digitalnz-mcp",
|
|
4
|
+
"description": "New Zealand cultural records from DigitalNZ. No key required.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/mrfentmen/digitalnz-mcp",
|
|
7
|
+
"source": "github"
|
|
8
|
+
},
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"packages": [
|
|
11
|
+
{
|
|
12
|
+
"registryType": "npm",
|
|
13
|
+
"identifier": "digitalnz-mcp",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"transport": {
|
|
16
|
+
"type": "stdio"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|