5
5
6
6
namespace HttpContext . Tools ;
7
7
8
- // <snippet_ConstructorParameter>
9
- public class ContextTools
10
- {
11
- private readonly IHttpContextAccessor _httpContextAccessor ;
12
-
13
- public ContextTools ( IHttpContextAccessor httpContextAccessor )
14
- {
15
- _httpContextAccessor = httpContextAccessor ;
16
- }
17
8
18
- // remainder of ContextTools follows
19
- // </snippet_ConstructorParameter>
20
-
21
- // <snippet_AccessHttpContext>
9
+ // <snippet_AccessHttpContext>
10
+ public class ContextTools ( IHttpContextAccessor _httpContextAccessor )
11
+ {
22
12
[ McpServerTool ( UseStructuredContent = true ) ]
23
13
[ Description ( "Retrieves the HTTP headers from the current request and returns them as a JSON object." ) ]
24
14
public object GetHttpHeaders ( )
@@ -40,47 +30,4 @@ public object GetHttpHeaders()
40
30
41
31
return headers ;
42
32
}
43
-
44
- [ McpServerTool ( UseStructuredContent = true ) ]
45
- [ Description ( "Retrieves the request information from the current HTTP context and returns it as structured content." ) ]
46
- public object GetRequestInfo ( )
47
- {
48
- var context = _httpContextAccessor . HttpContext ;
49
- if ( context == null )
50
- {
51
- return new { Error = "No HTTP context available" } ;
52
- }
53
-
54
- var requestInfo = new
55
- {
56
- context . Request . Method ,
57
- Path = context . Request . Path . Value ,
58
- QueryString = context . Request . QueryString . Value ,
59
- context . Request . ContentType ,
60
- UserAgent = context . Request . Headers . UserAgent . ToString ( ) ,
61
- RemoteIpAddress = context . Connection . RemoteIpAddress ? . ToString ( ) ,
62
- context . Request . IsHttps
63
- } ;
64
-
65
- return requestInfo ;
66
- }
67
-
68
- [ McpServerTool ( UseStructuredContent = true ) ]
69
- [ Description ( "Retrieves the user claims from the current HTTP context and returns them as a JSON object." ) ]
70
- public object GetUserClaims ( )
71
- {
72
- var context = _httpContextAccessor . HttpContext ;
73
- if ( context == null )
74
- {
75
- return "No HTTP context available" ;
76
- }
77
-
78
- var claims = context . User . Claims . Select ( c => new
79
- {
80
- c . Type ,
81
- c . Value
82
- } ) . ToList ( ) ;
83
-
84
- return claims ;
85
- }
86
33
}
0 commit comments