using System; using System.Text; using System.Text.Json; using System.Net.Http; using System.Threading.Tasks; namespace TestMcpClient { public class McpResponse { public string? jsonrpc { get; set; } public string? id { get; set; } public McpErrorBody? error { get; set; } public McpResult? result { get; set; } } public class McpErrorBody { public int? code { get; set; } public string? message { get; set; } } public class McpResult { public McpContentItem[]? content { get; set; } } public class McpContentItem { public string type { get; set; } = string.Empty; public string? text { get; set; } public string? data { get; set; } } class Program { static async Task Main(string[] args) { var client = new HttpClient(); var request = new { jsonrpc = "2.0", id = "test-1", method = "tools/call", @params = new { name = "extract_pid_tags", arguments = new { text = "P-10107-500A-F1A-H100 Pump", source_type = "dxf" } } }; var json = JsonSerializer.Serialize(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); using var httpRequest = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5001/mcp") { Content = content }; httpRequest.Headers.Add("Accept", "application/json"); httpRequest.Headers.Add("mcp-protocol-version", "2025-03-26"); var response = await client.SendAsync(httpRequest); Console.WriteLine($"Status: {response.StatusCode}"); if (response.IsSuccessStatusCode) { var body = await response.Content.ReadAsStringAsync(); Console.WriteLine($"\nResponse body (first 500 chars):\n{body.Substring(0, Math.Min(500, body.Length))}"); var result = JsonSerializer.Deserialize(body, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); Console.WriteLine($"\nDeserialized successfully!"); Console.WriteLine($"result: {result?.result != null}"); Console.WriteLine($"result.content: {result?.result?.content?.Length ?? 0}"); if (result?.result?.content != null) { var sb = new StringBuilder(); foreach (var item in result.result.content) { Console.WriteLine($" content item: type={item.type}, text length={item.text?.Length ?? 0}"); if (item.type == "text") sb.AppendLine(item.text); } Console.WriteLine($"\nExtracted text:\n{sb.ToString()}"); } } } } }