Skip to content

Refactor API handlers into route receivers - #324

Open
danielgaskins wants to merge 1 commit into
mozilla-ai:mainfrom
danielgaskins:refactor/api-route-handlers
Open

danielgaskins wants to merge 1 commit into
mozilla-ai:mainfrom
danielgaskins:refactor/api-route-handlers

Conversation

@danielgaskins

@danielgaskins danielgaskins commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Moves shared API dependencies onto receiver structs. serverRoutes owns the client accessor and tool-call timeout, while healthRoutes owns the health monitor. Handler methods now receive only request-specific inputs, and child route registration uses the same receiver.

The affected tests now construct the receiver types directly.

PR Type

  • New Feature
  • Bug Fix
  • Refactor
  • Documentation
  • Infrastructure / CI

Relevant issues

Fixes #272

Testing

  • go test ./...
  • golangci-lint run --concurrency 2

Checklist

  • I understand the code I am submitting.
  • I have added or updated tests that cover my change.
  • I ran relevant checks locally (make lint, make test).
  • Documentation was updated where necessary.
  • I have read and followed the contribution guidelines.

AI Usage

  • No AI was used.
  • AI was used for drafting/refactoring.
  • This is fully AI-generated.

AI Model/Tool used:

OpenAI Codex

Any additional AI details you'd like to share:

NOTE:
When responding to reviewer questions, please respond yourself rather than copy/pasting reviewer comments into an AI and pasting back its answer. We want to discuss with you, not your AI :)

  • I am an AI Agent filling out this form (check box if true)

Summary by CodeRabbit

  • Refactor

    • Consolidated health, prompt, resource, server and tool route handling into shared route components.
    • Preserved existing health monitoring, prompt, resource, server and tool API behaviour, including tool-call timeout handling.
    • Simplified route registration and internal handling without changing the available functionality.
  • Tests

    • Updated API coverage to use the consolidated route handling.
    • Retained existing scenarios for health, prompts, resources, servers and tools, including error and timeout cases.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 7e7a3868-dc68-482b-b317-8d1a94058c09

📥 Commits

Reviewing files that changed from the base of the PR and between a1b21ff and ab503bb.

📒 Files selected for processing (9)
  • internal/api/health.go
  • internal/api/health_test.go
  • internal/api/prompts.go
  • internal/api/prompts_test.go
  • internal/api/resources.go
  • internal/api/resources_test.go
  • internal/api/servers.go
  • internal/api/servers_test.go
  • internal/api/tools.go

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

The PR refactors internal API handlers into receiver methods. serverRoutes stores the client accessor and tool-call timeout. healthRoutes stores the health monitor. Route registrations and tests now use these receivers.

Changes

Route handler receiver refactor

Layer / File(s) Summary
Route receiver construction and registration
internal/api/servers.go
serverRoutes now stores shared route dependencies. RegisterServerRoutes constructs the receiver and registers server, tool, prompt, and resource routes through it.
Server and tool handler methods
internal/api/servers.go, internal/api/tools.go, internal/api/servers_test.go
Server and tool handlers now read the accessor and timeout from serverRoutes. Tool-call tests configure the timeout on the receiver.
Prompt and resource handler methods
internal/api/prompts.go, internal/api/resources.go, internal/api/prompts_test.go, internal/api/resources_test.go
Prompt and resource handlers and registrations now use serverRoutes methods. Existing test scenarios call the receiver methods.
Health handler receiver
internal/api/health.go, internal/api/health_test.go
Health handlers now use healthRoutes, which stores the health monitor. Health tests use the new route helper.

Suggested reviewers: peteski22

Priority: ⬇️ Low

Change: Refactor

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.98% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 43 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the receiver refactor, identifies the affected dependencies and handlers, links the relevant issue, records testing, selects Refactor, completes the checklist, and documents A…
Title check ✅ Passed The title clearly and concisely describes the main change: moving API handlers into route receiver structs.
Linked Issues check ✅ Passed The PR satisfies #272. serverRoutes stores contracts.MCPClientAccessor and toolCallTimeout. Server, tool, prompt, and resource handlers use receiver methods with per-call inputs only. `RegisterS…
Out of Scope Changes check ✅ Passed The changes stay within #272. Production changes refactor the listed API handlers and route registration. Test changes update handler construction for the new receiver types. No unrelated production b…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor internal/api handlers into a receiver struct to remove pass-through dependencies

1 participant