Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available:
5.38.2
metadata
license: apache-2.0
title: Township MCP Server
sdk: gradio
emoji: π
colorFrom: indigo
colorTo: blue
pinned: true
thumbnail: >-
https://cdn-uploads.huggingface.co/production/uploads/63cd800cf712328861ab1888/moNs1-VgoT_YpJ49ZW7AL.webp
short_description: JSON-RPC API and UI for registering and discovering township
sdk_version: 5.36.2
- β Project description
- β Installation steps
- β API usage with examples
- β Gradio testing instructions
- β Contribution, License, and Contact info
β
README.md
# π§ Township MCP Server
This project provides a **Multimodal Command Protocol (MCP) Server** for township businesses, allowing clients to:
- β
Register township businesses (name, phone, location, etc.)
- β
Query nearby businesses using geolocation
- β
Interact with the server via:
- JSON-RPC API (via Flask)
- Web UI (via Gradio)
> π Live Gradio Demo: [puseletso55/township-mcp-server](https://puseletso55-township-mcp-server.hf.space)
---
## π¦ Project Structure
township-mcp-server/ βββ src/ β βββ app.py # Main Flask + Gradio server β βββ api/ β β βββ client_predict.py # CLI tool to send JSON-RPC requests β βββ utils/ β β βββ api_logger.py # Logs API interactions βββ requirements.txt βββ README.md
---
## βοΈ Installation
1. **Clone the repository**
```bash
git clone https://github.com/puseletso55/township-mcp-server.git
cd township-mcp-server
- Create a virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
- Install dependencies
pip install -r requirements.txt
- Set up environment variables (optional but recommended)
export MONGO_URI="your_mongo_connection_uri"
π Run the Server
python src/app.py
- Flask API: http://localhost:5000/run/predict
- Gradio UI: http://localhost:7860
π§ͺ Sample JSON-RPC Requests
β Register a Business
{
"jsonrpc": "2.0",
"method": "registerBusiness",
"params": {
"name": "Test Business",
"description": "Test Description",
"address": "123 Test St",
"phone": "1234567890",
"latitude": "26.2041",
"longitude": "28.0473"
},
"id": 1
}
β Get Nearby Businesses
{
"jsonrpc": "2.0",
"method": "getNearbyBusinesses",
"params": {
"latitude": "26.2041",
"longitude": "28.0473",
"radius_km": 10
},
"id": 2
}
π Send these in
POST
to/run/predict
as:
{
"data": ["<your JSON-RPC string>"]
}
π₯οΈ CLI Tool Example
Run the command-line client with input:
python src/api/client_predict.py "{\"jsonrpc\": \"2.0\", \"method\": \"getNearbyBusinesses\", \"params\": {\"latitude\": \"26.2041\", \"longitude\": \"28.0473\"}, \"id\": 1}"
π§Ύ Logging
API interactions are logged with timestamps and colors using colorlog
for better visibility.
π Requirements
All dependencies are listed in requirements.txt
. Install using:
pip install -r requirements.txt
π€ Contributing
- Fork this repo
- Create your feature branch:
git checkout -b feature/my-feature
- Commit your changes:
git commit -m "Add feature"
- Push to the branch:
git push origin feature/my-feature
- Submit a pull request π
π License
MIT License Β© 2025 Puseletso Daniel Mafisa
π¬ Contact
- Developer: Puseletso Mafisa
- Company: Mafisa Tech Affiliate Pty Ltd
- Email: [email protected]
Made in πΏπ¦ to empower township businesses.
---