1- import { Injectable , Inject , UseGuards } from '@nestjs/common' ;
1+ import { Injectable , Inject } from '@nestjs/common' ;
22import { Tool } from '@tc/mcp-nest' ;
33import { REQUEST } from '@nestjs/core' ;
44import { QUERY_CHALLENGES_TOOL_PARAMETERS } from './queryChallenges.parameters' ;
55import { TopcoderChallengesService } from 'src/shared/topcoder/challenges.service' ;
66import { Logger } from 'src/shared/global' ;
77import { QUERY_CHALLENGES_TOOL_OUTPUT_SCHEMA } from './queryChallenges.output' ;
8- import { AuthGuard } from 'src/core/auth/guards' ;
8+ import {
9+ authGuard ,
10+ checkHasUserRole ,
11+ checkM2MScope ,
12+ } from 'src/core/auth/guards' ;
13+ import { M2mScope , Role } from 'src/core/auth/auth.constants' ;
914
1015@Injectable ( )
1116export class QueryChallengesTool {
@@ -16,19 +21,7 @@ export class QueryChallengesTool {
1621 @Inject ( REQUEST ) private readonly request : any ,
1722 ) { }
1823
19- @Tool ( {
20- name : 'query-tc-challenges' ,
21- description :
22- 'Returns a list of public Topcoder challenges based on the query parameters.' ,
23- parameters : QUERY_CHALLENGES_TOOL_PARAMETERS ,
24- outputSchema : QUERY_CHALLENGES_TOOL_OUTPUT_SCHEMA ,
25- annotations : {
26- title : 'Query Public Topcoder Challenges' ,
27- readOnlyHint : true ,
28- } ,
29- } )
30- @UseGuards ( AuthGuard )
31- async queryChallenges ( params ) {
24+ private async _queryChallenges ( params ) {
3225 // Validate the input parameters
3326 const validatedParams = QUERY_CHALLENGES_TOOL_PARAMETERS . safeParse ( params ) ;
3427 if ( ! validatedParams . success ) {
@@ -127,4 +120,67 @@ export class QueryChallengesTool {
127120 } ;
128121 }
129122 }
123+
124+ @Tool ( {
125+ name : 'query-tc-challenges-private' ,
126+ description :
127+ 'Returns a list of public Topcoder challenges based on the query parameters.' ,
128+ parameters : QUERY_CHALLENGES_TOOL_PARAMETERS ,
129+ outputSchema : QUERY_CHALLENGES_TOOL_OUTPUT_SCHEMA ,
130+ annotations : {
131+ title : 'Query Public Topcoder Challenges' ,
132+ readOnlyHint : true ,
133+ } ,
134+ canActivate : authGuard ,
135+ } )
136+ async queryChallengesPrivate ( params ) {
137+ return this . _queryChallenges ( params ) ;
138+ }
139+
140+ @Tool ( {
141+ name : 'query-tc-challenges-protected' ,
142+ description :
143+ 'Returns a list of public Topcoder challenges based on the query parameters.' ,
144+ parameters : QUERY_CHALLENGES_TOOL_PARAMETERS ,
145+ outputSchema : QUERY_CHALLENGES_TOOL_OUTPUT_SCHEMA ,
146+ annotations : {
147+ title : 'Query Public Topcoder Challenges' ,
148+ readOnlyHint : true ,
149+ } ,
150+ canActivate : checkHasUserRole ( Role . Admin ) ,
151+ } )
152+ async queryChallengesProtected ( params ) {
153+ return this . _queryChallenges ( params ) ;
154+ }
155+
156+ @Tool ( {
157+ name : 'query-tc-challenges-m2m' ,
158+ description :
159+ 'Returns a list of public Topcoder challenges based on the query parameters.' ,
160+ parameters : QUERY_CHALLENGES_TOOL_PARAMETERS ,
161+ outputSchema : QUERY_CHALLENGES_TOOL_OUTPUT_SCHEMA ,
162+ annotations : {
163+ title : 'Query Public Topcoder Challenges' ,
164+ readOnlyHint : true ,
165+ } ,
166+ canActivate : checkM2MScope ( M2mScope . QueryPublicChallenges ) ,
167+ } )
168+ async queryChallengesM2m ( params ) {
169+ return this . _queryChallenges ( params ) ;
170+ }
171+
172+ @Tool ( {
173+ name : 'query-tc-challenges-public' ,
174+ description :
175+ 'Returns a list of public Topcoder challenges based on the query parameters.' ,
176+ parameters : QUERY_CHALLENGES_TOOL_PARAMETERS ,
177+ outputSchema : QUERY_CHALLENGES_TOOL_OUTPUT_SCHEMA ,
178+ annotations : {
179+ title : 'Query Public Topcoder Challenges' ,
180+ readOnlyHint : true ,
181+ } ,
182+ } )
183+ async queryChallengesPublic ( params ) {
184+ return this . _queryChallenges ( params ) ;
185+ }
130186}
0 commit comments