(ctx context.Context, req mcp.CallToolRequest)
| 141 | } |
| 142 | |
| 143 | func (i *imlMcpModule) APIs(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 144 | serviceId, _ := req.GetArguments()["service"].(string) |
| 145 | if serviceId == "" { |
| 146 | return nil, fmt.Errorf("service id is empty") |
| 147 | } |
| 148 | s, err := i.serviceService.Get(ctx, serviceId) |
| 149 | if err != nil { |
| 150 | return nil, fmt.Errorf("get service error: %w,service id is %s", err, serviceId) |
| 151 | } |
| 152 | appId := utils.Label(ctx, "app") |
| 153 | if appId != "" { |
| 154 | subscribers, err := i.subscriberService.ListByApplication(ctx, serviceId, appId) |
| 155 | if err != nil { |
| 156 | return nil, fmt.Errorf("get subscriber error: %w,app id is %s", err, appId) |
| 157 | } |
| 158 | if len(subscribers) < 1 || subscribers[0].ApplyStatus != subscribe.ApplyStatusSubscribe { |
| 159 | return nil, fmt.Errorf("no subscriber found,app id is %s", appId) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | serviceRelease, err := i.releaseService.GetRunning(ctx, serviceId) |
| 164 | if err != nil { |
| 165 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 166 | return nil, fmt.Errorf("get service release error: %w,service id is %s", err, s.Id) |
| 167 | } |
| 168 | return nil, fmt.Errorf("no service found,service id is %s", serviceId) |
| 169 | } |
| 170 | _, _, apiDocRelease, _, _, err := i.releaseService.GetReleaseInfos(ctx, serviceRelease.UUID) |
| 171 | if err != nil { |
| 172 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 173 | return nil, fmt.Errorf("get service release info error: %w,service id is %s", err, s.Id) |
| 174 | } |
| 175 | return nil, fmt.Errorf("no service found,service id is %s", serviceId) |
| 176 | } |
| 177 | commit, err := i.apiDocService.GetDocCommit(ctx, apiDocRelease.Commit) |
| 178 | if err != nil { |
| 179 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 180 | return nil, fmt.Errorf("get api doc release error: %w,service id is %s", err, s.Id) |
| 181 | } |
| 182 | return nil, fmt.Errorf("no service found,service id is %s", serviceId) |
| 183 | } |
| 184 | T, err := openapi3Loader.LoadFromData([]byte(commit.Data.Content)) |
| 185 | if err != nil { |
| 186 | return nil, fmt.Errorf("load openapi3 error: %w,service id is %s", err, s.Id) |
| 187 | } |
| 188 | |
| 189 | result := &mcp_dto.ServiceAPI{ |
| 190 | ServiceID: serviceId, |
| 191 | ServiceName: s.Name, |
| 192 | APIDoc: T, |
| 193 | } |
| 194 | data, _ := json.Marshal(result) |
| 195 | return mcp.NewToolResultText(string(data)), nil |
| 196 | } |
| 197 | |
| 198 | var ( |
| 199 | client = &http.Client{} |
nothing calls this directly
no test coverage detected