Skip to content

refactor(agent): extract the embedded gateway and mcp composition out of agent.ts - #2034

Merged
Tonours merged 2 commits into
mainfrom
feature/prd-1543-extract-embedded-services
Oct 23, 2026
Merged

Tonours merged 2 commits into
mainfrom
feature/prd-1543-extract-embedded-services

Conversation

@Tonours

@Tonours Tonours commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Moves the embedded Gateway, MCP and API wiring out of Agent into EmbeddedServices. Pure move: no behavior, signature or startup-order change.

fixes PRD-1543

What

File Change
packages/agent/src/embedded-services.ts (new, 350 lines) Owns the MCP/Gateway/API state, the bodies of addGateway, mountAiMcpServer, addBff, plus prepareGateway, setRootHandlers, logGatewayRoutes, warnIfMcpExemptFromIpWhitelist, initializeMcpServer and the alias-mixing messages, copied verbatim
packages/agent/src/agent.ts (915 to 636 lines) Keeps lifecycle, datasource/customization builders, router and schema. The three builder methods keep their signature and JSDoc and delegate

Why

  • agent.ts took a commit on every Gateway ticket (17 in 90 days). Follow-up promised in the R1 review (PRD-1542).
  • FrameworkMounter exposes setMcpCallback, setGatewayCallback, setBffCallback, getInProcessDispatcher as protected, so Agent hands the service late-bound arrows (handler => this.setMcpCallback(handler)), never a method captured with .bind: agent.test.ts spies on setMcpCallback on the instance after construction and must keep seeing the calls.
  • start(), stop() and restart() keep the exact same sequence; only the receiver of each call changes.

How to test

Check Result
yarn workspace @forestadmin/agent test 95 suites, 1994 tests passed
git diff --stat origin/main -- packages/agent/test empty, no test touched
npx tsc --noEmit -p packages/agent clean
npx eslint on both files clean
Trust bench, subject 36294f5 vs baseline e98f1bd (main), embedded agent on a real stack: gateway-alias-mixing (7 addGateway/alias mixes) and gateway-api-rename (cli, bff, gateway, boot mounts) 0 differences over 197 assertions; alias-mixing PASS on both roles; api-rename fails the same 13 assertions on both roles (recipe pins old package versions and fixture tables), so no PR effect
git diff origin/main -- packages/agent/src/index.ts empty, no public export change

Definition of Done

General

  • Write an explicit title for the Pull Request, following Conventional Commits specification
  • Test manually the implemented changes
  • Validate the code quality (indentation, syntax, style, simplicity, readability)

Security

  • Consider the security impact of the changes made

@linear-code

linear-code Bot commented Oct 23, 2026

Copy link
Copy Markdown

PRD-1543

@qltysh

qltysh Bot commented Oct 23, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (2)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/agent/src/agent.ts100.0%
New file Coverage rating: A
packages/agent/src/embedded-services.ts100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@Tonours
Tonours marked this pull request as ready for review October 23, 2026 12:17

@PMerlet PMerlet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved after /validator run 2034-20261023145047-PMerlet: nothing blocking posted, 0 preferential or code style, 0 suppressed below all.

@Tonours
Tonours merged commit 63a6c7f into main Oct 23, 2026
33 checks passed
@Tonours
Tonours deleted the feature/prd-1543-extract-embedded-services branch October 23, 2026 15:27
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.

2 participants