1
- use std:: collections:: HashMap ;
2
-
3
1
use apollo_compiler:: ast:: { FragmentDefinition , Selection } ;
4
2
use apollo_compiler:: {
5
3
Name , Node , Schema as GraphqlSchema ,
6
4
ast:: { Definition , OperationDefinition , Type } ,
7
5
parser:: Parser ,
8
6
} ;
7
+ use regex:: Regex ;
9
8
use rmcp:: {
10
9
model:: Tool ,
11
10
schemars:: schema:: {
@@ -16,6 +15,7 @@ use rmcp::{
16
15
} ;
17
16
use rover_copy:: pq_manifest:: ApolloPersistedQueryManifest ;
18
17
use serde:: Serialize ;
18
+ use std:: collections:: HashMap ;
19
19
20
20
use crate :: errors:: { McpError , OperationError } ;
21
21
use crate :: graphql;
@@ -152,14 +152,8 @@ impl Operation {
152
152
fragment_defs : & [ & Node < FragmentDefinition > ] ,
153
153
) -> String {
154
154
let comment_description = comments. and_then ( |comments| {
155
- // TODO: there is probably a better way to do this with a regex, but I couldn't figure it out. So here is a crude version
156
- let formatted = comments
157
- . split ( "\n " )
158
- . map ( |line| line. trim ( ) )
159
- . collect :: < Vec < _ > > ( )
160
- . join ( "\n " )
161
- . replace ( "\n #" , "\n " ) ;
162
- let trimmed = formatted. trim ( ) ;
155
+ let content = Regex :: new ( r"(\n|^)\s*#" ) . ok ( ) ?. replace_all ( comments, "$1" ) ;
156
+ let trimmed = content. trim ( ) ;
163
157
164
158
if trimmed. is_empty ( ) {
165
159
None
@@ -1376,6 +1370,52 @@ mod tests {
1376
1370
) ;
1377
1371
}
1378
1372
1373
+ #[ test]
1374
+ fn tool_comment_description ( ) {
1375
+ let operation = Operation :: from_document (
1376
+ r###"
1377
+ # Overridden tool #description
1378
+ query GetABZ($state: String!) {
1379
+ b {
1380
+ d {
1381
+ f
1382
+ }
1383
+ }
1384
+ }
1385
+ "### ,
1386
+ & SCHEMA ,
1387
+ None ,
1388
+ )
1389
+ . unwrap ( ) ;
1390
+
1391
+ insta:: assert_snapshot!(
1392
+ operation. tool. description. as_ref( ) ,
1393
+ @r###"Overridden tool #description"###
1394
+ ) ;
1395
+ }
1396
+
1397
+ #[ test]
1398
+ fn tool_empty_comment_description ( ) {
1399
+ let operation = Operation :: from_document (
1400
+ r###"
1401
+ #
1402
+
1403
+ #
1404
+ query GetABZ($state: String!) {
1405
+ id
1406
+ }
1407
+ "### ,
1408
+ & SCHEMA ,
1409
+ None ,
1410
+ )
1411
+ . unwrap ( ) ;
1412
+
1413
+ insta:: assert_snapshot!(
1414
+ operation. tool. description. as_ref( ) ,
1415
+ @r###"The returned value is optional and has type `String`"###
1416
+ ) ;
1417
+ }
1418
+
1379
1419
#[ test]
1380
1420
fn it_extracts_operations_from_apollo_pq_manifest ( ) {
1381
1421
// The inner types needed to construct one of these are not exported,
0 commit comments