-
Notifications
You must be signed in to change notification settings - Fork 678
Expand file tree
/
Copy pathContextTools.cs
More file actions
28 lines (24 loc) · 821 Bytes
/
ContextTools.cs
File metadata and controls
28 lines (24 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using ModelContextProtocol.Server;
using System.ComponentModel;
namespace HttpContext.Tools;
// <snippet_AccessHttpContext>
public class ContextTools(IHttpContextAccessor httpContextAccessor)
{
[McpServerTool(UseStructuredContent = true)]
[Description("Retrieves the HTTP headers from the current request and returns them as a JSON object.")]
public object GetHttpHeaders()
{
var context = httpContextAccessor.HttpContext;
if (context == null)
{
return "No HTTP context available";
}
var headers = new Dictionary<string, string>();
foreach (var header in context.Request.Headers)
{
headers[header.Key] = string.Join(", ", header.Value.ToArray());
}
return headers;
}
// </snippet_AccessHttpContext>
}