| 174 | } |
| 175 | |
| 176 | func CompletionsHandler(getClient GetClientFn) func(ctx context.Context, req *mcp.CompleteRequest) (*mcp.CompleteResult, error) { |
| 177 | return func(ctx context.Context, req *mcp.CompleteRequest) (*mcp.CompleteResult, error) { |
| 178 | if req == nil || req.Params == nil || req.Params.Ref == nil { |
| 179 | return nil, fmt.Errorf("missing required parameter: ref") |
| 180 | } |
| 181 | switch req.Params.Ref.Type { |
| 182 | case "ref/resource": |
| 183 | if strings.HasPrefix(req.Params.Ref.URI, "repo://") { |
| 184 | return RepositoryResourceCompletionHandler(getClient)(ctx, req) |
| 185 | } |
| 186 | return nil, fmt.Errorf("unsupported resource URI: %s", req.Params.Ref.URI) |
| 187 | case "ref/prompt": |
| 188 | return nil, nil |
| 189 | default: |
| 190 | return nil, fmt.Errorf("unsupported ref type: %s", req.Params.Ref.Type) |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | func MarshalledTextResult(v any) *mcp.CallToolResult { |
| 196 | data, err := json.Marshal(v) |