biocontext-mcp 0.5.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.
Files changed (36) hide show
  1. biocontext_mcp-0.5.0/.dockerignore +14 -0
  2. biocontext_mcp-0.5.0/.github/ISSUE_TEMPLATE/bug_report.yml +49 -0
  3. biocontext_mcp-0.5.0/.github/ISSUE_TEMPLATE/feature_request.yml +26 -0
  4. biocontext_mcp-0.5.0/.github/pull_request_template.md +18 -0
  5. biocontext_mcp-0.5.0/.github/workflows/ci.yml +46 -0
  6. biocontext_mcp-0.5.0/.gitignore +22 -0
  7. biocontext_mcp-0.5.0/CITATION.cff +21 -0
  8. biocontext_mcp-0.5.0/CODE_OF_CONDUCT.md +121 -0
  9. biocontext_mcp-0.5.0/CONTRIBUTING.md +171 -0
  10. biocontext_mcp-0.5.0/Dockerfile +41 -0
  11. biocontext_mcp-0.5.0/LICENSE +190 -0
  12. biocontext_mcp-0.5.0/PKG-INFO +246 -0
  13. biocontext_mcp-0.5.0/README.md +222 -0
  14. biocontext_mcp-0.5.0/SECURITY.md +59 -0
  15. biocontext_mcp-0.5.0/docker-compose.yml +18 -0
  16. biocontext_mcp-0.5.0/docs/API.md +144 -0
  17. biocontext_mcp-0.5.0/docs/ARCHITECTURE.md +79 -0
  18. biocontext_mcp-0.5.0/docs/QUICKSTART.md +169 -0
  19. biocontext_mcp-0.5.0/pyproject.toml +48 -0
  20. biocontext_mcp-0.5.0/src/biocontext/__init__.py +2 -0
  21. biocontext_mcp-0.5.0/src/biocontext/adapters.py +1221 -0
  22. biocontext_mcp-0.5.0/src/biocontext/base.py +123 -0
  23. biocontext_mcp-0.5.0/src/biocontext/cli.py +256 -0
  24. biocontext_mcp-0.5.0/src/biocontext/config.py +181 -0
  25. biocontext_mcp-0.5.0/src/biocontext/logging.py +48 -0
  26. biocontext_mcp-0.5.0/src/biocontext/resolver.py +523 -0
  27. biocontext_mcp-0.5.0/src/biocontext/schemas.py +161 -0
  28. biocontext_mcp-0.5.0/src/biocontext/server.py +248 -0
  29. biocontext_mcp-0.5.0/tests/test_batch_processing.py +66 -0
  30. biocontext_mcp-0.5.0/tests/test_benchmark.py +157 -0
  31. biocontext_mcp-0.5.0/tests/test_e2e_pipeline.py +106 -0
  32. biocontext_mcp-0.5.0/tests/test_go_adapter.py +119 -0
  33. biocontext_mcp-0.5.0/tests/test_reactome_adapter.py +104 -0
  34. biocontext_mcp-0.5.0/tests/test_resolver.py +179 -0
  35. biocontext_mcp-0.5.0/tests/test_server.py +68 -0
  36. biocontext_mcp-0.5.0/uv.lock +845 -0
@@ -0,0 +1,14 @@
1
+ .git/
2
+ .venv/
3
+ __pycache__/
4
+ *.py[cod]
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .cache/
9
+ *.db
10
+ *.sqlite*
11
+ .pytest_cache/
12
+ .coverage
13
+ htmlcov/
14
+ PRD/
@@ -0,0 +1,49 @@
1
+ name: Bug report
2
+ description: Create a report to help us improve BioContext
3
+ labels: ["bug"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: Thanks for taking the time to report a bug!
8
+ - type: input
9
+ id: version
10
+ attributes:
11
+ label: BioContext Version
12
+ description: What version of BioContext are you using? (e.g., `biocontext --version`)
13
+ validations:
14
+ required: true
15
+ - type: textarea
16
+ id: description
17
+ attributes:
18
+ label: Bug Description
19
+ description: A clear and concise description of what the bug is.
20
+ validations:
21
+ required: true
22
+ - type: textarea
23
+ id: reproduction
24
+ attributes:
25
+ label: Steps To Reproduce
26
+ description: Steps or Python code snippet to reproduce the behavior.
27
+ placeholder: |
28
+ ```python
29
+ import asyncio
30
+ from biocontext.resolver import EntityResolver
31
+ async def run():
32
+ r = EntityResolver()
33
+ res = await r.resolve("...")
34
+ asyncio.run(run())
35
+ ```
36
+ validations:
37
+ required: true
38
+ - type: textarea
39
+ id: expected
40
+ attributes:
41
+ label: Expected Behavior
42
+ description: What did you expect to happen?
43
+ validations:
44
+ required: true
45
+ - type: textarea
46
+ id: logs
47
+ attributes:
48
+ label: Relevant Log Output or Traceback
49
+ render: shell
@@ -0,0 +1,26 @@
1
+ name: Feature request
2
+ description: Suggest an idea or new database adapter for BioContext
3
+ labels: ["enhancement"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: Thank you for suggesting a feature or new data adapter!
8
+ - type: textarea
9
+ id: problem
10
+ attributes:
11
+ label: Problem Statement
12
+ description: Is your feature request related to a specific biological database or workflow gap?
13
+ validations:
14
+ required: true
15
+ - type: textarea
16
+ id: solution
17
+ attributes:
18
+ label: Proposed Solution / Adapter
19
+ description: Describe the solution you'd like (e.g. adding WormBase adapter for C. elegans).
20
+ validations:
21
+ required: true
22
+ - type: textarea
23
+ id: alternatives
24
+ attributes:
25
+ label: Alternatives Considered
26
+ description: Any alternative solutions or workarounds you've considered.
@@ -0,0 +1,18 @@
1
+ ## Summary of Changes
2
+ <!-- Provide a brief description of what this PR introduces or fixes. -->
3
+
4
+ ## Related Issues
5
+ <!-- Link related issues, e.g. Closes #4 or Relates to #2 -->
6
+
7
+ ## Type of Change
8
+ - [ ] Bug fix (non-breaking change which fixes an issue)
9
+ - [ ] New feature (non-breaking change which adds functionality)
10
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
11
+ - [ ] Documentation update
12
+ - [ ] Refactoring / Adapter migration
13
+
14
+ ## Checklist
15
+ - [ ] My code follows the code style and guidelines of this project ([CONTRIBUTING.md](CONTRIBUTING.md)).
16
+ - [ ] I have added tests that prove my fix is effective or that my feature works.
17
+ - [ ] All new and existing tests pass locally (`uv run pytest`).
18
+ - [ ] I have updated the documentation / docstrings accordingly.
@@ -0,0 +1,46 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.11", "3.12", "3.13"]
15
+
16
+ steps:
17
+ - name: Checkout repository
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Install uv
21
+ uses: astral-sh/setup-uv@v5
22
+ with:
23
+ version: "latest"
24
+
25
+ - name: Set up Python ${{ matrix.python-version }}
26
+ run: uv python install ${{ matrix.python-version }}
27
+
28
+ - name: Install dependencies
29
+ run: uv sync
30
+
31
+ - name: Run full test suite
32
+ run: uv run pytest tests/ -v
33
+
34
+ build:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - name: Checkout repository
38
+ uses: actions/checkout@v4
39
+
40
+ - name: Install uv
41
+ uses: astral-sh/setup-uv@v5
42
+ with:
43
+ version: "latest"
44
+
45
+ - name: Verify package build
46
+ run: uv build
@@ -0,0 +1,22 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv/
11
+
12
+ # Caches and local data
13
+ .cache/
14
+ *.db
15
+ *.sqlite
16
+ *.sqlite3
17
+ .pytest_cache/
18
+ .coverage
19
+ htmlcov/
20
+
21
+ # Specification & internal documents
22
+ PRD/
@@ -0,0 +1,21 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use BioContext in your research, please cite it as below."
3
+ authors:
4
+ - family-names: "Nandatama"
5
+ given-names: "Engki"
6
+ orcid: "https://orcid.org/0009-0003-7308-3900"
7
+ title: "BioContext: Authoritative Biological Entity Resolution & Contextual Intelligence Framework"
8
+ version: 0.5.0
9
+ date-released: 2026-09-28
10
+ url: "https://github.com/CORE-Lab-Research/biocontext"
11
+ repository-code: "https://github.com/CORE-Lab-Research/biocontext"
12
+ license: Apache-2.0
13
+ keywords:
14
+ - bioinformatics
15
+ - genomics
16
+ - entity-resolution
17
+ - model-context-protocol
18
+ - mcp
19
+ - hgnc
20
+ - ncbi
21
+ - uniprot
@@ -0,0 +1,121 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders at [research@engkinandatama.my.id](mailto:research@engkinandatama.my.id).
63
+ All complaints will be reviewed and investigated promptly and fairly.
64
+
65
+ All community leaders are obligated to respect the privacy and security of the
66
+ reporter of any incident.
67
+
68
+ ## Enforcement Guidelines
69
+
70
+ Community leaders will follow these Community Impact Guidelines in determining
71
+ the consequences for any action they deem in violation of this Code of Conduct:
72
+
73
+ ### 1. Correction
74
+
75
+ **Community Impact**: Use of inappropriate language or other behavior deemed
76
+ unprofessional or unwelcome in the community.
77
+
78
+ **Consequence**: A private, written warning from community leaders, providing
79
+ clarity around the nature of the violation and an explanation of why the
80
+ behavior was inappropriate. A public apology may be requested.
81
+
82
+ ### 2. Warning
83
+
84
+ **Community Impact**: A violation through a single incident or series of
85
+ actions.
86
+
87
+ **Consequence**: A warning with consequences for continued behavior. No
88
+ interaction with the people involved, including unsolicited interaction with
89
+ those enforcing the Code of Conduct, for a specified period of time. This
90
+ includes avoiding interactions in community spaces as well as external channels
91
+ like social media. Violating these terms may lead to a temporary or
92
+ permanent ban.
93
+
94
+ ### 3. Temporary Ban
95
+
96
+ **Community Impact**: A serious violation of community standards, including
97
+ sustained inappropriate behavior.
98
+
99
+ **Consequence**: A temporary ban from any sort of interaction or public
100
+ communication with the community for a specified period of time. No public or
101
+ private interaction with the people involved, including unsolicited interaction
102
+ with those enforcing the Code of Conduct, is allowed during this period.
103
+ Violating these terms may lead to a permanent ban.
104
+
105
+ ### 4. Permanent Ban
106
+
107
+ **Community Impact**: Demonstrating a pattern of violation of community
108
+ standards, including sustained inappropriate behavior, harassment of an
109
+ individual, or aggression toward or disparagement of classes of individuals.
110
+
111
+ **Consequence**: A permanent ban from any sort of public interaction within
112
+ the community.
113
+
114
+ ## Attribution
115
+
116
+ This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org),
117
+ version 2.1, available at
118
+ https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
119
+
120
+ Community Impact Guidelines were inspired by
121
+ [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
@@ -0,0 +1,171 @@
1
+ # Contributing to BioContext
2
+
3
+ Thank you for your interest in contributing to BioContext! We welcome contributions from researchers, bioinformaticians, and software engineers.
4
+
5
+ Please read our [Code of Conduct](CODE_OF_CONDUCT.md) and [Security Policy](SECURITY.md) before participating in our community.
6
+
7
+ ---
8
+
9
+ ## Getting Started
10
+
11
+ ### Prerequisites
12
+ - Python 3.11 or higher
13
+ - [uv](https://docs.astral.sh/uv/) (recommended package installer and resolver) or `pip`
14
+ - Git
15
+
16
+ ### Development Setup
17
+
18
+ 1. Fork the repository on GitHub and clone your fork:
19
+ ```bash
20
+ git clone https://github.com/<your-username>/biocontext.git
21
+ cd biocontext
22
+ ```
23
+
24
+ 2. Add the upstream repository remote:
25
+ ```bash
26
+ git remote add upstream https://github.com/CORE-Lab-Research/biocontext.git
27
+ ```
28
+
29
+ 3. Create a virtual environment and install dependencies with development tools:
30
+ ```bash
31
+ uv sync
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Architecture & Code Organization
37
+
38
+ ```
39
+ src/biocontext/
40
+ ├── base.py # BaseBioAdapter abstract class, SQLiteCache, AsyncRateLimiter
41
+ ├── config.py # ClientConfig, RateLimitConfig, CLI_COMMANDS_REGISTRY
42
+ ├── schemas.py # Pydantic v2 domain models (GeneEntity, ProteinEntity, GOAnnotation, PathwayContext)
43
+ ├── adapters.py # Database adapters (HGNC, NCBI, UniProt, Ensembl, MGI, QuickGO, Reactome)
44
+ ├── resolver.py # EntityResolver multi-authority resolution engine & batch engine
45
+ ├── server.py # FastMCP tool-calling interface for AI agents
46
+ ├── cli.py # CLI subcommand parsers and argument handlers
47
+ └── logging.py # Structured logging formatted to stderr
48
+ ```
49
+
50
+ ---
51
+
52
+ ## How to Build a New Biological Adapter
53
+
54
+ BioContext follows an extensible adapter pattern. To connect a new biological database:
55
+
56
+ ### Step 1: Subclass `BaseBioAdapter`
57
+ All adapters must inherit from `BaseBioAdapter` in [`base.py`](file:///home/nanda/projects/biocontext/src/biocontext/base.py):
58
+
59
+ ```python
60
+ from typing import Optional, Dict, Any
61
+ import httpx
62
+ from biocontext.base import BaseBioAdapter, SQLiteCache
63
+ from biocontext.config import ClientConfig, RateLimitConfig
64
+
65
+ class MyNewBioAdapter(BaseBioAdapter):
66
+ """Adapter for MyNewDatabase REST API."""
67
+ BASE_URL = "https://api.mynewdatabase.org"
68
+
69
+ def __init__(self, cache: Optional[SQLiteCache] = None, email: Optional[str] = None):
70
+ super().__init__(name="MyNewDatabase", cache=cache)
71
+ self.email = ClientConfig.get_email(email)
72
+ self.headers = ClientConfig.get_headers(self.email)
73
+
74
+ async def fetch_data(self, query_id: str) -> Optional[Dict[str, Any]]:
75
+ # 1. Check SQLite cache
76
+ cache_key = f"record:{query_id.upper()}"
77
+ cached = self.cache.get("mynewdb", cache_key)
78
+ if cached:
79
+ return cached
80
+
81
+ # 2. Query external API with rate limiting & error handling
82
+ url = f"{self.BASE_URL}/records/{query_id}"
83
+ async with httpx.AsyncClient(timeout=10.0) as client:
84
+ resp = await client.get(url, headers=self.headers)
85
+ if resp.status_code != 200:
86
+ return None
87
+ data = resp.json()
88
+
89
+ # 3. Store in cache & return
90
+ self.cache.set("mynewdb", cache_key, data)
91
+ return data
92
+ ```
93
+
94
+ ### Step 2: Define Strongly-Typed Schemas
95
+ Add domain models in [`schemas.py`](file:///home/nanda/projects/biocontext/src/biocontext/schemas.py) using Pydantic v2:
96
+ ```python
97
+ class MyEntity(BaseModel):
98
+ id: str
99
+ name: str
100
+ provenance: str = "MyNewDatabase"
101
+ ```
102
+
103
+ ### Step 3: Wire into `EntityResolver` and `server.py`
104
+ 1. Instantiate the adapter in `EntityResolver.__init__()` ([`resolver.py`](file:///home/nanda/projects/biocontext/src/biocontext/resolver.py)).
105
+ 2. Expose an MCP tool in `server.py` decorated with `@mcp.tool()` for AI clients.
106
+ 3. Register the CLI subcommand in `config.py` and `cli.py`.
107
+
108
+ ---
109
+
110
+ ## Testing & Quality Assurance
111
+
112
+ All contributions must pass existing tests and include tests for new functionality.
113
+
114
+ 1. **Run the full test suite**:
115
+ ```bash
116
+ uv run pytest tests/ -v
117
+ ```
118
+
119
+ 2. **Run specific test suites**:
120
+ ```bash
121
+ # Core resolver & schemas
122
+ uv run pytest tests/test_resolver.py -v
123
+
124
+ # Biological benchmark accuracy (50 curated test cases)
125
+ uv run pytest tests/test_benchmark.py -v
126
+
127
+ # High-throughput batch processing engine
128
+ uv run pytest tests/test_batch_processing.py -v
129
+
130
+ # Functional annotations & Pathways
131
+ uv run pytest tests/test_go_adapter.py tests/test_reactome_adapter.py -v
132
+
133
+ # MCP Server tool execution
134
+ uv run pytest tests/test_server.py -v
135
+ ```
136
+
137
+ 3. **Verify CLI subcommands**:
138
+ ```bash
139
+ uv run biocontext --help
140
+ uv run biocontext resolve TP53
141
+ uv run biocontext batch TP53 EGFR BRCA1
142
+ uv run biocontext annotate TP53
143
+ uv run biocontext pathway TP53
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Commit Guidelines
149
+
150
+ We follow the [Conventional Commits](https://www.conventionalcommits.org/) convention:
151
+
152
+ - `feat(scope): add new feature or adapter`
153
+ - `fix(scope): fix bug or error handling`
154
+ - `docs: update documentation or README`
155
+ - `test: add or update test suites`
156
+ - `refactor: code changes without altering external behavior`
157
+
158
+ **Git Hygiene Notice**: Do not add AI attribution trailers (e.g. `Co-Authored-By: <AI>`) in commit messages.
159
+
160
+ ---
161
+
162
+ ## Pull Request Process
163
+
164
+ 1. Ensure all tests pass locally (`uv run pytest tests/`).
165
+ 2. Push your topic branch to your fork:
166
+ ```bash
167
+ git push origin feat/your-feature-name
168
+ ```
169
+ 3. Open a Pull Request against the `main` branch of `CORE-Lab-Research/biocontext`.
170
+ 4. Fill out the PR template describing the purpose of the change, test results, and any relevant issue references.
171
+ 5. Maintainers will review your PR and coordinate merging.
@@ -0,0 +1,41 @@
1
+ # syntax=docker/dockerfile:1
2
+ FROM python:3.12-slim-bookworm
3
+
4
+ ENV PYTHONUNBUFFERED=1 \
5
+ PYTHONDONTWRITEBYTECODE=1 \
6
+ PIP_NO_CACHE_DIR=1 \
7
+ BIOCONTEXT_CACHE_PATH=/data/biocontext_cache.db
8
+
9
+ WORKDIR /app
10
+
11
+ # Install system dependencies
12
+ RUN apt-get update && apt-get install -y --no-install-recommends \
13
+ curl \
14
+ ca-certificates \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ # Install uv for fast, reliable dependency management
18
+ COPY --from=ghcr.io/astral-sh/uv:0.6.14 /uv /uvx /bin/
19
+
20
+ # Copy dependency specifications first for layer caching
21
+ COPY pyproject.toml README.md ./
22
+
23
+ # Install python dependencies without the project first
24
+ RUN uv pip install --system -r pyproject.toml
25
+
26
+ # Copy project source code
27
+ COPY src/ ./src/
28
+
29
+ # Install biocontext package
30
+ RUN uv pip install --system -e .
31
+
32
+ # Create cache data directory
33
+ RUN mkdir -p /data
34
+
35
+ VOLUME ["/data"]
36
+
37
+ EXPOSE 8000
38
+
39
+ # Default entrypoint runs the MCP server via stdio
40
+ ENTRYPOINT ["biocontext"]
41
+ CMD ["serve"]