Skip to content

Commit 942b30e

Browse files
[prompts] Add three new high-value prompts
Adds three essential workflow prompts to complement the existing three: New Prompts: - setup-mapbox-project: Complete project initialization with tokens, styles, and integration guidance. Handles web, mobile, backend, and fullstack projects with proper security (URL restrictions, secret token management). - debug-mapbox-integration: Systematic 6-phase troubleshooting workflow. Diagnoses token issues, style problems, and API errors. Provides specific solutions for 401, 403, and layer/source errors. - design-data-driven-style: Guide for creating styles with data-driven expressions. Supports color/size/heatmap visualizations with sequential, diverging, and categorical color schemes. Includes advanced expressions and best practices. Test Coverage: - 3 new prompt implementation files - 3 new comprehensive test files (44 tests total) - Updated promptRegistry test (now validates 6 prompts) - All 370 tests passing ✅ Documentation: - Updated README with detailed prompt descriptions, arguments, and examples - Each prompt includes workflow steps and example usage 🤖 Generated with Claude Code
1 parent 07d59a4 commit 942b30e

9 files changed

+1590
-3
lines changed

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,100 @@ Arguments:
546546
convert_coordinates: "false"
547547
```
548548

549+
### setup-mapbox-project
550+
551+
Complete setup workflow for a new Mapbox project with proper token security and style initialization.
552+
553+
**Arguments:**
554+
555+
- `project_name` (required): Name of the project or application
556+
- `project_type` (optional): Type of project: "web", "mobile", "backend", or "fullstack" (default: "web")
557+
- `production_domain` (optional): Production domain for URL restrictions (e.g., "myapp.com")
558+
- `style_theme` (optional): Initial style theme: "light", "dark", "streets", "outdoors", "satellite" (default: "light")
559+
560+
**What it does:**
561+
562+
1. Creates development token with localhost URL restrictions
563+
2. Creates production token with domain URL restrictions (if provided)
564+
3. Creates backend secret token for server-side operations (if needed)
565+
4. Creates an initial map style using the specified theme
566+
5. Generates preview link and provides integration guidance
567+
568+
**Example usage:**
569+
570+
```
571+
Use prompt: setup-mapbox-project
572+
Arguments:
573+
project_name: "Restaurant Finder"
574+
project_type: "fullstack"
575+
production_domain: "restaurantfinder.com"
576+
style_theme: "light"
577+
```
578+
579+
### debug-mapbox-integration
580+
581+
Systematic troubleshooting workflow for diagnosing and fixing Mapbox integration issues.
582+
583+
**Arguments:**
584+
585+
- `issue_description` (required): Description of the problem (e.g., "map not loading", "401 error")
586+
- `error_message` (optional): Exact error message from console or logs
587+
- `style_id` (optional): Mapbox style ID being used, if applicable
588+
- `environment` (optional): Where the issue occurs: "development", "production", "staging"
589+
590+
**What it does:**
591+
592+
1. Verifies token validity and required scopes
593+
2. Checks style configuration and existence
594+
3. Analyzes error messages and provides specific solutions
595+
4. Tests API endpoints to isolate the problem
596+
5. Provides step-by-step fix instructions
597+
6. Offers prevention strategies
598+
599+
**Example usage:**
600+
601+
```
602+
Use prompt: debug-mapbox-integration
603+
Arguments:
604+
issue_description: "Getting 401 errors when map loads"
605+
error_message: "401 Unauthorized"
606+
style_id: "my-style-id"
607+
environment: "production"
608+
```
609+
610+
### design-data-driven-style
611+
612+
Create a map style with data-driven properties that respond dynamically to feature data using expressions.
613+
614+
**Arguments:**
615+
616+
- `style_name` (required): Name for the data-driven style
617+
- `data_description` (required): Description of the data (e.g., "population by city", "earthquake magnitudes")
618+
- `property_name` (required): Name of the data property to visualize (e.g., "population", "magnitude")
619+
- `visualization_type` (optional): How to visualize: "color", "size", "both", "heatmap" (default: "color")
620+
- `color_scheme` (optional): Color scheme: "sequential", "diverging", "categorical" (default: "sequential")
621+
622+
**What it does:**
623+
624+
1. Explains data-driven styling concepts and expressions
625+
2. Provides appropriate expression templates for your use case
626+
3. Offers color scales and size ranges based on visualization type
627+
4. Creates the style with data-driven layers
628+
5. Includes advanced expression examples (zoom-based, conditional)
629+
6. Provides best practices for accessibility and performance
630+
631+
**Example usage:**
632+
633+
```
634+
Use prompt: design-data-driven-style
635+
Arguments:
636+
style_name: "Population Density Map"
637+
data_description: "City population data"
638+
property_name: "population"
639+
visualization_type: "both"
640+
color_scheme: "sequential"
641+
```
642+
549643
## Resources
550644

551645
This server exposes static reference documentation as MCP Resources. While these are primarily accessed through the `get_reference_tool`, MCP clients that fully support the resources protocol can access them directly.
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
// Copyright (c) Mapbox, Inc.
2+
// Licensed under the MIT License.
3+
4+
import type { PromptMessage } from '@modelcontextprotocol/sdk/types.js';
5+
import { BasePrompt, type PromptArgument } from './BasePrompt.js';
6+
7+
/**
8+
* Prompt for systematically debugging Mapbox integration issues
9+
*
10+
* This prompt guides users through a comprehensive troubleshooting workflow:
11+
* 1. Verify token validity and scopes
12+
* 2. Check style configuration and existence
13+
* 3. Validate GeoJSON if applicable
14+
* 4. Test API endpoints
15+
* 5. Review error messages and provide solutions
16+
*/
17+
export class DebugMapboxIntegrationPrompt extends BasePrompt {
18+
readonly name = 'debug-mapbox-integration';
19+
readonly description =
20+
'Systematic troubleshooting workflow for Mapbox integration issues. Diagnoses token problems, style errors, API issues, and provides actionable solutions.';
21+
22+
readonly arguments: ReadonlyArray<PromptArgument> = [
23+
{
24+
name: 'issue_description',
25+
description:
26+
'Description of the problem (e.g., "map not loading", "401 error")',
27+
required: true
28+
},
29+
{
30+
name: 'error_message',
31+
description: 'Exact error message from console or logs, if available',
32+
required: false
33+
},
34+
{
35+
name: 'style_id',
36+
description: 'Mapbox style ID being used, if applicable',
37+
required: false
38+
},
39+
{
40+
name: 'environment',
41+
description:
42+
'Where the issue occurs: "development", "production", "staging"',
43+
required: false
44+
}
45+
];
46+
47+
getMessages(args: Record<string, string>): PromptMessage[] {
48+
const issueDescription = args['issue_description'];
49+
const errorMessage = args['error_message'];
50+
const styleId = args['style_id'];
51+
const environment = args['environment'] || 'development';
52+
53+
let instructionText = `Debug Mapbox integration issue: "${issueDescription}"
54+
${errorMessage ? `\nError message: "${errorMessage}"` : ''}
55+
${styleId ? `Style ID: ${styleId}` : ''}
56+
Environment: ${environment}
57+
58+
Let's systematically diagnose and fix this issue.
59+
60+
## Phase 1: Token Verification
61+
62+
First, verify that tokens are properly configured:
63+
64+
1. **List all tokens**
65+
- Use list_tokens_tool to see all available tokens
66+
- Check the output carefully
67+
68+
2. **Analyze token issues**
69+
Look for common problems:
70+
- ❌ **No tokens exist**: Need to create tokens first
71+
- ❌ **Wrong token type**: Using secret token (sk.*) in client code
72+
- ❌ **Missing scopes**: Token doesn't have required scopes for the operation
73+
- ❌ **URL restrictions**: Token is restricted to different URLs than where it's being used
74+
- ❌ **Revoked token**: Token may have been revoked
75+
76+
3. **Check required scopes**
77+
Based on the issue, verify the token has the correct scopes:
78+
`;
79+
80+
if (errorMessage && errorMessage.includes('401')) {
81+
instructionText += ` - **401 Unauthorized** typically means:
82+
* Token is invalid or revoked
83+
* Token is missing required scopes
84+
* Token is not set correctly (check: mapboxgl.accessToken = '...')
85+
`;
86+
} else if (errorMessage && errorMessage.includes('403')) {
87+
instructionText += ` - **403 Forbidden** typically means:
88+
* Token lacks required scope for this operation
89+
* URL restriction blocks this domain
90+
* Rate limit exceeded
91+
`;
92+
} else {
93+
instructionText += ` - Displaying maps: needs \`styles:read\`, \`fonts:read\`
94+
- Creating styles: needs \`styles:write\`
95+
- Listing styles: needs \`styles:list\`
96+
- Managing tokens: needs \`tokens:read\` or \`tokens:write\`
97+
`;
98+
}
99+
100+
if (styleId) {
101+
instructionText += `
102+
## Phase 2: Style Verification
103+
104+
Since a style ID was provided, let's verify it exists and is valid:
105+
106+
1. **List user's styles**
107+
- Use list_styles_tool to see all available styles
108+
- Check if "${styleId}" appears in the list
109+
110+
2. **Analyze style issues**
111+
- ❌ **Style not found**: Style ID may be incorrect or from different account
112+
- ❌ **Style from wrong account**: Using someone else's private style
113+
- ❌ **Malformed style ID**: Should be in format "mapbox://styles/username/style-id"
114+
115+
`;
116+
} else {
117+
instructionText += `
118+
## Phase 2: Style Verification
119+
120+
No style ID provided. If the issue involves a specific style:
121+
1. Ask the user for the style ID they're trying to use
122+
2. Use list_styles_tool to verify it exists
123+
3. Check the style configuration
124+
125+
`;
126+
}
127+
128+
instructionText += `## Phase 3: Common Error Pattern Matching
129+
130+
Analyze the error and provide specific solutions:
131+
132+
`;
133+
134+
if (errorMessage) {
135+
instructionText += `Based on the error message "${errorMessage}", check for:
136+
137+
`;
138+
139+
if (
140+
errorMessage.toLowerCase().includes('401') ||
141+
errorMessage.toLowerCase().includes('unauthorized')
142+
) {
143+
instructionText += `### 401 Unauthorized Solutions:
144+
1. **Token not set**: Verify \`mapboxgl.accessToken = 'your-token'\` is called before creating the map
145+
2. **Invalid token**: The token may be malformed, revoked, or expired
146+
3. **Check token validity**: Use list_tokens_tool to verify the token exists
147+
4. **Environment variable**: If using env vars, ensure MAPBOX_ACCESS_TOKEN is set correctly
148+
149+
`;
150+
}
151+
152+
if (
153+
errorMessage.toLowerCase().includes('403') ||
154+
errorMessage.toLowerCase().includes('forbidden')
155+
) {
156+
instructionText += `### 403 Forbidden Solutions:
157+
1. **URL restriction**: Token is restricted to different URLs
158+
- Development: Check token allows http://localhost:*
159+
- Production: Check token allows your domain
160+
2. **Missing scope**: Token needs additional scopes
161+
- Use list_tokens_tool to check current scopes
162+
- Use update_token_tool to add required scopes
163+
3. **Rate limit**: Check if you've exceeded API rate limits
164+
165+
`;
166+
}
167+
168+
if (
169+
errorMessage.toLowerCase().includes('style') ||
170+
errorMessage.toLowerCase().includes('404')
171+
) {
172+
instructionText += `### Style Not Found Solutions:
173+
1. **Wrong style URL**: Verify format is "mapbox://styles/username/style-id"
174+
2. **Private style**: Ensure token has access to this style
175+
3. **Style deleted**: Check if style still exists using list_styles_tool
176+
4. **Typo in style ID**: Double-check the style ID spelling
177+
178+
`;
179+
}
180+
181+
if (
182+
errorMessage.toLowerCase().includes('source') ||
183+
errorMessage.toLowerCase().includes('layer')
184+
) {
185+
instructionText += `### Layer/Source Error Solutions:
186+
1. **Source not defined**: Ensure source is added before layers that reference it
187+
2. **Invalid layer type**: Check layer type matches source geometry
188+
3. **Missing required property**: Verify all required layer properties are set
189+
4. **Use get_reference_tool**: Get 'style-spec-reference' for layer requirements
190+
191+
`;
192+
}
193+
} else {
194+
instructionText += `### General debugging steps:
195+
196+
**If map isn't displaying:**
197+
1. Check browser console for errors
198+
2. Verify container div exists: \`<div id="map"></div>\`
199+
3. Ensure container has dimensions set in CSS: \`#map { height: 400px; }\`
200+
4. Confirm token is set before map initialization
201+
5. Check network tab for failed API requests
202+
203+
**If map loads but looks wrong:**
204+
1. Verify style ID is correct
205+
2. Check if custom layers are properly configured
206+
3. Ensure zoom/center coordinates are valid
207+
4. Review layer order and visibility
208+
209+
**If getting rate limit errors:**
210+
1. Check token usage in Mapbox dashboard
211+
2. Consider implementing request caching
212+
3. Review rate limit documentation
213+
4. Upgrade plan if needed
214+
215+
`;
216+
}
217+
218+
instructionText += `## Phase 4: Testing & Validation
219+
220+
Run these diagnostic checks:
221+
222+
1. **Test token directly**
223+
- Use the token to list_styles_tool or list_tokens_tool
224+
- If these calls fail, the token itself is the issue
225+
226+
2. **Generate test preview**
227+
- If a style exists, use preview_style_tool to generate a working preview
228+
- Compare the working preview with the broken implementation
229+
230+
3. **Check documentation**
231+
- Use get_reference_tool with:
232+
* 'style-spec-reference' for style JSON issues
233+
* 'token-scopes-reference' for token scope questions
234+
* 'streets-v8-fields-reference' for data layer questions
235+
236+
## Phase 5: Solution Summary
237+
238+
After completing diagnostics, provide:
239+
240+
1. **Root cause identified**: Clearly state what the problem is
241+
2. **Immediate fix**: Step-by-step instructions to resolve the issue
242+
3. **Prevention**: How to avoid this issue in the future
243+
4. **Additional resources**: Relevant documentation links
244+
245+
## Phase 6: Verification
246+
247+
After applying fixes:
248+
249+
1. **Retest the integration**
250+
- Clear browser cache if testing in development
251+
- Check console for any new errors
252+
- Verify map loads and displays correctly
253+
254+
2. **Monitor for issues**
255+
- Watch for similar errors in production
256+
- Set up error tracking (Sentry, etc.)
257+
- Review Mapbox dashboard for usage patterns
258+
259+
---
260+
261+
Begin the diagnostic process now. Run each phase systematically and present findings clearly to the user.`;
262+
263+
return [
264+
{
265+
role: 'user',
266+
content: {
267+
type: 'text',
268+
text: instructionText
269+
}
270+
}
271+
];
272+
}
273+
}

0 commit comments

Comments
 (0)