brainx-skill 1.0.13 → 1.0.14

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 (44) hide show
  1. package/README.md +26 -0
  2. package/installation/lib/cli.js +16 -4
  3. package/installation/lib/literature-mcp.js +536 -0
  4. package/manifest.json +2 -0
  5. package/mcp-servers/codex/README.md +24 -4
  6. package/mcp-servers/codex/UPSTREAM.md +3 -1
  7. package/mcp-servers/codex/server.mjs +2 -0
  8. package/mcp-servers/codex/system-prompt.md +30 -19
  9. package/mcp-servers/codex/test/server.test.mjs +12 -1
  10. package/mcp-servers/fulltext-resolver/README.md +136 -0
  11. package/mcp-servers/fulltext-resolver/REUSE.md +32 -0
  12. package/mcp-servers/fulltext-resolver/THIRD_PARTY_NOTICES.md +57 -0
  13. package/mcp-servers/fulltext-resolver/server.mjs +128 -0
  14. package/mcp-servers/fulltext-resolver/src/document.mjs +253 -0
  15. package/mcp-servers/fulltext-resolver/src/http.mjs +173 -0
  16. package/mcp-servers/fulltext-resolver/src/identifiers.mjs +123 -0
  17. package/mcp-servers/fulltext-resolver/src/model.mjs +105 -0
  18. package/mcp-servers/fulltext-resolver/src/resolver.mjs +305 -0
  19. package/mcp-servers/fulltext-resolver/src/sources/biorxiv.mjs +135 -0
  20. package/mcp-servers/fulltext-resolver/src/sources/europe-pmc.mjs +132 -0
  21. package/mcp-servers/fulltext-resolver/src/sources/openalex.mjs +165 -0
  22. package/mcp-servers/fulltext-resolver/test/document.test.mjs +82 -0
  23. package/mcp-servers/fulltext-resolver/test/resolver.test.mjs +287 -0
  24. package/mcp-servers/fulltext-resolver/test/server.test.mjs +63 -0
  25. package/mcp-servers/fulltext-resolver/test/sources.test.mjs +229 -0
  26. package/package.json +10 -3
  27. package/skills/bio-neuro-lit/SKILL.md +206 -0
  28. package/skills/bio-neuro-lit/THIRD_PARTY_NOTICES.md +34 -0
  29. package/skills/bio-neuro-lit/agents/openai.yaml +4 -0
  30. package/skills/bio-neuro-lit/references/tool-contracts.md +73 -0
  31. package/skills/bio-neuro-lit/scripts/deepxiv_fetch.py +110 -0
  32. package/skills/bio-neuro-lit/scripts/exa_search.py +190 -0
  33. package/skills/brainx-general-guard/SKILL.md +17 -0
  34. package/skills/brainx-modeling-loop/SKILL.md +33 -20
  35. package/skills/brainx-modeling-loop/references/parameter-fitting-workflow.md +47 -7
  36. package/skills/brainx-visualization/SKILL.md +157 -0
  37. package/skills/brainx-visualization/agents/openai.yaml +4 -0
  38. package/skills/brainx-visualization/references/interactive-and-visualization-styling.md +155 -0
  39. package/skills/brainx-visualization/references/neural-data-visualization.md +141 -0
  40. package/skills/brainx-visualization/references/statistical-and-model-visualization.md +133 -0
  41. package/skills/package-skills/braincell/SKILL.md +16 -6
  42. package/skills/package-skills/braincell/references/braintools/input-current.md +200 -0
  43. package/skills/package-skills/braincell/references/braintools/metric.md +152 -0
  44. package/skills/package-skills/braincell/references/braintools/optimizer.md +179 -0
@@ -24,6 +24,7 @@ Require the smallest clear implementation built on the highest-level suitable Br
24
24
 
25
25
  - Prefer the owning modeling package's orchestrators, models, simulators, fitters, monitors, and visualization APIs; use lower-level BrainX infrastructure or generic numerical libraries only at uncovered boundaries.
26
26
  - Flag manual loops, array manipulation, State bookkeeping, integration, optimization, or plotting scaffolding when a selected reference establishes a simpler API. Name that verified replacement; do not invent APIs.
27
+ - When generic optimization, metrics, input generation, integration, encoding, or other infrastructure replaces a BrainTools-owned operation, require the iteration's `BrainTools API gap` artifact to name the checked APIs, exact missing capability, smallest external boundary, and unit, State, shape, and numerical parity evidence. An unavailable optional backend does not justify bypassing another suitable routed BrainTools API. Return `REFUSE` when this evidence is absent.
27
28
  - Preserve scientific meaning, units, reproducibility, performance, and figure quality. Keep plotting code minimal and clean: prefer package visualization, then BrainTools, then one basic `matplotlib.pyplot.subplots(...)` composition.
28
29
 
29
30
  ## 3. Is training or fitting good enough?
@@ -39,24 +40,34 @@ Return `REFUSE` when optimization adequacy is required for the scoped outcome bu
39
40
 
40
41
  Good enough means valid and sufficient for the scoped outcome. It does not mean positive, novel, or publishable. Accept a rigorous refutation or bounded inconclusive result when its evidence is sufficient.
41
42
 
42
- Return exactly this structure:
43
-
44
- ```text
45
- OUTCOME: PASS | REFUSE
46
- SCIENTIFIC_OUTCOME: SUPPORTED | PARTIALLY_SUPPORTED | REFUTED | INCONCLUSIVE | INVALID
47
- LOSS_CLOSURE: NOT_APPLICABLE | CLOSED | EXPLAINED_GAP | OPEN | UNRESOLVED
48
- OPTIMIZATION_ADEQUACY: NOT_APPLICABLE | SUFFICIENT | INSUFFICIENT | UNRESOLVED
49
- GOOD_ENOUGH_REASON: one concise evidence-based explanation
50
- FINDINGS:
51
- - ID: stable ID
52
- SEVERITY: critical | major | minor
53
- LOCATION: file and line or artifact path
54
- PROBLEM: concrete defect
55
- SCIENTIFIC_CONSEQUENCE: how it affects validity or interpretation
56
- MINIMUM_FIX: smallest sufficient correction or experiment
57
- UNVERIFIED_ASSUMPTIONS:
58
- - assumption and why available artifacts cannot resolve it
59
- NEXT_ACTION: ADVANCE_TO_VISUALIZATION | RETURN_TO_IMPLEMENTATION
60
- ```
43
+ Return a Markdown document as the tool response. Do not write the report to the filesystem, wrap the document in a code fence, or add text before its title. Use exactly this structure:
44
+
45
+ # BrainX iteration review
46
+
47
+ - **OUTCOME:** `PASS | REFUSE`
48
+ - **SCIENTIFIC_OUTCOME:** `SUPPORTED | PARTIALLY_SUPPORTED | REFUTED | INCONCLUSIVE | INVALID`
49
+ - **LOSS_CLOSURE:** `NOT_APPLICABLE | CLOSED | EXPLAINED_GAP | OPEN | UNRESOLVED`
50
+ - **OPTIMIZATION_ADEQUACY:** `NOT_APPLICABLE | SUFFICIENT | INSUFFICIENT | UNRESOLVED`
51
+ - **NEXT_ACTION:** `ADVANCE_TO_VISUALIZATION | RETURN_TO_STUDY`
52
+
53
+ ## Good-enough reason
54
+
55
+ One concise evidence-based explanation.
56
+
57
+ ## Findings
58
+
59
+ Use one subsection per finding, or write `None.` when there are no findings.
60
+
61
+ ### <stable ID>: <short title>
62
+
63
+ - **Severity:** `critical | major | minor`
64
+ - **Location:** file and line or artifact path
65
+ - **Problem:** concrete defect
66
+ - **Scientific consequence:** how it affects validity or interpretation
67
+ - **Minimum fix:** smallest sufficient correction or experiment
68
+
69
+ ## Unverified assumptions
70
+
71
+ - Assumption and why available artifacts cannot resolve it, or `None.`
61
72
 
62
73
  Return `PASS` only when the iteration is valid and sufficient for its scoped scientific outcome. Return `REFUSE` when a correction, additional in-spec experiment, researcher decision, or unresolved capability is required. Do not return a numeric quality score. Do not manufacture findings when the supplied evidence is correct.
@@ -44,6 +44,8 @@ test('injects the reviewer prompt and configured BrainX skills into fresh sessio
44
44
  name: 'codex',
45
45
  arguments: {
46
46
  prompt: 'Review iteration 4',
47
+ 'approval-policy': 'on-request',
48
+ sandbox: 'danger-full-access',
47
49
  config: { model_reasoning_effort: 'xhigh' },
48
50
  },
49
51
  },
@@ -60,13 +62,22 @@ test('injects the reviewer prompt and configured BrainX skills into fresh sessio
60
62
  assert.match(args['base-instructions'], /\*\*Hyperparameters and method:\*\*/);
61
63
  assert.match(args['base-instructions'], /BrainState's prebuilt `brainstate\.nn` layers/);
62
64
  assert.match(args['base-instructions'], /braintools\.optim\.Adam/);
63
- assert.match(args['base-instructions'], /LOSS_CLOSURE: NOT_APPLICABLE/);
65
+ assert.match(args['base-instructions'], /BrainTools API gap/);
66
+ assert.match(args['base-instructions'], /RETURN_TO_STUDY/);
67
+ assert.match(args['base-instructions'], /Return a Markdown document as the tool response/);
68
+ assert.match(args['base-instructions'], /# BrainX iteration review/);
69
+ assert.match(args['base-instructions'], /- \*\*OUTCOME:\*\* `PASS \| REFUSE`/);
70
+ assert.match(args['base-instructions'], /- \*\*LOSS_CLOSURE:\*\* `NOT_APPLICABLE/);
71
+ assert.match(args['base-instructions'], /## Findings/);
72
+ assert.doesNotMatch(args['base-instructions'], /```text\s+OUTCOME:/);
64
73
  assert.match(args['base-instructions'], /Keep plotting code minimal and clean/);
65
74
  assert.match(args['developer-instructions'], /brainx-general-guard/);
66
75
  assert.match(args['developer-instructions'], /TRAINING_REVIEW_REFERENCE: \/.*\/training-workflow\.md/);
67
76
  assert.match(args['developer-instructions'], /FITTING_REVIEW_REFERENCE: \/.*\/parameter-fitting-workflow\.md/);
68
77
  assert.doesNotMatch(args['developer-instructions'], /^- brainx-modeling-loop$/m);
69
78
  assert.equal(args.config.model_reasoning_effort, 'xhigh');
79
+ assert.equal(args['approval-policy'], 'never');
80
+ assert.equal(args.sandbox, 'read-only');
70
81
  assert.equal(args.config['skills.config'].length, 8);
71
82
  assert.ok(args.config['skills.config'].every((skill) => skill.enabled));
72
83
  assert.ok(args.config['skills.config'].every((skill) => skill.path.startsWith('/')));
@@ -0,0 +1,136 @@
1
+ # Full-text resolver MCP
2
+
3
+ This stdio MCP resolves biology and neuroscience papers to the best accessible full-text version without duplicating general literature search.
4
+
5
+ Source priority is:
6
+
7
+ ```text
8
+ published PMC or publisher OA
9
+ accepted repository manuscript
10
+ submitted bioRxiv/medRxiv or repository preprint
11
+ unresolved
12
+ ```
13
+
14
+ Every result preserves the requested work separately from the retrieved document. A preprint is never labeled as the final journal article.
15
+
16
+ ## Tools
17
+
18
+ | Tool | Use |
19
+ |---|---|
20
+ | `resolve_fulltext` | Resolve the best accessible version and return provenance without downloading the document. |
21
+ | `get_fulltext` | Retrieve JATS or HTML as Markdown. Preserve PDF-only versions as source links. |
22
+ | `list_versions` | List every known accessible published, accepted, and submitted version. |
23
+
24
+ All tools accept any useful combination of `doi`, `pmid`, `pmcid`, `title`, `authors`, and `year`. Prefer DOI. Title resolution requires a normalized exact title match; the resolver does not confirm relationships from title similarity alone.
25
+
26
+ `get_fulltext` also accepts:
27
+
28
+ | Input | Meaning |
29
+ |---|---|
30
+ | `version` | Restrict retrieval to `publishedVersion`, `acceptedVersion`, `submittedVersion`, or `unknown`. |
31
+ | `source` | Restrict retrieval to `PMC`, `OpenAlex`, `bioRxiv`, or `medRxiv`. |
32
+ | `include_raw` | Include retrieved JATS or HTML in `structuredContent`. Defaults to `false`. |
33
+ | `max_chars` | Optionally truncate returned Markdown. Omit for the complete converted document. |
34
+
35
+ ## Install and register
36
+
37
+ Install this resolver together with Europe PMC search and the BrainX Codex reviewer:
38
+
39
+ ```bash
40
+ npx brainx-skill mcp install
41
+ ```
42
+
43
+ The installer creates a durable runtime under `~/.brainx/mcp`, registers the resolver as `fulltext_resolver`, and refuses to overwrite an existing user-owned registration. Restart Codex or reload MCP configuration after installation. Use `npx brainx-skill mcp remove` to remove the managed registrations and runtime.
44
+
45
+ For repository development, install dependencies and start the stdio server directly:
46
+
47
+ ```bash
48
+ npm install
49
+ node mcp-servers/fulltext-resolver/server.mjs
50
+ ```
51
+
52
+ The second command waits for an MCP client and does not print protocol data to stderr during normal startup.
53
+
54
+ For manual Codex registration, add the server to `~/.codex/config.toml`, or to `.codex/config.toml` in a trusted project:
55
+
56
+ ```toml
57
+ [mcp_servers.fulltext_resolver]
58
+ command = "node"
59
+ args = ["/absolute/path/to/brainx-skill-bundle/mcp-servers/fulltext-resolver/server.mjs"]
60
+ startup_timeout_sec = 20
61
+ tool_timeout_sec = 120
62
+ ```
63
+
64
+ Optional environment configuration:
65
+
66
+ ```toml
67
+ [mcp_servers.fulltext_resolver.env]
68
+ OPENALEX_MAILTO = "researcher@example.edu"
69
+ OPENALEX_API_KEY = "optional-key"
70
+ FULLTEXT_RESOLVER_USER_AGENT = "lab-fulltext-resolver/1.0 (mailto:researcher@example.edu)"
71
+ FULLTEXT_HTTP_TIMEOUT_MS = "30000"
72
+ FULLTEXT_MAX_BYTES = "8000000"
73
+ ```
74
+
75
+ OpenAlex works anonymously by default. Europe PMC and the bioRxiv/medRxiv metadata and publication-crosswalk APIs require no key. No paid publisher API or AWS credential is required.
76
+
77
+ ## Example calls
78
+
79
+ Resolve by DOI:
80
+
81
+ ```json
82
+ {
83
+ "doi": "10.1038/s41586-020-2649-2"
84
+ }
85
+ ```
86
+
87
+ Retrieve a known preprint version of a journal paper:
88
+
89
+ ```json
90
+ {
91
+ "doi": "10.1371/journal.pone.0256482",
92
+ "source": "medRxiv"
93
+ }
94
+ ```
95
+
96
+ A successful result identifies at least:
97
+
98
+ ```text
99
+ requested DOI
100
+ retrieved DOI or identifier
101
+ source
102
+ version
103
+ relationship
104
+ license when known
105
+ source location
106
+ original format
107
+ normalized format
108
+ ```
109
+
110
+ ## Retrieval behavior
111
+
112
+ - PMC: fetch Europe PMC JATS and convert the article body, abstract, figures, tables, and references to Markdown.
113
+ - OpenAlex: inspect `best_oa_location`, `primary_location`, and `locations[]`; preserve each location's version and license.
114
+ - bioRxiv/medRxiv: query the official published-DOI crosswalk, fetch the latest preprint revision, and prefer its JATS URL.
115
+ - HTML repositories: extract the main article container and convert it to Markdown.
116
+ - PDFs: return the accessible PDF URL and provenance. PDF parsing is an explicit v1 non-goal.
117
+
118
+ Source outages are isolated. A Europe PMC, OpenAlex, or bioRxiv failure is recorded in `source_errors` and does not prevent another source from resolving the work.
119
+
120
+ ## Security and correctness boundaries
121
+
122
+ - The resolver follows only public HTTP(S) URLs and rejects localhost and private literal IP addresses.
123
+ - It does not authenticate to institutions, bypass paywalls, automate browser logins, or call publisher-specific APIs.
124
+ - It does not fabricate content when retrieval fails.
125
+ - OpenAlex repository locations can point to landing pages rather than direct manuscripts. `get_fulltext` reports a fetch failure and tries the next ranked version when the page cannot yield article text.
126
+ - Raw JATS/HTML is returned only when `include_raw=true`.
127
+
128
+ ## Test
129
+
130
+ ```bash
131
+ node --test mcp-servers/fulltext-resolver/test/*.test.mjs
132
+ ```
133
+
134
+ The default tests use fixtures and mocked source clients. Live smoke checks are intentionally separate from the deterministic suite.
135
+
136
+ See `REUSE.md` for the reuse audit and `THIRD_PARTY_NOTICES.md` for attribution.
@@ -0,0 +1,32 @@
1
+ # Reuse audit
2
+
3
+ Audit completed on September 4, 2026. Forks were created under `Wilsonnijc-bot` before implementation.
4
+
5
+ | Component | Source repository and audited revision | Reused files or modules | License | Changes required |
6
+ |---|---|---|---|---|
7
+ | Europe PMC metadata and JATS retrieval | `CoChatAI/europepmc-mcp-server` at `a1af9d06ec7f5f2caef56005fdc1d9d4f12cb115`; fork `Wilsonnijc-bot/europepmc-mcp-server` | `server.py`: REST base URL, search contract, full-text XML endpoint, timeout and user-agent behavior | MIT | Adapted to a Node source adapter; retained only lookup and JATS retrieval needed by the resolver. Added accepted-manuscript detection and normalized provenance. |
8
+ | OpenAlex DOI and title resolution | `DeyangLiu123/openalex-mcp` at `e139b22ced22e0b724ad84ce43bacb470017161a`; fork `Wilsonnijc-bot/openalex-mcp` | `ids.py`: DOI normalization, conservative exact-title matching, identifier parsing; `formats.py`: OA location access patterns | MIT | Ported pure normalization and conservative matching behavior to Node. Removed search/harvesting and paid content-download functionality. |
9
+ | OpenAlex transport and location fields | `cyanheads/openalex-mcp-server` at `513f1158f03bd1dda4a180941c75d7506e6723c5`; fork `Wilsonnijc-bot/openalex-mcp-server` | `openalex-service.ts`, `types.ts`, `server-config.ts`, `field-catalog.json`: anonymous/keyed configuration, retries, `best_oa_location`, `primary_location`, `locations[]`, `version`, license, and URL fields | Apache-2.0 | Adapted the works-only subset to Node 18 and the official MCP SDK. Kept API key and `mailto` optional. Did not use the paid OpenAlex content endpoint. |
10
+ | bioRxiv/medRxiv crosswalk and full text | `cyanheads/biorxiv-mcp-server` at `2b406943815192328481797332cc706b386887ff`; fork `Wilsonnijc-bot/biorxiv-mcp-server` | `biorxiv-service.ts`, `biorxiv-fulltext-service.ts`, `types.ts`, `shared.ts`: `/pubs`, `/details`, revision selection, JATS/HTML URLs, markup cleanup, retries and error isolation | Apache-2.0 | Added the official reverse lookup from published DOI to preprint DOI, selected the latest revision, and normalized the result into the common provenance model. Removed framework-specific storage and transport dependencies. |
11
+ | JATS conversion fallback | `yogsoth-ai/biorxiv-mcp` at `c17747a4a635003d692d4e05b6eda093536908dd`; fork `Wilsonnijc-bot/biorxiv-mcp` | `convert.py`: JATS-first conversion and degraded text fallback; `fetch.py`: structured-source preference | Apache-2.0 | Reimplemented the converter in Node with `linkedom`, preserving structured abstract, sections, figure captions, tables, and references. The AWS requester-pays MECA backend remains optional and is not required in v1. |
12
+ | MCP stdio server | Official `@modelcontextprotocol/sdk` package, version range `^1.30.0` | `McpServer`, `StdioServerTransport`, Zod input validation, tool annotations | MIT | Registered only `resolve_fulltext`, `get_fulltext`, and `list_versions`; no custom JSON-RPC transport was written. |
13
+
14
+ ## Selection decision
15
+
16
+ Use Node.js because the host repository already requires Node 18 and the richest reusable bioRxiv implementation is TypeScript. This avoids requiring Python, Pandoc, FastMCP, Bun, Node 24, AWS, or a second environment for the default resolver.
17
+
18
+ The upstream MCP servers were not vendored whole because they expose broad search and analysis interfaces outside this resolver's boundary. The implementation adapts only the source-client, normalization, retry, conversion, and provenance behavior needed by the three public tools.
19
+
20
+ ## Reuse boundary
21
+
22
+ New code is limited to:
23
+
24
+ ```text
25
+ common resolver orchestration
26
+ normalized version/provenance model
27
+ source ranking and fallback
28
+ MCP tool composition
29
+ end-to-end tests
30
+ ```
31
+
32
+ No Nature, Cell Press, Neuron, PNAS, arXiv, Crossref, Unpaywall, CORE, Semantic Scholar, or paywall-specific client was added.
@@ -0,0 +1,57 @@
1
+ # Third-party notices
2
+
3
+ This resolver adapts behavior and selected source code from the projects listed in `REUSE.md`.
4
+
5
+ ## CoChatAI Europe PMC MCP server
6
+
7
+ MIT License
8
+
9
+ Copyright (c) 2026 CoChat AI
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+
17
+ ## DeyangLiu123 OpenAlex MCP
18
+
19
+ MIT License
20
+
21
+ Copyright (c) 2026 DeyangLiu123
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+
29
+ ## cyanheads OpenAlex and bioRxiv MCP servers
30
+
31
+ Copyright (c) Casey Hand and contributors.
32
+
33
+ Licensed under the Apache License, Version 2.0. The repository root `LICENSE` contains the applicable license terms. Adapted files in this resolver carry modification notices.
34
+
35
+ Source projects:
36
+
37
+ ```text
38
+ cyanheads/openalex-mcp-server
39
+ cyanheads/biorxiv-mcp-server
40
+ ```
41
+
42
+ ## yogsoth-ai bioRxiv MCP
43
+
44
+ Copyright (c) yogsoth-ai and contributors.
45
+
46
+ Licensed under the Apache License, Version 2.0. The repository root `LICENSE` contains the applicable license terms. Adapted files in this resolver carry modification notices.
47
+
48
+ ## Runtime libraries
49
+
50
+ The resolver uses the following packages under their published licenses:
51
+
52
+ ```text
53
+ @modelcontextprotocol/sdk
54
+ linkedom
55
+ turndown
56
+ zod
57
+ ```
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { pathToFileURL } from 'node:url';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
6
+ import { z } from 'zod';
7
+ import { FullTextResolver } from './src/resolver.mjs';
8
+
9
+ const workInputSchema = {
10
+ doi: z.string().optional().describe('Published or preprint DOI. Preferred when available.'),
11
+ pmid: z.string().optional().describe('PubMed identifier.'),
12
+ pmcid: z.string().optional().describe('PubMed Central identifier, with or without the PMC prefix.'),
13
+ title: z.string().optional().describe('Exact publication title. Used conservatively when no stronger identifier is available.'),
14
+ authors: z.union([z.string(), z.array(z.string())]).optional().describe('Author names used only to narrow title lookup.'),
15
+ year: z.number().int().min(1600).max(3000).optional().describe('Publication year used only to narrow title lookup.'),
16
+ };
17
+
18
+ const annotations = {
19
+ readOnlyHint: true,
20
+ destructiveHint: false,
21
+ idempotentHint: true,
22
+ openWorldHint: true,
23
+ };
24
+
25
+ function jsonContent(value) {
26
+ return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
27
+ }
28
+
29
+ function fulltextContent(result) {
30
+ const resolved = result.resolved_document;
31
+ const lines = [
32
+ '# Full-text resolution',
33
+ '',
34
+ `- Requested DOI: ${result.requested_work.doi || 'not supplied'}`,
35
+ `- Retrieved identifier: ${resolved?.resolved_doi || resolved?.identifier || 'none'}`,
36
+ `- Source: ${result.source || 'none'}`,
37
+ `- Version: ${result.version || 'none'}`,
38
+ `- Relationship: ${result.relationship || 'none'}`,
39
+ `- Location: ${result.location || 'none'}`,
40
+ '',
41
+ ];
42
+ if (result.document?.markdown) {
43
+ lines.push(result.document.markdown);
44
+ } else {
45
+ lines.push(result.document?.retrieval_note || result.unresolved_reason || 'No full text was retrieved.');
46
+ }
47
+ return [{ type: 'text', text: lines.join('\n') }];
48
+ }
49
+
50
+ export function createMcpServer(options = {}) {
51
+ const resolver = options.resolver ?? new FullTextResolver(options);
52
+ const server = new McpServer({
53
+ name: 'brainx-fulltext-resolver',
54
+ version: '1.0.0',
55
+ });
56
+
57
+ server.registerTool('resolve_fulltext', {
58
+ title: 'Resolve full text',
59
+ description: 'Resolve the best accessible version of a biology or neuroscience work through PMC, OpenAlex, then bioRxiv/medRxiv. Returns provenance without downloading the document.',
60
+ inputSchema: workInputSchema,
61
+ annotations,
62
+ }, async (input, extra) => {
63
+ const result = await resolver.resolve(input, { signal: extra.signal });
64
+ return {
65
+ content: jsonContent(result),
66
+ structuredContent: result,
67
+ };
68
+ });
69
+
70
+ server.registerTool('list_versions', {
71
+ title: 'List full-text versions',
72
+ description: 'List accessible published, accepted-manuscript, and submitted/preprint versions while preserving source and identifier relationships.',
73
+ inputSchema: workInputSchema,
74
+ annotations,
75
+ }, async (input, extra) => {
76
+ const result = await resolver.listVersions(input, { signal: extra.signal });
77
+ return {
78
+ content: jsonContent(result),
79
+ structuredContent: result,
80
+ };
81
+ });
82
+
83
+ server.registerTool('get_fulltext', {
84
+ title: 'Get full text',
85
+ description: 'Resolve and retrieve the best accessible document as Markdown when JATS or HTML is available. PDF-only versions are returned as provenance-preserving source links and are not parsed in v1.',
86
+ inputSchema: {
87
+ ...workInputSchema,
88
+ version: z.enum(['publishedVersion', 'acceptedVersion', 'submittedVersion', 'unknown'])
89
+ .optional()
90
+ .describe('Optional version selector.'),
91
+ source: z.enum(['PMC', 'OpenAlex', 'bioRxiv', 'medRxiv'])
92
+ .optional()
93
+ .describe('Optional source selector.'),
94
+ include_raw: z.boolean().default(false).describe('Include source JATS/HTML in structuredContent.'),
95
+ max_chars: z.number().int().min(1000).max(2_000_000)
96
+ .optional()
97
+ .describe('Optionally truncate returned Markdown to this many characters.'),
98
+ },
99
+ annotations,
100
+ }, async ({ version, source, include_raw, max_chars, ...work }, extra) => {
101
+ const result = await resolver.getFulltext(
102
+ work,
103
+ { version, source, include_raw, max_chars },
104
+ { signal: extra.signal },
105
+ );
106
+ return {
107
+ content: fulltextContent(result),
108
+ structuredContent: result,
109
+ isError: !result.resolved,
110
+ };
111
+ });
112
+
113
+ return server;
114
+ }
115
+
116
+ export async function main() {
117
+ const server = createMcpServer();
118
+ const transport = new StdioServerTransport();
119
+ await server.connect(transport);
120
+ }
121
+
122
+ const invokedPath = process.argv[1] ? pathToFileURL(process.argv[1]).href : '';
123
+ if (import.meta.url === invokedPath) {
124
+ main().catch((error) => {
125
+ process.stderr.write(`Full-text resolver MCP failed: ${error.stack || error.message}\n`);
126
+ process.exitCode = 1;
127
+ });
128
+ }