@@ -31,6 +31,38 @@ type graphCommInfo struct {
3131 Cohesion float64 `json:"cohesion"`
3232}
3333
34+ // listFlowsResponse holds the listFlows wire payload.
35+ // @intent preserve the legacy listFlows response shape with typed fields.
36+ type listFlowsResponse struct {
37+ Flows []graphFlowInfo `json:"flows"`
38+ DerivedState map [string ]any `json:"derived_state"`
39+ Pagination map [string ]any `json:"pagination"`
40+ }
41+
42+ // listCommunitiesResponse holds the listCommunities wire payload.
43+ // @intent preserve the legacy listCommunities response shape with typed fields.
44+ type listCommunitiesResponse struct {
45+ Communities []graphCommInfo `json:"communities"`
46+ DerivedState map [string ]any `json:"derived_state"`
47+ Pagination map [string ]any `json:"pagination"`
48+ }
49+
50+ // communityMemberSummary is a typed member entry for getCommunity.
51+ // @intent preserve the legacy community member shape with typed fields.
52+ type communityMemberSummary = nodeSummary
53+
54+ // getCommunityResponse holds the getCommunity wire payload.
55+ // @intent preserve the legacy getCommunity response shape with typed fields.
56+ type getCommunityResponse struct {
57+ ID uint `json:"id"`
58+ Label string `json:"label"`
59+ NodeCount int64 `json:"node_count"`
60+ DerivedState map [string ]any `json:"derived_state"`
61+ Coverage * float64 `json:"coverage,omitempty"`
62+ Members []communityMemberSummary `json:"members,omitempty"`
63+ MembersPagination map [string ]any `json:"members_pagination,omitempty"`
64+ }
65+
3466// archCommCount is a helper struct for counting community nodes in architecture overview.
3567// @intent support community node counting in getArchitectureOverview without polluting model.Community.
3668type archCommCount struct {
@@ -39,6 +71,34 @@ type archCommCount struct {
3971 NodeCount int64
4072}
4173
74+ // architectureOverviewCommunity is a typed community entry for architecture overview.
75+ // @intent preserve the legacy communities item shape with typed fields.
76+ type architectureOverviewCommunity struct {
77+ ID uint `json:"id"`
78+ Label string `json:"label"`
79+ NodeCount int64 `json:"node_count"`
80+ }
81+
82+ // architectureOverviewCoupling is a typed coupling entry for architecture overview.
83+ // @intent preserve the legacy coupling item shape with typed fields.
84+ type architectureOverviewCoupling struct {
85+ From string `json:"from"`
86+ To string `json:"to"`
87+ EdgeCount int64 `json:"edge_count"`
88+ Strength float64 `json:"strength"`
89+ }
90+
91+ // architectureOverviewResponse holds the architecture overview wire payload.
92+ // @intent preserve the legacy architecture overview response shape with typed fields.
93+ type architectureOverviewResponse struct {
94+ Communities []architectureOverviewCommunity `json:"communities"`
95+ CommunitiesPagination map [string ]any `json:"communities_pagination"`
96+ Coupling []architectureOverviewCoupling `json:"coupling"`
97+ CouplingPagination map [string ]any `json:"coupling_pagination"`
98+ Warnings []string `json:"warnings"`
99+ DerivedState map [string ]any `json:"derived_state"`
100+ }
101+
42102// communityRow is a helper struct for counting community nodes in listCommunities.
43103// @intent support community node counting in listCommunities without polluting model.Community.
44104type communityRow struct {
@@ -119,10 +179,10 @@ func (h *handlers) listFlows(ctx context.Context, request mcp.CallToolRequest) (
119179 }
120180 }
121181
122- result , err := marshalJSON (map [ string ] any {
123- "flows" : infos ,
124- "derived_state" : derivedStateFlows (),
125- "pagination" : buildPaginationMetadata (limit , offset , len (infos ), hasMore ),
182+ result , err := marshalJSON (listFlowsResponse {
183+ Flows : infos ,
184+ DerivedState : derivedStateFlows (),
185+ Pagination : buildPaginationMetadata (limit , offset , len (infos ), hasMore ),
126186 })
127187 if err != nil {
128188 return "" , trace .Wrap (err , "marshal result" )
@@ -192,10 +252,10 @@ func (h *handlers) listCommunities(ctx context.Context, request mcp.CallToolRequ
192252 }
193253 }
194254
195- result , err := marshalJSON (map [ string ] any {
196- "communities" : infos ,
197- "derived_state" : derivedStateCommunities (),
198- "pagination" : buildPaginationMetadata (limit , offset , len (infos ), hasMore ),
255+ result , err := marshalJSON (listCommunitiesResponse {
256+ Communities : infos ,
257+ DerivedState : derivedStateCommunities (),
258+ Pagination : buildPaginationMetadata (limit , offset , len (infos ), hasMore ),
199259 })
200260 if err != nil {
201261 return "" , trace .Wrap (err , "marshal result" )
@@ -247,17 +307,18 @@ func (h *handlers) getCommunity(ctx context.Context, request mcp.CallToolRequest
247307 return "" , trace .Wrap (err , "count community members" )
248308 }
249309
250- gcData := map [ string ] any {
251- "id" : comm .ID ,
252- "label" : comm .Label ,
253- "node_count" : memberCount ,
254- "derived_state" : derivedStateCommunities (),
310+ gcData := getCommunityResponse {
311+ ID : comm .ID ,
312+ Label : comm .Label ,
313+ NodeCount : memberCount ,
314+ DerivedState : derivedStateCommunities (),
255315 }
256316
257317 if h .deps .CoverageAnalyzer != nil {
258318 cc , err := h .deps .CoverageAnalyzer .ByCommunity (ctx , comm .ID )
259319 if err == nil && cc != nil {
260- gcData ["coverage" ] = cc .Ratio
320+ coverage := cc .Ratio
321+ gcData .Coverage = & coverage
261322 }
262323 }
263324
@@ -284,12 +345,12 @@ func (h *handlers) getCommunity(ctx context.Context, request mcp.CallToolRequest
284345 nodes = nodes [:memberLimit ]
285346 }
286347
287- members := make ([]map [ string ] any , len (nodes ))
348+ members := make ([]communityMemberSummary , len (nodes ))
288349 for i , n := range nodes {
289- members [i ] = nodeToBasicMap (n )
350+ members [i ] = nodeToSummary (n )
290351 }
291- gcData [ "members" ] = members
292- gcData [ "members_pagination" ] = buildPaginationMetadata (memberLimit , memberOffset , len (members ), hasMore )
352+ gcData . Members = members
353+ gcData . MembersPagination = buildPaginationMetadata (memberLimit , memberOffset , len (members ), hasMore )
293354 }
294355
295356 result , err := marshalJSON (gcData )
@@ -355,16 +416,12 @@ func (h *handlers) getArchitectureOverview(ctx context.Context, request mcp.Call
355416 archCCRows = archCCRows [:communityLimit ]
356417 }
357418
358- commInfos := make ([]map [ string ] any , len (archCCRows ))
419+ commInfos := make ([]architectureOverviewCommunity , len (archCCRows ))
359420 for i , c := range archCCRows {
360- commInfos [i ] = map [string ]any {
361- "id" : c .ID ,
362- "label" : c .Label ,
363- "node_count" : c .NodeCount ,
364- }
421+ commInfos [i ] = architectureOverviewCommunity {ID : c .ID , Label : c .Label , NodeCount : c .NodeCount }
365422 }
366423
367- couplingPairs := []map [ string ] any {}
424+ couplingPairs := []architectureOverviewCoupling {}
368425 warnings := []string {}
369426 if len (archCCRows ) == 0 {
370427 warnings = []string {"No communities found. Run community rebuild first." }
@@ -375,12 +432,7 @@ func (h *handlers) getArchitectureOverview(ctx context.Context, request mcp.Call
375432 page , err := h .deps .CouplingAnalyzer .AnalyzePage (ctx , paging.Request {Limit : couplingLimit , Offset : couplingOffset })
376433 if err == nil {
377434 for _ , cp := range page .Items {
378- couplingPairs = append (couplingPairs , map [string ]any {
379- "from" : cp .FromCommunity ,
380- "to" : cp .ToCommunity ,
381- "edge_count" : cp .EdgeCount ,
382- "strength" : cp .Strength ,
383- })
435+ couplingPairs = append (couplingPairs , architectureOverviewCoupling {From : cp .FromCommunity , To : cp .ToCommunity , EdgeCount : cp .EdgeCount , Strength : cp .Strength })
384436 if cp .Strength > 0.8 {
385437 warnings = append (warnings , fmt .Sprintf ("High coupling between %s and %s (strength: %.2f)" , cp .FromCommunity , cp .ToCommunity , cp .Strength ))
386438 }
@@ -389,13 +441,13 @@ func (h *handlers) getArchitectureOverview(ctx context.Context, request mcp.Call
389441 }
390442 }
391443
392- result , err := marshalJSON (map [ string ] any {
393- "communities" : commInfos ,
394- "communities_pagination" : buildPaginationMetadata (communityLimit , communityOffset , len (commInfos ), communityHasMore ),
395- "coupling" : couplingPairs ,
396- "coupling_pagination" : buildPaginationMetadata (couplingLimit , couplingOffset , len (couplingPairs ), couplingHasMore ),
397- "warnings" : warnings ,
398- "derived_state" : derivedStateSummary (),
444+ result , err := marshalJSON (architectureOverviewResponse {
445+ Communities : commInfos ,
446+ CommunitiesPagination : buildPaginationMetadata (communityLimit , communityOffset , len (commInfos ), communityHasMore ),
447+ Coupling : couplingPairs ,
448+ CouplingPagination : buildPaginationMetadata (couplingLimit , couplingOffset , len (couplingPairs ), couplingHasMore ),
449+ Warnings : warnings ,
450+ DerivedState : derivedStateSummary (),
399451 })
400452 if err != nil {
401453 return "" , trace .Wrap (err , "marshal result" )
0 commit comments