Eliminate duplicate code in server HTTP endpoint registration#1186
Merged
Eliminate duplicate code in server HTTP endpoint registration#1186
Conversation
- Replace inline auth conditionals in routed.go with applyAuthIfConfigured helper - Extract registerCommonEndpoints helper to consolidate OAuth, health, and close endpoint registration - Both routed.go and transport.go now use shared helpers, eliminating ~20 lines of duplication Fixes #1160 and #1159 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors internal/server HTTP server setup to remove duplicated endpoint registration and authentication-wrapping logic, keeping routed and unified (streamable HTTP) modes consistent and easier to maintain.
Changes:
- Centralized OAuth discovery,
/health, and/closeregistration into a newregisterCommonEndpoints()helper. - Standardized conditional auth wrapping in routed mode by using the existing
applyAuthIfConfigured()helper.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/server/transport.go | Replaces inlined common endpoint registrations with registerCommonEndpoints() in unified mode. |
| internal/server/routed.go | Uses registerCommonEndpoints() and switches to applyAuthIfConfigured() for per-route auth wrapping. |
| internal/server/handlers.go | Adds registerCommonEndpoints() implementation to register OAuth discovery, health, and close endpoints consistently. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lpcox
added a commit
that referenced
this pull request
Feb 20, 2026
Investigation of smoke test run #22238913503 reveals the Serena MCP test failure is a false negative - the server operates correctly but the Copilot agent cannot discover its tools due to incorrect tool naming. ## Root Cause Serena MCP server initializes successfully: - Loads 40 tools, exposes 23 in 'codex' context (excludes `create_text_file`, `read_file`, `execute_shell_command`, `prepare_for_new_conversation`, `replace_content`) - Auto-configures project, detects Go as primary language (53.2%) - Registers in gateway alongside other MCP servers - Both `activate_project` and `find_symbol` are available in the exposed toolset Agent reports tools unavailable without attempting invocation: ``` rpc safeoutputs→tools/call missing_tool reason: "The Serena MCP server tools (activate_project, find_symbol) are not available" ``` **Issue**: The smoke test referenced tools without the server name prefix (`activate_project`, `find_symbol`), but the Copilot agent framework expects the `server-toolname` pattern for proper tool discovery in routed mode. ## Changes Made Updated `.github/workflows/smoke-copilot.md` to use correct tool naming convention: - Changed `activate_project` → `serena-activate_project` - Changed `find_symbol` → `serena-find_symbol` This matches the naming pattern used by other MCP tools in the workflow (e.g., `safeinputs-gh`, `safeinputs-make`) where tools are prefixed with their MCP server name using hyphens. ## Analysis **Confirmed Working**: - Container launch: `ghcr.io/github/serena-mcp-server:latest` - Server initialization: v0.1.4, process id=1 - Project configuration: `/home/runner/work/gh-aw-mcpg/gh-aw-mcpg/.serena/project.yml` - Gateway registration: Listed in startup logs with 6 total servers **Fixed Issue**: - Tool naming now follows the `server-toolname` convention required by the agent framework for tool discoverability - Recompiled workflow lock file with gh-aw v0.47.4 **Note**: Playwright test failure (network timeout to github.com) is expected due to firewall constraints, not a code issue. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Smoke Test: Copilot - 22238913503</issue_title> > <issue_description>## Smoke Test Results > > | Test | Status | > |------|--------| > | GitHub MCP Testing (last 2 merged PRs) | ✅ | > | Safe Inputs GH CLI Testing | ✅ | > | Serena MCP Testing | ❌ (not available) | > | Make Build Testing | ✅ | > | Playwright Testing | ❌ (network timeout) | > | File Writing Testing | ✅ | > | Bash Tool Testing | ✅ | > | Discussion Interaction Testing | ✅ | > | Agentic Workflows MCP Testing | ✅ | > > **Overall Status: PASS** (7/9 - 2 tests failed due to environment constraints) > > ### Test Details > > - **GitHub MCP**: Found PRs #1186 "Eliminate duplicate code in server HTTP endpoint registration" and #1173 "Addressing PR comments" > - **GH CLI**: Queried PRs successfully (no open PRs) > - **Serena MCP**: ❌ Tools not available in this environment > - **Build**: `make build` succeeded, `awmg` binary created > - **Playwright**: ❌ Network timeout (github.com blocked by firewall) > - **File Writing**: Created `/tmp/gh-aw/agent/smoke-test-copilot-22238913503.txt` > - **Bash**: Verified file contents > - **Discussion**: Got discussion #45, added comment > - **Agentic Workflows**: smoke-copilot workflow is compiled and active (triggers: PR label, reaction, schedule every 12h) > > **Run URL**: https://github.com/github/gh-aw-mcpg/actions/runs/22238913503 > **Timestamp**: 2026-02-20T19:58:14Z > > > > > > 📰 *BREAKING: Report filed by [Smoke Copilot](https://github.com/github/gh-aw-mcpg/actions/runs/22238913503)* > > - [x] expires <!-- gh-aw-expires: 2026-02-20T22:02:03.746Z --> on Feb 20, 2026, 10:02 PM UTC > > <!-- gh-aw-agentic-workflow: Smoke Copilot, engine: copilot, run: https://github.com/github/gh-aw-mcpg/actions/runs/22238913503 --> > > <!-- gh-aw-workflow-id: smoke-copilot --></issue_description> > > <agent_instructions>Try to understand why the serena test is failing</agent_instructions> > > ## Comments on the Issue (you are @claude[agent] in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #1190
lpcox
added a commit
that referenced
this pull request
Feb 20, 2026
- [x] Fix Serena tools configuration in smoke-copilot.md (change nested languages structure to array format) - [x] Recompile smoke-copilot workflow to regenerate lock file - [x] Verify the fix matches working configurations in other workflows - [x] Store memory about correct Serena tool configuration format <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Smoke Test: Copilot - 22243401416</issue_title> > <issue_description>## Smoke Test Results > > | Test | Status | > |------|--------| > | GitHub MCP - Last 2 merged PRs | ✅ PR #1195 "Fix Serena MCP test tool discovery in smoke test workflow", PR #1186 "Eliminate duplicate code in server HTTP endpoint registration" | > | Safe Inputs GH CLI - 2 PRs | ✅ PR #1196 "[WIP] Refactor semantic function clustering for code organization" | > | Serena MCP - activate_project + find_symbol | ❌ Tools not available in this agent context | > | Make Build | ✅ `make build` succeeded, `awmg` binary produced | > | Playwright - github.com title | ✅ Title contains "GitHub" | > | File Writing | ✅ `/tmp/gh-aw/agent/smoke-test-copilot-22243401416.txt` created | > | Bash Tool | ✅ File read back successfully | > | Discussion Interaction | ✅ Comment added to discussion #45 | > | Agentic Workflows MCP Status | ✅ smoke-copilot: compiled=Yes, triggers=PR/reaction/schedule | > > ## Overall Status:⚠️ PARTIAL PASS (8/9 tests passed, Serena tools unavailable) > > **Run URL**: https://github.com/github/gh-aw-mcpg/actions/runs/22243401416 > **Timestamp**: 2026-02-20T22:21 UTC > > > > > > 📰 *BREAKING: Report filed by [Smoke Copilot](https://github.com/github/gh-aw-mcpg/actions/runs/22243401416)* > > - [x] expires <!-- gh-aw-expires: 2026-02-21T00:23:33.836Z --> on Feb 21, 2026, 12:23 AM UTC > > <!-- gh-aw-agentic-workflow: Smoke Copilot, engine: copilot, run: https://github.com/github/gh-aw-mcpg/actions/runs/22243401416 --> > > <!-- gh-aw-workflow-id: smoke-copilot --></issue_description> > > <agent_instructions>Figure out why serena is not passing</agent_instructions> > > ## Comments on the Issue (you are @claude[agent] in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #1198
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The server package contained ~20 lines of duplicated code across
routed.goandtransport.gofor auth middleware application and common HTTP endpoint registration.Changes
Extract
registerCommonEndpoints()helper (handlers.go:87-104)Consolidates OAuth discovery, health check, and close endpoint registration for both routed and unified modes. Previously duplicated across both server creation functions.
Standardize on
applyAuthIfConfigured()helperReplaced inline auth conditionals in
routed.gowith existing helper fromtransport.go. Both modes now use identical auth application logic.Before
After
Changes to shared endpoint behavior now only require updates in one location.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build1821963260/b275/launcher.test /tmp/go-build1821963260/b275/launcher.test -test.testlogfile=/tmp/go-build1821963260/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true v0.12.18/builtin.go v0.12.18/code.go 64/pkg/tool/linux_amd64/compile go1.25.6 -c=4 -nolocalimports 64/pkg/tool/linux_amd64/compile -I g_.a -I cal/bin/as --gdwarf-5 ernal/sys -o ortcfg(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build1821963260/b260/config.test /tmp/go-build1821963260/b260/config.test -test.testlogfile=/tmp/go-build1821963260/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net x5Bl6W7wQ 64/pkg/tool/linux_amd64/vet -p internal/fmtsortrev-parse -lang=go1.25 64/pkg/tool/linuHEAD ortc�� se httptrace/trace.go 64/pkg/tool/linux_amd64/vet -o /dev/null /tmp/cc13LNSQ.s 64/pkg/tool/linux_amd64/vet(dns block)nonexistent.local/tmp/go-build1821963260/b275/launcher.test /tmp/go-build1821963260/b275/launcher.test -test.testlogfile=/tmp/go-build1821963260/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true v0.12.18/builtin.go v0.12.18/code.go 64/pkg/tool/linux_amd64/compile go1.25.6 -c=4 -nolocalimports 64/pkg/tool/linux_amd64/compile -I g_.a -I cal/bin/as --gdwarf-5 ernal/sys -o ortcfg(dns block)slow.example.com/tmp/go-build1821963260/b275/launcher.test /tmp/go-build1821963260/b275/launcher.test -test.testlogfile=/tmp/go-build1821963260/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true v0.12.18/builtin.go v0.12.18/code.go 64/pkg/tool/linux_amd64/compile go1.25.6 -c=4 -nolocalimports 64/pkg/tool/linux_amd64/compile -I g_.a -I cal/bin/as --gdwarf-5 ernal/sys -o ortcfg(dns block)this-host-does-not-exist-12345.com/tmp/go-build1821963260/b284/mcp.test /tmp/go-build1821963260/b284/mcp.test -test.testlogfile=/tmp/go-build1821963260/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true eutil.test 3538032/b048/vet.cfg ortcfg.link --gdwarf-5 --64 -o L8U9Qyx1I3DkwMKxtw/MSkguOXFE0oGgHEAD -uns�� submodules | head -n 10 /tmp/go-build3313538032/b012/vet.cfg g_.a show-toplevel --global(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt