### Example Workflow: Create Multi-Environment Setup Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-devkit-patterns/references/troubleshooting.md Illustrates setting up styles and tokens for different environments (dev, staging, prod) with specific access levels and domain restrictions. ```text You: "Set up styles and tokens for dev, staging, prod: - Dev: Full access, localhost - Staging: Read-only, staging.example.com - Prod: Minimal scopes, example.com Each environment needs its own style variant." AI: [Creates 3 styles and 3 tokens with specifications] ``` -------------------------------- ### Start Development Server Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/examples/web/performance-optimized/README.md Run this command to start the development server for the application. ```bash npm run dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/examples/web/performance-optimized/README.md Run this command to install the necessary project dependencies. ```bash npm install ``` -------------------------------- ### Run All Python Examples Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Execute all Python examples by navigating to the 'python' directory and running the main script. ```bash cd python python pydantic_ai_example.py python crewai_example.py python smolagents_example.py ``` -------------------------------- ### Example .env.example file Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-web-integration-patterns/references/token-management.md Provide an example .env file for your team to show the required environment variables and their format, without exposing actual tokens. ```bash VITE_MAPBOX_ACCESS_TOKEN=your_token_here ``` -------------------------------- ### Python Setup for Mapbox MCP Integration Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Sets up the Python environment by installing dependencies and exporting necessary environment variables for Mapbox, OpenAI, and HuggingFace tokens. ```bash cd python pip install -r requirements.txt # Set environment variables export MAPBOX_ACCESS_TOKEN="your_token_here" export OPENAI_API_KEY="your_openai_key" export HF_TOKEN="your_huggingface_token" # For smolagents ``` -------------------------------- ### Run Smolagents Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Executes the Smolagents example script, demonstrating lightweight agents with direct MCP connection or custom tools. ```bash python smolagents_example.py ``` -------------------------------- ### TypeScript Example Commands Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Commands to type-check and run individual TypeScript examples. Ensure you are in the 'typescript' directory. ```bash cd typescript npm run build npm run mastra npm run langchain ``` -------------------------------- ### Run LangChain Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Executes the LangChain example script, showcasing a conversational AI framework with tool chaining and memory management. ```bash npm run langchain ``` -------------------------------- ### Install Mapbox Plugin Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Install the Mapbox plugin from the added marketplace. This makes Mapbox skills available in your AI tool. ```bash /plugin install mapbox ``` -------------------------------- ### TypeScript Setup for Mapbox MCP Integration Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Sets up the TypeScript environment by installing dependencies and exporting necessary environment variables for Mapbox and OpenAI API keys. ```bash cd typescript npm install # Set environment variables export MAPBOX_ACCESS_TOKEN="your_token_here" export OPENAI_API_KEY="your_openai_key" ``` -------------------------------- ### Install and Run MCP Server (Self-Hosted) Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/AGENTS.md Install the MCP server using npm and run it with your Mapbox access token configured in the environment. ```bash npm install @mapbox/mcp-server # Or: npx @mapbox/mcp-server export MAPBOX_ACCESS_TOKEN="your_token" ``` -------------------------------- ### Run Mastra Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Executes the Mastra example script, demonstrating type-safe tool creation with Zod schemas and Mapbox MCP server integration. ```bash npm run mastra ``` -------------------------------- ### iOS Demo Quick Start Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/demos/README.md Commands to set up and run the iOS demo application. Ensure your Mapbox access token is added to `Info.plist`. ```bash cd ios-demo # Add your token to Sources/MapboxIOSDemo/Info.plist swift package resolve open Package.swift ``` -------------------------------- ### Example Workflow Steps Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Illustrates a typical user request and the sequence of skill and tool interactions to fulfill it. ```text User: "Create a high-performance map for my restaurant finder" 1. [mapbox-cartography skill] → Understands restaurant maps need high contrast, muted background 2. [mapbox-token-security skill] → Creates token with only styles:read scope, URL restrictions 3. [mapbox-style-patterns skill] → Applies POI Finder pattern 4. [MCP style_builder_tool] → Generates style JSON 5. [MCP create_style_tool] → Creates style in Mapbox account 6. [mapbox-web-performance-patterns skill] → Recommends clustering for > 1,000 markers 7. [MCP preview_style_tool] → Generates preview link ``` -------------------------------- ### Install Mapbox Search JS Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-web-integration-patterns/SKILL.md Installs the Mapbox Search JS library for React or other web frameworks. ```bash npm install @mapbox/search-js-react@^1.0.0 # React npm install @mapbox/search-js-web@^1.0.0 # Other frameworks ``` -------------------------------- ### Loading a Reference File Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-google-maps-migration/SKILL.md Example of how to load a reference markdown file within the skill's directory structure. ```bash Load references/shapes-geocoding.md ``` -------------------------------- ### Run CrewAI Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Executes the CrewAI example script, showcasing multi-agent orchestration with specialized roles and task dependencies. ```bash python crewai_example.py ``` -------------------------------- ### Skill Structure Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/CONTRIBUTING.md Illustrates the required directory structure for a new skill, including metadata, documentation, assets, scripts, and evaluation files. ```bash skills/your-skill-name/ ├── SKILL.md # Required: Metadata + instructions (<500 lines) ├── references/ # Optional: Documentation loaded on demand │ ├── framework-a.md │ └── framework-b.md ├── assets/ # Optional: Templates, schemas, static resources │ └── project-template.md ├── scripts/ # Optional: Executable code agents can run │ └── validate.sh ├── evals/ │ └── evals.json # Required: Skill evaluation metrics (3-5 evals) └── AGENTS.md # Optional: Condensed version for Cursor/Copilot ``` -------------------------------- ### Clone and Install Mapbox Agent Skills Locally Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Clone the repository and install the skills locally for development using Claude Code or by creating a symlink. ```bash git clone https://github.com/mapbox/mapbox-agent-skills.git cd mapbox-agent-skills # Install in Claude Code npx skills add . -a claude-code # Or symlink for development mkdir -p .claude ln -s $(pwd)/skills .claude/skills ``` -------------------------------- ### Install Mapbox Search JS Core Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-search-integration/references/nodejs-search.md Install the Mapbox Search JS Core library using npm. This is the recommended approach for server-side search. ```bash npm install @mapbox/search-js-core ``` -------------------------------- ### Install Mapbox GL JS with npm Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-web-integration-patterns/SKILL.md Installs the latest v3.x version of Mapbox GL JS. Recommended for production environments. ```bash npm install mapbox-gl@^3.0.0 # Installs latest v3.x ``` -------------------------------- ### Basic Crew Initialization and Execution Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/references/crewai.md Demonstrates the fundamental setup for a CrewAI crew with agents and tasks, followed by execution. ```python crew = Crew( agents=[location_analyst, route_planner], tasks=[find_restaurants_task, plan_route_task], verbose=True ) result = crew.kickoff() print(result) ``` -------------------------------- ### Self-Host Mapbox DevKit Server Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-devkit-patterns/AGENTS.md Instructions for cloning, installing, and building the Mapbox DevKit server for self-hosting. ```bash git clone https://github.com/mapbox/mcp-devkit-server.git cd mcp-devkit-server && npm install && npm run build ``` -------------------------------- ### Install All Mapbox Agent Skills Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Use this command to install all available skills for Claude Code. For development, you can manually symlink the skills directory. ```bash npx skills add mapbox/mapbox-agent-skills ``` ```bash # Or manually symlink (for development) mkdir -p .claude ln -s ~/git/mapbox-agent-skills/skills .claude/skills ``` -------------------------------- ### Install Mapbox Agent Skills for VS Code (GitHub Copilot) Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Install the Mapbox Agent Skills for integration with VS Code and GitHub Copilot. ```bash npx skills add mapbox/mapbox-agent-skills -a vscode ``` -------------------------------- ### Install All Mapbox Agent Skills via CLI Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Install all Mapbox Agent Skills using the skills CLI. This command fetches all available skills for the Mapbox organization. ```bash npx skills add mapbox/mapbox-agent-skills ``` -------------------------------- ### Install Mapbox GL JS and Turf Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-store-locator-patterns/SKILL.md Install the necessary Mapbox GL JS and Turf.js libraries using npm. These are required for map display and spatial calculations. ```bash npm install mapbox-gl @turf/turf ``` -------------------------------- ### Install Mapbox MCP Server with npm Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/SKILL.md Use this command to install the Mapbox MCP Server package locally for custom deployments or development. ```bash npm install @mapbox/mcp-server ``` -------------------------------- ### Mapbox Access Token Setup Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-google-maps-migration/AGENTS.md Shows how to set the Mapbox access token, typically stored in environment variables for client-side use. ```javascript // Store in environment variables mapboxgl.accessToken = process.env.NEXT_PUBLIC_MAPBOX_TOKEN; ``` -------------------------------- ### Install Specific Mapbox Skill via CLI Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Install a specific Mapbox skill using the skills CLI by providing the skill name. This is useful for targeted skill management. ```bash npx skills add mapbox/mapbox-agent-skills --skill mapbox-web-performance-patterns ``` -------------------------------- ### Run Pydantic AI Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/examples/README.md Executes the Pydantic AI example script, which demonstrates type-safe agents with validation and Mapbox MCP server integration. ```bash python pydantic_ai_example.py ``` -------------------------------- ### Verify Mapbox DevKit Tools Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-devkit-patterns/references/setup.md A sample prompt to verify the installation of the Mapbox DevKit tools by asking the AI assistant to list available tools. ```text "List the available Mapbox DevKit tools" ``` -------------------------------- ### Install Mapbox Search JS Packages Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-web-integration-patterns/SKILL.md Install the appropriate Mapbox Search JS package for your framework. The React and Vanilla/Vue/Svelte packages include core functionality. ```bash npm install @mapbox/search-js-react # React npm install @mapbox/search-js-web # Vanilla/Vue/Svelte ``` -------------------------------- ### Manual Installation for AGENTS.md-based Tools Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Manually download the AGENTS.md file for tools like Codex and Copilot. This is for AI assistants that use AGENTS.md format. ```bash # For Codex, Copilot, and other AGENTS.md-based tools — copy to project root curl -O https://raw.githubusercontent.com/mapbox/mapbox-agent-skills/main/skills/mapbox-web-performance-patterns/AGENTS.md ``` -------------------------------- ### Clone and Build Mapbox DevKit Server Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-devkit-patterns/references/setup.md Instructions for cloning the Mapbox DevKit server repository, installing dependencies, and building the server for self-hosted deployment. ```bash git clone https://github.com/mapbox/mcp-devkit-server.git cd mcp-devkit-server npm install npm run build ``` -------------------------------- ### Least Privilege Scope Examples Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-token-security/SKILL.md Demonstrates the principle of least privilege by showing overly permissive versus minimal required scopes for Mapbox tokens. ```javascript // Overly permissive - don't do this { scopes: ['styles:read', 'styles:write', 'styles:list', 'styles:delete', 'tokens:read', 'tokens:write']; } ``` ```javascript // Only what's needed for displaying a map { scopes: ['styles:read', 'fonts:read']; } // Add 'styles:tiles' if your map uses raster tile sources { scopes: ['styles:read', 'fonts:read', 'styles:tiles']; } ``` -------------------------------- ### Add mapbox_maps_flutter Dependency Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-flutter-patterns/SKILL.md Add the mapbox_maps_flutter package to your pubspec.yaml file and run flutter pub get to install it. ```yaml dependencies: mapbox_maps_flutter: ^2.0.0 ``` -------------------------------- ### Android Demo Quick Start Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/demos/README.md Commands to set up and run the Android demo application. Ensure your Mapbox access token is added to `mapbox_access_token.xml` and sync Gradle. ```bash cd android-demo # Add your token to app/src/main/res/values/mapbox_access_token.xml # Open in Android Studio and sync Gradle ``` -------------------------------- ### Example Workflow: Build a Restaurant Finder Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-devkit-patterns/references/troubleshooting.md Demonstrates a conversational workflow for building a restaurant finder app, including style creation, token generation, data validation, and applying filters. ```text You: "I'm building a restaurant finder app. Create: 1. A light, neutral style emphasizing restaurants 2. A token for localhost with minimal scopes 3. Validate this GeoJSON with restaurant locations: [paste]" AI: [Creates style, token, validates data] You: "Add filters to show only 4+ star restaurants" AI: [Updates style with expression] You: "Generate a preview URL" AI: [Returns preview] ``` -------------------------------- ### Mapbox Expression Calculations Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-data-visualization-patterns/AGENTS.md Perform mathematical calculations within Mapbox expressions. Examples include division, multiplication, and percentage calculations using `get` to retrieve property values. ```javascript // Divide ['/', ['get', 'numerator'], ['get', 'denominator']] // Multiply ['*', ['get', 'value'], 1.5] // Percentage ['*', ['/', ['get', 'part'], ['get', 'total']], 100] ``` -------------------------------- ### Get Current Location Once with Mapbox Android Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-android-patterns/references/location-tracking.md Retrieve the user's last known location and center the camera on it. This is useful for initial map setup or one-time location-based actions. ```kotlin mapView.location.getLastLocation { location -> location?.let { val point = Point.fromLngLat(it.longitude, it.latitude) mapView.camera.easeTo( CameraOptions.Builder() .center(point) .zoom(14.0) .build() ) } } ``` -------------------------------- ### Create Mastra Agent with Mapbox Tools Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/references/mastra.md Defines and configures a Mastra agent with specific geospatial tools for searching points of interest and getting directions. Ensure Zod is installed for schema validation. ```typescript // Create Mastra agent with Mapbox tools import { Agent } from '@mastra/core/agent'; import { createTool } from '@mastra/core/tools'; import { z } from 'zod'; const mcp = new MapboxMCP(); // Create Mapbox tools const searchPOITool = createTool({ id: 'search-poi', description: 'Find places of a specific category near a location', inputSchema: z.object({ category: z.string(), location: z.array(z.number()).length(2) }), execute: async ({ category, location }) => { return await mcp.callTool('category_search_tool', { category, proximity: { longitude: location[0], latitude: location[1] } }); } }); const getDirectionsTool = createTool({ id: 'get-directions', description: 'Get driving directions with traffic', inputSchema: z.object({ origin: z.array(z.number()).length(2), destination: z.array(z.number()).length(2) }), execute: async ({ origin, destination }) => { return await mcp.callTool('directions_tool', { coordinates: [ { longitude: origin[0], latitude: origin[1] }, { longitude: destination[0], latitude: destination[1] } ], routing_profile: 'mapbox/driving-traffic' }); } }); // Create location agent const locationAgent = new Agent({ id: 'location-agent', name: 'Location Intelligence Agent', instructions: 'You help users find places and plan routes with geospatial tools.', model: 'openai/gpt-5.2', tools: { searchPOITool, getDirectionsTool } }); // Use agent const result = await locationAgent.generate([ { role: 'user', content: 'Find restaurants near Times Square NYC (-73.9857, 40.7484)' } ]); ``` -------------------------------- ### Multi-Environment Setup Prompt Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-devkit-patterns/AGENTS.md This prompt outlines the creation of multiple environments (Dev, Staging, Prod) with distinct configurations for tokens and styles, emphasizing security and optimization. ```text "Create 3 environments: Dev: - Token: all scopes, localhost only - Style: app-dev (debug labels enabled) Staging: - Token: read-only, staging.example.com - Style: app-staging (production-like) Prod: - Token: minimal scopes, example.com - Style: app-prod (optimized)" ``` -------------------------------- ### Install Mapbox Agent Skills for Cursor Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md Install the Mapbox Agent Skills specifically for use with Cursor. ```bash npx skills add mapbox/mapbox-agent-skills -a cursor ``` -------------------------------- ### Install Pods After Podfile Change Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-flutter-patterns/references/platform-setup.md After modifying the Podfile, navigate to the ios directory and run 'pod install' to update dependencies. ```bash cd ios && pod install && cd .. ``` -------------------------------- ### Map Initialization: Mapbox GL JS (After) Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-maplibre-migration/references/api-compatibility.md This example demonstrates initializing a map with Mapbox GL JS. Key differences include the package import, the need for a Mapbox access token, and a Mapbox-specific style URL. ```javascript import mapboxgl from 'mapbox-gl'; import 'mapbox-gl/dist/mapbox-gl.css'; // Add your Mapbox token mapboxgl.accessToken = 'pk.your_mapbox_access_token'; const map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v12', center: [-122.4194, 37.7749], zoom: 12 }); map.on('load', () => { new mapboxgl.Marker() .setLngLat([-122.4194, 37.7749]) .setPopup(new mapboxgl.Popup().setText('San Francisco')) .addTo(map); }); ``` -------------------------------- ### Initialize Map with CDN (No Bundler) Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-web-integration-patterns/references/vanilla.md This pattern is suitable for quick prototyping or simple projects where a bundler is not used. It includes Mapbox GL JS CSS and JS via CDN links in the HTML. For production, it's recommended to use npm and a bundler for better version control and optimization. ```html Mapbox GL JS - No Bundler
``` -------------------------------- ### Skill Structure Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/CONTRIBUTING.md Illustrates a typical skill file structure, including frontmatter for metadata, a main heading, core principles with anti-patterns and solutions, a decision matrix, common scenarios, and reference links. ```markdown # Mapbox [Domain] Skill Expert guidance on [what this covers]. Use this skill when: - [Specific use case 1] - [Specific use case 2] ## Core Principles ### Principle 1: [Name] [Why this matters] **Anti-pattern:** ```javascript // ❌ BAD: [Why this is wrong] code example ``` **Solution:** ```javascript // ✅ GOOD: [Why this is better] code example ``` **Impact:** [Performance gain, UX improvement, etc.] ### Decision Matrix | Scenario | Use Approach A | Use Approach B | | ------------ | -------------- | -------------- | | < 1000 items | ✅ | ❌ | | 1000-10000 | ⚠️ | ✅ | ## Common Scenarios ### Scenario: [Restaurant Finder] [Specific guidance for this use case] ## Reference - [Link to official docs] - [Link to examples] ``` -------------------------------- ### Run All Optimizations Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-style-quality/references/optimization.md Use this command to apply all available optimizations to a style. This is recommended for production deployment. ```javascript optimize_style_tool({ style }) ``` -------------------------------- ### GeoJSON Data Structure Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-store-locator-patterns/AGENTS.md Example of a GeoJSON FeatureCollection for storing location data, including properties like name, address, and category. ```json { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [-77.034084, 38.909671] }, "properties": { "id": "store-001", "name": "Downtown Store", "address": "123 Main St, DC 20001", "phone": "(202) 555-0123", "category": "retail", "hours": "Mon-Sat: 9am-9pm" } } ] } ``` -------------------------------- ### Complete Web Search JS Implementation Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-search-integration/references/web-search-js.md A full example demonstrating how to initialize the SearchSession, integrate with Mapbox GL JS for map display, handle user input for search suggestions, and render custom results. It also shows how to retrieve full details for a selected result and update the map. ```javascript import { SearchSession } from '@mapbox/search-js-core'; import mapboxgl from 'mapbox-gl'; // Initialize search session const search = new SearchSession({ accessToken: 'YOUR_MAPBOX_TOKEN' }); // Initialize map mapboxgl.accessToken = 'YOUR_MAPBOX_TOKEN'; const map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v12', center: [-122.4194, 37.7749], zoom: 12 }); // Your custom search input const searchInput = document.getElementById('search-input'); const resultsContainer = document.getElementById('results'); // Handle user input searchInput.addEventListener('input', async (e) => { const query = e.target.value; if (query.length < 2) { resultsContainer.innerHTML = ''; return; } // Get suggestions (Search JS Core handles debouncing and session tokens) const response = await search.suggest(query, { proximity: map.getCenter().toArray(), country: 'US', // Optional types: ['address', 'poi'] }); // Render custom results UI resultsContainer.innerHTML = response.suggestions .map( (suggestion) => `
${suggestion.name}
${suggestion.place_formatted}
` ) .join(''); }); // Handle result selection resultsContainer.addEventListener('click', async (e) => { const resultItem = e.target.closest('.result-item'); if (!resultItem) return; const mapboxId = resultItem.dataset.id; // Retrieve full details const result = await search.retrieve(mapboxId); const feature = result.features[0]; const [lng, lat] = feature.geometry.coordinates; // Update map map.flyTo({ center: [lng, lat], zoom: 15 }); new mapboxgl.Marker().setLngLat([lng, lat]).addTo(map); // Clear search searchInput.value = feature.properties.name; resultsContainer.innerHTML = ''; }); ``` -------------------------------- ### Initialize Search Engine Core Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-search-integration/references/android-search.md Create an instance of the SearchEngine using SearchEngineSettings, providing your Mapbox access token. The SDK automatically handles debouncing and session tokens. ```kotlin import com.mapbox.search.SearchEngine import com.mapbox.search.SearchEngineSettings // Initialize Search Engine (SDK handles debouncing and session tokens) searchEngine = SearchEngine.createSearchEngine( SearchEngineSettings("YOUR_MAPBOX_TOKEN") ) ``` -------------------------------- ### Benchmarking with Chrome DevTools and Lighthouse Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/examples/web/performance-optimized/README.md Instructions for benchmarking application performance using Chrome DevTools and Lighthouse. Ensure the application is built before running preview commands. ```bash # Chrome DevTools 1. Open DevTools → Performance tab 2. Start recording 3. Reload page 4. Stop after map loads 5. Check metrics: Load time, FPS, Memory # Lighthouse npm run build npm run preview # Run Lighthouse audit ``` -------------------------------- ### Configure Mapbox Access Token Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/examples/web/performance-optimized/README.md Create a .env.local file and add your Mapbox access token to this file. ```bash VITE_MAPBOX_ACCESS_TOKEN=pk.your_token_here ``` -------------------------------- ### Update Packages: Remove MapLibre, Install Mapbox Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-maplibre-migration/SKILL.md Use npm to uninstall the MapLibre GL JS package and install the Mapbox GL JS package. ```bash # Remove MapLibre npm uninstall maplibre-gl # Install Mapbox npm install mapbox-gl ``` -------------------------------- ### Update Package: Uninstall MapLibre, Install Mapbox Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-maplibre-migration/AGENTS.md Remove the MapLibre GL JS package and install the Mapbox GL JS package using npm. ```bash npm uninstall maplibre-gl npm install mapbox-gl ``` -------------------------------- ### Map Initialization: MapLibre GL JS (Before) Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-maplibre-migration/references/api-compatibility.md This example shows how to initialize a map using MapLibre GL JS with OpenStreetMap tiles. Note the specific import and style URL. ```javascript import maplibregl from 'maplibre-gl'; import 'maplibre-gl/dist/maplibre-gl.css'; // No token needed for OSM tiles const map = new maplibregl.Map({ container: 'map', style: 'https://demotiles.maplibre.org/style.json', center: [-122.4194, 37.7749], zoom: 12 }); map.on('load', () => { new maplibregl.Marker() .setLngLat([-122.4194, 37.7749]) .setPopup(new maplibregl.Popup().setText('San Francisco')) .addTo(map); }); ``` -------------------------------- ### Mapbox Search Usage Example Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-search-integration/references/web-search-js.md Demonstrates how to instantiate and use the MapboxSearch class, attach it to an input field, display results, and handle user selection by retrieving full feature details. ```javascript // Usage example const search = new MapboxSearch('YOUR_MAPBOX_TOKEN', { country: 'US', // Based on discovery Question 2 types: 'poi', // Based on discovery Question 1 proximity: [-122.4194, 37.7749] // Or 'ip' for user location }); // Attach to input field const input = document.getElementById('search-input'); const resultsContainer = document.getElementById('search-results'); input.addEventListener('input', (e) => { const query = e.target.value; search.search(query, (results) => { displayResults(results); }); }); function displayResults(results) { resultsContainer.innerHTML = results .map( (result) => `
${result.name}

${result.place_formatted || ''}

` ) .join(''); // Handle result selection resultsContainer.querySelectorAll('.result').forEach((el) => { el.addEventListener('click', async () => { const feature = await search.retrieve(el.dataset.id); handleResultSelection(feature); }); }); } function handleResultSelection(feature) { const [lng, lat] = feature.geometry.coordinates; // Fly map to result map.flyTo({ center: [lng, lat], zoom: 15 }); // Add marker new mapboxgl.Marker().setLngLat([lng, lat]).addTo(map); // Close results resultsContainer.innerHTML = ''; input.value = feature.properties.name; } ``` -------------------------------- ### Run Agent with Complex Query Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/references/smolagents.md Demonstrates how to run an agent with a complex natural language query that includes location, search criteria, and distance calculations. Ensure the agent is properly initialized with necessary tools. ```python result = agent.run( "Find restaurants within 10 minutes walking from Times Square NYC " "(coordinates: -73.9857, 40.7484). Calculate distances to each." ) print(result) ``` -------------------------------- ### Example GeoJSON Feature Structure Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-data-visualization-patterns/AGENTS.md Illustrates the structure of a GeoJSON feature with properties that can be accessed by Mapbox Style expressions. ```json { "type": "Feature", "geometry": { "type": "Point", "coordinates": [-77.0323, 38.9131] // [longitude, latitude] }, "properties": { "magnitude": 7.8, // Custom data property "value": 42, // Another property "category": "coffee" // Can be any data type } } ``` -------------------------------- ### Tool Selection Flowchart Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-search-patterns/SKILL.md A flowchart to guide the selection of the appropriate Mapbox tool based on the user's query. ```text User query contains... -> Specific name/brand (Starbucks, Empire State Building) -> search_and_geocode_tool -> Generic category/plural (coffee shops, museums, any restaurant) -> category_search_tool -> Coordinates -> Address -> reverse_geocode_tool -> Address -> Coordinates -> search_and_geocode_tool with types: ["address"] ``` -------------------------------- ### Get MapboxMap Controller Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-flutter-patterns/SKILL.md Obtain the `MapboxMap` controller via the `onMapCreated` callback to interact with the map after it's initialized. ```dart class MapScreen extends StatefulWidget { const MapScreen({super.key}); @override State createState() => _MapScreenState(); } class _MapScreenState extends State { MapboxMap? mapboxMap; void _onMapCreated(MapboxMap controller) { mapboxMap = controller; } @override Widget build(BuildContext context) { return MapWidget( key: const ValueKey('mapWidget'), onMapCreated: _onMapCreated, cameraOptions: CameraOptions( center: Point(coordinates: Position(-122.4194, 37.7749)), zoom: 12, ), ); } } ``` -------------------------------- ### Initialize Self-Hosted Mapbox MCP Server Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-mcp-runtime-patterns/references/pydantic-ai.md This class provides a basic structure for interacting with a self-hosted Mapbox MCP server using subprocess. It handles server startup and token management. ```python import subprocess class MapboxMCPLocal: def __init__(self, token: str): self.token = token self.mcp_process = subprocess.Popen( ['npx', '@mapbox/mcp-server'], env={'MAPBOX_ACCESS_TOKEN': token}, stdin=subprocess.PIPE, stdout=subprocess.PIPE ) def call_tool(self, tool_name: str, params: dict) -> dict: # ... similar to hosted but via subprocess pass ``` -------------------------------- ### Handle Map Taps Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-ios-patterns/AGENTS.md Observe map tap gestures to get the coordinate of the tap location. Requires Combine framework. ```swift mapView.gestures.onMapTap.observe { [weak self] context in let coordinate = context.coordinate print("Tapped at: \(coordinate)") }.store(in: &cancelables) ``` -------------------------------- ### List Available Mapbox Skills via CLI Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/README.md List all available Mapbox skills using the skills CLI. This command helps in discovering skills that can be installed. ```bash npx skills add mapbox/mapbox-agent-skills --list ``` -------------------------------- ### Get Layer Paint Properties Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-style-patterns/AGENTS.md Retrieves the current paint properties for a specified layer. Useful for inspecting styling values. ```javascript // ✅ Get layer paint properties console.log(map.getPaintProperty('layer', 'fill-color')); ``` -------------------------------- ### React SearchBox Component Source: https://github.com/mapbox/mapbox-agent-skills/blob/main/skills/mapbox-search-integration/references/web-search-js.md Use the SearchBox component in React applications for an integrated autocomplete and map experience. Requires installation of @mapbox/search-js-react. ```jsx import { SearchBox } from '@mapbox/search-js-react'; import mapboxgl from 'mapbox-gl'; function App() { const [map, setMap] = React.useState(null); React.useEffect(() => { mapboxgl.accessToken = 'YOUR_MAPBOX_TOKEN'; const mapInstance = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v12', center: [-122.4194, 37.7749], zoom: 12 }); setMap(mapInstance); }, []); const handleRetrieve = (result) => { const [lng, lat] = result.features[0].geometry.coordinates; map.flyTo({ center: [lng, lat], zoom: 14 }); new mapboxgl.Marker().setLngLat([lng, lat]).addTo(map); }; return (
); } ```