This commit is contained in:
38
docs/snippets/csharp/mcp/mcp_custom_client.md
Normal file
38
docs/snippets/csharp/mcp/mcp_custom_client.md
Normal file
@@ -0,0 +1,38 @@
|
||||
<!-- snippet:syntax-only -->
|
||||
|
||||
```csharp title="C#"
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
|
||||
var processInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "kreuzberg",
|
||||
Arguments = "mcp",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
|
||||
using var process = Process.Start(processInfo)
|
||||
?? throw new InvalidOperationException("Failed to start kreuzberg mcp");
|
||||
|
||||
var request = new
|
||||
{
|
||||
method = "tools/call",
|
||||
@params = new
|
||||
{
|
||||
name = "extract_file",
|
||||
arguments = new { path = "document.pdf" },
|
||||
},
|
||||
};
|
||||
|
||||
await process.StandardInput.WriteLineAsync(JsonSerializer.Serialize(request));
|
||||
await process.StandardInput.FlushAsync();
|
||||
|
||||
var line = await process.StandardOutput.ReadLineAsync();
|
||||
Console.WriteLine(line);
|
||||
|
||||
process.StandardInput.Close();
|
||||
await process.WaitForExitAsync();
|
||||
```
|
||||
Reference in New Issue
Block a user