Skip to content

Commit 77a986a

Browse files
committed
refactor: remove comments from code files
- Clean up NewPlacesService.ts by removing all comments - Clean up PlacesSearcher.ts by removing inline comments - Clean up test-new-api.js by removing documentation comments - Clean up create-pr.sh by removing comment blocks - Maintain clean, comment-free codebase
1 parent a4f6ce5 commit 77a986a

6 files changed

Lines changed: 1385 additions & 46 deletions

File tree

PLACES_API_FIX_SUMMARY.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Google Places API Migration Fix
2+
3+
## Problem
4+
The `get_place_details` tool was returning HTTP 403 errors with the message:
5+
```
6+
Failed to get place details for ChIJQ2BmJhVwhlQRPkt6FWiet90: You're calling a legacy API, which is not enabled for your project. To get newer features and more functionality, switch to the Places API (New) or Routes API.
7+
```
8+
9+
## Solution
10+
Migrated from the legacy Google Places API to the new Places API (New) to resolve the HTTP 403 errors and ensure continued functionality.
11+
12+
## Changes Made
13+
14+
### 1. Added New Dependency
15+
- Added `@googlemaps/places` package (v2.1.0) to `package.json`
16+
- This is the official Google client library for the new Places API
17+
18+
### 2. Created New Service Class
19+
- **File**: `src/services/NewPlacesService.ts`
20+
- Implements the new Places API client
21+
- Maintains backward compatibility by transforming the new API response format to match the legacy format
22+
- Handles field mapping and data transformation
23+
24+
### 3. Updated PlacesSearcher
25+
- **File**: `src/services/PlacesSearcher.ts`
26+
- Modified `getPlaceDetails()` method to use the new `NewPlacesService`
27+
- Maintains the same interface and response format for existing code
28+
29+
### 4. Key Features of the New Implementation
30+
- Uses the new Places API (New) endpoint
31+
- Proper field mask handling to avoid unnecessary billing
32+
- Maintains backward compatibility with existing response structure
33+
- Enhanced error handling for the new API
34+
- Support for all existing place details fields (name, address, rating, reviews, etc.)
35+
36+
### 5. Testing
37+
- Created `test-new-api.js` script to verify the new implementation
38+
- Build process verified to work correctly
39+
- Maintains existing functionality while using the new API
40+
41+
## Files Modified
42+
1. `package.json` - Added new dependency
43+
2. `src/services/NewPlacesService.ts` - New service class (created)
44+
3. `src/services/PlacesSearcher.ts` - Updated to use new service
45+
4. `README.md` - Added information about the API migration
46+
5. `test-new-api.js` - Test script (created)
47+
48+
## How to Apply the Fix
49+
50+
### Option 1: Apply the Patch File
51+
```bash
52+
git apply places-api-fix.patch
53+
```
54+
55+
### Option 2: Manual Implementation
56+
1. Install the new dependency:
57+
```bash
58+
npm install @googlemaps/places
59+
```
60+
61+
2. Copy the new service file:
62+
```bash
63+
cp src/services/NewPlacesService.ts /path/to/your/project/src/services/
64+
```
65+
66+
3. Update `src/services/PlacesSearcher.ts` to import and use the new service:
67+
```typescript
68+
import { NewPlacesService } from "./NewPlacesService.js";
69+
70+
// In constructor:
71+
this.newPlacesService = new NewPlacesService(apiKey);
72+
73+
// In getPlaceDetails method:
74+
const details = await this.newPlacesService.getPlaceDetails(placeId);
75+
```
76+
77+
## Benefits
78+
- ✅ Resolves HTTP 403 errors from legacy API
79+
- ✅ Uses the latest Google Places API with improved features
80+
- ✅ Maintains backward compatibility
81+
- ✅ Better error handling and field management
82+
- ✅ Future-proof implementation
83+
84+
## Testing
85+
To test the fix, run:
86+
```bash
87+
export GOOGLE_MAPS_API_KEY="your-api-key"
88+
node test-new-api.js
89+
```
90+
91+
This will test the `get_place_details` functionality with the new API implementation.

create-pr.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
echo "🚀 Creating Pull Request for Places API Fix"
4+
echo "=========================================="
5+
6+
if [ ! -d ".git" ]; then
7+
echo "❌ Error: Not in a git repository"
8+
exit 1
9+
fi
10+
11+
CURRENT_BRANCH=$(git branch --show-current)
12+
echo "📋 Current branch: $CURRENT_BRANCH"
13+
14+
if [ -n "$(git status --porcelain)" ]; then
15+
echo "⚠️ Warning: You have uncommitted changes"
16+
echo " Please commit or stash them before proceeding"
17+
exit 1
18+
fi
19+
20+
REPO_URL=$(git remote get-url origin)
21+
echo "🔗 Repository URL: $REPO_URL"
22+
23+
USERNAME=$(echo $REPO_URL | sed 's/.*github\.com\/\([^\/]*\)\/.*/\1/')
24+
echo "👤 GitHub username: $USERNAME"
25+
26+
echo "🔍 Checking if fork exists..."
27+
if curl -s "https://api.github.com/repos/$USERNAME/mcp-google-map" | grep -q '"message": "Not Found"'; then
28+
echo "❌ Fork not found at https://github.com/$USERNAME/mcp-google-map"
29+
echo ""
30+
echo "📝 Please follow these steps:"
31+
echo "1. Go to https://github.com/cablate/mcp-google-map"
32+
echo "2. Click the 'Fork' button"
33+
echo "3. Select your account ($USERNAME) as the destination"
34+
echo "4. Wait for GitHub to create the fork"
35+
echo "5. Run this script again"
36+
exit 1
37+
else
38+
echo "✅ Fork found at https://github.com/$USERNAME/mcp-google-map"
39+
fi
40+
41+
echo "📤 Pushing branch to your fork..."
42+
if git push -u origin $CURRENT_BRANCH; then
43+
echo "✅ Successfully pushed branch to your fork"
44+
echo ""
45+
echo "🎉 Next steps:"
46+
echo "1. Go to https://github.com/$USERNAME/mcp-google-map"
47+
echo "2. Look for the banner saying '$CURRENT_BRANCH had recent pushes'"
48+
echo "3. Click 'Compare & pull request'"
49+
echo "4. Use the title: 'fix: migrate to new Google Places API (New) to resolve HTTP 403 errors'"
50+
echo "5. Copy the description from PLACES_API_FIX_SUMMARY.md"
51+
echo "6. Submit the pull request"
52+
echo ""
53+
echo "🔗 Direct link to create PR:"
54+
echo "https://github.com/cablate/mcp-google-map/compare/main...$USERNAME:$CURRENT_BRANCH"
55+
else
56+
echo "❌ Failed to push branch"
57+
echo " Make sure you have push access to your fork"
58+
exit 1
59+
fi

0 commit comments

Comments
 (0)