scopus-mcp-server 1.0.0__tar.gz
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.
- scopus_mcp_server-1.0.0/.env.example +1 -0
- scopus_mcp_server-1.0.0/.gitignore +9 -0
- scopus_mcp_server-1.0.0/LICENSE +21 -0
- scopus_mcp_server-1.0.0/PKG-INFO +89 -0
- scopus_mcp_server-1.0.0/README.md +71 -0
- scopus_mcp_server-1.0.0/pyproject.toml +29 -0
- scopus_mcp_server-1.0.0/requirements.txt +2 -0
- scopus_mcp_server-1.0.0/server.py +454 -0
- scopus_mcp_server-1.0.0/src/scopus_mcp_server/__init__.py +4 -0
- scopus_mcp_server-1.0.0/src/scopus_mcp_server/server.py +454 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
SCOPUS_API_KEY=your-scopus-api-key-here
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SMABoundless
|
|
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.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scopus-mcp-server
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: MCP server for the Scopus API — search abstracts, authors, and export citations
|
|
5
|
+
Project-URL: Repository, https://github.com/SMABoundless/scopus-mcp-server
|
|
6
|
+
Author: SMABoundless
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: citations,elsevier,mcp,scholarly,scopus
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: httpx>=0.27.0
|
|
16
|
+
Requires-Dist: mcp[cli]>=1.0.0
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Scopus MCP Server
|
|
20
|
+
|
|
21
|
+
An MCP (Model Context Protocol) server for searching [Scopus](https://www.scopus.com/), Elsevier's abstract and citation database covering 90M+ records across science, technology, medicine, social sciences, and arts & humanities.
|
|
22
|
+
|
|
23
|
+
Built with [FastMCP](https://github.com/modelcontextprotocol/python-sdk).
|
|
24
|
+
|
|
25
|
+
## Tools
|
|
26
|
+
|
|
27
|
+
| Tool | Description |
|
|
28
|
+
|------|-------------|
|
|
29
|
+
| `scopus_search` | Search by keyword, title, author, affiliation, DOI, or advanced query |
|
|
30
|
+
| `scopus_abstract` | Retrieve full abstract and metadata for a specific record |
|
|
31
|
+
| `scopus_author` | Look up author profiles (h-index, document count, subject areas) |
|
|
32
|
+
| `scopus_author_papers` | List an author's publications |
|
|
33
|
+
| `scopus_export_ris` | Export results as RIS (for Zotero, EndNote, etc.) |
|
|
34
|
+
| `scopus_export_bibtex` | Export results as BibTeX |
|
|
35
|
+
|
|
36
|
+
## Setup
|
|
37
|
+
|
|
38
|
+
### 1. Get a Scopus API key
|
|
39
|
+
|
|
40
|
+
You need a Scopus API key from the [Elsevier Developer Portal](https://dev.elsevier.com/). Institutional access (e.g., through a university) is typically required for full functionality.
|
|
41
|
+
|
|
42
|
+
### 2. Install
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
cd scopus-mcp-server
|
|
46
|
+
python3 -m venv venv
|
|
47
|
+
source venv/bin/activate
|
|
48
|
+
pip install -r requirements.txt
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. Add to Claude Desktop
|
|
52
|
+
|
|
53
|
+
Add this to your `claude_desktop_config.json`:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"mcpServers": {
|
|
58
|
+
"scopus": {
|
|
59
|
+
"command": "/path/to/scopus-mcp-server/venv/bin/python",
|
|
60
|
+
"args": ["/path/to/scopus-mcp-server/server.py"],
|
|
61
|
+
"env": {
|
|
62
|
+
"SCOPUS_API_KEY": "your-api-key"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Or if using Claude Code CLI:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
claude mcp add scopus \
|
|
73
|
+
/path/to/scopus-mcp-server/venv/bin/python \
|
|
74
|
+
/path/to/scopus-mcp-server/server.py \
|
|
75
|
+
-e SCOPUS_API_KEY=your-api-key
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Usage examples
|
|
79
|
+
|
|
80
|
+
- "Search Scopus for recent articles on deep learning in medical imaging"
|
|
81
|
+
- "Look up the author profile for Smith at Northwestern University"
|
|
82
|
+
- "Get the abstract for Scopus ID 85142567890"
|
|
83
|
+
- "Find this author's papers and export them as BibTeX"
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
|
88
|
+
|
|
89
|
+
<!-- mcp-name: io.github.SMABoundless/scopus -->
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Scopus MCP Server
|
|
2
|
+
|
|
3
|
+
An MCP (Model Context Protocol) server for searching [Scopus](https://www.scopus.com/), Elsevier's abstract and citation database covering 90M+ records across science, technology, medicine, social sciences, and arts & humanities.
|
|
4
|
+
|
|
5
|
+
Built with [FastMCP](https://github.com/modelcontextprotocol/python-sdk).
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
| `scopus_search` | Search by keyword, title, author, affiliation, DOI, or advanced query |
|
|
12
|
+
| `scopus_abstract` | Retrieve full abstract and metadata for a specific record |
|
|
13
|
+
| `scopus_author` | Look up author profiles (h-index, document count, subject areas) |
|
|
14
|
+
| `scopus_author_papers` | List an author's publications |
|
|
15
|
+
| `scopus_export_ris` | Export results as RIS (for Zotero, EndNote, etc.) |
|
|
16
|
+
| `scopus_export_bibtex` | Export results as BibTeX |
|
|
17
|
+
|
|
18
|
+
## Setup
|
|
19
|
+
|
|
20
|
+
### 1. Get a Scopus API key
|
|
21
|
+
|
|
22
|
+
You need a Scopus API key from the [Elsevier Developer Portal](https://dev.elsevier.com/). Institutional access (e.g., through a university) is typically required for full functionality.
|
|
23
|
+
|
|
24
|
+
### 2. Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
cd scopus-mcp-server
|
|
28
|
+
python3 -m venv venv
|
|
29
|
+
source venv/bin/activate
|
|
30
|
+
pip install -r requirements.txt
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 3. Add to Claude Desktop
|
|
34
|
+
|
|
35
|
+
Add this to your `claude_desktop_config.json`:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"mcpServers": {
|
|
40
|
+
"scopus": {
|
|
41
|
+
"command": "/path/to/scopus-mcp-server/venv/bin/python",
|
|
42
|
+
"args": ["/path/to/scopus-mcp-server/server.py"],
|
|
43
|
+
"env": {
|
|
44
|
+
"SCOPUS_API_KEY": "your-api-key"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or if using Claude Code CLI:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
claude mcp add scopus \
|
|
55
|
+
/path/to/scopus-mcp-server/venv/bin/python \
|
|
56
|
+
/path/to/scopus-mcp-server/server.py \
|
|
57
|
+
-e SCOPUS_API_KEY=your-api-key
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage examples
|
|
61
|
+
|
|
62
|
+
- "Search Scopus for recent articles on deep learning in medical imaging"
|
|
63
|
+
- "Look up the author profile for Smith at Northwestern University"
|
|
64
|
+
- "Get the abstract for Scopus ID 85142567890"
|
|
65
|
+
- "Find this author's papers and export them as BibTeX"
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT
|
|
70
|
+
|
|
71
|
+
<!-- mcp-name: io.github.SMABoundless/scopus -->
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scopus-mcp-server"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "MCP server for the Scopus API — search abstracts, authors, and export citations"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "SMABoundless" }]
|
|
13
|
+
keywords = ["mcp", "scopus", "elsevier", "scholarly", "citations"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"mcp[cli]>=1.0.0",
|
|
22
|
+
"httpx>=0.27.0",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
scopus-mcp-server = "scopus_mcp_server:main"
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Repository = "https://github.com/SMABoundless/scopus-mcp-server"
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Scopus MCP Server for Claude Desktop
|
|
4
|
+
Built for Northwestern University Library
|
|
5
|
+
|
|
6
|
+
Provides Claude Desktop with tools to search Scopus, retrieve abstracts,
|
|
7
|
+
look up author profiles, and export citations in RIS/BibTeX format.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import json
|
|
12
|
+
from typing import Optional
|
|
13
|
+
from mcp.server.fastmcp import FastMCP
|
|
14
|
+
import httpx
|
|
15
|
+
|
|
16
|
+
# ── Configuration ──────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
API_KEY = os.environ.get("SCOPUS_API_KEY", "")
|
|
19
|
+
BASE_URL = "https://api.elsevier.com"
|
|
20
|
+
HEADERS = {
|
|
21
|
+
"X-ELS-APIKey": API_KEY,
|
|
22
|
+
"Accept": "application/json",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
mcp = FastMCP("Scopus")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ── Helpers ────────────────────────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
async def _get(path: str, params: dict = None) -> dict:
|
|
31
|
+
"""Make an authenticated GET request to the Scopus API."""
|
|
32
|
+
async with httpx.AsyncClient(timeout=30) as client:
|
|
33
|
+
resp = await client.get(
|
|
34
|
+
f"{BASE_URL}{path}",
|
|
35
|
+
headers=HEADERS,
|
|
36
|
+
params=params or {},
|
|
37
|
+
)
|
|
38
|
+
resp.raise_for_status()
|
|
39
|
+
return resp.json()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _format_authors(entry: dict) -> str:
|
|
43
|
+
"""Extract author names from a search result entry."""
|
|
44
|
+
if "author" in entry:
|
|
45
|
+
return "; ".join(a.get("authname", "") for a in entry["author"])
|
|
46
|
+
return entry.get("dc:creator", "Unknown")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _build_citation_line(entry: dict) -> str:
|
|
50
|
+
"""Build a short citation string: Journal (Year), Vol(Issue), Pages."""
|
|
51
|
+
parts = []
|
|
52
|
+
journal = entry.get("prism:publicationName", "")
|
|
53
|
+
if journal:
|
|
54
|
+
parts.append(journal)
|
|
55
|
+
year = (entry.get("prism:coverDate") or "")[:4]
|
|
56
|
+
if year:
|
|
57
|
+
parts.append(f"({year})")
|
|
58
|
+
vol = entry.get("prism:volume", "")
|
|
59
|
+
issue = entry.get("prism:issueIdentifier", "")
|
|
60
|
+
if vol:
|
|
61
|
+
v = vol
|
|
62
|
+
if issue:
|
|
63
|
+
v += f"({issue})"
|
|
64
|
+
parts.append(v)
|
|
65
|
+
pages = entry.get("prism:pageRange", "")
|
|
66
|
+
if pages:
|
|
67
|
+
parts.append(pages)
|
|
68
|
+
return ", ".join(parts)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _entries_to_text(entries: list) -> str:
|
|
72
|
+
"""Convert a list of Scopus search entries to readable text."""
|
|
73
|
+
if not entries:
|
|
74
|
+
return "No results found."
|
|
75
|
+
lines = []
|
|
76
|
+
for i, e in enumerate(entries, 1):
|
|
77
|
+
if "error" in e:
|
|
78
|
+
return "No results found."
|
|
79
|
+
title = e.get("dc:title", "Untitled")
|
|
80
|
+
authors = _format_authors(e)
|
|
81
|
+
citation = _build_citation_line(e)
|
|
82
|
+
doi = e.get("prism:doi", "")
|
|
83
|
+
cited = e.get("citedby-count", "0")
|
|
84
|
+
doc_type = e.get("subtypeDescription", "")
|
|
85
|
+
scopus_id = (e.get("dc:identifier") or "").replace("SCOPUS_ID:", "")
|
|
86
|
+
|
|
87
|
+
line = f"{i}. {title}\n Authors: {authors}\n {citation}"
|
|
88
|
+
if doc_type:
|
|
89
|
+
line += f"\n Type: {doc_type}"
|
|
90
|
+
line += f"\n Cited by: {cited}"
|
|
91
|
+
if doi:
|
|
92
|
+
line += f"\n DOI: https://doi.org/{doi}"
|
|
93
|
+
if scopus_id:
|
|
94
|
+
line += f"\n Scopus ID: {scopus_id}"
|
|
95
|
+
lines.append(line)
|
|
96
|
+
return "\n\n".join(lines)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _entries_to_ris(entries: list) -> str:
|
|
100
|
+
"""Convert Scopus entries to RIS format for Zotero import."""
|
|
101
|
+
records = []
|
|
102
|
+
for e in entries:
|
|
103
|
+
if "error" in e:
|
|
104
|
+
continue
|
|
105
|
+
lines = ["TY - JOUR"]
|
|
106
|
+
authors = e.get("author", [])
|
|
107
|
+
if authors:
|
|
108
|
+
for a in authors:
|
|
109
|
+
lines.append(f"AU - {a.get('authname', '')}")
|
|
110
|
+
elif e.get("dc:creator"):
|
|
111
|
+
lines.append(f"AU - {e['dc:creator']}")
|
|
112
|
+
if e.get("dc:title"):
|
|
113
|
+
lines.append(f"TI - {e['dc:title']}")
|
|
114
|
+
if e.get("prism:publicationName"):
|
|
115
|
+
lines.append(f"JO - {e['prism:publicationName']}")
|
|
116
|
+
if e.get("prism:volume"):
|
|
117
|
+
lines.append(f"VL - {e['prism:volume']}")
|
|
118
|
+
if e.get("prism:issueIdentifier"):
|
|
119
|
+
lines.append(f"IS - {e['prism:issueIdentifier']}")
|
|
120
|
+
if e.get("prism:pageRange"):
|
|
121
|
+
lines.append(f"SP - {e['prism:pageRange']}")
|
|
122
|
+
year = (e.get("prism:coverDate") or "")[:4]
|
|
123
|
+
if year:
|
|
124
|
+
lines.append(f"PY - {year}")
|
|
125
|
+
if e.get("prism:doi"):
|
|
126
|
+
lines.append(f"DO - {e['prism:doi']}")
|
|
127
|
+
if e.get("dc:description"):
|
|
128
|
+
lines.append(f"AB - {e['dc:description']}")
|
|
129
|
+
eid = e.get("eid", "")
|
|
130
|
+
if eid:
|
|
131
|
+
lines.append(f"AN - {eid}")
|
|
132
|
+
lines.append("ER - ")
|
|
133
|
+
records.append("\n".join(lines))
|
|
134
|
+
return "\n\n".join(records)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _entries_to_bibtex(entries: list) -> str:
|
|
138
|
+
"""Convert Scopus entries to BibTeX format."""
|
|
139
|
+
records = []
|
|
140
|
+
for e in entries:
|
|
141
|
+
if "error" in e:
|
|
142
|
+
continue
|
|
143
|
+
first_author = ""
|
|
144
|
+
if e.get("author"):
|
|
145
|
+
first_author = e["author"][0].get("authname", "unknown").split(" ")[0]
|
|
146
|
+
elif e.get("dc:creator"):
|
|
147
|
+
first_author = e["dc:creator"].split(" ")[0]
|
|
148
|
+
else:
|
|
149
|
+
first_author = "unknown"
|
|
150
|
+
year = (e.get("prism:coverDate") or "")[:4] or "nd"
|
|
151
|
+
key = f"{first_author}{year}"
|
|
152
|
+
|
|
153
|
+
authors = ""
|
|
154
|
+
if e.get("author"):
|
|
155
|
+
authors = " and ".join(a.get("authname", "") for a in e["author"])
|
|
156
|
+
elif e.get("dc:creator"):
|
|
157
|
+
authors = e["dc:creator"]
|
|
158
|
+
|
|
159
|
+
lines = [f"@article{{{key},"]
|
|
160
|
+
if e.get("dc:title"):
|
|
161
|
+
lines.append(f" title = {{{e['dc:title']}}},")
|
|
162
|
+
if authors:
|
|
163
|
+
lines.append(f" author = {{{authors}}},")
|
|
164
|
+
if e.get("prism:publicationName"):
|
|
165
|
+
lines.append(f" journal = {{{e['prism:publicationName']}}},")
|
|
166
|
+
if year != "nd":
|
|
167
|
+
lines.append(f" year = {{{year}}},")
|
|
168
|
+
if e.get("prism:volume"):
|
|
169
|
+
lines.append(f" volume = {{{e['prism:volume']}}},")
|
|
170
|
+
if e.get("prism:issueIdentifier"):
|
|
171
|
+
lines.append(f" number = {{{e['prism:issueIdentifier']}}},")
|
|
172
|
+
if e.get("prism:pageRange"):
|
|
173
|
+
lines.append(f" pages = {{{e['prism:pageRange']}}},")
|
|
174
|
+
if e.get("prism:doi"):
|
|
175
|
+
lines.append(f" doi = {{{e['prism:doi']}}},")
|
|
176
|
+
lines.append("}")
|
|
177
|
+
records.append("\n".join(lines))
|
|
178
|
+
return "\n\n".join(records)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# ── Store last search results for export ───────────────────────────────────
|
|
182
|
+
|
|
183
|
+
_last_results: list = []
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
# ── Tools ──────────────────────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
@mcp.tool()
|
|
189
|
+
async def scopus_search(
|
|
190
|
+
query: str,
|
|
191
|
+
search_type: str = "keyword",
|
|
192
|
+
year_from: Optional[str] = None,
|
|
193
|
+
year_to: Optional[str] = None,
|
|
194
|
+
count: int = 25,
|
|
195
|
+
) -> str:
|
|
196
|
+
"""
|
|
197
|
+
Search Scopus for academic articles.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
query: Search terms or advanced Scopus query
|
|
201
|
+
search_type: One of: keyword, title, author, affiliation, doi, advanced
|
|
202
|
+
year_from: Optional start year (e.g. "2020")
|
|
203
|
+
year_to: Optional end year (e.g. "2025")
|
|
204
|
+
count: Number of results (max 50, default 25)
|
|
205
|
+
"""
|
|
206
|
+
global _last_results
|
|
207
|
+
|
|
208
|
+
# Build the Scopus query based on search type
|
|
209
|
+
type_map = {
|
|
210
|
+
"keyword": lambda q: f"KEY({q})",
|
|
211
|
+
"title": lambda q: f"TITLE({q})",
|
|
212
|
+
"author": lambda q: f"AUTHLASTNAME({q})",
|
|
213
|
+
"affiliation": lambda q: f"AFFIL({q})",
|
|
214
|
+
"doi": lambda q: f"DOI({q})",
|
|
215
|
+
"advanced": lambda q: q,
|
|
216
|
+
}
|
|
217
|
+
builder = type_map.get(search_type, type_map["keyword"])
|
|
218
|
+
scopus_query = builder(query)
|
|
219
|
+
|
|
220
|
+
params = {
|
|
221
|
+
"query": scopus_query,
|
|
222
|
+
"apiKey": API_KEY,
|
|
223
|
+
"count": min(count, 50),
|
|
224
|
+
"sort": "-coverDate",
|
|
225
|
+
"field": "dc:title,dc:creator,prism:publicationName,prism:coverDate,"
|
|
226
|
+
"prism:doi,prism:volume,prism:issueIdentifier,prism:pageRange,"
|
|
227
|
+
"dc:description,citedby-count,author,eid,dc:identifier,"
|
|
228
|
+
"subtypeDescription",
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
# Date range
|
|
232
|
+
if year_from and year_to:
|
|
233
|
+
params["date"] = f"{year_from}-{year_to}"
|
|
234
|
+
elif year_from:
|
|
235
|
+
params["date"] = f"{year_from}-2026"
|
|
236
|
+
elif year_to:
|
|
237
|
+
params["date"] = f"1900-{year_to}"
|
|
238
|
+
|
|
239
|
+
try:
|
|
240
|
+
data = await _get("/content/search/scopus", params)
|
|
241
|
+
results = data.get("search-results", {})
|
|
242
|
+
entries = results.get("entry", [])
|
|
243
|
+
total = results.get("opensearch:totalResults", "0")
|
|
244
|
+
|
|
245
|
+
_last_results = entries
|
|
246
|
+
|
|
247
|
+
header = f"Scopus Search: {total} total results found, showing {len(entries)}\n"
|
|
248
|
+
header += f"Query: {scopus_query}\n"
|
|
249
|
+
header += "=" * 60 + "\n\n"
|
|
250
|
+
|
|
251
|
+
return header + _entries_to_text(entries)
|
|
252
|
+
except httpx.HTTPStatusError as e:
|
|
253
|
+
return f"Scopus API error: {e.response.status_code} — {e.response.text}"
|
|
254
|
+
except Exception as e:
|
|
255
|
+
return f"Error: {str(e)}"
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
@mcp.tool()
|
|
259
|
+
async def scopus_abstract(scopus_id: str) -> str:
|
|
260
|
+
"""
|
|
261
|
+
Retrieve full abstract and metadata for a Scopus record.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
scopus_id: The Scopus ID (e.g. "85142567890")
|
|
265
|
+
"""
|
|
266
|
+
try:
|
|
267
|
+
data = await _get(f"/content/abstract/scopus_id/{scopus_id}", {"apiKey": API_KEY})
|
|
268
|
+
resp = data.get("abstracts-retrieval-response", {})
|
|
269
|
+
coredata = resp.get("coredata", {})
|
|
270
|
+
|
|
271
|
+
title = coredata.get("dc:title", "Unknown")
|
|
272
|
+
abstract = coredata.get("dc:description", "No abstract available.")
|
|
273
|
+
doi = coredata.get("prism:doi", "")
|
|
274
|
+
journal = coredata.get("prism:publicationName", "")
|
|
275
|
+
date = coredata.get("prism:coverDate", "")
|
|
276
|
+
cited = coredata.get("citedby-count", "0")
|
|
277
|
+
vol = coredata.get("prism:volume", "")
|
|
278
|
+
issue = coredata.get("prism:issueIdentifier", "")
|
|
279
|
+
pages = coredata.get("prism:pageRange", "")
|
|
280
|
+
|
|
281
|
+
# Authors
|
|
282
|
+
authors_data = resp.get("authors", {}).get("author", [])
|
|
283
|
+
if isinstance(authors_data, dict):
|
|
284
|
+
authors_data = [authors_data]
|
|
285
|
+
authors = "; ".join(
|
|
286
|
+
f"{a.get('ce:surname', '')}, {a.get('ce:given-name', '')}"
|
|
287
|
+
for a in authors_data
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
# Keywords
|
|
291
|
+
kw_data = resp.get("authkeywords", {})
|
|
292
|
+
keywords = []
|
|
293
|
+
if kw_data and "author-keyword" in kw_data:
|
|
294
|
+
kws = kw_data["author-keyword"]
|
|
295
|
+
if isinstance(kws, dict):
|
|
296
|
+
kws = [kws]
|
|
297
|
+
keywords = [k.get("$", "") for k in kws]
|
|
298
|
+
|
|
299
|
+
output = f"Title: {title}\n"
|
|
300
|
+
output += f"Authors: {authors}\n"
|
|
301
|
+
output += f"Journal: {journal}"
|
|
302
|
+
if vol:
|
|
303
|
+
output += f", {vol}"
|
|
304
|
+
if issue:
|
|
305
|
+
output += f"({issue})"
|
|
306
|
+
if pages:
|
|
307
|
+
output += f", {pages}"
|
|
308
|
+
output += f"\nDate: {date}\n"
|
|
309
|
+
output += f"Cited by: {cited}\n"
|
|
310
|
+
if doi:
|
|
311
|
+
output += f"DOI: https://doi.org/{doi}\n"
|
|
312
|
+
if keywords:
|
|
313
|
+
output += f"Keywords: {', '.join(keywords)}\n"
|
|
314
|
+
output += f"\nAbstract:\n{abstract}"
|
|
315
|
+
|
|
316
|
+
return output
|
|
317
|
+
except httpx.HTTPStatusError as e:
|
|
318
|
+
return f"Scopus API error: {e.response.status_code} — {e.response.text}"
|
|
319
|
+
except Exception as e:
|
|
320
|
+
return f"Error: {str(e)}"
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
@mcp.tool()
|
|
324
|
+
async def scopus_author(
|
|
325
|
+
author_name: str,
|
|
326
|
+
affiliation: Optional[str] = None,
|
|
327
|
+
) -> str:
|
|
328
|
+
"""
|
|
329
|
+
Look up author profiles on Scopus. Returns h-index, document count,
|
|
330
|
+
citation count, and subject areas.
|
|
331
|
+
|
|
332
|
+
Args:
|
|
333
|
+
author_name: Author's last name
|
|
334
|
+
affiliation: Optional affiliation to narrow results (e.g. "Northwestern")
|
|
335
|
+
"""
|
|
336
|
+
query = f"authlast({author_name})"
|
|
337
|
+
if affiliation:
|
|
338
|
+
query += f" AND affil({affiliation})"
|
|
339
|
+
|
|
340
|
+
try:
|
|
341
|
+
data = await _get("/content/search/author", {
|
|
342
|
+
"query": query,
|
|
343
|
+
"apiKey": API_KEY,
|
|
344
|
+
"count": 10,
|
|
345
|
+
})
|
|
346
|
+
entries = data.get("search-results", {}).get("entry", [])
|
|
347
|
+
|
|
348
|
+
if not entries or (len(entries) == 1 and "error" in entries[0]):
|
|
349
|
+
return f"No authors found for '{author_name}'."
|
|
350
|
+
|
|
351
|
+
lines = []
|
|
352
|
+
for i, a in enumerate(entries, 1):
|
|
353
|
+
pref = a.get("preferred-name", {})
|
|
354
|
+
name = f"{pref.get('surname', '')}, {pref.get('given-name', '')}"
|
|
355
|
+
affil_name = (a.get("affiliation-current") or {}).get("affiliation-name", "—")
|
|
356
|
+
docs = a.get("document-count", "—")
|
|
357
|
+
author_id = (a.get("dc:identifier") or "").replace("AUTHOR_ID:", "")
|
|
358
|
+
subjects = a.get("subject-area", [])
|
|
359
|
+
if isinstance(subjects, dict):
|
|
360
|
+
subjects = [subjects]
|
|
361
|
+
subj_list = ", ".join(s.get("$", "") for s in subjects[:5])
|
|
362
|
+
|
|
363
|
+
line = f"{i}. {name}\n Affiliation: {affil_name}\n Documents: {docs}"
|
|
364
|
+
if subj_list:
|
|
365
|
+
line += f"\n Subjects: {subj_list}"
|
|
366
|
+
if author_id:
|
|
367
|
+
line += f"\n Author ID: {author_id}"
|
|
368
|
+
line += f"\n Scopus Profile: https://www.scopus.com/authid/detail.uri?authorId={author_id}"
|
|
369
|
+
lines.append(line)
|
|
370
|
+
|
|
371
|
+
return "\n\n".join(lines)
|
|
372
|
+
except httpx.HTTPStatusError as e:
|
|
373
|
+
return f"Scopus API error: {e.response.status_code} — {e.response.text}"
|
|
374
|
+
except Exception as e:
|
|
375
|
+
return f"Error: {str(e)}"
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
@mcp.tool()
|
|
379
|
+
async def scopus_author_papers(
|
|
380
|
+
author_id: str,
|
|
381
|
+
count: int = 25,
|
|
382
|
+
year_from: Optional[str] = None,
|
|
383
|
+
) -> str:
|
|
384
|
+
"""
|
|
385
|
+
List an author's publications from Scopus.
|
|
386
|
+
|
|
387
|
+
Args:
|
|
388
|
+
author_id: Scopus Author ID (from scopus_author results)
|
|
389
|
+
count: Number of results (max 50, default 25)
|
|
390
|
+
year_from: Optional start year filter
|
|
391
|
+
"""
|
|
392
|
+
global _last_results
|
|
393
|
+
|
|
394
|
+
query = f"AU-ID({author_id})"
|
|
395
|
+
params = {
|
|
396
|
+
"query": query,
|
|
397
|
+
"apiKey": API_KEY,
|
|
398
|
+
"count": min(count, 50),
|
|
399
|
+
"sort": "-coverDate",
|
|
400
|
+
"field": "dc:title,dc:creator,prism:publicationName,prism:coverDate,"
|
|
401
|
+
"prism:doi,prism:volume,prism:issueIdentifier,prism:pageRange,"
|
|
402
|
+
"dc:description,citedby-count,author,eid,dc:identifier,"
|
|
403
|
+
"subtypeDescription",
|
|
404
|
+
}
|
|
405
|
+
if year_from:
|
|
406
|
+
params["date"] = f"{year_from}-2026"
|
|
407
|
+
|
|
408
|
+
try:
|
|
409
|
+
data = await _get("/content/search/scopus", params)
|
|
410
|
+
results = data.get("search-results", {})
|
|
411
|
+
entries = results.get("entry", [])
|
|
412
|
+
total = results.get("opensearch:totalResults", "0")
|
|
413
|
+
|
|
414
|
+
_last_results = entries
|
|
415
|
+
|
|
416
|
+
header = f"Author ID {author_id}: {total} total publications, showing {len(entries)}\n"
|
|
417
|
+
header += "=" * 60 + "\n\n"
|
|
418
|
+
|
|
419
|
+
return header + _entries_to_text(entries)
|
|
420
|
+
except httpx.HTTPStatusError as e:
|
|
421
|
+
return f"Scopus API error: {e.response.status_code} — {e.response.text}"
|
|
422
|
+
except Exception as e:
|
|
423
|
+
return f"Error: {str(e)}"
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
@mcp.tool()
|
|
427
|
+
async def scopus_export_ris() -> str:
|
|
428
|
+
"""
|
|
429
|
+
Export the most recent search results as RIS format.
|
|
430
|
+
Import the output into Zotero: File → Import → paste or save as .ris file.
|
|
431
|
+
"""
|
|
432
|
+
if not _last_results:
|
|
433
|
+
return "No results to export. Run a search first."
|
|
434
|
+
ris = _entries_to_ris(_last_results)
|
|
435
|
+
count = len([e for e in _last_results if "error" not in e])
|
|
436
|
+
return f"RIS Export ({count} records) — Save as .ris and import into Zotero:\n\n{ris}"
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
@mcp.tool()
|
|
440
|
+
async def scopus_export_bibtex() -> str:
|
|
441
|
+
"""
|
|
442
|
+
Export the most recent search results as BibTeX format.
|
|
443
|
+
"""
|
|
444
|
+
if not _last_results:
|
|
445
|
+
return "No results to export. Run a search first."
|
|
446
|
+
bib = _entries_to_bibtex(_last_results)
|
|
447
|
+
count = len([e for e in _last_results if "error" not in e])
|
|
448
|
+
return f"BibTeX Export ({count} records):\n\n{bib}"
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
# ── Run ────────────────────────────────────────────────────────────────────
|
|
452
|
+
|
|
453
|
+
if __name__ == "__main__":
|
|
454
|
+
mcp.run()
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Scopus MCP Server for Claude Desktop
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Provides Claude Desktop with tools to search Scopus, retrieve abstracts,
|
|
7
|
+
look up author profiles, and export citations in RIS/BibTeX format.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import json
|
|
12
|
+
from typing import Optional
|
|
13
|
+
from mcp.server.fastmcp import FastMCP
|
|
14
|
+
import httpx
|
|
15
|
+
|
|
16
|
+
# ── Configuration ──────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
API_KEY = os.environ.get("SCOPUS_API_KEY", "")
|
|
19
|
+
BASE_URL = "https://api.elsevier.com"
|
|
20
|
+
HEADERS = {
|
|
21
|
+
"X-ELS-APIKey": API_KEY,
|
|
22
|
+
"Accept": "application/json",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
mcp = FastMCP("Scopus")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ── Helpers ────────────────────────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
async def _get(path: str, params: dict = None) -> dict:
|
|
31
|
+
"""Make an authenticated GET request to the Scopus API."""
|
|
32
|
+
async with httpx.AsyncClient(timeout=30) as client:
|
|
33
|
+
resp = await client.get(
|
|
34
|
+
f"{BASE_URL}{path}",
|
|
35
|
+
headers=HEADERS,
|
|
36
|
+
params=params or {},
|
|
37
|
+
)
|
|
38
|
+
resp.raise_for_status()
|
|
39
|
+
return resp.json()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _format_authors(entry: dict) -> str:
|
|
43
|
+
"""Extract author names from a search result entry."""
|
|
44
|
+
if "author" in entry:
|
|
45
|
+
return "; ".join(a.get("authname", "") for a in entry["author"])
|
|
46
|
+
return entry.get("dc:creator", "Unknown")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _build_citation_line(entry: dict) -> str:
|
|
50
|
+
"""Build a short citation string: Journal (Year), Vol(Issue), Pages."""
|
|
51
|
+
parts = []
|
|
52
|
+
journal = entry.get("prism:publicationName", "")
|
|
53
|
+
if journal:
|
|
54
|
+
parts.append(journal)
|
|
55
|
+
year = (entry.get("prism:coverDate") or "")[:4]
|
|
56
|
+
if year:
|
|
57
|
+
parts.append(f"({year})")
|
|
58
|
+
vol = entry.get("prism:volume", "")
|
|
59
|
+
issue = entry.get("prism:issueIdentifier", "")
|
|
60
|
+
if vol:
|
|
61
|
+
v = vol
|
|
62
|
+
if issue:
|
|
63
|
+
v += f"({issue})"
|
|
64
|
+
parts.append(v)
|
|
65
|
+
pages = entry.get("prism:pageRange", "")
|
|
66
|
+
if pages:
|
|
67
|
+
parts.append(pages)
|
|
68
|
+
return ", ".join(parts)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _entries_to_text(entries: list) -> str:
|
|
72
|
+
"""Convert a list of Scopus search entries to readable text."""
|
|
73
|
+
if not entries:
|
|
74
|
+
return "No results found."
|
|
75
|
+
lines = []
|
|
76
|
+
for i, e in enumerate(entries, 1):
|
|
77
|
+
if "error" in e:
|
|
78
|
+
return "No results found."
|
|
79
|
+
title = e.get("dc:title", "Untitled")
|
|
80
|
+
authors = _format_authors(e)
|
|
81
|
+
citation = _build_citation_line(e)
|
|
82
|
+
doi = e.get("prism:doi", "")
|
|
83
|
+
cited = e.get("citedby-count", "0")
|
|
84
|
+
doc_type = e.get("subtypeDescription", "")
|
|
85
|
+
scopus_id = (e.get("dc:identifier") or "").replace("SCOPUS_ID:", "")
|
|
86
|
+
|
|
87
|
+
line = f"{i}. {title}\n Authors: {authors}\n {citation}"
|
|
88
|
+
if doc_type:
|
|
89
|
+
line += f"\n Type: {doc_type}"
|
|
90
|
+
line += f"\n Cited by: {cited}"
|
|
91
|
+
if doi:
|
|
92
|
+
line += f"\n DOI: https://doi.org/{doi}"
|
|
93
|
+
if scopus_id:
|
|
94
|
+
line += f"\n Scopus ID: {scopus_id}"
|
|
95
|
+
lines.append(line)
|
|
96
|
+
return "\n\n".join(lines)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _entries_to_ris(entries: list) -> str:
|
|
100
|
+
"""Convert Scopus entries to RIS format for Zotero import."""
|
|
101
|
+
records = []
|
|
102
|
+
for e in entries:
|
|
103
|
+
if "error" in e:
|
|
104
|
+
continue
|
|
105
|
+
lines = ["TY - JOUR"]
|
|
106
|
+
authors = e.get("author", [])
|
|
107
|
+
if authors:
|
|
108
|
+
for a in authors:
|
|
109
|
+
lines.append(f"AU - {a.get('authname', '')}")
|
|
110
|
+
elif e.get("dc:creator"):
|
|
111
|
+
lines.append(f"AU - {e['dc:creator']}")
|
|
112
|
+
if e.get("dc:title"):
|
|
113
|
+
lines.append(f"TI - {e['dc:title']}")
|
|
114
|
+
if e.get("prism:publicationName"):
|
|
115
|
+
lines.append(f"JO - {e['prism:publicationName']}")
|
|
116
|
+
if e.get("prism:volume"):
|
|
117
|
+
lines.append(f"VL - {e['prism:volume']}")
|
|
118
|
+
if e.get("prism:issueIdentifier"):
|
|
119
|
+
lines.append(f"IS - {e['prism:issueIdentifier']}")
|
|
120
|
+
if e.get("prism:pageRange"):
|
|
121
|
+
lines.append(f"SP - {e['prism:pageRange']}")
|
|
122
|
+
year = (e.get("prism:coverDate") or "")[:4]
|
|
123
|
+
if year:
|
|
124
|
+
lines.append(f"PY - {year}")
|
|
125
|
+
if e.get("prism:doi"):
|
|
126
|
+
lines.append(f"DO - {e['prism:doi']}")
|
|
127
|
+
if e.get("dc:description"):
|
|
128
|
+
lines.append(f"AB - {e['dc:description']}")
|
|
129
|
+
eid = e.get("eid", "")
|
|
130
|
+
if eid:
|
|
131
|
+
lines.append(f"AN - {eid}")
|
|
132
|
+
lines.append("ER - ")
|
|
133
|
+
records.append("\n".join(lines))
|
|
134
|
+
return "\n\n".join(records)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _entries_to_bibtex(entries: list) -> str:
|
|
138
|
+
"""Convert Scopus entries to BibTeX format."""
|
|
139
|
+
records = []
|
|
140
|
+
for e in entries:
|
|
141
|
+
if "error" in e:
|
|
142
|
+
continue
|
|
143
|
+
first_author = ""
|
|
144
|
+
if e.get("author"):
|
|
145
|
+
first_author = e["author"][0].get("authname", "unknown").split(" ")[0]
|
|
146
|
+
elif e.get("dc:creator"):
|
|
147
|
+
first_author = e["dc:creator"].split(" ")[0]
|
|
148
|
+
else:
|
|
149
|
+
first_author = "unknown"
|
|
150
|
+
year = (e.get("prism:coverDate") or "")[:4] or "nd"
|
|
151
|
+
key = f"{first_author}{year}"
|
|
152
|
+
|
|
153
|
+
authors = ""
|
|
154
|
+
if e.get("author"):
|
|
155
|
+
authors = " and ".join(a.get("authname", "") for a in e["author"])
|
|
156
|
+
elif e.get("dc:creator"):
|
|
157
|
+
authors = e["dc:creator"]
|
|
158
|
+
|
|
159
|
+
lines = [f"@article{{{key},"]
|
|
160
|
+
if e.get("dc:title"):
|
|
161
|
+
lines.append(f" title = {{{e['dc:title']}}},")
|
|
162
|
+
if authors:
|
|
163
|
+
lines.append(f" author = {{{authors}}},")
|
|
164
|
+
if e.get("prism:publicationName"):
|
|
165
|
+
lines.append(f" journal = {{{e['prism:publicationName']}}},")
|
|
166
|
+
if year != "nd":
|
|
167
|
+
lines.append(f" year = {{{year}}},")
|
|
168
|
+
if e.get("prism:volume"):
|
|
169
|
+
lines.append(f" volume = {{{e['prism:volume']}}},")
|
|
170
|
+
if e.get("prism:issueIdentifier"):
|
|
171
|
+
lines.append(f" number = {{{e['prism:issueIdentifier']}}},")
|
|
172
|
+
if e.get("prism:pageRange"):
|
|
173
|
+
lines.append(f" pages = {{{e['prism:pageRange']}}},")
|
|
174
|
+
if e.get("prism:doi"):
|
|
175
|
+
lines.append(f" doi = {{{e['prism:doi']}}},")
|
|
176
|
+
lines.append("}")
|
|
177
|
+
records.append("\n".join(lines))
|
|
178
|
+
return "\n\n".join(records)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# ── Store last search results for export ───────────────────────────────────
|
|
182
|
+
|
|
183
|
+
_last_results: list = []
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
# ── Tools ──────────────────────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
@mcp.tool()
|
|
189
|
+
async def scopus_search(
|
|
190
|
+
query: str,
|
|
191
|
+
search_type: str = "keyword",
|
|
192
|
+
year_from: Optional[str] = None,
|
|
193
|
+
year_to: Optional[str] = None,
|
|
194
|
+
count: int = 25,
|
|
195
|
+
) -> str:
|
|
196
|
+
"""
|
|
197
|
+
Search Scopus for academic articles.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
query: Search terms or advanced Scopus query
|
|
201
|
+
search_type: One of: keyword, title, author, affiliation, doi, advanced
|
|
202
|
+
year_from: Optional start year (e.g. "2020")
|
|
203
|
+
year_to: Optional end year (e.g. "2025")
|
|
204
|
+
count: Number of results (max 50, default 25)
|
|
205
|
+
"""
|
|
206
|
+
global _last_results
|
|
207
|
+
|
|
208
|
+
# Build the Scopus query based on search type
|
|
209
|
+
type_map = {
|
|
210
|
+
"keyword": lambda q: f"KEY({q})",
|
|
211
|
+
"title": lambda q: f"TITLE({q})",
|
|
212
|
+
"author": lambda q: f"AUTHLASTNAME({q})",
|
|
213
|
+
"affiliation": lambda q: f"AFFIL({q})",
|
|
214
|
+
"doi": lambda q: f"DOI({q})",
|
|
215
|
+
"advanced": lambda q: q,
|
|
216
|
+
}
|
|
217
|
+
builder = type_map.get(search_type, type_map["keyword"])
|
|
218
|
+
scopus_query = builder(query)
|
|
219
|
+
|
|
220
|
+
params = {
|
|
221
|
+
"query": scopus_query,
|
|
222
|
+
"apiKey": API_KEY,
|
|
223
|
+
"count": min(count, 50),
|
|
224
|
+
"sort": "-coverDate",
|
|
225
|
+
"field": "dc:title,dc:creator,prism:publicationName,prism:coverDate,"
|
|
226
|
+
"prism:doi,prism:volume,prism:issueIdentifier,prism:pageRange,"
|
|
227
|
+
"dc:description,citedby-count,author,eid,dc:identifier,"
|
|
228
|
+
"subtypeDescription",
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
# Date range
|
|
232
|
+
if year_from and year_to:
|
|
233
|
+
params["date"] = f"{year_from}-{year_to}"
|
|
234
|
+
elif year_from:
|
|
235
|
+
params["date"] = f"{year_from}-2026"
|
|
236
|
+
elif year_to:
|
|
237
|
+
params["date"] = f"1900-{year_to}"
|
|
238
|
+
|
|
239
|
+
try:
|
|
240
|
+
data = await _get("/content/search/scopus", params)
|
|
241
|
+
results = data.get("search-results", {})
|
|
242
|
+
entries = results.get("entry", [])
|
|
243
|
+
total = results.get("opensearch:totalResults", "0")
|
|
244
|
+
|
|
245
|
+
_last_results = entries
|
|
246
|
+
|
|
247
|
+
header = f"Scopus Search: {total} total results found, showing {len(entries)}\n"
|
|
248
|
+
header += f"Query: {scopus_query}\n"
|
|
249
|
+
header += "=" * 60 + "\n\n"
|
|
250
|
+
|
|
251
|
+
return header + _entries_to_text(entries)
|
|
252
|
+
except httpx.HTTPStatusError as e:
|
|
253
|
+
return f"Scopus API error: {e.response.status_code} — {e.response.text}"
|
|
254
|
+
except Exception as e:
|
|
255
|
+
return f"Error: {str(e)}"
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
@mcp.tool()
|
|
259
|
+
async def scopus_abstract(scopus_id: str) -> str:
|
|
260
|
+
"""
|
|
261
|
+
Retrieve full abstract and metadata for a Scopus record.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
scopus_id: The Scopus ID (e.g. "85142567890")
|
|
265
|
+
"""
|
|
266
|
+
try:
|
|
267
|
+
data = await _get(f"/content/abstract/scopus_id/{scopus_id}", {"apiKey": API_KEY})
|
|
268
|
+
resp = data.get("abstracts-retrieval-response", {})
|
|
269
|
+
coredata = resp.get("coredata", {})
|
|
270
|
+
|
|
271
|
+
title = coredata.get("dc:title", "Unknown")
|
|
272
|
+
abstract = coredata.get("dc:description", "No abstract available.")
|
|
273
|
+
doi = coredata.get("prism:doi", "")
|
|
274
|
+
journal = coredata.get("prism:publicationName", "")
|
|
275
|
+
date = coredata.get("prism:coverDate", "")
|
|
276
|
+
cited = coredata.get("citedby-count", "0")
|
|
277
|
+
vol = coredata.get("prism:volume", "")
|
|
278
|
+
issue = coredata.get("prism:issueIdentifier", "")
|
|
279
|
+
pages = coredata.get("prism:pageRange", "")
|
|
280
|
+
|
|
281
|
+
# Authors
|
|
282
|
+
authors_data = resp.get("authors", {}).get("author", [])
|
|
283
|
+
if isinstance(authors_data, dict):
|
|
284
|
+
authors_data = [authors_data]
|
|
285
|
+
authors = "; ".join(
|
|
286
|
+
f"{a.get('ce:surname', '')}, {a.get('ce:given-name', '')}"
|
|
287
|
+
for a in authors_data
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
# Keywords
|
|
291
|
+
kw_data = resp.get("authkeywords", {})
|
|
292
|
+
keywords = []
|
|
293
|
+
if kw_data and "author-keyword" in kw_data:
|
|
294
|
+
kws = kw_data["author-keyword"]
|
|
295
|
+
if isinstance(kws, dict):
|
|
296
|
+
kws = [kws]
|
|
297
|
+
keywords = [k.get("$", "") for k in kws]
|
|
298
|
+
|
|
299
|
+
output = f"Title: {title}\n"
|
|
300
|
+
output += f"Authors: {authors}\n"
|
|
301
|
+
output += f"Journal: {journal}"
|
|
302
|
+
if vol:
|
|
303
|
+
output += f", {vol}"
|
|
304
|
+
if issue:
|
|
305
|
+
output += f"({issue})"
|
|
306
|
+
if pages:
|
|
307
|
+
output += f", {pages}"
|
|
308
|
+
output += f"\nDate: {date}\n"
|
|
309
|
+
output += f"Cited by: {cited}\n"
|
|
310
|
+
if doi:
|
|
311
|
+
output += f"DOI: https://doi.org/{doi}\n"
|
|
312
|
+
if keywords:
|
|
313
|
+
output += f"Keywords: {', '.join(keywords)}\n"
|
|
314
|
+
output += f"\nAbstract:\n{abstract}"
|
|
315
|
+
|
|
316
|
+
return output
|
|
317
|
+
except httpx.HTTPStatusError as e:
|
|
318
|
+
return f"Scopus API error: {e.response.status_code} — {e.response.text}"
|
|
319
|
+
except Exception as e:
|
|
320
|
+
return f"Error: {str(e)}"
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
@mcp.tool()
|
|
324
|
+
async def scopus_author(
|
|
325
|
+
author_name: str,
|
|
326
|
+
affiliation: Optional[str] = None,
|
|
327
|
+
) -> str:
|
|
328
|
+
"""
|
|
329
|
+
Look up author profiles on Scopus. Returns h-index, document count,
|
|
330
|
+
citation count, and subject areas.
|
|
331
|
+
|
|
332
|
+
Args:
|
|
333
|
+
author_name: Author's last name
|
|
334
|
+
affiliation: Optional affiliation to narrow results (e.g. "Northwestern")
|
|
335
|
+
"""
|
|
336
|
+
query = f"authlast({author_name})"
|
|
337
|
+
if affiliation:
|
|
338
|
+
query += f" AND affil({affiliation})"
|
|
339
|
+
|
|
340
|
+
try:
|
|
341
|
+
data = await _get("/content/search/author", {
|
|
342
|
+
"query": query,
|
|
343
|
+
"apiKey": API_KEY,
|
|
344
|
+
"count": 10,
|
|
345
|
+
})
|
|
346
|
+
entries = data.get("search-results", {}).get("entry", [])
|
|
347
|
+
|
|
348
|
+
if not entries or (len(entries) == 1 and "error" in entries[0]):
|
|
349
|
+
return f"No authors found for '{author_name}'."
|
|
350
|
+
|
|
351
|
+
lines = []
|
|
352
|
+
for i, a in enumerate(entries, 1):
|
|
353
|
+
pref = a.get("preferred-name", {})
|
|
354
|
+
name = f"{pref.get('surname', '')}, {pref.get('given-name', '')}"
|
|
355
|
+
affil_name = (a.get("affiliation-current") or {}).get("affiliation-name", "—")
|
|
356
|
+
docs = a.get("document-count", "—")
|
|
357
|
+
author_id = (a.get("dc:identifier") or "").replace("AUTHOR_ID:", "")
|
|
358
|
+
subjects = a.get("subject-area", [])
|
|
359
|
+
if isinstance(subjects, dict):
|
|
360
|
+
subjects = [subjects]
|
|
361
|
+
subj_list = ", ".join(s.get("$", "") for s in subjects[:5])
|
|
362
|
+
|
|
363
|
+
line = f"{i}. {name}\n Affiliation: {affil_name}\n Documents: {docs}"
|
|
364
|
+
if subj_list:
|
|
365
|
+
line += f"\n Subjects: {subj_list}"
|
|
366
|
+
if author_id:
|
|
367
|
+
line += f"\n Author ID: {author_id}"
|
|
368
|
+
line += f"\n Scopus Profile: https://www.scopus.com/authid/detail.uri?authorId={author_id}"
|
|
369
|
+
lines.append(line)
|
|
370
|
+
|
|
371
|
+
return "\n\n".join(lines)
|
|
372
|
+
except httpx.HTTPStatusError as e:
|
|
373
|
+
return f"Scopus API error: {e.response.status_code} — {e.response.text}"
|
|
374
|
+
except Exception as e:
|
|
375
|
+
return f"Error: {str(e)}"
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
@mcp.tool()
|
|
379
|
+
async def scopus_author_papers(
|
|
380
|
+
author_id: str,
|
|
381
|
+
count: int = 25,
|
|
382
|
+
year_from: Optional[str] = None,
|
|
383
|
+
) -> str:
|
|
384
|
+
"""
|
|
385
|
+
List an author's publications from Scopus.
|
|
386
|
+
|
|
387
|
+
Args:
|
|
388
|
+
author_id: Scopus Author ID (from scopus_author results)
|
|
389
|
+
count: Number of results (max 50, default 25)
|
|
390
|
+
year_from: Optional start year filter
|
|
391
|
+
"""
|
|
392
|
+
global _last_results
|
|
393
|
+
|
|
394
|
+
query = f"AU-ID({author_id})"
|
|
395
|
+
params = {
|
|
396
|
+
"query": query,
|
|
397
|
+
"apiKey": API_KEY,
|
|
398
|
+
"count": min(count, 50),
|
|
399
|
+
"sort": "-coverDate",
|
|
400
|
+
"field": "dc:title,dc:creator,prism:publicationName,prism:coverDate,"
|
|
401
|
+
"prism:doi,prism:volume,prism:issueIdentifier,prism:pageRange,"
|
|
402
|
+
"dc:description,citedby-count,author,eid,dc:identifier,"
|
|
403
|
+
"subtypeDescription",
|
|
404
|
+
}
|
|
405
|
+
if year_from:
|
|
406
|
+
params["date"] = f"{year_from}-2026"
|
|
407
|
+
|
|
408
|
+
try:
|
|
409
|
+
data = await _get("/content/search/scopus", params)
|
|
410
|
+
results = data.get("search-results", {})
|
|
411
|
+
entries = results.get("entry", [])
|
|
412
|
+
total = results.get("opensearch:totalResults", "0")
|
|
413
|
+
|
|
414
|
+
_last_results = entries
|
|
415
|
+
|
|
416
|
+
header = f"Author ID {author_id}: {total} total publications, showing {len(entries)}\n"
|
|
417
|
+
header += "=" * 60 + "\n\n"
|
|
418
|
+
|
|
419
|
+
return header + _entries_to_text(entries)
|
|
420
|
+
except httpx.HTTPStatusError as e:
|
|
421
|
+
return f"Scopus API error: {e.response.status_code} — {e.response.text}"
|
|
422
|
+
except Exception as e:
|
|
423
|
+
return f"Error: {str(e)}"
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
@mcp.tool()
|
|
427
|
+
async def scopus_export_ris() -> str:
|
|
428
|
+
"""
|
|
429
|
+
Export the most recent search results as RIS format.
|
|
430
|
+
Import the output into Zotero: File → Import → paste or save as .ris file.
|
|
431
|
+
"""
|
|
432
|
+
if not _last_results:
|
|
433
|
+
return "No results to export. Run a search first."
|
|
434
|
+
ris = _entries_to_ris(_last_results)
|
|
435
|
+
count = len([e for e in _last_results if "error" not in e])
|
|
436
|
+
return f"RIS Export ({count} records) — Save as .ris and import into Zotero:\n\n{ris}"
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
@mcp.tool()
|
|
440
|
+
async def scopus_export_bibtex() -> str:
|
|
441
|
+
"""
|
|
442
|
+
Export the most recent search results as BibTeX format.
|
|
443
|
+
"""
|
|
444
|
+
if not _last_results:
|
|
445
|
+
return "No results to export. Run a search first."
|
|
446
|
+
bib = _entries_to_bibtex(_last_results)
|
|
447
|
+
count = len([e for e in _last_results if "error" not in e])
|
|
448
|
+
return f"BibTeX Export ({count} records):\n\n{bib}"
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
# ── Run ────────────────────────────────────────────────────────────────────
|
|
452
|
+
|
|
453
|
+
if __name__ == "__main__":
|
|
454
|
+
mcp.run()
|