This commit is contained in:
52
docs/snippets/csharp/mcp_custom_client.md
Normal file
52
docs/snippets/csharp/mcp_custom_client.md
Normal file
@@ -0,0 +1,52 @@
|
||||
```csharp title="C#"
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
var processInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "kreuzberg",
|
||||
Arguments = "mcp",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true
|
||||
};
|
||||
|
||||
var process = Process.Start(processInfo);
|
||||
|
||||
var clientInput = process.StandardInput;
|
||||
var clientOutput = process.StandardOutput;
|
||||
|
||||
// Initialize session by sending initialize request
|
||||
var initRequest = new
|
||||
{
|
||||
jsonrpc = "2.0",
|
||||
id = 1,
|
||||
method = "initialize",
|
||||
parameters = new { }
|
||||
};
|
||||
|
||||
await clientInput.WriteLineAsync(System.Text.Json.JsonSerializer.Serialize(initRequest));
|
||||
await clientInput.FlushAsync();
|
||||
|
||||
var initResponse = await clientOutput.ReadLineAsync();
|
||||
Console.WriteLine($"Init response: {initResponse}");
|
||||
|
||||
// List available tools
|
||||
var listRequest = new
|
||||
{
|
||||
jsonrpc = "2.0",
|
||||
id = 2,
|
||||
method = "tools/list"
|
||||
};
|
||||
|
||||
await clientInput.WriteLineAsync(System.Text.Json.JsonSerializer.Serialize(listRequest));
|
||||
await clientInput.FlushAsync();
|
||||
|
||||
var listResponse = await clientOutput.ReadLineAsync();
|
||||
Console.WriteLine($"Available tools: {listResponse}");
|
||||
|
||||
process?.WaitForExit();
|
||||
```
|
||||
Reference in New Issue
Block a user