AI-assisted symptom analysis with PubMed-backed research β FastAPI + MCP server
Describe symptoms in plain language, get a possible diagnosis from GPT-4, and receive a summary grounded in recent PubMed abstracts.
Features Β· Quick Start Β· Usage Β· MCP Server Β· Project Structure
Disclaimer: Clinisight is an educational demo from the MCP Bootcamp. It is not a medical device and does not provide professional diagnosis or treatment advice. Always consult a qualified healthcare provider for real medical concerns.
| Capability | Description |
|---|---|
| π Symptom extraction | Pulls known symptom keywords (headache, fever, nausea, fatigue, pain) from free-text descriptions |
| π§ AI diagnosis | Uses GPT-4 to suggest possible conditions and general guidance from extracted symptoms |
| π PubMed lookup | Searches NCBI E-utilities for up to 3 relevant articles |
| π Research summary | GPT-4 summarizes fetched abstracts into a short, readable overview |
| π REST API | FastAPI endpoint at POST /diagnosis for programmatic use |
| π MCP integration | Exposes a single clinisight_ai tool for AI agents (Cursor, Claude Desktop, etc.) |
flowchart TB
subgraph Input["User Input"]
A[Symptom description text]
end
subgraph Core["functions/"]
B[extract_symptoms]
C[get_diagnosis]
D[fetch_pubmed_articles_with_metadata]
E[summarize_text]
end
subgraph Interfaces["Entry points"]
F[FastAPI app.py]
G[MCP mcp_tool.py]
end
subgraph External["External Services"]
H[(OpenAI GPT-4)]
I[(NCBI PubMed E-utilities)]
end
A --> F
A --> G
F --> B
G --> B
B --> C
B --> D
D --> E
C --> H
E --> H
D --> I
style Input fill:#1E1E2E,stroke:#009688,color:#fff
style Core fill:#1E1E2E,stroke:#412991,color:#fff
style Interfaces fill:#1E1E2E,stroke:#326599,color:#fff
style External fill:#1E1E2E,stroke:#97D700,color:#fff
Before you begin, make sure you have:
- Python 3.13+ (see
.python-version) - An OpenAI API key β used for diagnosis and abstract summarization
- uv (recommended) or
pipfor dependency management - Network access to PubMed E-utilities (no separate PubMed API key required)
cd projects/clinisightOption A β uv (recommended)
uv syncOption B β pip
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
pip install mcp # MCP SDK (included in pyproject.toml when using uv)Create a .env file in the project root:
OPENAI_API_KEY=sk-your-openai-key-here
β οΈ Never commit.envto version control. It is already listed in.gitignore.
uv run python app.py
# or
python app.pyThe API listens on http://0.0.0.0:8000. Interactive docs: http://localhost:8000/docs.
Endpoint: POST /diagnosis
Request body:
{
"description": "I have had a bad headache and fever for two days with nausea."
}Example with curl:
curl -X POST http://localhost:8000/diagnosis \
-H "Content-Type: application/json" \
-d '{"description": "headache, fever, and fatigue for 3 days"}'Response:
{
"symptoms": ["headache", "fever", "fatigue"],
"diagnosis": "... GPT-4 generated text ...",
"summary": "... GPT-4 summary of PubMed abstracts ..."
}- Extract β Regex matches supported symptom keywords in the input text.
- Diagnose β GPT-4 (
gpt-4) suggests possible conditions from the symptom list. - Research β PubMed is queried using the joined symptom terms; metadata (title, abstract, authors, date, URL) is parsed from XML.
- Summarize β Abstracts are concatenated and summarized by GPT-4 for the
summaryfield.
If PubMed returns no results or the request fails, the fetcher can fall back to mock article data so the pipeline still completes (see use_mock_if_empty in functions/pubmed_articles.py).
The extractor currently recognizes:
headache Β· fever Β· nausea Β· fatigue Β· pain
Extend the pattern in functions/symptom_extractor.py to support more terms.
Clinisight includes an MCP (Model Context Protocol) server built with FastMCP so AI assistants can run the full pipeline as a single tool.
| Tool | Parameters | Returns |
|---|---|---|
clinisight_ai |
symptom_text (string) |
symptom, diagnosis, pubmed_summary |
uv run python mcp_tool.py
# or
python mcp_tool.pyThe server uses stdio transport by default.
Add this to your Cursor MCP settings (.cursor/mcp.json or Settings β MCP):
{
"mcpServers": {
"clinisight": {
"command": "uv",
"args": ["run", "python", "mcp_tool.py"],
"cwd": "/absolute/path/to/projects/clinisight",
"env": {
"OPENAI_API_KEY": "your-openai-key"
}
}
}
}Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
"mcpServers": {
"clinisight": {
"command": "uv",
"args": ["run", "python", "mcp_tool.py"],
"cwd": "/absolute/path/to/projects/clinisight"
}
}
}Ensure OPENAI_API_KEY is available in the environment (via .env when run from the project directory, or in the MCP config env block).
clinisight/
βββ app.py # FastAPI app β POST /diagnosis
βββ mcp_tool.py # MCP server (stdio) β tool: clinisight_ai
βββ pyproject.toml # Project metadata & dependencies (uv)
βββ requirements.txt # Pip-compatible dependency list
βββ uv.lock # Locked dependency versions
βββ .env # API keys (local only β not committed)
βββ .python-version # Python version pin (3.13)
βββ functions/
βββ symptom_extractor.py # Regex-based symptom keyword extraction
βββ diagnos_symptoms.py # OpenAI diagnosis from symptom list
βββ pubmed_articles.py # PubMed search + XML metadata parsing
βββ summerize_pubmed.py # OpenAI abstract summarization
| Layer | Technology |
|---|---|
| API | FastAPI + Uvicorn |
| LLM | OpenAI GPT-4 |
| Literature | NCBI E-utilities (esearch + efetch) |
| HTML/XML parsing | BeautifulSoup4 + lxml |
| HTTP | requests |
| Agent protocol | MCP / FastMCP |
| Config | python-dotenv |
| Package manager | uv |
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY |
β | OpenAI API key for diagnosis and PubMed abstract summarization |
# Install deps
uv sync
# Run API server
uv run python app.py
# Run MCP server locally
uv run python mcp_tool.py
# Open API docs in browser
open http://localhost:8000/docs- Diagnosis and summaries are generative; quality depends on symptom extraction coverage and PubMed search results.
- PubMed requests use a standard browser
User-Agentheader; respect NCBI usage guidelines for rate limits in production. - The MCP tool and REST API share the same
functions/modules but may format PubMed input to the summarizer slightly differently. - Default OpenAI model is
gpt-4in both diagnosis and summarization modules.
This project is part of the MCP Bootcamp β Next-Gen AI Agents course. Use and modify freely for learning purposes.
Built for learning how agents combine LLMs, APIs, and MCP