mcp-community-tools
by sourav267
README.md
# MCP Community Tools - Model Context Protocol Server
A professional-grade MCP (Model Context Protocol) server that provides tools for querying community and world databases. Designed with clean architecture patterns and ready for integration with GitHub Copilot.
## ๐ฏ Quick Start
### 1. **Connect to GitHub Copilot** (3 steps)
See [QUICK_START.md](QUICK_START.md) for instant setup.
**TL;DR:**
1. Open VS Code Settings (Cmd+,)
2. Add this to `settings.json`:
```json
{
"github.copilot.mcp": [
{
"name": "mcp-community-tools",
"command": "${workspaceFolder}/.venv/bin/python3",
"args": ["${workspaceFolder}/hello_mcp.py"],
"env": {"PYTHONPATH": "${workspaceFolder}"}
}
]
}
```
3. Restart VS Code
### 2. **Ask Copilot**
Now you can ask Copilot to use your tools:
- "Get the top 10 highest comments"
- "Show me 5 countries from Europe"
- "Generate a random name"
---
## ๐ Available Tools
| Tool | Description | Example |
|------|-------------|---------|
| `get_random_name()` | Generate a random name | `get_random_name()` |
| `get_top_10_highest_comments()` | Get top 10 users by message count | Returns: Top 10 chatters |
| `fetch_countries()` | Query countries by region and limit | `fetch_countries(region="Asia", limit=5)` |
---
## ๐๏ธ Project Structure
```
mcp-course/
โโโ hello_mcp.py # Main entry point (50 lines - clean!)
โโโ setup-copilot.sh # Auto-generate config helper
โโโ QUICK_START.md # 3-step Copilot integration
โโโ SETUP_COPILOT.md # Detailed setup guide
โโโ ARCHITECTURE.md # Design patterns & structure
โโโ INTEGRATION_DIAGRAM.md # Visual flow diagrams
โโโ REFACTORING_SUMMARY.md # Before/after comparison
โ
โโโ db_connection/
โ โโโ connection.py # Database Connection Factory
โ
โโโ repositories/
โ โโโ base_repository.py # Abstract Base Class
โ โโโ chatters_repository.py # Community data queries
โ โโโ countries_repository.py # World data queries
โ
โโโ tools/
โ โโโ tools.py # Tool implementations (DI)
โ
โโโ db/
โโโ community.db # Chatters data (251 records)
โโโ world.db # Countries data (250 records)
```
---
## โจ Key Features
### ๐ฏ Clean Architecture
- **Repository Pattern**: Database access abstraction
- **Dependency Injection**: Loose coupling between layers
- **Factory Pattern**: Centralized connection management
- **SOLID Principles**: All five principles applied
### ๐ก๏ธ Professional Code
- โ
Type hints throughout
- โ
Comprehensive error handling
- โ
Well-documented with docstrings
- โ
Easy to test and extend
### ๐ Ready for Production
- โ
Works with GitHub Copilot
- โ
Works with Claude Desktop
- โ
Works with any MCP-compatible client
- โ
Secure local execution
---
## ๐ Documentation
| Document | Purpose |
|----------|---------|
| [QUICK_START.md](QUICK_START.md) | Get Copilot working in 3 steps |
| [SETUP_COPILOT.md](SETUP_COPILOT.md) | Detailed setup & troubleshooting |
| [ARCHITECTURE.md](ARCHITECTURE.md) | Design patterns & principles |
| [INTEGRATION_DIAGRAM.md](INTEGRATION_DIAGRAM.md) | Visual flows and connections |
| [REFACTORING_SUMMARY.md](REFACTORING_SUMMARY.md) | Before/after code comparison |
---
## ๐ Running Locally
### Prerequisites
- Python 3.11+
- Virtual environment (`venv`)
### Setup
```bash
# Clone and enter directory
cd /Users/souravkumar/WebstormProjects/mcp-course
# Activate virtual environment
source .venv/bin/activate
# Install dependencies (if needed)
pip install -r requirements.txt
```
### Run Server
```bash
python3 hello_mcp.py
```
Output should show:
```
Server started on stdio
```
---
## ๐ Integration Options
### Option 1: GitHub Copilot in VS Code โ
**RECOMMENDED**
See [QUICK_START.md](QUICK_START.md)
### Option 2: Claude Desktop App
See [SETUP_COPILOT.md](SETUP_COPILOT.md) - Claude Desktop section
### Option 3: Manual Testing
```bash
# Terminal 1: Start server
python3 hello_mcp.py
# Terminal 2: Test tools
curl -X POST http://localhost:3000/call \
-H "Content-Type: application/json" \
-d '{"tool": "get_top_10_highest_comments"}'
```
---
## ๐พ Databases
### community.db
```sql
SELECT * FROM chatters;
-- id, name, messages, last_message_at
```
**251 community members** with activity tracking
### world.db
```sql
SELECT * FROM countries;
-- id, name, iso2, iso3, capital, region, subregion, currency, currency_symbol, phonecode, emoji
```
**250 countries** with detailed information
---
## ๐ ๏ธ Example Usage with Copilot
### Example 1: Get Top Commenters
```
You: "Who are the top 10 most active community members?"
Copilot:
โ Calls: get_top_10_highest_comments()
โ Returns: Top 10 users with message counts
โ Shows: Their last activity timestamps
```
### Example 2: Find Countries
```
You: "Show me all European countries and their capitals"
Copilot:
โ Calls: fetch_countries(region="Europe")
โ Returns: All 50 European countries
โ Shows: Capital, currency, phone code, flag emoji
```
### Example 3: Generate Names
```
You: "Give me 5 random names"
Copilot:
โ Calls: get_random_name() (5 times)
โ Returns: 5 random names from the list
```
---
## ๐๏ธ Architecture at a Glance
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ GitHub Copilot / Claude โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Protocol (JSON-RPC)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ hello_mcp.py (Tool Registration) โ
โ โโ @mcp.tool() decorators โ
โ โโ Dependency injection setup โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ tools/tools.py (Business Logic) โ
โ โโ TopCommentsTool โ
โ โโ CountriesTool โ
โ โโ RandomNameTool โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ repositories/ (Data Access) โ
โ โโ ChattersRepository โ
โ โโ CountriesRepository โ
โ โโ BaseRepository (Abstract) โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ db_connection/ (Connection Factory) โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ db/ (SQLite Databases) โ
โ โโ community.db โ
โ โโ world.db โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
---
## ๐ SOLID Principles Applied
โ
**S**ingle Responsibility: Each class has one reason to change
โ
**O**pen/Closed: Open for extension, closed for modification
โ
**L**iskov Substitution: Repositories are interchangeable
โ
**I**nterface Segregation: Minimal required interfaces
โ
**D**ependency Inversion: Depend on abstractions, not concretions
---
## ๐ Security
- โ
**Local Execution**: Runs on your machine only
- โ
**No Data Upload**: All data stays local
- โ
**No Authentication**: Local database access
- โ
**Read-Only**: Tools only query, don't modify data
---
## ๐งช Testing
### Run Tests (when available)
```bash
pytest tests/
```
### Manual Testing
```python
from repositories.chatters_repository import ChattersRepository
from db_connection.connection import DatabaseConnection
conn = DatabaseConnection.get_connection("community.db")
repo = ChattersRepository(conn)
results = repo.get_top_highest_comments(10)
print(results)
repo.close()
```
---
## ๐ค Contributing
To add a new tool:
1. **Create a Repository** (if needed):
```python
# repositories/my_data_repository.py
class MyDataRepository(BaseRepository):
def get_data(self):
return self.execute_query("SELECT * FROM my_table")
```
2. **Create a Tool**:
```python
# In tools/tools.py
class MyDataTool:
def __init__(self, repository):
self.repository = repository
def execute(self):
return self.repository.get_data()
```
3. **Register in hello_mcp.py**:
```python
@mcp.tool()
def my_data_tool() -> list[dict]:
conn = DatabaseConnection.get_connection("my_db.db")
repo = MyDataRepository(conn)
tool = MyDataTool(repo)
return tool.execute()
```
---
## ๐ Troubleshooting
### Common Issues
| Issue | Solution |
|-------|----------|
| "Tool not found" in Copilot | Restart VS Code completely (Cmd+Q) |
| "ModuleNotFoundError" | Check PYTHONPATH in config |
| Connection timeout | Verify `hello_mcp.py` runs without errors |
| Tools not available | Wait 10 seconds after restart for extension load |
For detailed troubleshooting, see [SETUP_COPILOT.md](SETUP_COPILOT.md#troubleshooting)
---
## ๐ License
MIT License - Feel free to use, modify, and distribute.
---
## ๐ Learning Resources
- [MCP Protocol Documentation](https://modelcontextprotocol.io)
- [Design Patterns](https://refactoring.guru/design-patterns)
- [SOLID Principles](https://en.wikipedia.org/wiki/SOLID)
- [Repository Pattern](https://martinfowler.com/eaaCatalog/repository.html)
---
## โ
Quick Checklist
- [ ] Read [QUICK_START.md](QUICK_START.md)
- [ ] Copy configuration to `settings.json`
- [ ] Restart VS Code
- [ ] Test with Copilot
- [ ] Read [ARCHITECTURE.md](ARCHITECTURE.md) to understand design
- [ ] Check [INTEGRATION_DIAGRAM.md](INTEGRATION_DIAGRAM.md) for visuals
---
## ๐ You're Ready!
Your MCP server is production-ready. Enjoy using it with GitHub Copilot! ๐
**Questions?** Check the documentation files or the troubleshooting section above.
This server cannot be deployed
Maintenance
ActivityStale
ResponsivenessNo issues