Commit 3524e75
refactor(controller): invoke agents directly in MCP handler (#1855)
Replace the HTTP round-trip through the controller's own A2A listener
with direct invocation via a new `AgentClientRegistry`. The registry is
owned by `A2ARegistrar`, which already maintains an `A2AClient` per
agent for its HTTP mux — the registry gives the MCP handler access to
those same clients without an extra network hop.
The old approach routed through the controller's public A2A endpoint,
meaning requests could traverse the external network (and any ingress or
load-balancer in front of it) unnecessarily. The new path stays
in-process.
The old handler also cached its own `A2AClient` per agent in a
`sync.Map` with no eviction, so clients for deleted agents would remain
indefinitely. The registry is kept consistent by the registrar's
add/update/delete lifecycle, eliminating that staleness.
`A2ARegistrar.upsertAgentHandler` writes to both the HTTP mux (for
inbound /api/a2a/<ns>/<name>/ routing) and the registry (for direct
invocation). The registry is exposed via `ClientRegistry()` and passed
to `NewMCPHandler` in app.go.
~Note:~
~- currently includes changes from #1853 as well since this needs to
adjust the tests added in that PR.~
---------
Signed-off-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Eitan Yarmush <eitan.yarmush@solo.io>1 parent 59f5a65 commit 3524e75
5 files changed
Lines changed: 250 additions & 80 deletions
File tree
- go/core
- internal
- a2a
- mcp
- pkg/app
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
56 | 62 | | |
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | | - | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
117 | 123 | | |
118 | 124 | | |
119 | 125 | | |
| 126 | + | |
120 | 127 | | |
121 | 128 | | |
122 | 129 | | |
| |||
182 | 189 | | |
183 | 190 | | |
184 | 191 | | |
185 | | - | |
| 192 | + | |
| 193 | + | |
186 | 194 | | |
187 | 195 | | |
188 | 196 | | |
| 197 | + | |
| 198 | + | |
189 | 199 | | |
190 | 200 | | |
191 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | | - | |
15 | 12 | | |
16 | 13 | | |
17 | 14 | | |
18 | 15 | | |
19 | | - | |
20 | 16 | | |
21 | 17 | | |
22 | | - | |
23 | 18 | | |
24 | 19 | | |
25 | 20 | | |
26 | 21 | | |
27 | 22 | | |
28 | 23 | | |
29 | | - | |
30 | | - | |
| 24 | + | |
31 | 25 | | |
32 | 26 | | |
33 | 27 | | |
34 | | - | |
35 | 28 | | |
36 | 29 | | |
37 | 30 | | |
| |||
58 | 51 | | |
59 | 52 | | |
60 | 53 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
71 | 57 | | |
72 | 58 | | |
73 | | - | |
74 | | - | |
| 59 | + | |
75 | 60 | | |
76 | 61 | | |
77 | 62 | | |
| |||
198 | 183 | | |
199 | 184 | | |
200 | 185 | | |
201 | | - | |
202 | | - | |
203 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
204 | 189 | | |
205 | 190 | | |
206 | 191 | | |
207 | 192 | | |
208 | 193 | | |
209 | 194 | | |
210 | 195 | | |
| 196 | + | |
211 | 197 | | |
212 | | - | |
213 | 198 | | |
214 | 199 | | |
215 | 200 | | |
| |||
219 | 204 | | |
220 | 205 | | |
221 | 206 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
263 | 210 | | |
264 | 211 | | |
265 | 212 | | |
| |||
0 commit comments