File size: 28,413 Bytes
891fe52 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 | # Architecture Documentation
System design and implementation details for Polyhedra MCP Server.
## Table of Contents
1. [Overview](#overview)
2. [System Architecture](#system-architecture)
3. [Component Design](#component-design)
4. [Data Flow](#data-flow)
5. [Technology Stack](#technology-stack)
6. [Integration Points](#integration-points)
7. [Performance Considerations](#performance-considerations)
8. [Security & Privacy](#security--privacy)
---
## Overview
Polyhedra is an MCP (Model Context Protocol) server that extends IDE AI assistants with academic research capabilities. It follows a service-oriented architecture with clean separation of concerns.
### Design Principles
1. **Simplicity**: Pure tool server, no UI components
2. **Composability**: Services can be used independently or combined
3. **Reliability**: Comprehensive error handling and graceful degradation
4. **Performance**: Caching, batching, and async operations
5. **Testability**: 100% test coverage, dependency injection
### Architecture Patterns
- **Service Layer Pattern**: Business logic in dedicated services
- **Repository Pattern**: Data access abstracted behind interfaces
- **Strategy Pattern**: Pluggable search/retrieval strategies
- **Facade Pattern**: MCP server provides unified interface
---
## System Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β IDE (Cursor, VS Code, etc.) β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β AI Assistant (Claude, GPT-4, etc.) β β
β ββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ
β
β MCP Protocol (JSON-RPC over stdio)
β
ββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ
β Polyhedra MCP Server β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Server (server.py) β β
β β β’ Tool registration β β
β β β’ Request routing β β
β β β’ Error handling β β
β ββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββ β
β β Service Layer β β
β β β β
β β ββββββββββββββββ ββββββββββββββββ ββββββββββββββ β β
β β β Semantic β β Citation β β File β β β
β β β Scholar β β Management β β Context β β β
β β β Service β β Service β β Service β β β
β β ββββββββββββββββ ββββββββββββββββ ββββββββββββββ β β
β β β β
β β ββββββββββββββββ ββββββββββββββββ β β
β β β RAG β β Project β β β
β β β Retrieval β β Initializer β β β
β β β Service β β Service β β β
β β ββββββββββββββββ ββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β External Dependencies β β
β β β β
β β β’ Semantic Scholar API β β
β β β’ sentence-transformers (RAG) β β
β β β’ FAISS (vector indexing) β β
β β β’ bibtexparser (citations) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β File System
β
ββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ
β Research Project β
β β
β .polyhedra/ papers/ β
β βββ embeddings.index βββ paper1.pdf β
β βββ metadata.json βββ paper2.pdf β
β βββ cache/ β
β notes/ β
β references.bib βββ summary.md β
β βββ ideas.md β
β README.md β
β literature-review/ β
β βββ draft.md β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
---
## Component Design
### MCP Server (`server.py`)
**Responsibility**: Bridge between IDE and services.
```python
class PolyhedraMCPServer:
"""Main MCP server implementing tool interface."""
def __init__(self):
self.semantic_scholar = SemanticScholarService()
self.citation_manager = CitationManager()
self.file_context = FileContextService()
self.rag_retrieval = RAGRetrievalService()
self.project_init = ProjectInitializer()
async def list_tools(self) -> list[Tool]:
"""Register all 10 tools with MCP."""
async def call_tool(self, name: str, arguments: dict) -> list[TextContent]:
"""Route tool calls to appropriate service."""
```
**Key Features**:
- **Tool Registration**: Defines schemas for 10 tools
- **Request Routing**: Maps tool names to service methods
- **Error Wrapping**: Catches exceptions, returns formatted errors
- **Async Support**: Uses asyncio for concurrent operations
**Design Decisions**:
- Single server instance per IDE process
- Stateless tool calls (no session management)
- Services instantiated once and reused
---
### Semantic Scholar Service
**Responsibility**: Paper search and retrieval via Semantic Scholar API.
```python
class SemanticScholarService:
"""Academic paper search via Semantic Scholar API."""
BASE_URL = "https://api.semanticscholar.org/graph/v1"
def __init__(self):
self.session = requests.Session()
self.cache = RequestCache()
async def search_papers(
self,
query: str,
year_range: Optional[str] = None,
limit: int = 10
) -> dict:
"""Search for papers by query."""
async def get_paper(
self,
paper_id: str,
fields: Optional[list[str]] = None
) -> dict:
"""Get detailed paper information."""
```
**Features**:
- **Rate Limiting**: Respects 100 req/5min limit
- **Retry Logic**: Exponential backoff on failures
- **Caching**: LRU cache for repeated queries
- **Error Recovery**: Returns cached data on network errors
**API Integration**:
```python
# Search endpoint
GET /paper/search?query={query}&year={year}&limit={limit}
# Details endpoint
GET /paper/{paper_id}?fields={fields}
```
**Cache Strategy**:
- Search results: 1 hour TTL
- Paper details: 24 hour TTL
- Cache location: `.polyhedra/cache/`
---
### Citation Manager
**Responsibility**: BibTeX bibliography management.
```python
class CitationManager:
"""Manage BibTeX citations in references.bib."""
def __init__(self, bib_file: str = "references.bib"):
self.bib_file = Path(bib_file)
self.parser = bibtexparser.bparser.BibTexParser()
def add_citation(self, citation_key: str, bibtex: str) -> dict:
"""Add citation to bibliography."""
def get_citations(self) -> list[dict]:
"""Get all citations from bibliography."""
```
**Features**:
- **Validation**: Checks BibTeX syntax
- **Duplicate Detection**: Prevents duplicate keys
- **Atomic Writes**: Tmp file + rename for safety
- **Parsing**: Converts BibTeX to structured JSON
**File Format**:
```bibtex
@article{vaswani2017attention,
title={Attention is all you need},
author={Vaswani, Ashish and ...},
journal={NeurIPS},
year={2017}
}
```
**Lock Strategy**:
- File lock for concurrent writes
- 5 second timeout
- Retry with exponential backoff
---
### RAG Retrieval Service
**Responsibility**: Semantic search over collected papers using embeddings.
```python
class RAGRetrievalService:
"""Semantic paper search using sentence transformers."""
MODEL = "sentence-transformers/all-MiniLM-L6-v2"
def __init__(self):
self.model = SentenceTransformer(self.MODEL)
self.index = None
self.papers = []
async def index_papers(
self,
papers: list[dict],
force_rebuild: bool = False
) -> dict:
"""Build FAISS index from papers."""
async def query_similar_papers(
self,
query: str,
limit: int = 10,
min_similarity: float = 0.7
) -> list[dict]:
"""Find similar papers to query."""
```
**Architecture**:
```
Papers β Sentence Transformer β Embeddings (384-dim) β FAISS Index
β
Query β Sentence Transformer β Query Embedding β FAISS Search β Similar Papers
```
**Embedding Model**:
- **Model**: all-MiniLM-L6-v2
- **Dimensions**: 384
- **Size**: ~80MB
- **Speed**: ~1000 sentences/sec on CPU
**Index Structure**:
```python
{
"embeddings": np.ndarray, # (N, 384) float32
"papers": list[dict], # Paper metadata
"version": str, # Index version
"created_at": datetime # Build timestamp
}
```
**Similarity Metric**:
- Cosine similarity (dot product of normalized vectors)
- Range: [-1, 1], typical useful range: [0.5, 1.0]
---
### File Context Service
**Responsibility**: Read/write project files safely.
```python
class FileContextService:
"""Manage project file operations."""
def __init__(self, project_root: Optional[Path] = None):
self.project_root = project_root or Path.cwd()
def save_file(
self,
path: str,
content: str,
create_dirs: bool = True
) -> dict:
"""Write content to file."""
def get_context(
self,
paths: list[str]
) -> list[dict]:
"""Read content from files."""
```
**Safety Features**:
- **Path Validation**: Prevents directory traversal
- **Atomic Writes**: Tmp file + rename
- **Encoding**: UTF-8 with fallbacks
- **Directory Creation**: Automatic parent dir creation
**Path Resolution**:
```python
# Relative to project root
path = "notes/summary.md"
full_path = project_root / path # /home/user/project/notes/summary.md
# Absolute paths rejected
path = "/etc/passwd" # Error: must be relative
# Traversal rejected
path = "../../../etc/passwd" # Error: outside project
```
---
### Project Initializer
**Responsibility**: Create standardized research project structure.
```python
class ProjectInitializer:
"""Initialize research project structure."""
DIRECTORIES = [
".polyhedra",
"papers",
"notes",
"literature-review",
"data"
]
def initialize(
self,
project_name: str,
base_path: Optional[Path] = None
) -> dict:
"""Create project structure."""
```
**Created Structure**:
```
project_name/
βββ .polyhedra/ # Tool data (index, cache)
βββ papers/ # Paper PDFs and metadata
βββ notes/ # Research notes
βββ literature-review/ # Literature review drafts
βββ data/ # Datasets
βββ references.bib # BibTeX bibliography (empty)
βββ README.md # Project overview (template)
```
**Idempotency**:
- Safe to run multiple times
- Only creates missing dirs/files
- Returns report of created vs. existing
---
## Data Flow
### Search Papers Flow
```
User β IDE AI β MCP Request
β
[Server: call_tool]
β
[SemanticScholarService]
β
Check Cache? ββYesβ Return cached
β No
API Request
β
[Semantic Scholar API]
β
Parse Response
β
Cache Result
β
Return to Server
β
Format as TextContent
β
Return via MCP
β
IDE AI β User
```
**Timing**:
- Cache hit: <10ms
- API request: 200-500ms
- With retry: up to 2 seconds
---
### RAG Query Flow
```
User Query β IDE AI β MCP Request
β
[Server: call_tool]
β
[RAGRetrievalService]
β
Check Index Exists?
β Yes
Load Index from Disk
β
[Sentence Transformer Model]
β
Generate Query Embedding (384-dim)
β
[FAISS Index]
β
Search for Similar Embeddings
β
Return Top K Papers with Scores
β
Filter by min_similarity Threshold
β
Format Results with Metadata
β
Return via MCP
β
IDE AI β User
```
**Timing**:
- Model load (first time): 2-3 seconds
- Embedding generation: 10-50ms
- FAISS search: 1-5ms
- **Total**: 50-100ms (after first query)
---
### Citation Management Flow
```
User + BibTeX β IDE AI β MCP Request
β
[Server: call_tool]
β
[CitationManager]
β
Acquire File Lock
β
Load references.bib
β
Parse BibTeX
β
Check Duplicate Key? ββYesβ Error
β No
Validate BibTeX Syntax
β
Append to Bibliography
β
Write to Temp File (references.bib.tmp)
β
Rename Temp β references.bib (atomic)
β
Release Lock
β
Return Success
β
Return via MCP
β
IDE AI β User
```
**Concurrency**:
- File lock prevents concurrent writes
- Timeout: 5 seconds
- Retry: 3 attempts with backoff
---
## Technology Stack
### Core Dependencies
| Package | Version | Purpose |
|---------|---------|---------|
| `mcp` | 1.0+ | Model Context Protocol SDK |
| `requests` | 2.31+ | HTTP client for API calls |
| `sentence-transformers` | 2.2+ | Embedding model for RAG |
| `faiss-cpu` | 1.7+ | Vector similarity search |
| `bibtexparser` | 1.4+ | BibTeX parsing |
| `aiofiles` | 23.0+ | Async file operations |
### Development Dependencies
| Package | Version | Purpose |
|---------|---------|---------|
| `pytest` | 8.0+ | Testing framework |
| `pytest-asyncio` | 0.21+ | Async test support |
| `pytest-cov` | 4.1+ | Coverage reporting |
| `ruff` | 0.1+ | Linting and formatting |
### Python Version
- **Minimum**: Python 3.11
- **Recommended**: Python 3.12
- **Reason**: Type hints, asyncio improvements, performance
### External APIs
- **Semantic Scholar API**: v1
- No authentication required
- Rate limit: 100 req/5min
- Documentation: https://api.semanticscholar.org/
---
## Integration Points
### MCP Protocol
**Communication**: JSON-RPC over stdio
**Request Format**:
```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "search_papers",
"arguments": {
"query": "transformers",
"limit": 10
}
}
}
```
**Response Format**:
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": "{\"papers\": [...]}"
}
]
}
}
```
**Error Format**:
```json
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32603,
"message": "Internal error",
"data": {
"details": "Network connection failed"
}
}
}
```
---
### IDE Integration
**Supported IDEs**:
1. **Cursor**
- Config: `~/.cursor/mcp.json`
- Launch: `uvx --from polyhedra polyhedra`
2. **VS Code + GitHub Copilot**
- Config: `.vscode/settings.json`
- Extension: GitHub Copilot Chat
- MCP support: Via Copilot
3. **Windsurf**
- Config: `~/.windsurf/mcp.json`
- Launch: `uvx --from polyhedra polyhedra`
4. **VS Code + MCP Extension**
- Config: `.vscode/settings.json`
- Extension: MCP Tools
- Launch: Direct MCP integration
**Configuration Schema**:
```json
{
"mcpServers": {
"polyhedra": {
"command": "uvx",
"args": ["--from", "polyhedra", "polyhedra"],
"env": {
"POLYHEDRA_PROJECT_ROOT": "/path/to/project"
}
}
}
}
```
---
### File System
**Project Structure Convention**:
```
project-root/
βββ .polyhedra/ # Hidden tool directory
β βββ embeddings.index # FAISS index (binary)
β βββ metadata.json # Index metadata
β βββ cache/ # API response cache
β βββ search/ # Search results cache
β βββ papers/ # Paper details cache
β
βββ papers/ # Paper storage
β βββ *.pdf # Paper PDFs
β βββ *.json # Paper metadata
β
βββ notes/ # Research notes
β βββ *.md # Markdown notes
β
βββ literature-review/ # Review drafts
β βββ *.md # Markdown sections
β
βββ data/ # Research data
β βββ *.csv, *.json # Datasets
β
βββ references.bib # BibTeX bibliography
βββ README.md # Project overview
```
**File Permissions**:
- Read: All files in project
- Write: Files in project only (no traversal)
- Create: Directories and files in project
---
## Performance Considerations
### Caching Strategy
**API Response Cache**:
- **Location**: `.polyhedra/cache/`
- **Structure**: `{endpoint}/{hash}.json`
- **TTL**: 1 hour (search), 24 hours (papers)
- **Eviction**: LRU, max 1000 entries
**Embedding Cache**:
- **Location**: `.polyhedra/embeddings.index`
- **Format**: FAISS IndexFlatIP + metadata JSON
- **Update**: Incremental (append new papers)
- **Rebuild**: Manual with `force_rebuild=true`
### Async Operations
**Concurrent API Calls**:
```python
# Batch paper retrieval
papers = await asyncio.gather(*[
get_paper(paper_id) for paper_id in paper_ids
])
```
**File I/O**:
```python
# Async file reading
async with aiofiles.open(path) as f:
content = await f.read()
```
### Memory Management
**Embedding Model**:
- Loaded once, kept in memory
- ~150MB RAM
- Lazy loading on first RAG query
**FAISS Index**:
- Loaded on demand
- Memory: ~1.5MB per 1000 papers
- Unloaded after idle timeout (5 minutes)
**Paper Metadata**:
- Stored with index
- ~2KB per paper
- Total: ~2MB for 1000 papers
### Rate Limiting
**Semantic Scholar API**:
```python
class RateLimiter:
def __init__(self):
self.requests = deque()
self.max_requests = 100
self.window = 300 # 5 minutes
async def acquire(self):
now = time.time()
# Remove requests outside window
while self.requests and self.requests[0] < now - self.window:
self.requests.popleft()
# Wait if at limit
if len(self.requests) >= self.max_requests:
wait = self.requests[0] + self.window - now
await asyncio.sleep(wait)
self.requests.append(now)
```
### Optimization Tips
1. **Batch Operations**: Use `asyncio.gather()` for concurrent requests
2. **Cache Aggressively**: API responses, embeddings, parsed BibTeX
3. **Lazy Load**: Don't load embedding model until needed
4. **Index Incrementally**: Append to index instead of rebuilding
5. **Limit Results**: Default to 10 results, max 100
---
## Security & Privacy
### Data Privacy
**No Data Transmission**:
- All processing happens locally
- No telemetry or analytics
- No user tracking
**API Calls**:
- Only to Semantic Scholar (public API)
- No authentication tokens stored
- Query data not retained by API
**File Access**:
- Restricted to project directory
- No system file access
- Path traversal prevented
### Input Validation
**Path Validation**:
```python
def validate_path(path: str, project_root: Path) -> Path:
"""Ensure path is within project."""
full_path = (project_root / path).resolve()
# Check still within project
if not full_path.is_relative_to(project_root):
raise ValueError("Path outside project")
return full_path
```
**BibTeX Validation**:
```python
def validate_bibtex(bibtex: str) -> bool:
"""Check BibTeX syntax."""
try:
parser.parse_string(bibtex)
return True
except Exception:
return False
```
**Query Sanitization**:
```python
def sanitize_query(query: str) -> str:
"""Remove special characters from search query."""
# Remove control characters
# Limit length to 500 chars
# URL encode for API
```
### Error Information Disclosure
**Safe Errors**:
```python
# Good: Generic error
return {"error": "File not found"}
# Bad: Exposes system info
return {"error": f"Cannot read /home/user/.ssh/id_rsa"}
```
**Error Messages**:
- No system paths in errors
- No internal implementation details
- No stack traces to user (logged only)
### Dependency Security
**Pinned Versions**:
- All dependencies pinned in `pyproject.toml`
- Regular security updates
- Automated vulnerability scanning (Dependabot)
**Trusted Sources**:
- PyPI packages only
- Verified publishers
- Popular, maintained projects
---
## Deployment
### Installation
**Via pip**:
```bash
pip install polyhedra
```
**Via uv** (recommended):
```bash
uv pip install polyhedra
uvx --from polyhedra polyhedra # Run directly
```
### Configuration
**Environment Variables**:
- `POLYHEDRA_PROJECT_ROOT`: Override project root
- `POLYHEDRA_CACHE_DIR`: Custom cache location
- `POLYHEDRA_LOG_LEVEL`: Logging level (DEBUG, INFO, WARNING, ERROR)
**Example**:
```bash
export POLYHEDRA_PROJECT_ROOT=/path/to/research
export POLYHEDRA_LOG_LEVEL=INFO
```
### Logging
**Log Locations**:
- **Console**: stderr (captured by IDE)
- **File**: `.polyhedra/polyhedra.log` (optional)
**Log Format**:
```
2024-01-15 10:30:45 INFO [server] Tool call: search_papers
2024-01-15 10:30:45 DEBUG [semantic_scholar] Query: transformers
2024-01-15 10:30:46 INFO [semantic_scholar] Found 25 papers
2024-01-15 10:30:46 INFO [server] Tool call completed: 1.2s
```
---
## Testing Architecture
### Test Structure
```
tests/
βββ test_server.py # MCP server integration tests
βββ test_services/
β βββ test_semantic_scholar.py
β βββ test_citation_manager.py
β βββ test_file_context.py
β βββ test_rag_retrieval.py
β βββ test_project_initializer.py
βββ test_integration_workflows.py # End-to-end workflows
βββ test_error_handling.py # Error scenarios
```
### Test Coverage
- **Unit Tests**: 88-100% coverage per service
- **Integration Tests**: Full workflows tested
- **Error Tests**: All error paths covered
### Test Strategy
1. **Unit Tests**: Mock external dependencies (API, file system)
2. **Integration Tests**: Real dependencies, test data
3. **E2E Tests**: Full workflows with actual API calls (limited)
---
## Future Extensibility
### Planned Extensions
1. **Additional APIs**:
- arXiv direct integration
- Google Scholar (via SerpAPI)
- PubMed for biomedical papers
2. **Enhanced RAG**:
- Multiple embedding models
- Hybrid search (keyword + semantic)
- Re-ranking with cross-encoders
3. **Collaboration**:
- Shared indexes
- Team bibliographies
- Comment/annotation system
4. **Export Formats**:
- LaTeX integration
- Markdown citations
- Zotero/Mendeley import/export
### Extension Points
**Custom Services**:
```python
class CustomPaperService:
"""Implement your own paper source."""
async def search(self, query: str) -> list[dict]:
"""Custom search implementation."""
```
**Custom Embeddings**:
```python
class CustomEmbeddingModel:
"""Use your own embedding model."""
def encode(self, texts: list[str]) -> np.ndarray:
"""Generate custom embeddings."""
```
---
## Troubleshooting
For detailed troubleshooting, see:
- [Error Handling Guide](ERROR_HANDLING.md)
- [Setup Guide](SETUP.md)
- [Manual Testing](MANUAL_TESTING.md)
---
## References
- **MCP Protocol**: https://modelcontextprotocol.io
- **Semantic Scholar API**: https://api.semanticscholar.org
- **Sentence Transformers**: https://www.sbert.net
- **FAISS**: https://github.com/facebookresearch/faiss
---
*Architecture documentation maintained by Polyhedra team. Last updated: January 2024.*
|