-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Pass Mapbox state to the MCP to provide context #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,16 +2,16 @@ import { createStreamableUI } from 'ai/rsc' | |||||
| import { retrieveTool } from './retrieve' | ||||||
| import { searchTool } from './search' | ||||||
| import { videoSearchTool } from './video-search' | ||||||
| import { geospatialTool } from './geospatial' // Removed useGeospatialToolMcp import | ||||||
| import { geospatialTool } from './geospatial' | ||||||
| import { MapData } from '@/components/map/map-data-context' | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import MapData as a type to avoid bundling a client module on the server MapData is declared in a 'use client' file under components. Importing it as a value risks pulling a client-only module (and its deps like mapbox-gl) into server bundles. Use a type-only import, or better, move the type to a shared, non-client module (e.g., lib/types/map.ts) and import from there. Apply the minimal fix: -import { MapData } from '@/components/map/map-data-context'
+import type { MapData } from '@/components/map/map-data-context'Longer-term, extract MapData into a server-safe shared types module (e.g., lib/types/map.ts) and update all imports in lib/* to reference that instead of a client component file. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| export interface ToolProps { | ||||||
| uiStream: ReturnType<typeof createStreamableUI> | ||||||
| fullResponse: string | ||||||
| // mcp?: any; // Removed mcp property as it's no longer passed down for geospatialTool | ||||||
| mapData?: MapData | ||||||
| } | ||||||
|
|
||||||
| // Removed mcp from parameters | ||||||
| export const getTools = ({ uiStream, fullResponse }: ToolProps) => { | ||||||
| export const getTools = ({ uiStream, fullResponse, mapData }: ToolProps) => { | ||||||
| const tools: any = { | ||||||
| search: searchTool({ | ||||||
| uiStream, | ||||||
|
|
@@ -21,10 +21,9 @@ export const getTools = ({ uiStream, fullResponse }: ToolProps) => { | |||||
| uiStream, | ||||||
| fullResponse | ||||||
| }), | ||||||
| // geospatialTool now only requires uiStream | ||||||
| geospatialQueryTool: geospatialTool({ | ||||||
| uiStream | ||||||
| // mcp: mcp || null // Removed mcp argument | ||||||
| uiStream, | ||||||
| mapData | ||||||
| }) | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untrusted JSON.parse on client-provided map_data can crash the action
map_data comes from the browser. A malformed payload will throw and break the request. Wrap in try/catch and default to undefined.
Apply this defensive parsing:
Optional follow-up: avoid including the raw map_data blob in the persisted user message content (JSON.stringify(Object.fromEntries(formData))) to prevent inflating message history and storage. Instead, construct the user-visible content from a filtered copy of FormData that excludes map_data. I can provide a patch if you want that change now.
📝 Committable suggestion
🤖 Prompt for AI Agents