File size: 5,235 Bytes
59ce7b1 |
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 |
# MCP Integration Guide
> **Last Updated**: 2025-12-06
This guide covers setting up DeepBoner's MCP (Model Context Protocol) server for integration with Claude Desktop and other MCP clients.
## Overview
DeepBoner exposes an MCP server via Gradio's built-in support. This allows Claude Desktop and other MCP-compatible clients to use DeepBoner's search tools directly.
## MCP Server URL
When DeepBoner is running:
```
http://localhost:7860/gradio_api/mcp/
```
On HuggingFace Spaces:
```
https://mcp-1st-birthday-deepboner.hf.space/gradio_api/mcp/
```
## Available Tools
| Tool | Description |
|------|-------------|
| `search_pubmed` | Search peer-reviewed biomedical literature |
| `search_clinical_trials` | Search ClinicalTrials.gov for active/completed trials |
| `search_europepmc` | Search Europe PMC preprints and papers |
| `search_all_sources` | Search all sources simultaneously with deduplication |
### Tool Signatures
```python
def search_pubmed(query: str, max_results: int = 10) -> list[Evidence]:
"""Search PubMed for biomedical literature."""
def search_clinical_trials(query: str, max_results: int = 10) -> list[Evidence]:
"""Search ClinicalTrials.gov."""
def search_europepmc(query: str, max_results: int = 10) -> list[Evidence]:
"""Search Europe PMC."""
def search_all_sources(query: str, max_results_per_source: int = 10) -> SearchResult:
"""Search all sources with cross-source deduplication."""
```
## Claude Desktop Setup
### 1. Start DeepBoner
```bash
uv run python src/app.py
```
### 2. Configure Claude Desktop
Edit your Claude Desktop configuration:
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
Add the MCP server:
```json
{
"mcpServers": {
"deepboner": {
"url": "http://localhost:7860/gradio_api/mcp/"
}
}
}
```
### 3. Restart Claude Desktop
Close and reopen Claude Desktop to load the new configuration.
### 4. Verify Connection
In Claude Desktop, you should see DeepBoner's tools available. Try:
```
Use the search_pubmed tool to find recent papers on testosterone therapy
```
## Using with HuggingFace Spaces
Point to the deployed Space:
```json
{
"mcpServers": {
"deepboner-cloud": {
"url": "https://mcp-1st-birthday-deepboner.hf.space/gradio_api/mcp/"
}
}
}
```
Note: HuggingFace Spaces may sleep after inactivity. The first request will wake the Space (30-60 second delay).
## Tool Implementation
Tools are defined in `src/mcp_tools.py`:
```python
def search_pubmed(query: str, max_results: int = 10) -> list[Evidence]:
"""Search PubMed for biomedical literature.
Args:
query: Search query for PubMed
max_results: Maximum number of results to return
Returns:
List of Evidence objects with citations
"""
tool = PubMedTool()
result = tool.search(query, max_results=max_results)
return result.evidence
```
## Adding New Tools
To expose additional tools via MCP:
1. Add the function to `src/mcp_tools.py`:
```python
def search_openalex(query: str, max_results: int = 10) -> list[Evidence]:
"""Search OpenAlex for scholarly metadata."""
tool = OpenAlexTool()
result = tool.search(query, max_results=max_results)
return result.evidence
```
2. Register in Gradio app (`src/app.py`):
The tools are automatically exposed via Gradio's MCP support when added to the interface.
## Troubleshooting
### Tools not appearing in Claude Desktop
1. Verify DeepBoner is running:
```bash
curl http://localhost:7860/gradio_api/mcp/
```
2. Check config syntax:
```bash
cat ~/Library/Application\ Support/Claude/claude_desktop_config.json | python -m json.tool
```
3. Restart Claude Desktop
### Connection refused
- Check DeepBoner is running on port 7860
- Verify no firewall blocking
- Try accessing in browser: http://localhost:7860
### Slow responses
- First query loads ML models
- HuggingFace Space may need to wake up
- External APIs have rate limits
### Authentication errors
MCP server doesn't require authentication for local use. For production:
- Use API gateway
- Implement auth middleware
## Security Considerations
### Local Development
Local MCP server is accessible only from localhost by default.
### Production
For production deployments:
1. **Use HTTPS** - Enable TLS via reverse proxy
2. **Add authentication** - Consider API keys or OAuth
3. **Rate limit** - Prevent abuse
4. **Monitor** - Log tool usage
### Data Privacy
- Search queries are sent to external APIs (PubMed, etc.)
- Review external API privacy policies
- Don't expose sensitive research queries
## Protocol Details
### MCP Protocol Version
DeepBoner uses MCP protocol via Gradio 6.x integration.
### Request/Response Format
Requests follow the MCP specification:
```json
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "search_pubmed",
"arguments": {
"query": "testosterone therapy",
"max_results": 10
}
},
"id": 1
}
```
## Related Documentation
- [Docker Deployment](docker.md)
- [HuggingFace Spaces](huggingface-spaces.md)
- [Component Inventory](../architecture/component-inventory.md)
|