@pipeworx/mcp-openalex 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/package.json +18 -0
  4. package/src/index.ts +320 -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,32 @@
1
+ # @pipeworx/mcp-openalex
2
+
3
+ MCP server for scholarly works, authors, and institutions via the [OpenAlex API](https://openalex.org/). Free, no authentication required.
4
+
5
+ ## Tools
6
+
7
+ | Tool | Description |
8
+ |------|-------------|
9
+ | `search_works` | Search scholarly works (papers, books, datasets) by keyword |
10
+ | `search_authors` | Search researchers and authors by name |
11
+ | `search_institutions` | Search academic institutions by name |
12
+ | `get_concept` | Look up an academic concept or field of study |
13
+
14
+ ## Quickstart via Pipeworx Gateway
15
+
16
+ ```bash
17
+ curl -X POST https://gateway.pipeworx.io/mcp \
18
+ -H "Content-Type: application/json" \
19
+ -d '{
20
+ "jsonrpc": "2.0",
21
+ "method": "tools/call",
22
+ "params": {
23
+ "name": "openalex__search_works",
24
+ "arguments": { "query": "transformer neural networks", "limit": 5 }
25
+ },
26
+ "id": 1
27
+ }'
28
+ ```
29
+
30
+ ## License
31
+
32
+ MIT
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@pipeworx/mcp-openalex",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for scholarly works, authors, and institutions via OpenAlex API",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "files": ["src"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "check": "tsc --noEmit"
11
+ },
12
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "openalex", "academic", "scholarly", "research"],
13
+ "author": "Pipeworx",
14
+ "license": "MIT",
15
+ "devDependencies": {
16
+ "typescript": "^5.0.0"
17
+ }
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,320 @@
1
+ /**
2
+ * OpenAlex MCP — wraps the OpenAlex API (scholarly works, free, no auth)
3
+ *
4
+ * Tools:
5
+ * - search_works: search scholarly works by keyword
6
+ * - search_authors: search researchers/authors by name
7
+ * - search_institutions: search academic institutions by name
8
+ * - get_concept: look up an academic concept/field of study
9
+ */
10
+
11
+ interface McpToolDefinition {
12
+ name: string;
13
+ description: string;
14
+ inputSchema: {
15
+ type: 'object';
16
+ properties: Record<string, unknown>;
17
+ required?: string[];
18
+ };
19
+ }
20
+
21
+ interface McpToolExport {
22
+ tools: McpToolDefinition[];
23
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
24
+ }
25
+
26
+ const BASE = 'https://api.openalex.org';
27
+
28
+ // -- API Response Types --
29
+
30
+ type OpenAlexMeta = {
31
+ count: number;
32
+ db_response_time_ms: number;
33
+ page: number;
34
+ per_page: number;
35
+ };
36
+
37
+ type OpenAlexAuthorship = {
38
+ author: { id: string; display_name: string; orcid: string | null };
39
+ institutions: Array<{ id: string; display_name: string; country_code: string | null }>;
40
+ };
41
+
42
+ type OpenAlexConcept = {
43
+ id: string;
44
+ display_name: string;
45
+ score?: number;
46
+ level?: number;
47
+ };
48
+
49
+ type OpenAlexWork = {
50
+ id: string;
51
+ doi: string | null;
52
+ title: string | null;
53
+ display_name: string | null;
54
+ publication_year: number | null;
55
+ publication_date: string | null;
56
+ type: string | null;
57
+ open_access: { is_oa: boolean; oa_url: string | null } | null;
58
+ authorships: OpenAlexAuthorship[];
59
+ cited_by_count: number;
60
+ concepts: OpenAlexConcept[];
61
+ primary_location: {
62
+ source: { display_name: string | null; issn: string[] | null } | null;
63
+ } | null;
64
+ abstract_inverted_index: Record<string, number[]> | null;
65
+ };
66
+
67
+ type OpenAlexAuthor = {
68
+ id: string;
69
+ display_name: string;
70
+ orcid: string | null;
71
+ works_count: number;
72
+ cited_by_count: number;
73
+ last_known_institution: {
74
+ display_name: string | null;
75
+ country_code: string | null;
76
+ } | null;
77
+ x_concepts: OpenAlexConcept[];
78
+ updated_date: string | null;
79
+ };
80
+
81
+ type OpenAlexInstitution = {
82
+ id: string;
83
+ display_name: string;
84
+ ror: string | null;
85
+ country_code: string | null;
86
+ type: string | null;
87
+ works_count: number;
88
+ cited_by_count: number;
89
+ homepage_url: string | null;
90
+ x_concepts: OpenAlexConcept[];
91
+ };
92
+
93
+ type OpenAlexConceptFull = {
94
+ id: string;
95
+ display_name: string;
96
+ level: number;
97
+ description: string | null;
98
+ works_count: number;
99
+ cited_by_count: number;
100
+ ancestors: Array<{ id: string; display_name: string; level: number }>;
101
+ related_concepts: Array<{ id: string; display_name: string; level: number; score: number }>;
102
+ };
103
+
104
+ type OpenAlexListResponse<T> = {
105
+ meta: OpenAlexMeta;
106
+ results: T[];
107
+ };
108
+
109
+ // -- Helpers --
110
+
111
+ /**
112
+ * Reconstruct abstract from OpenAlex's inverted index format.
113
+ * The inverted index maps each word to the positions it appears at.
114
+ */
115
+ function reconstructAbstract(invertedIndex: Record<string, number[]> | null): string | null {
116
+ if (!invertedIndex) return null;
117
+ const entries: Array<[number, string]> = [];
118
+ for (const [word, positions] of Object.entries(invertedIndex)) {
119
+ for (const pos of positions) {
120
+ entries.push([pos, word]);
121
+ }
122
+ }
123
+ entries.sort((a, b) => a[0] - b[0]);
124
+ return entries.map(([, word]) => word).join(' ');
125
+ }
126
+
127
+ function mapWork(w: OpenAlexWork) {
128
+ return {
129
+ id: w.id,
130
+ doi: w.doi ?? null,
131
+ title: w.display_name ?? w.title ?? null,
132
+ publication_year: w.publication_year ?? null,
133
+ type: w.type ?? null,
134
+ open_access: w.open_access?.is_oa ?? false,
135
+ oa_url: w.open_access?.oa_url ?? null,
136
+ cited_by_count: w.cited_by_count,
137
+ journal: w.primary_location?.source?.display_name ?? null,
138
+ authors: w.authorships.map((a) => a.author.display_name),
139
+ concepts: w.concepts.slice(0, 5).map((c) => c.display_name),
140
+ abstract: reconstructAbstract(w.abstract_inverted_index),
141
+ };
142
+ }
143
+
144
+ // -- Tool Definitions --
145
+
146
+ const tools: McpToolExport['tools'] = [
147
+ {
148
+ name: 'search_works',
149
+ description:
150
+ 'Search scholarly works (papers, books, datasets) in the OpenAlex index. Returns title, authors, journal, year, citation count, and abstract.',
151
+ inputSchema: {
152
+ type: 'object',
153
+ properties: {
154
+ query: { type: 'string', description: 'Search query (e.g., "transformer neural networks")' },
155
+ limit: {
156
+ type: 'number',
157
+ description: 'Number of results to return (1-25, default 10)',
158
+ },
159
+ },
160
+ required: ['query'],
161
+ },
162
+ },
163
+ {
164
+ name: 'search_authors',
165
+ description:
166
+ 'Search researchers and authors by name in OpenAlex. Returns display name, ORCID, institution, works count, and citation count.',
167
+ inputSchema: {
168
+ type: 'object',
169
+ properties: {
170
+ query: { type: 'string', description: 'Author name to search for (e.g., "Yoshua Bengio")' },
171
+ limit: {
172
+ type: 'number',
173
+ description: 'Number of results to return (1-25, default 10)',
174
+ },
175
+ },
176
+ required: ['query'],
177
+ },
178
+ },
179
+ {
180
+ name: 'search_institutions',
181
+ description:
182
+ 'Search academic institutions (universities, research labs) by name in OpenAlex. Returns name, country, type, works count, and top concepts.',
183
+ inputSchema: {
184
+ type: 'object',
185
+ properties: {
186
+ query: { type: 'string', description: 'Institution name to search for (e.g., "MIT")' },
187
+ limit: {
188
+ type: 'number',
189
+ description: 'Number of results to return (1-25, default 10)',
190
+ },
191
+ },
192
+ required: ['query'],
193
+ },
194
+ },
195
+ {
196
+ name: 'get_concept',
197
+ description:
198
+ 'Look up an academic concept or field of study by name. Returns description, works count, related concepts, and ancestor concepts in the hierarchy.',
199
+ inputSchema: {
200
+ type: 'object',
201
+ properties: {
202
+ query: { type: 'string', description: 'Concept name to look up (e.g., "deep learning")' },
203
+ },
204
+ required: ['query'],
205
+ },
206
+ },
207
+ ];
208
+
209
+ // -- Tool Implementations --
210
+
211
+ async function searchWorks(query: string, limit: number) {
212
+ const perPage = Math.min(25, Math.max(1, limit));
213
+ const params = new URLSearchParams({ search: query, per_page: String(perPage) });
214
+
215
+ const res = await fetch(`${BASE}/works?${params}`);
216
+ if (!res.ok) throw new Error(`OpenAlex works search error: ${res.status}`);
217
+
218
+ const data = (await res.json()) as OpenAlexListResponse<OpenAlexWork>;
219
+
220
+ return {
221
+ total: data.meta.count,
222
+ results: data.results.map(mapWork),
223
+ };
224
+ }
225
+
226
+ async function searchAuthors(query: string, limit: number) {
227
+ const perPage = Math.min(25, Math.max(1, limit));
228
+ const params = new URLSearchParams({ search: query, per_page: String(perPage) });
229
+
230
+ const res = await fetch(`${BASE}/authors?${params}`);
231
+ if (!res.ok) throw new Error(`OpenAlex authors search error: ${res.status}`);
232
+
233
+ const data = (await res.json()) as OpenAlexListResponse<OpenAlexAuthor>;
234
+
235
+ return {
236
+ total: data.meta.count,
237
+ results: data.results.map((a) => ({
238
+ id: a.id,
239
+ display_name: a.display_name,
240
+ orcid: a.orcid ?? null,
241
+ works_count: a.works_count,
242
+ cited_by_count: a.cited_by_count,
243
+ last_known_institution: a.last_known_institution?.display_name ?? null,
244
+ institution_country: a.last_known_institution?.country_code ?? null,
245
+ top_concepts: a.x_concepts.slice(0, 5).map((c) => c.display_name),
246
+ })),
247
+ };
248
+ }
249
+
250
+ async function searchInstitutions(query: string, limit: number) {
251
+ const perPage = Math.min(25, Math.max(1, limit));
252
+ const params = new URLSearchParams({ search: query, per_page: String(perPage) });
253
+
254
+ const res = await fetch(`${BASE}/institutions?${params}`);
255
+ if (!res.ok) throw new Error(`OpenAlex institutions search error: ${res.status}`);
256
+
257
+ const data = (await res.json()) as OpenAlexListResponse<OpenAlexInstitution>;
258
+
259
+ return {
260
+ total: data.meta.count,
261
+ results: data.results.map((i) => ({
262
+ id: i.id,
263
+ display_name: i.display_name,
264
+ ror: i.ror ?? null,
265
+ country_code: i.country_code ?? null,
266
+ type: i.type ?? null,
267
+ works_count: i.works_count,
268
+ cited_by_count: i.cited_by_count,
269
+ homepage_url: i.homepage_url ?? null,
270
+ top_concepts: i.x_concepts.slice(0, 5).map((c) => c.display_name),
271
+ })),
272
+ };
273
+ }
274
+
275
+ async function getConcept(query: string) {
276
+ const params = new URLSearchParams({ search: query, per_page: '1' });
277
+
278
+ const res = await fetch(`${BASE}/concepts?${params}`);
279
+ if (!res.ok) throw new Error(`OpenAlex concepts search error: ${res.status}`);
280
+
281
+ const data = (await res.json()) as OpenAlexListResponse<OpenAlexConceptFull>;
282
+
283
+ if (data.results.length === 0) {
284
+ throw new Error(`No concept found for: "${query}"`);
285
+ }
286
+
287
+ const c = data.results[0];
288
+
289
+ return {
290
+ id: c.id,
291
+ display_name: c.display_name,
292
+ level: c.level,
293
+ description: c.description ?? null,
294
+ works_count: c.works_count,
295
+ cited_by_count: c.cited_by_count,
296
+ ancestors: c.ancestors.map((a) => ({ name: a.display_name, level: a.level })),
297
+ related_concepts: c.related_concepts
298
+ .slice(0, 10)
299
+ .map((r) => ({ name: r.display_name, level: r.level, score: r.score })),
300
+ };
301
+ }
302
+
303
+ // -- Dispatcher --
304
+
305
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
306
+ switch (name) {
307
+ case 'search_works':
308
+ return searchWorks(args.query as string, (args.limit as number) ?? 10);
309
+ case 'search_authors':
310
+ return searchAuthors(args.query as string, (args.limit as number) ?? 10);
311
+ case 'search_institutions':
312
+ return searchInstitutions(args.query as string, (args.limit as number) ?? 10);
313
+ case 'get_concept':
314
+ return getConcept(args.query as string);
315
+ default:
316
+ throw new Error(`Unknown tool: ${name}`);
317
+ }
318
+ }
319
+
320
+ export default { tools, callTool } satisfies McpToolExport;