ebi-search-mcp 1.0.1 → 1.0.3
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 +2 -0
- package/dist/api.js +51 -0
- package/dist/server.js +30 -4
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/api.js
CHANGED
|
@@ -34,3 +34,54 @@ export async function entry(args) {
|
|
|
34
34
|
const fields = (d.fields ?? []).slice(0, 15).map((f) => `* ${f.name ?? '?'}: ${(f.value ?? '').slice(0, 120)}`);
|
|
35
35
|
return `Entry ${d.id} (${d.source ?? args.domain}):\n` + fields.join('\n');
|
|
36
36
|
}
|
|
37
|
+
async function explainFailure(res) {
|
|
38
|
+
let why = `HTTP ${res.status}`;
|
|
39
|
+
try {
|
|
40
|
+
const body = (await res.json());
|
|
41
|
+
if (body?.diagnostics?.message)
|
|
42
|
+
why = body.diagnostics.message;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// the body was not JSON, so the status code is the only reason we have
|
|
46
|
+
why = `HTTP ${res.status}`;
|
|
47
|
+
}
|
|
48
|
+
return why;
|
|
49
|
+
}
|
|
50
|
+
async function getEbi(url) {
|
|
51
|
+
const res = await fetch(url, {
|
|
52
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
53
|
+
signal: AbortSignal.timeout(25000),
|
|
54
|
+
});
|
|
55
|
+
if (!res.ok)
|
|
56
|
+
throw new Error(`EBI Search said ${await explainFailure(res)}`);
|
|
57
|
+
return res.json();
|
|
58
|
+
}
|
|
59
|
+
export async function domainIndex(_args = {}) {
|
|
60
|
+
const data = (await getEbi(`${BASE}?format=json`));
|
|
61
|
+
const roots = data.domains ?? [];
|
|
62
|
+
if (!roots.length)
|
|
63
|
+
throw new Error('EBI Search returned no domains.');
|
|
64
|
+
const nodes = [];
|
|
65
|
+
const walk = (node, depth) => {
|
|
66
|
+
const entry = { id: node.id, name: node.name ?? '', depth, descendants: 0 };
|
|
67
|
+
nodes.push(entry);
|
|
68
|
+
for (const child of node.subdomains ?? [])
|
|
69
|
+
entry.descendants += 1 + walk(child, depth + 1);
|
|
70
|
+
return entry.descendants;
|
|
71
|
+
};
|
|
72
|
+
for (const root of roots)
|
|
73
|
+
walk(root, 0);
|
|
74
|
+
const at = (depth) => nodes.filter((n) => n.depth === depth);
|
|
75
|
+
const lines = [
|
|
76
|
+
`EBI Search holds ${nodes.length} domains in one tree, ${nodes.length - roots.length} of them below the top level.`,
|
|
77
|
+
];
|
|
78
|
+
for (const root of at(0))
|
|
79
|
+
lines.push(`${root.id}${root.name ? ` (${root.name})` : ''}`);
|
|
80
|
+
lines.push(' the groups directly below it:');
|
|
81
|
+
for (const group of at(1)) {
|
|
82
|
+
lines.push(` ${group.id}${group.name ? ` (${group.name})` : ''}: ${group.descendants} domain(s) inside`);
|
|
83
|
+
}
|
|
84
|
+
const deepest = nodes.reduce((max, n) => Math.max(max, n.depth), 0);
|
|
85
|
+
lines.push(` the tree is ${deepest + 1} level(s) deep; pass any of these ids to the search or entry tool.`);
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { entry } from "./api.js";
|
|
4
|
-
import { search } from "./api.js";
|
|
3
|
+
import { entry, search, domainIndex } from "./api.js";
|
|
5
4
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
6
5
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
7
6
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -18,7 +17,7 @@ export function createServer() {
|
|
|
18
17
|
return text(await search(args));
|
|
19
18
|
}
|
|
20
19
|
catch (e) {
|
|
21
|
-
return textError(
|
|
20
|
+
return textError(String(e));
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
23
|
server.registerTool("entry", {
|
|
@@ -31,7 +30,34 @@ export function createServer() {
|
|
|
31
30
|
return text(await entry(args));
|
|
32
31
|
}
|
|
33
32
|
catch (e) {
|
|
34
|
-
return textError(
|
|
33
|
+
return textError(String(e));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
server.registerTool("domain_index", {
|
|
37
|
+
title: "Domain index",
|
|
38
|
+
description: "The whole tree of databases EBI Search can query, with how many domains sit inside each group, so a caller can see what is searchable instead of guessing a domain name.",
|
|
39
|
+
inputSchema: z.object({}),
|
|
40
|
+
annotations: READ_ONLY,
|
|
41
|
+
}, async (args) => {
|
|
42
|
+
try {
|
|
43
|
+
return text(await domainIndex());
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
return textError(String(e));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
server.registerTool("domain_info", {
|
|
50
|
+
title: "Domain info",
|
|
51
|
+
description: "One database's own facts: the entry count and release dates EBI Search reports for it, and which of its fields are searchable. The search tool only returns results, it never describes the domain.",
|
|
52
|
+
inputSchema: z.object({ domain: z.string().describe("A domain id from the domain index, like uniprot, ensembl or literature.") }),
|
|
53
|
+
annotations: READ_ONLY,
|
|
54
|
+
}, async (args) => {
|
|
55
|
+
// TODO: implement info locally (paywall removed)
|
|
56
|
+
try {
|
|
57
|
+
return textError("Not yet implemented: info");
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
return textError(String(e));
|
|
35
61
|
}
|
|
36
62
|
});
|
|
37
63
|
return server;
|