@pipeworx/mcp-wikidata 0.1.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 +21 -0
- package/README.md +55 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +271 -0
- package/tsconfig.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pipeworx
|
|
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,55 @@
|
|
|
1
|
+
# mcp-wikidata
|
|
2
|
+
|
|
3
|
+
Wikidata MCP — wraps Wikidata API (wikidata.org/w/api.php)
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ live data sources.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"mcpServers": {
|
|
19
|
+
"wikidata": {
|
|
20
|
+
"url": "https://gateway.pipeworx.io/wikidata/mcp"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or connect to the full Pipeworx gateway for access to all 965+ data sources:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"pipeworx": {
|
|
32
|
+
"url": "https://gateway.pipeworx.io/mcp"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Using with ask_pipeworx
|
|
39
|
+
|
|
40
|
+
Instead of calling tools directly, you can ask questions in plain English:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
ask_pipeworx({ question: "your question about Wikidata data" })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The gateway picks the right tool and fills the arguments automatically.
|
|
47
|
+
|
|
48
|
+
## More
|
|
49
|
+
|
|
50
|
+
- [All tools and guides](https://github.com/pipeworx-io/examples)
|
|
51
|
+
- [pipeworx.io](https://pipeworx.io)
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-wikidata",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Wikidata MCP — wraps Wikidata API (wikidata.org/w/api.php)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "wikidata"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-wikidata"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.pipeworx-io/wikidata",
|
|
4
|
+
"title": "Wikidata",
|
|
5
|
+
"description": "Wikidata MCP — wraps Wikidata API (wikidata.org/w/api.php)",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/wikidata",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-wikidata",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/wikidata/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
interface McpToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
required?: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface McpToolExport {
|
|
12
|
+
tools: McpToolDefinition[];
|
|
13
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
14
|
+
meter?: { credits: number };
|
|
15
|
+
cost?: Record<string, unknown>;
|
|
16
|
+
provider?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wikidata MCP — wraps Wikidata API (wikidata.org/w/api.php)
|
|
21
|
+
*
|
|
22
|
+
* Free, no authentication required. Uses wbsearchentities and wbgetentities actions.
|
|
23
|
+
*
|
|
24
|
+
* Tools:
|
|
25
|
+
* - search_entities: search Wikidata entities by label (people, places, concepts)
|
|
26
|
+
* - get_entity: get full entity data by Wikidata ID (e.g., Q42 = Douglas Adams)
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const API_BASE = 'https://www.wikidata.org/w/api.php';
|
|
31
|
+
|
|
32
|
+
// ── Tool definitions ──────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
const tools: McpToolExport['tools'] = [
|
|
35
|
+
{
|
|
36
|
+
name: 'search_entities',
|
|
37
|
+
description:
|
|
38
|
+
'Search Wikidata entities by label or alias (e.g., "Albert Einstein", "Python programming language", "Tokyo"). Returns entity IDs, labels, descriptions, and aliases. Useful for finding the Wikidata ID of any concept.',
|
|
39
|
+
inputSchema: {
|
|
40
|
+
type: 'object' as const,
|
|
41
|
+
properties: {
|
|
42
|
+
query: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
description: 'Search query (e.g., "Marie Curie", "Bitcoin", "Great Wall of China")',
|
|
45
|
+
},
|
|
46
|
+
language: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
description: 'Language code for labels (default "en"). E.g., "fr", "de", "ja"',
|
|
49
|
+
},
|
|
50
|
+
limit: {
|
|
51
|
+
type: 'number',
|
|
52
|
+
description: 'Max results to return (1-50, default 10)',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
required: ['query'],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'get_entity',
|
|
60
|
+
description:
|
|
61
|
+
'Get full Wikidata entity by ID (e.g., "Q42" for Douglas Adams, "Q5" for human, "Q1764" for Budapest). Returns labels, descriptions, aliases, claims/statements (properties and values), and sitelinks.',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: 'object' as const,
|
|
64
|
+
properties: {
|
|
65
|
+
id: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
description: 'Wikidata entity ID (e.g., "Q42", "Q937", "P31")',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ['id'],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'get_wikidata_facts',
|
|
75
|
+
description:
|
|
76
|
+
'Structured facts about a Wikidata entity in HUMAN-READABLE form — property names and values resolved to labels, not raw P/Q codes. PREFER OVER get_entity for "what is X\x27s <attribute>", "facts about X", "X\x27s date of birth / capital / population". E.g. Q42 (Douglas Adams) -> {"date of birth":["1952-03-11..."],"occupation":["writer",...],"place of birth":["Cambridge"]}. Pass a Q-id from search_entities.',
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: { id: { type: 'string', description: 'Wikidata entity Q-id (e.g. "Q42"). Find it with search_entities.' } },
|
|
80
|
+
required: ['id'],
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
// ── callTool dispatcher ───────────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
const WD_HEADERS = { Accept: 'application/json', 'User-Agent': 'Pipeworx-Wikidata-MCP/1.0' };
|
|
88
|
+
async function wdEntities(ids: string, props: string) {
|
|
89
|
+
const res = await fetch(`${API_BASE}?${new URLSearchParams({ action: 'wbgetentities', ids, format: 'json', languages: 'en', props })}`, { headers: WD_HEADERS });
|
|
90
|
+
if (!res.ok) throw new Error(`Wikidata API error (${res.status})`);
|
|
91
|
+
return (await res.json()) as { entities?: Record<string, { labels?: Record<string, { value: string }>; descriptions?: Record<string, { value: string }>; claims?: Record<string, Array<{ mainsnak: { datavalue?: { type: string; value: unknown } } }>> }> };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function getFacts(idRaw: string) {
|
|
95
|
+
const qid = String(idRaw ?? '').trim().toUpperCase();
|
|
96
|
+
if (!/^Q\d+$/.test(qid)) throw new Error('Required argument "id" must be a Wikidata Q-id like "Q42". Use search_entities to find it.');
|
|
97
|
+
const data = await wdEntities(qid, 'labels|descriptions|claims');
|
|
98
|
+
const ent = data.entities?.[qid];
|
|
99
|
+
if (!ent) throw new Error(`Entity not found: ${qid}`);
|
|
100
|
+
const claims = ent.claims ?? {};
|
|
101
|
+
const propIds = Object.keys(claims).slice(0, 40);
|
|
102
|
+
const valueQids = new Set<string>();
|
|
103
|
+
for (const p of propIds) for (const s of (claims[p] || []).slice(0, 10)) {
|
|
104
|
+
const dv = s.mainsnak?.datavalue;
|
|
105
|
+
if (dv?.type === 'wikibase-entityid') { const v = dv.value as { id?: string }; if (v.id) valueQids.add(v.id); }
|
|
106
|
+
}
|
|
107
|
+
const toResolve = [...propIds, ...valueQids];
|
|
108
|
+
const labels: Record<string, string> = {};
|
|
109
|
+
for (let i = 0; i < toResolve.length; i += 50) {
|
|
110
|
+
const ld = await wdEntities(toResolve.slice(i, i + 50).join('|'), 'labels');
|
|
111
|
+
for (const [k, e] of Object.entries(ld.entities ?? {})) { const lab = e.labels?.en?.value; if (lab) labels[k] = lab; }
|
|
112
|
+
}
|
|
113
|
+
const facts: Record<string, unknown[]> = {};
|
|
114
|
+
for (const p of propIds) {
|
|
115
|
+
const vals = (claims[p] || []).slice(0, 10).map((s) => {
|
|
116
|
+
const dv = s.mainsnak?.datavalue; if (!dv) return null;
|
|
117
|
+
if (dv.type === 'wikibase-entityid') { const v = dv.value as { id?: string }; return v.id ? (labels[v.id] || v.id) : null; }
|
|
118
|
+
if (dv.type === 'time') return (dv.value as { time: string }).time;
|
|
119
|
+
if (dv.type === 'quantity') return (dv.value as { amount: string }).amount;
|
|
120
|
+
if (dv.type === 'monolingualtext') return (dv.value as { text: string }).text;
|
|
121
|
+
if (dv.type === 'globecoordinate') { const v = dv.value as { latitude: number; longitude: number }; return `${v.latitude},${v.longitude}`; }
|
|
122
|
+
if (dv.type === 'string' || dv.type === 'url' || dv.type === 'external-id') return dv.value;
|
|
123
|
+
return dv.value;
|
|
124
|
+
}).filter((v) => v != null);
|
|
125
|
+
if (vals.length) facts[labels[p] || p] = vals;
|
|
126
|
+
}
|
|
127
|
+
return { id: qid, label: ent.labels?.en?.value ?? null, description: ent.descriptions?.en?.value ?? null, facts };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
131
|
+
switch (name) {
|
|
132
|
+
case 'search_entities':
|
|
133
|
+
return searchEntities(
|
|
134
|
+
args.query as string,
|
|
135
|
+
(args.language as string) ?? 'en',
|
|
136
|
+
(args.limit as number) ?? 10,
|
|
137
|
+
);
|
|
138
|
+
case 'get_wikidata_facts':
|
|
139
|
+
return getFacts(args.id as string);
|
|
140
|
+
case 'get_entity':
|
|
141
|
+
return getEntity(args.id as string);
|
|
142
|
+
default:
|
|
143
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ── Tool implementations ─────────────────────────────────────────────
|
|
148
|
+
|
|
149
|
+
async function searchEntities(query: string, language: string, limit: number) {
|
|
150
|
+
const safeLimit = Math.min(50, Math.max(1, limit));
|
|
151
|
+
const params = new URLSearchParams({
|
|
152
|
+
action: 'wbsearchentities',
|
|
153
|
+
search: query,
|
|
154
|
+
language,
|
|
155
|
+
limit: String(safeLimit),
|
|
156
|
+
format: 'json',
|
|
157
|
+
uselang: language,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const res = await fetch(`${API_BASE}?${params}`, {
|
|
161
|
+
headers: { Accept: 'application/json', 'User-Agent': 'Pipeworx-Wikidata-MCP/1.0' },
|
|
162
|
+
});
|
|
163
|
+
if (!res.ok) throw new Error(`Wikidata API error (${res.status})`);
|
|
164
|
+
|
|
165
|
+
const data = (await res.json()) as {
|
|
166
|
+
search: Array<{
|
|
167
|
+
id: string;
|
|
168
|
+
label: string;
|
|
169
|
+
description: string;
|
|
170
|
+
aliases: string[];
|
|
171
|
+
concepturi: string;
|
|
172
|
+
}>;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
results: (data.search ?? []).map((e) => ({
|
|
177
|
+
id: e.id,
|
|
178
|
+
label: e.label ?? null,
|
|
179
|
+
description: e.description ?? null,
|
|
180
|
+
aliases: e.aliases ?? [],
|
|
181
|
+
uri: e.concepturi ?? null,
|
|
182
|
+
})),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function getEntity(id: string) {
|
|
187
|
+
const params = new URLSearchParams({
|
|
188
|
+
action: 'wbgetentities',
|
|
189
|
+
ids: id,
|
|
190
|
+
format: 'json',
|
|
191
|
+
languages: 'en',
|
|
192
|
+
props: 'labels|descriptions|aliases|claims|sitelinks',
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const res = await fetch(`${API_BASE}?${params}`, {
|
|
196
|
+
headers: { Accept: 'application/json', 'User-Agent': 'Pipeworx-Wikidata-MCP/1.0' },
|
|
197
|
+
});
|
|
198
|
+
if (!res.ok) throw new Error(`Wikidata API error (${res.status})`);
|
|
199
|
+
|
|
200
|
+
const data = (await res.json()) as {
|
|
201
|
+
entities: Record<string, {
|
|
202
|
+
id: string;
|
|
203
|
+
type: string;
|
|
204
|
+
labels: Record<string, { value: string }>;
|
|
205
|
+
descriptions: Record<string, { value: string }>;
|
|
206
|
+
aliases: Record<string, Array<{ value: string }>>;
|
|
207
|
+
claims: Record<string, Array<{
|
|
208
|
+
mainsnak: {
|
|
209
|
+
property: string;
|
|
210
|
+
datavalue?: {
|
|
211
|
+
type: string;
|
|
212
|
+
value: unknown;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
}>>;
|
|
216
|
+
sitelinks: Record<string, { site: string; title: string }>;
|
|
217
|
+
}>;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const entity = data.entities?.[id];
|
|
221
|
+
if (!entity) throw new Error(`Entity not found: ${id}`);
|
|
222
|
+
|
|
223
|
+
// Extract a simplified claims summary (top properties with values)
|
|
224
|
+
const claims: Record<string, unknown[]> = {};
|
|
225
|
+
for (const [prop, statements] of Object.entries(entity.claims ?? {})) {
|
|
226
|
+
claims[prop] = statements.slice(0, 5).map((s) => {
|
|
227
|
+
const dv = s.mainsnak?.datavalue;
|
|
228
|
+
if (!dv) return null;
|
|
229
|
+
if (dv.type === 'wikibase-entityid') {
|
|
230
|
+
const v = dv.value as { id: string };
|
|
231
|
+
return v.id;
|
|
232
|
+
}
|
|
233
|
+
if (dv.type === 'time') {
|
|
234
|
+
const v = dv.value as { time: string };
|
|
235
|
+
return v.time;
|
|
236
|
+
}
|
|
237
|
+
if (dv.type === 'quantity') {
|
|
238
|
+
const v = dv.value as { amount: string; unit: string };
|
|
239
|
+
return { amount: v.amount, unit: v.unit };
|
|
240
|
+
}
|
|
241
|
+
if (dv.type === 'string' || dv.type === 'url' || dv.type === 'external-id') {
|
|
242
|
+
return dv.value;
|
|
243
|
+
}
|
|
244
|
+
if (dv.type === 'monolingualtext') {
|
|
245
|
+
const v = dv.value as { text: string; language: string };
|
|
246
|
+
return v.text;
|
|
247
|
+
}
|
|
248
|
+
return dv.value;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Limit claims to first 30 properties to avoid huge payloads
|
|
253
|
+
const limitedClaims: Record<string, unknown[]> = {};
|
|
254
|
+
const claimKeys = Object.keys(claims).slice(0, 30);
|
|
255
|
+
for (const k of claimKeys) {
|
|
256
|
+
limitedClaims[k] = claims[k];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return {
|
|
260
|
+
id: entity.id,
|
|
261
|
+
type: entity.type,
|
|
262
|
+
label: entity.labels?.en?.value ?? null,
|
|
263
|
+
description: entity.descriptions?.en?.value ?? null,
|
|
264
|
+
aliases: (entity.aliases?.en ?? []).map((a) => a.value),
|
|
265
|
+
claims: limitedClaims,
|
|
266
|
+
sitelinks_count: Object.keys(entity.sitelinks ?? {}).length,
|
|
267
|
+
wikipedia_en: entity.sitelinks?.enwiki?.title ?? null,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|