@mrfentmen/uniprot-mcp 0.0.0-stage → 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 +33 -2
- package/dist/api.d.ts +4 -0
- package/dist/api.js +80 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +26 -0
- package/package.json +42 -4
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# UniProt MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Protein records from the UniProt knowledgebase, with sequences and organism names. Keyless — no signup, no API key, no environment variables.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx -y @mrfentmen/uniprot-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or add it to your MCP client:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"uniprot-mcp": { "command": "npx", "args": ["-y", "@mrfentmen/uniprot-mcp"] }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Tools
|
|
22
|
+
|
|
23
|
+
| Tool | What it does |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `search_proteins` | Search UniProtKB protein records |
|
|
26
|
+
| `get_entry` | Full UniProt record by accession |
|
|
27
|
+
|
|
28
|
+
## Notes
|
|
29
|
+
|
|
30
|
+
UniProt's REST service needs no key. Search accepts the full UniProt query syntax, e.g. gene:BRCA1 or organism_id:9606.
|
|
31
|
+
|
|
32
|
+
## Licence
|
|
33
|
+
|
|
34
|
+
MIT
|
package/dist/api.d.ts
ADDED
package/dist/api.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UniProt — Protein records from the UniProt knowledgebase, with sequences and organism names. Keyless: no signup, no API key, no environment variables.
|
|
3
|
+
*
|
|
4
|
+
* Verified live against rest.uniprot.org.
|
|
5
|
+
*/
|
|
6
|
+
const API = "https://rest.uniprot.org";
|
|
7
|
+
export class UniProtError extends Error {
|
|
8
|
+
}
|
|
9
|
+
const val = (v) => {
|
|
10
|
+
if (typeof v === "string")
|
|
11
|
+
return v;
|
|
12
|
+
if (typeof v === "number")
|
|
13
|
+
return Number.isFinite(v) ? String(v) : "";
|
|
14
|
+
if (Array.isArray(v))
|
|
15
|
+
return v.length > 0 ? val(v[0]) : "";
|
|
16
|
+
if (v && typeof v === "object") {
|
|
17
|
+
const o = v;
|
|
18
|
+
if ("en" in o)
|
|
19
|
+
return val(o.en);
|
|
20
|
+
const first = Object.values(o)[0];
|
|
21
|
+
return first === undefined ? "" : val(first);
|
|
22
|
+
}
|
|
23
|
+
return "";
|
|
24
|
+
};
|
|
25
|
+
const at = (o, path) => path === "" ? o : path.split(".").reduce((acc, k) => (acc && typeof acc === "object" ? acc[k] : undefined), o);
|
|
26
|
+
const rows = (v) => (Array.isArray(v) ? v : []);
|
|
27
|
+
async function get(url, init, timeoutMs = 25000) {
|
|
28
|
+
const ctrl = new AbortController();
|
|
29
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
30
|
+
try {
|
|
31
|
+
const res = await fetch(url, {
|
|
32
|
+
...init,
|
|
33
|
+
signal: ctrl.signal,
|
|
34
|
+
headers: { "user-agent": "uniprot-mcp", accept: "application/json", ...(init?.headers ?? {}) },
|
|
35
|
+
});
|
|
36
|
+
if (!res.ok)
|
|
37
|
+
throw new UniProtError(`UniProt returned HTTP ${res.status}`);
|
|
38
|
+
return (await res.json());
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
if (e instanceof UniProtError)
|
|
42
|
+
throw e;
|
|
43
|
+
if (e.name === "AbortError")
|
|
44
|
+
throw new UniProtError("UniProt request timed out");
|
|
45
|
+
throw new UniProtError(`UniProt request failed: ${e.message}`);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function searchProteins(query, limit = 5) {
|
|
52
|
+
const q = query.trim();
|
|
53
|
+
if (q === "")
|
|
54
|
+
throw new UniProtError("query must not be empty");
|
|
55
|
+
const size = Math.min(50, Math.max(1, limit));
|
|
56
|
+
const body = await get(`${API}/uniprotkb/search?query=${encodeURIComponent(q)}&size=${size}&format=json&fields=accession,protein_name,organism_name,length`);
|
|
57
|
+
const items = rows(at(body, "results"));
|
|
58
|
+
if (items.length === 0)
|
|
59
|
+
return `UniProt found nothing for "${q}".`;
|
|
60
|
+
const lines = items.map((r, i) => {
|
|
61
|
+
const name = val(at(r, "proteinDescription.recommendedName.fullName.value")) || val(at(r, "proteinDescription.submissionNames"));
|
|
62
|
+
return `${i + 1}. ${val(at(r, "primaryAccession"))} — ${name} (${val(at(r, "organism.scientificName"))}, ${val(at(r, "sequence.length"))} aa)`;
|
|
63
|
+
});
|
|
64
|
+
return [`UniProt results for "${q}" — ${items.length} shown`, "", ...lines].join("\n");
|
|
65
|
+
}
|
|
66
|
+
export async function getEntry(accession) {
|
|
67
|
+
const acc = accession.trim().toUpperCase();
|
|
68
|
+
if (acc === "")
|
|
69
|
+
throw new UniProtError("accession must not be empty");
|
|
70
|
+
const body = await get(`${API}/uniprotkb/${encodeURIComponent(acc)}.json`);
|
|
71
|
+
const name = val(at(body, "proteinDescription.recommendedName.fullName.value"));
|
|
72
|
+
return [
|
|
73
|
+
`${val(at(body, "primaryAccession"))} — ${name}`,
|
|
74
|
+
"",
|
|
75
|
+
`Organism: ${val(at(body, "organism.scientificName"))}`,
|
|
76
|
+
`Length: ${val(at(body, "sequence.length"))} aa`,
|
|
77
|
+
`Mass: ${val(at(body, "sequence.molWeight"))} Da`,
|
|
78
|
+
`Reviewed: ${val(at(body, "entryType"))}`,
|
|
79
|
+
].join("\n");
|
|
80
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { createServer } from "./server.js";
|
|
4
|
+
async function main() {
|
|
5
|
+
const server = createServer();
|
|
6
|
+
const transport = new StdioServerTransport();
|
|
7
|
+
await server.connect(transport);
|
|
8
|
+
console.error("uniprot-mcp running on stdio");
|
|
9
|
+
}
|
|
10
|
+
main().catch((err) => {
|
|
11
|
+
console.error("Fatal error:", err);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
});
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { searchProteins, getEntry } from "./api.js";
|
|
4
|
+
const text = (t) => ({ content: [{ type: "text", text: t }] });
|
|
5
|
+
const fail = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
6
|
+
const errorMessage = (e) => `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
7
|
+
export function createServer() {
|
|
8
|
+
const server = new McpServer({ name: "uniprot-mcp", version: "1.0.0" });
|
|
9
|
+
server.tool("search_proteins", "Search UniProtKB protein records", { query: z.string().min(1).describe("UniProt query, e.g. insulin or gene:BRCA1"), limit: z.number().int().min(1).max(50).default(5).describe("How many records") }, async ({ query, limit }) => {
|
|
10
|
+
try {
|
|
11
|
+
return text(await searchProteins(query, limit));
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
return fail(errorMessage(e));
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
server.tool("get_entry", "Full UniProt record by accession", { accession: z.string().min(1).describe("UniProt accession, e.g. P01308") }, async ({ accession }) => {
|
|
18
|
+
try {
|
|
19
|
+
return text(await getEntry(accession));
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return fail(errorMessage(e));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return server;
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrfentmen/uniprot-mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "UniProt: protein records, sequences and organism names from the UniProtKB - keyless.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"mcpName": "io.github.mrfentmen/uniprot-mcp",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mrfentmen/awesome-servers.git"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"uniprot-mcp": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"start": "node dist/index.js",
|
|
21
|
+
"test": "node tests/smoke.mjs"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"mcp",
|
|
25
|
+
"uniprot",
|
|
26
|
+
"protein",
|
|
27
|
+
"biology",
|
|
28
|
+
"sequences",
|
|
29
|
+
"science",
|
|
30
|
+
"keyless"
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
35
|
+
"zod": "^3.23.8"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.0.0",
|
|
39
|
+
"typescript": "^5.6.0"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
}
|
|
44
|
+
}
|