Skip to content

fix(trails): response.url crash + MCP tool deduplication#2362

Merged
andrew-bierman merged 2 commits into
developmentfrom
fix/osm-trail-p1-followup
May 1, 2026
Merged

fix(trails): response.url crash + MCP tool deduplication#2362
andrew-bierman merged 2 commits into
developmentfrom
fix/osm-trail-p1-followup

Conversation

@andrew-bierman
Copy link
Copy Markdown
Collaborator

Summary

Follow-up fixes for issues found during OSM trail POC review after #2306 merged.

  • response.url crash: POST /api/trails/alltrails-preview returned 502 in all test cases because response.url is an empty string when the Response is constructed directly (test mocks, some CF Worker fetch contexts). Now falls back to parsed.href which is already validated as an alltrails.com URL.
  • MCP duplicate registrations: trails.ts had search_trails, get_trail, and get_trail_geometry each registered twice (once from the OSM DB version, once from the Overpass merge artefact). Removed the duplicates, keeping the cleaner OSM DB parameter names. Also fixed preview_alltrails_url endpoint path (/alltrails/preview/trails/alltrails-preview).

What was already fine (no changes needed)

  • pg_trgm GIN index: already in packages/osm-db/drizzle/0001_osm_schema.sql
  • trips.trail_osm_id index: already in packages/api/drizzle/0037_trips_trail_osm_id.sql
  • drizzle tablesFilter: already in packages/api/drizzle.config.ts

Test plan

  • POST /api/trails/alltrails-preview happy-path tests pass (previously returned 502)
  • MCP server starts without duplicate tool registration errors
  • preview_alltrails_url MCP tool calls the correct route

🤖 Generated with Claude Code

- alltrails-preview: fall back to parsed.href when response.url is empty
  string (occurs in test environments and some CF Worker fetch contexts)
- mcp/trails.ts: remove duplicate search_trails/get_trail/get_trail_geometry
  registrations left from merge; fix preview_alltrails_url endpoint path
  from /alltrails/preview to /trails/alltrails-preview
Copilot AI review requested due to automatic review settings May 1, 2026 02:21
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6190acf4-d350-467a-8102-0e38732ad495

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: String must contain at most 250 character(s) at "tone_instructions"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/osm-trail-p1-followup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the api label May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Coverage Report for API Unit Tests Coverage (./packages/api)

Status Category Percentage Covered / Total
🔵 Lines 72.93% 609 / 835
🔵 Statements 72.93% (🎯 65%) 609 / 835
🔵 Functions 96% 48 / 50
🔵 Branches 88.27% 271 / 307
File CoverageNo changed files found.
Generated in workflow #959 for commit dfa9847 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Coverage Report for Expo Unit Tests Coverage (./apps/expo)

Status Category Percentage Covered / Total
🔵 Lines 81.65% 534 / 654
🔵 Statements 81.65% (🎯 75%) 534 / 654
🔵 Functions 92.98% 53 / 57
🔵 Branches 90.13% 201 / 223
File CoverageNo changed files found.
Generated in workflow #959 for commit dfa9847 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Follow-up fixes to the trails + MCP integration after the OSM trail POC merge, addressing an AllTrails preview response edge case and removing duplicated MCP tool registrations.

Changes:

  • Prevent POST /api/trails/alltrails-preview from returning an empty url by falling back to the already-validated parsed.href when response.url is empty.
  • Remove duplicate MCP tool registrations for trails tools and keep a single canonical registration set.
  • Update the MCP preview_alltrails_url tool to call the correct API route (/trails/alltrails-preview).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/mcp/src/tools/trails.ts Removes duplicated tool registrations and fixes the preview tool’s route path.
packages/api/src/routes/trails/index.ts Fixes AllTrails preview response to avoid empty url values from synthetic Response objects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…clean up tests

- search_trails returns { trails, hasMore } instead of bare array (006)
  LIMIT n+1 trick — caller can page with offset until hasMore is false
- remove POST /trails/alltrails-preview; /alltrails/preview (alltrails.ts)
  is the canonical endpoint (015); MCP tool updated to match
- drop dead alltrails-preview test block from trails.test.ts — covered by
  alltrails.test.ts (012); remove unused afterEach/vi imports
- fix misleading test name: stitching does not write back to DB (014)
@andrew-bierman andrew-bierman merged commit 056a177 into development May 1, 2026
10 checks passed
@andrew-bierman andrew-bierman deleted the fix/osm-trail-p1-followup branch May 1, 2026 03:02
andrew-bierman added a commit that referenced this pull request May 14, 2026
fix(trails): response.url crash + MCP tool deduplication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants