(ctx context.Context, req mcp.CallToolRequest)
| 63 | } |
| 64 | |
| 65 | func (i *imlMcpModule) Services(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 66 | |
| 67 | keyword, _ := req.GetArguments()["keyword"].(string) |
| 68 | appId := utils.Label(ctx, "app") |
| 69 | condition := map[string]interface{}{ |
| 70 | "as_server": true, |
| 71 | } |
| 72 | if appId != "" { |
| 73 | serviceIds, err := i.subscribeServiceIds(ctx, appId) |
| 74 | if err != nil { |
| 75 | return nil, fmt.Errorf("get subscriber service ids error: %w,app id is %s", err, appId) |
| 76 | } |
| 77 | condition["uuid"] = serviceIds |
| 78 | } |
| 79 | |
| 80 | list, err := i.serviceService.Search(ctx, keyword, condition, "update_at desc") |
| 81 | if err != nil { |
| 82 | return nil, fmt.Errorf("search service error: %w", err) |
| 83 | } |
| 84 | if len(list) == 0 { |
| 85 | list, err = i.serviceService.Search(ctx, "", condition, "update_at desc") |
| 86 | if err != nil { |
| 87 | return nil, fmt.Errorf("search service error: %w", err) |
| 88 | } |
| 89 | } |
| 90 | result := make([]*mcp_dto.Service, 0, len(list)) |
| 91 | for _, s := range list { |
| 92 | serviceRelease, err := i.releaseService.GetRunning(ctx, s.Id) |
| 93 | if err != nil { |
| 94 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 95 | return nil, fmt.Errorf("get service release error: %w,service id is %s", err, s.Id) |
| 96 | } |
| 97 | continue |
| 98 | } |
| 99 | _, _, apiDocRelease, _, _, err := i.releaseService.GetReleaseInfos(ctx, serviceRelease.UUID) |
| 100 | if err != nil { |
| 101 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 102 | return nil, fmt.Errorf("get service release info error: %w,service id is %s", err, s.Id) |
| 103 | } |
| 104 | continue |
| 105 | } |
| 106 | commit, err := i.apiDocService.GetDocCommit(ctx, apiDocRelease.Commit) |
| 107 | if err != nil { |
| 108 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 109 | return nil, fmt.Errorf("get api doc release error: %w,service id is %s", err, s.Id) |
| 110 | } |
| 111 | continue |
| 112 | } |
| 113 | T, err := openapi3Loader.LoadFromData([]byte(commit.Data.Content)) |
| 114 | if err != nil { |
| 115 | return nil, fmt.Errorf("load openapi3 error: %w,service id is %s", err, s.Id) |
| 116 | } |
| 117 | apis := make([]*mcp_dto.API, 0, len(T.Paths.Map())) |
| 118 | for path, v := range T.Paths.Map() { |
| 119 | for method, opt := range v.Operations() { |
| 120 | apis = append(apis, &mcp_dto.API{ |
| 121 | Name: opt.Summary, |
| 122 | Method: method, |
nothing calls this directly
no test coverage detected