@quantaroute/mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 QuantaRoute
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,481 @@
1
+ # QuantaRoute MCP Server
2
+
3
+ A Model Context Protocol (MCP) server that provides AI assistants (Claude Desktop, Cursor, and more) with powerful geocoding, location lookup, and DigiPin processing capabilities using the QuantaRoute Geocoding API.
4
+
5
+ **Package**: `@quantaroute/mcp-server` (MCP Server for AI Agents)
6
+ **SDK**: [`quantaroute-geocoding`](https://www.npmjs.com/package/quantaroute-geocoding) (Node.js/TypeScript SDK)
7
+
8
+ **βœ… Fully compatible with Claude Desktop and Cursor**
9
+
10
+ ## Features
11
+
12
+ ### πŸ—ΊοΈ Geocoding Tools
13
+ - **Geocode addresses** to DigiPin codes and coordinates
14
+ - **Reverse geocode** DigiPin codes to addresses
15
+ - **Convert coordinates** to DigiPin codes
16
+ - **Validate DigiPin** format and location
17
+ - **Batch geocode** multiple addresses (up to 100)
18
+ - **Autocomplete** address suggestions
19
+
20
+ ### πŸš€ Revolutionary Location Lookup with Nominatim + Pincode + Digipin
21
+ - **Lookup administrative boundaries** from coordinates (pincode, state, division, locality)
22
+ - **Lookup from DigiPin** codes
23
+ - **Batch location lookup** for multiple locations
24
+ - **Find nearby boundaries** within a radius [COMING SOON...]
25
+ - Access to **36,000+ postal boundaries** across India
26
+
27
+ ### πŸ“Š Utility Tools
28
+ - **Get API usage** statistics
29
+ - **Get location statistics** (boundaries, states, divisions)
30
+ - **Check API health** status
31
+
32
+ ## Installation
33
+
34
+ This MCP server is compatible with **Claude Desktop** and **Cursor**. Follow the instructions below for your platform.
35
+
36
+ ### For Claude Desktop
37
+
38
+ 1. **Locate the Claude Desktop configuration file:**
39
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
40
+ - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
41
+ - **Linux**: `~/.config/Claude/claude_desktop_config.json`
42
+
43
+ 2. **Edit the configuration file** and add:
44
+
45
+ ```json
46
+ {
47
+ "mcpServers": {
48
+ "quantaroute": {
49
+ "command": "npx",
50
+ "args": [
51
+ "-y",
52
+ "@quantaroute/mcp-server"
53
+ ],
54
+ "env": {
55
+ "QUANTAROUTE_API_KEY": "your-api-key-here"
56
+ }
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ 3. **Save and restart Claude Desktop** to apply the changes.
63
+
64
+ ### For Cursor
65
+
66
+ Add to your MCP configuration file (`~/.cursor/mcp.json`):
67
+
68
+ ```json
69
+ {
70
+ "mcpServers": {
71
+ "quantaroute": {
72
+ "command": "npx",
73
+ "args": [
74
+ "-y",
75
+ "@quantaroute/mcp-server"
76
+ ],
77
+ "env": {
78
+ "QUANTAROUTE_API_KEY": "your-api-key-here"
79
+ }
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ Restart Cursor after making changes.
86
+
87
+ ### Environment Variables
88
+
89
+ - `QUANTAROUTE_API_KEY` (required): Your QuantaRoute API key
90
+ - Get your API key from: https://developers.quantaroute.com
91
+ - Free tier test key: `demo_free_key_123` (for testing)
92
+
93
+ ## Available Tools
94
+
95
+ ### `geocode`
96
+ Geocode an address to get DigiPin code and coordinates.
97
+
98
+ **Parameters:**
99
+ - `address` (required): The address to geocode
100
+ - `city` (optional): City name
101
+ - `state` (optional): State name
102
+ - `pincode` (optional): Postal code
103
+ - `country` (optional): Country name (defaults to India)
104
+
105
+ **Example:**
106
+ ```json
107
+ {
108
+ "address": "Rohra Address, New Town",
109
+ "city": "New Town",
110
+ "state": "West Bengal",
111
+ "pincode": "700163"
112
+ }
113
+ ```
114
+
115
+ ### `reverse_geocode`
116
+ Reverse geocode a DigiPin code to get coordinates and address.
117
+
118
+ **Parameters:**
119
+ - `digipin` (required): DigiPin code (format: XXX-XXX-XXXX)
120
+
121
+ ### `coordinates_to_digipin`
122
+ Convert latitude and longitude to DigiPin code.
123
+
124
+ **Parameters:**
125
+ - `latitude` (required): Latitude (-90 to 90)
126
+ - `longitude` (required): Longitude (-180 to 180)
127
+
128
+ ### `lookup_location_from_coordinates`
129
+ πŸš€ **REVOLUTIONARY**: Get administrative boundaries from coordinates.
130
+
131
+ Returns: pincode, state, division, locality, district, population density, and more.
132
+
133
+ **Parameters:**
134
+ - `latitude` (required): Latitude coordinate
135
+ - `longitude` (required): Longitude coordinate
136
+
137
+ ### `lookup_location_from_digipin`
138
+ Get administrative boundaries from a DigiPin code.
139
+
140
+ **Parameters:**
141
+ - `digipin` (required): DigiPin code
142
+
143
+ ### `batch_location_lookup`
144
+ Batch lookup for multiple locations (up to 100).
145
+
146
+ **Parameters:**
147
+ - `locations` (required): Array of location objects
148
+ - Each object can have `latitude` + `longitude` OR `digipin`
149
+
150
+ ### `batch_geocode`
151
+ Geocode multiple addresses in a single request (up to 100).
152
+
153
+ **Parameters:**
154
+ - `addresses` (required): Array of address objects
155
+
156
+ ### `autocomplete`
157
+ Get address autocomplete suggestions.
158
+
159
+ **Parameters:**
160
+ - `query` (required): Search query (minimum 3 characters)
161
+ - `limit` (optional): Max suggestions (default: 5, max: 10)
162
+
163
+ ### `find_nearby_boundaries [COMING SOON...]`
164
+ Find nearby postal boundaries within a radius.
165
+
166
+ **Parameters:**
167
+ - `latitude` (required): Center latitude
168
+ - `longitude` (required): Center longitude
169
+ - `radius_km` (optional): Search radius in km (default: 5.0, max: 100)
170
+ - `limit` (optional): Max results (default: 10, max: 50)
171
+
172
+ ### `validate_digipin`
173
+ Validate DigiPin format and check if it's a real location.
174
+
175
+ **Parameters:**
176
+ - `digipin` (required): DigiPin code to validate
177
+
178
+ ### `get_usage`
179
+ Get API usage statistics and quota information.
180
+
181
+ ### `get_location_statistics`
182
+ Get live statistics about the Location Lookup service.
183
+
184
+ ### `get_health`
185
+ Check API health status.
186
+
187
+ ## REST API Wrapper
188
+
189
+ This project includes a REST API wrapper that makes all MCP tools accessible via HTTP endpoints for mobile and web applications.
190
+
191
+ ### Features
192
+
193
+ - βœ… **RESTful API**: All MCP tools exposed as HTTP endpoints
194
+ - βœ… **Authentication**: API key via header or environment variable
195
+ - βœ… **CORS Support**: Ready for web and mobile apps
196
+ - βœ… **Vercel Ready**: Optimized for serverless deployment
197
+ - βœ… **Error Handling**: Comprehensive error handling and validation
198
+
199
+ ### Quick Start
200
+
201
+ The REST API is **already deployed** and ready to use at:
202
+
203
+ **Base URL**: `https://mcp-gc.quantaroute.com/api`
204
+
205
+ **Note**: `mcp-gc` stands for MCP Geocoding. This follows the naming convention:
206
+ - `mcp-gc.quantaroute.com` - Geocoding MCP Server (this project)
207
+
208
+ #### Using the REST API
209
+
210
+ **1. Get API Information:**
211
+ ```bash
212
+ curl https://mcp-gc.quantaroute.com/api
213
+ ```
214
+
215
+ **2. Geocode an Address:**
216
+ ```bash
217
+ curl -X POST https://mcp-gc.quantaroute.com/api/geocode \
218
+ -H "Content-Type: application/json" \
219
+ -H "x-api-key: your-api-key-here" \
220
+ -d '{
221
+ "address": "Rohra Address, New Town",
222
+ "city": "New Town",
223
+ "state": "West Bengal",
224
+ "pincode": "700163"
225
+ }'
226
+ ```
227
+
228
+ **3. Health Check:**
229
+ ```bash
230
+ curl -X GET https://mcp-gc.quantaroute.com/api/health \
231
+ -H "x-api-key: your-api-key-here"
232
+ ```
233
+
234
+ **4. Find Nearby Boundaries:[NOT RELEASED, COMING SOON...]**
235
+ ```bash
236
+ curl -X POST https://mcp-gc.quantaroute.com/api/find-nearby-boundaries \
237
+ -H "Content-Type: application/json" \
238
+ -H "x-api-key: your-api-key-here" \
239
+ -d '{
240
+ "latitude": 28.6139,
241
+ "longitude": 77.2090,
242
+ "radius_km": 5.0,
243
+ "limit": 10
244
+ }'
245
+ ```
246
+
247
+ This endpoint finds nearby postal boundaries within a specified radius. Useful for:
248
+ - Finding all pincodes within X km of a location
249
+ - Discovering nearby administrative boundaries
250
+ - Location-based search and discovery
251
+
252
+ #### JavaScript/TypeScript Example
253
+
254
+ ```javascript
255
+ // Geocode an address
256
+ const response = await fetch('https://mcp-gc.quantaroute.com/api/geocode', {
257
+ method: 'POST',
258
+ headers: {
259
+ 'Content-Type': 'application/json',
260
+ 'x-api-key': 'your-api-key-here'
261
+ },
262
+ body: JSON.stringify({
263
+ address: 'Rohra Address, Action Area I',
264
+ city: 'New Town',
265
+ state: 'West Bengal'
266
+ })
267
+ });
268
+
269
+ const data = await response.json();
270
+ console.log(data);
271
+ ```
272
+
273
+ #### Python Example
274
+
275
+ ```python
276
+ import requests
277
+
278
+ # Geocode an address
279
+ response = requests.post(
280
+ 'https://mcp-gc.quantaroute.com/api/geocode',
281
+ headers={
282
+ 'Content-Type': 'application/json',
283
+ 'x-api-key': 'your-api-key-here'
284
+ },
285
+ json={
286
+ 'address': 'Rohra Address, Action Area I, Ghuni',
287
+ 'city': 'New Town',
288
+ 'state': 'West Bengal'
289
+ }
290
+ )
291
+
292
+ data = response.json()
293
+ print(data)
294
+ ```
295
+
296
+ #### Deploying Your Own Instance
297
+
298
+ If you want to deploy your own instance:
299
+
300
+ 1. **Deploy to Vercel**:
301
+ ```bash
302
+ vercel
303
+ ```
304
+
305
+ 2. **Set Environment Variable** (optional, for testing):
306
+ ```bash
307
+ vercel env add QUANTAROUTE_API_KEY
308
+ ```
309
+
310
+ 3. **Configure Custom Domain** (optional):
311
+ - Add your custom domain in Vercel
312
+ - Configure DNS CNAME record pointing to Vercel
313
+ - Wait for DNS propagation and SSL certificate
314
+
315
+ ### API Documentation
316
+
317
+ For complete REST API documentation, see [API.md](./API.md).
318
+
319
+ **Available Endpoints:**
320
+ - `GET /api` - API information
321
+ - `GET /api/health` - Health check
322
+ - `GET /api/usage` - Usage statistics
323
+ - `GET /api/location-statistics` - Location service statistics
324
+ - `GET /api/autocomplete?q=query` - Address autocomplete
325
+ - `GET /api/validate-digipin?digipin=XXX-XXX-XXXX` - Validate DigiPin
326
+ - `POST /api/geocode` - Geocode an address
327
+ - `POST /api/reverse-geocode` - Reverse geocode DigiPin
328
+ - `POST /api/coordinates-to-digipin` - Convert coordinates to DigiPin
329
+ - `POST /api/batch-geocode` - Batch geocode addresses
330
+ - `POST /api/lookup-location-from-coordinates` - Lookup from coordinates
331
+ - `POST /api/lookup-location-from-digipin` - Lookup from DigiPin
332
+ - `POST /api/batch-location-lookup` - Batch location lookup
333
+ - `POST /api/find-nearby-boundaries` - Find nearby boundaries [COMING SOON...]
334
+
335
+ ### Authentication
336
+
337
+ The API supports authentication in two ways:
338
+
339
+ 1. **Request Header** (Recommended for production):
340
+ ```
341
+ x-api-key: your-api-key-here
342
+ ```
343
+ - Users should get their own API key from [developers.quantaroute.com](https://developers.quantaroute.com)
344
+ - Send the API key in the `x-api-key` header with each request
345
+ - Each user's API key is validated by the backend API and usage is tracked separately
346
+
347
+ 2. **Environment Variable** (Optional fallback for testing):
348
+ ```
349
+ QUANTAROUTE_API_KEY=your-api-key-here
350
+ ```
351
+ - Only used if no `x-api-key` header is provided
352
+ - Useful for testing and development
353
+ - Not recommended for production use
354
+
355
+ **Priority**: The request header takes precedence over the environment variable.
356
+
357
+ **Getting an API Key**:
358
+ - Visit [developers.quantaroute.com](https://developers.quantaroute.com)
359
+ - Sign up and get your API key
360
+ - Use it in the `x-api-key` header for all API requests
361
+
362
+ ## Development
363
+
364
+ ### Prerequisites
365
+ - Node.js 18+
366
+ - TypeScript 5+
367
+
368
+ ### Setup
369
+
370
+ ```bash
371
+ # Install dependencies
372
+ npm install
373
+
374
+ # Build the project
375
+ npm run build
376
+
377
+ # Run in development mode
378
+ npm run dev
379
+ ```
380
+
381
+ ### Project Structure
382
+
383
+ ```
384
+ mcp-server/
385
+ β”œβ”€β”€ src/
386
+ β”‚ β”œβ”€β”€ index.ts # Main MCP server implementation
387
+ β”‚ └── client.ts # QuantaRoute API client
388
+ β”œβ”€β”€ api/
389
+ β”‚ └── [...path].ts # REST API wrapper (Vercel serverless function)
390
+ β”œβ”€β”€ dist/ # Compiled JavaScript (generated)
391
+ β”œβ”€β”€ package.json
392
+ β”œβ”€β”€ tsconfig.json
393
+ β”œβ”€β”€ vercel.json # Vercel configuration
394
+ β”œβ”€β”€ README.md
395
+ └── API.md # REST API documentation
396
+ ```
397
+
398
+ ## API Documentation
399
+
400
+ Full API documentation: https://api.quantaroute.com/v1/digipin/docs
401
+
402
+ ## License
403
+
404
+ MIT License
405
+
406
+ ## Support
407
+
408
+ - **Website**: https://quantaroute.com
409
+ - **API Docs**: https://api.quantaroute.com/v1/digipin/docs
410
+ - **Issues**: https://github.com/mapdevsaikat/quantaroute-geocoder/issues
411
+
412
+ ## Supported Platforms
413
+
414
+ βœ… **Claude Desktop** - Fully supported
415
+ βœ… **Cursor** - Fully supported
416
+ βœ… **Other MCP-compatible clients** - Should work with any MCP-compatible application
417
+
418
+ ## Example Usage in AI Assistants
419
+
420
+ Once configured, AI assistants (Claude, Cursor AI, etc.) can use tools like:
421
+
422
+ ### Example 1: Geocoding
423
+ ```
424
+ User: "What's the DigiPin for Biswa Bangla Gate, New Town?"
425
+
426
+ Assistant: [Uses geocode tool]
427
+ The DigiPin code for that address is 2TF-39M-JT5F, located at coordinates 22.5788545, 88.4716628.
428
+ Full Address: Biswa Bangla Gate, New Town, Biswa Bangla Sarani, Action Area I, New Town, Bidhannagar, North 24 Parganas, West Bengal, 700156, India
429
+ ```
430
+
431
+ ### Example 2: Location Lookup
432
+ ```
433
+ User: "What administrative boundaries are at coordinates 28.6139, 77.2090?"
434
+
435
+ Assistant: [Uses lookup_location_from_coordinates tool]
436
+ That location is in:
437
+ - Pincode: 110001
438
+ - State: Delhi
439
+ - Division: New Delhi Central
440
+ - Locality: Connaught Place
441
+ - District: New Delhi
442
+ ```
443
+
444
+ ### Example 3: Reverse Geocoding
445
+ ```
446
+ User: "What's the address for DigiPin 2TF-3FT-J825?"
447
+
448
+ Assistant: [Uses reverse_geocode tool]
449
+ The DigiPin 2TF-3FT-J825 corresponds to:
450
+ - Address: FE Block, Sector III, Bidhannagar, North 24 Parganas, West Bengal, 700106, India
451
+ - Coordinates: 22.580587Β°N, 88.419001Β°E
452
+ ```
453
+
454
+ ## Troubleshooting
455
+
456
+ ### Claude Desktop Issues
457
+
458
+ 1. **Server not appearing in Claude Desktop:**
459
+ - Verify the config file path is correct for your OS
460
+ - Check that the JSON syntax is valid
461
+ - Restart Claude Desktop completely
462
+
463
+ 2. **"Command not found" errors:**
464
+ - Ensure Node.js 18+ is installed: `node --version`
465
+ - Verify `npx` is available: `which npx`
466
+
467
+ 3. **API authentication errors:**
468
+ - Check that `QUANTAROUTE_API_KEY` is set correctly in the config
469
+ - Verify the API key is valid at https://api.quantaroute.com
470
+
471
+ ### Cursor Issues
472
+
473
+ 1. **MCP server not loading:**
474
+ - Check `~/.cursor/mcp.json` exists and has valid JSON
475
+ - Restart Cursor completely
476
+ - Check Cursor's MCP logs for errors
477
+
478
+ 2. **Tools not available:**
479
+ - Verify the server is running (check Cursor's MCP status)
480
+ - Ensure API key is configured correctly
481
+
@@ -0,0 +1,3 @@
1
+ import type { VercelRequest, VercelResponse } from '@vercel/node';
2
+ export default function handler(req: VercelRequest, res: VercelResponse): Promise<void>;
3
+ //# sourceMappingURL=%5B...path%5D.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"[...path].d.ts","sourceRoot":"","sources":["../../api/[...path].ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAyElE,wBAA8B,OAAO,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,iBAmU5E"}