lobid-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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lukas Lerche
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # lobid-mcp
2
+
3
+ Tiny, deterministic, LLM-facing MCP server for semantic reconciliation against the GND authority ecosystem via `lobid` + the GND reconciliation API.
4
+
5
+ Designed for local MCP clients such as:
6
+ - Claude Code
7
+ - Claude Desktop
8
+ - OpenCode
9
+ - Cursor
10
+
11
+ Typical workflow:
12
+ 1. provide ambiguous names, concepts, or Schlagwörter
13
+ 2. MCP returns plausible GND candidates
14
+ 3. LLM compares and interprets the results
15
+ 4. optionally retrieve enriched authority records
16
+
17
+ The MCP intentionally stays:
18
+ - tiny
19
+ - deterministic
20
+ - stdio-only
21
+ - token-aware
22
+ - additive instead of transformative
23
+ - KISS/YAGNI-first
24
+
25
+ ## Tools
26
+
27
+ - `match_gnd_entities`
28
+ - `get_gnd_record`
29
+ - `get_gnd_records`
30
+
31
+ ## Install
32
+
33
+ No local clone required.
34
+
35
+ Run directly via `npx`:
36
+
37
+ ```bash
38
+ npx lobid-mcp
39
+ ```
40
+
41
+ Or install globally:
42
+
43
+ ```bash
44
+ npm install -g lobid-mcp
45
+ ```
46
+
47
+ Then run:
48
+
49
+ ```bash
50
+ lobid-mcp
51
+ ```
52
+
53
+ ## Claude Desktop / OpenCode config
54
+
55
+ Example MCP configuration:
56
+
57
+ ```json
58
+ {
59
+ "mcpServers": {
60
+ "lobid-gnd": {
61
+ "command": "npx",
62
+ "args": ["lobid-mcp"]
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ ## Local development
69
+
70
+ ```bash
71
+ pnpm install
72
+ pnpm build
73
+ pnpm start
74
+ ```
75
+
76
+ ## Example prompts
77
+
78
+ - "Find likely GND entities for the following Schlagwörter"
79
+ - "Search the GND for these ambiguous author names"
80
+ - "Resolve these historical concepts against the GND"
81
+ - "Find plausible GND subject headings for these terms"
82
+
83
+ ## Example `match_gnd_entities`
84
+
85
+ ```json
86
+ {
87
+ "terms": [
88
+ "Goethe",
89
+ "Kafka",
90
+ "Thomas Mann"
91
+ ],
92
+ "limitPerTerm": 5,
93
+ "entityTypes": [
94
+ "Person"
95
+ ]
96
+ }
97
+ ```
98
+
99
+ ## Example `get_gnd_records`
100
+
101
+ ```json
102
+ {
103
+ "ids": [
104
+ "118540238",
105
+ "118560239"
106
+ ]
107
+ }
108
+ ```
109
+
110
+ ## Deployment checklist
111
+
112
+ ### Push code to GitHub
113
+
114
+ ```bash
115
+ git status
116
+ git add .
117
+ git commit -m "feat: improve lobid MCP"
118
+ git push
119
+ ```
120
+
121
+ ### Publish to npm
122
+
123
+ Make sure you are logged into npm:
124
+
125
+ ```bash
126
+ npm login
127
+ ```
128
+
129
+ Build the package:
130
+
131
+ ```bash
132
+ pnpm build
133
+ ```
134
+
135
+ Optionally inspect the package contents:
136
+
137
+ ```bash
138
+ npm pack --dry-run
139
+ ```
140
+
141
+ Publish:
142
+
143
+ ```bash
144
+ npm publish
145
+ ```
146
+
147
+ ### Verify installation
148
+
149
+ Test from a clean shell:
150
+
151
+ ```bash
152
+ npx lobid-mcp
153
+ ```
154
+
155
+ Or in Claude Desktop/OpenCode:
156
+
157
+ ```json
158
+ {
159
+ "mcpServers": {
160
+ "lobid-gnd": {
161
+ "command": "npx",
162
+ "args": ["lobid-mcp"]
163
+ }
164
+ }
165
+ }
166
+ ```
package/build/index.js ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer, StdioServerTransport } from "@modelcontextprotocol/server";
3
+ import { z } from "zod";
4
+ import { getGndEntry, matchGndEntities } from "./lobid.js";
5
+ const server = new McpServer({
6
+ name: "lobid-mcp",
7
+ version: "1.0.0",
8
+ });
9
+ function jsonContent(data) {
10
+ return {
11
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
12
+ };
13
+ }
14
+ function errorContent(error) {
15
+ const message = error instanceof Error ? error.message : "unknown MCP error";
16
+ return jsonContent({
17
+ error: {
18
+ message,
19
+ },
20
+ });
21
+ }
22
+ server.registerTool("match_gnd_entities", {
23
+ description: "Search the GND authority ecosystem for plausible entities matching one or more names, concepts, subjects, organizations, places, or works. Use this tool first when resolving ambiguous terms against the GND. If no useful candidates are returned, retry with alternative spellings, singular forms, or related concepts.",
24
+ inputSchema: z.object({
25
+ terms: z.array(z.string().min(1).max(200)).min(1).max(50).describe("Research terms to match against GND"),
26
+ limitPerTerm: z.number().min(1).max(20).optional().default(5),
27
+ entityTypes: z
28
+ .array(z.string().min(1).max(100))
29
+ .max(20)
30
+ .optional()
31
+ .describe("Optional GND type filters such as Person, SubjectHeading, PlaceOrGeographicName, or CorporateBody"),
32
+ }),
33
+ }, async ({ terms, limitPerTerm, entityTypes }) => {
34
+ try {
35
+ return jsonContent({
36
+ matches: await matchGndEntities(terms, limitPerTerm, entityTypes),
37
+ });
38
+ }
39
+ catch (error) {
40
+ console.error("match_gnd_entities failed", error);
41
+ return errorContent(error);
42
+ }
43
+ });
44
+ server.registerTool("get_gnd_record", {
45
+ description: "Retrieve a compact enriched GND authority record by identifier or canonical GND URL. Use this after candidate matching when additional semantic context is needed.",
46
+ inputSchema: z.object({
47
+ id: z.string().min(1).max(200).describe("GND identifier or full GND URL"),
48
+ }),
49
+ }, async ({ id }) => {
50
+ try {
51
+ return jsonContent(await getGndEntry(id));
52
+ }
53
+ catch (error) {
54
+ console.error("get_gnd_record failed", error);
55
+ return errorContent(error);
56
+ }
57
+ });
58
+ server.registerTool("get_gnd_records", {
59
+ description: "Retrieve multiple compact enriched GND authority records by identifier or canonical GND URL. Use this to reduce repeated MCP roundtrips when inspecting several entities.",
60
+ inputSchema: z.object({
61
+ ids: z
62
+ .array(z.string().min(1).max(200))
63
+ .min(1)
64
+ .max(50)
65
+ .describe("GND identifiers or canonical GND URLs"),
66
+ }),
67
+ }, async ({ ids }) => {
68
+ try {
69
+ return jsonContent({
70
+ records: await Promise.all(ids.map((id) => getGndEntry(id))),
71
+ });
72
+ }
73
+ catch (error) {
74
+ console.error("get_gnd_records failed", error);
75
+ return errorContent(error);
76
+ }
77
+ });
78
+ const transport = new StdioServerTransport();
79
+ await server.connect(transport);
package/build/lobid.js ADDED
@@ -0,0 +1,161 @@
1
+ const GND_BASE = "https://lobid.org/gnd";
2
+ const RECONCILE_BASE = "https://reconcile.gnd.network/gnd/reconcile/";
3
+ const FETCH_TIMEOUT_MS = 10_000;
4
+ const MAX_CONCURRENT_FETCHES = 10;
5
+ const MAX_VARIANT_NAMES = 5;
6
+ const MAX_BIOGRAPHICAL_ENTRIES = 2;
7
+ const MAX_TEXT_LENGTH = 240;
8
+ const MAX_ENTITY_REFERENCES = 5;
9
+ const CACHE_TTL_MS = 60 * 60 * 1000;
10
+ const gndEntryCache = new Map();
11
+ export async function getGndEntry(id) {
12
+ const url = normalizeGndUrl(id);
13
+ const cached = gndEntryCache.get(url);
14
+ if (cached && cached.expiresAt > Date.now()) {
15
+ return cached.value;
16
+ }
17
+ const res = await fetch(url, {
18
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
19
+ });
20
+ if (!res.ok) {
21
+ throw new Error(`lobid-gnd lookup failed: ${res.status} ${res.statusText}`);
22
+ }
23
+ const entry = (await res.json());
24
+ const compactEntry = compactGndEntry(entry);
25
+ gndEntryCache.set(url, {
26
+ expiresAt: Date.now() + CACHE_TTL_MS,
27
+ value: compactEntry,
28
+ });
29
+ return compactEntry;
30
+ }
31
+ export async function matchGndEntities(terms, limitPerTerm = 5, entityTypes) {
32
+ const url = new URL(RECONCILE_BASE);
33
+ url.searchParams.set("queries", JSON.stringify(Object.fromEntries(terms.map((term, index) => [`q${index}`, { query: term, limit: limitPerTerm }]))));
34
+ const res = await fetch(url.toString(), {
35
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
36
+ });
37
+ if (!res.ok) {
38
+ throw new Error(`gnd reconcile failed: ${res.status} ${res.statusText}`);
39
+ }
40
+ const data = (await res.json());
41
+ return Promise.all(terms.map(async (term, index) => {
42
+ const candidates = data[`q${index}`]?.result ?? [];
43
+ const results = [];
44
+ for (let offset = 0; offset < candidates.length; offset += MAX_CONCURRENT_FETCHES) {
45
+ const chunk = candidates.slice(offset, offset + MAX_CONCURRENT_FETCHES);
46
+ const enriched = await Promise.all(chunk.map(async (candidate) => {
47
+ try {
48
+ const entry = await getGndEntry(candidate.id);
49
+ const summary = buildSummary(entry);
50
+ return {
51
+ gndId: entry.gndIdentifier || candidate.id,
52
+ preferredName: entry.preferredName || candidate.name,
53
+ type: entry.type.filter((t) => t !== "AuthorityResource").sort(),
54
+ score: candidate.score,
55
+ variantName: truncateArray(entry.variantName ?? [], MAX_VARIANT_NAMES).sort(),
56
+ id: entry.id,
57
+ ...(summary ? { summary } : {}),
58
+ confidence: buildConfidence(candidate.score),
59
+ matchSignals: buildMatchSignals(entry, candidate.name),
60
+ };
61
+ }
62
+ catch (error) {
63
+ console.error(`Failed to enrich GND candidate ${candidate.id}:`, error);
64
+ return null;
65
+ }
66
+ }));
67
+ results.push(...enriched.filter((candidate) => candidate !== null && matchesEntityTypes(candidate.type, entityTypes)));
68
+ }
69
+ return {
70
+ query: term,
71
+ candidates: results,
72
+ };
73
+ }));
74
+ }
75
+ function matchesEntityTypes(candidateTypes, entityTypes) {
76
+ if (!entityTypes?.length) {
77
+ return true;
78
+ }
79
+ const normalizedFilters = entityTypes.map((type) => type.toLowerCase());
80
+ return candidateTypes.some((candidateType) => normalizedFilters.some((filter) => candidateType.toLowerCase().includes(filter)));
81
+ }
82
+ function normalizeGndUrl(id) {
83
+ if (!id.startsWith("http")) {
84
+ return `${GND_BASE}/${id}.json`;
85
+ }
86
+ const url = new URL(id);
87
+ const hostname = url.hostname.replace(/\.$/, "");
88
+ if (!["lobid.org", "d-nb.info"].includes(hostname)) {
89
+ throw new Error(`unsupported GND host: ${hostname}`);
90
+ }
91
+ if (!url.pathname.startsWith("/gnd/")) {
92
+ throw new Error("only /gnd/ URLs supported");
93
+ }
94
+ if (url.search || url.hash) {
95
+ throw new Error("query parameters and fragments not allowed in GND URLs");
96
+ }
97
+ return `${url.origin}${url.pathname.endsWith(".json") ? url.pathname : `${url.pathname}.json`}`;
98
+ }
99
+ function buildDescription(entry) {
100
+ return [
101
+ entry.professionOrOccupation?.map((item) => item.label).join(", "),
102
+ [entry.dateOfBirth, entry.dateOfDeath].filter(Boolean).join("-"),
103
+ ]
104
+ .filter(Boolean)
105
+ .join(" | ");
106
+ }
107
+ function compactGndEntry(entry) {
108
+ return {
109
+ ...entry,
110
+ type: [...entry.type].sort(),
111
+ variantName: truncateArray(entry.variantName ?? [], MAX_VARIANT_NAMES).sort(),
112
+ biographicalOrHistoricalInformation: truncateArray((entry.biographicalOrHistoricalInformation ?? []).map(truncateText), MAX_BIOGRAPHICAL_ENTRIES),
113
+ professionOrOccupation: truncateArray(entry.professionOrOccupation ?? [], MAX_ENTITY_REFERENCES),
114
+ placeOfBirth: truncateArray(entry.placeOfBirth ?? [], MAX_ENTITY_REFERENCES),
115
+ placeOfDeath: truncateArray(entry.placeOfDeath ?? [], MAX_ENTITY_REFERENCES),
116
+ summary: buildSummary(entry),
117
+ };
118
+ }
119
+ function buildSummary(entry) {
120
+ const summary = [
121
+ buildDescription(entry),
122
+ truncateArray(entry.biographicalOrHistoricalInformation ?? [], MAX_BIOGRAPHICAL_ENTRIES).join(" | "),
123
+ ]
124
+ .filter(Boolean)
125
+ .join(" | ");
126
+ return truncateText(summary);
127
+ }
128
+ function buildConfidence(score) {
129
+ if (score >= 90) {
130
+ return "high";
131
+ }
132
+ if (score >= 60) {
133
+ return "medium";
134
+ }
135
+ return "low";
136
+ }
137
+ function buildMatchSignals(entry, candidateName) {
138
+ const signals = [];
139
+ if (entry.preferredName?.toLowerCase() === candidateName.toLowerCase()) {
140
+ signals.push("exact preferred name");
141
+ }
142
+ if (entry.variantName?.length) {
143
+ signals.push("variant names available");
144
+ }
145
+ if (entry.type.some((type) => type !== "AuthorityResource")) {
146
+ signals.push("entity type available");
147
+ }
148
+ if (entry.dateOfBirth || entry.dateOfDeath) {
149
+ signals.push("lifespan available");
150
+ }
151
+ return signals;
152
+ }
153
+ function truncateArray(items, limit) {
154
+ return items.slice(0, limit);
155
+ }
156
+ function truncateText(text) {
157
+ if (text.length <= MAX_TEXT_LENGTH) {
158
+ return text;
159
+ }
160
+ return `${text.slice(0, MAX_TEXT_LENGTH - 1)}…`;
161
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "lobid-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for lobid-gnd authority data",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/lukaslerche/lobid-mcp.git"
9
+ },
10
+ "author": {
11
+ "name": "Lukas Lerche",
12
+ "email": "lukas.lerche@tu-dortmund.de",
13
+ "url": "https://lukaslerche.de"
14
+ },
15
+ "type": "module",
16
+ "bin": {
17
+ "lobid-mcp": "build/index.js"
18
+ },
19
+ "files": [
20
+ "build",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "start": "node build/index.js",
30
+ "dev": "tsx watch src/index.ts"
31
+ },
32
+ "keywords": [
33
+ "mcp",
34
+ "gnd",
35
+ "lobid",
36
+ "llm",
37
+ "authority-data",
38
+ "claude",
39
+ "opencode"
40
+ ],
41
+ "homepage": "https://github.com/lukaslerche/lobid-mcp",
42
+ "dependencies": {
43
+ "@modelcontextprotocol/server": "2.0.0-alpha.2",
44
+ "zod": "^4.4.3"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^26.0.1",
48
+ "tsx": "^4.22.4",
49
+ "typescript": "^6.0.3"
50
+ }
51
+ }