Skip to content

Commit cfd3482

Browse files
MCP
1 parent afc1352 commit cfd3482

File tree

5 files changed

+80
-408
lines changed

5 files changed

+80
-408
lines changed

RestClient.Net.McpGenerator/McpToolGenerator.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ public static string GenerateTools(
7878
using System.Text.Json;
7979
using Outcome;
8080
using {{extensionsNamespace}};
81+
using ModelContextProtocol.Server;
8182
8283
namespace {{@namespace}};
8384
8485
/// <summary>MCP server tools for {{serverName}} API.</summary>
85-
public class {{serverName}}Tools(IHttpClientFactory httpClientFactory)
86+
[McpServerToolType]
87+
public static class {{serverName}}Tools
8688
{
8789
private static readonly JsonSerializerOptions JsonOptions = new()
8890
{
@@ -225,13 +227,16 @@ string errorType
225227
var okAlias = $"Ok{responseType}";
226228
var errorAlias = $"Error{responseType}";
227229

230+
var httpClientParam = methodParamsStr.Length > 0 ? "HttpClient httpClient, " : "HttpClient httpClient";
231+
var allParams = httpClientParam + methodParamsStr;
232+
228233
return $$"""
229234
/// <summary>{{SanitizeDescription(summary)}}</summary>
230235
{{paramDescriptions}}
231-
[Description("{{SanitizeDescription(summary)}}")]
232-
public async Task<string> {{toolName}}({{methodParamsStr}})
236+
/// <param name="httpClient">HttpClient instance</param>
237+
[McpServerTool, Description("{{SanitizeDescription(summary)}}")]
238+
public static async Task<string> {{toolName}}({{allParams}})
233239
{
234-
var httpClient = httpClientFactory.CreateClient();
235240
var result = await httpClient.{{extensionMethodName}}({{extensionCallArgsStr}});
236241
237242
return result switch

Samples/NucliaDbClient.McpServer/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
var nucleaBaseUrl =
1717
Environment.GetEnvironmentVariable("NUCLIA_BASE_URL") ?? "http://localhost:8080/api/v1";
1818

19-
// Configure HttpClient with base URL
19+
// Configure default HttpClient with base URL
2020
builder.Services.AddHttpClient(
2121
string.Empty,
2222
client =>
@@ -26,9 +26,6 @@
2626
}
2727
);
2828

29-
// Add the NucliaDB tools to DI
30-
builder.Services.AddSingleton<NucliaDbTools>();
31-
3229
// Add MCP server with stdio transport and tools from assembly
3330
builder.Services.AddMcpServer().WithStdioServerTransport().WithToolsFromAssembly();
3431

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
#!/bin/bash
2-
3-
# Quick run script for the MCP server (assumes NucliaDB is already running)
42
set -e
53

64
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
COMPOSE_DIR="$SCRIPT_DIR/../NucliaDbClient"
76

8-
echo "Starting NucliaDB MCP Server..."
9-
echo "==============================="
10-
echo ""
7+
cd "$COMPOSE_DIR"
8+
docker compose down -v
9+
docker compose up -d
1110

12-
# Check if NucliaDB is running
13-
if ! curl -s -f "http://localhost:8080" > /dev/null 2>&1; then
14-
echo "⚠ Warning: NucliaDB doesn't appear to be running on http://localhost:8080"
15-
echo "Run ./start-mcp-server.sh to start both docker-compose and the MCP server"
16-
echo ""
17-
fi
11+
until curl -s -f "http://localhost:8080" > /dev/null 2>&1; do sleep 1; done
1812

1913
cd "$SCRIPT_DIR"
20-
21-
# Set environment variable for NucliaDB URL
2214
export NUCLIA_BASE_URL="http://localhost:8080/api/v1"
23-
24-
# Run the MCP server
2515
dotnet run
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# Test if MCP server exposes tools correctly
3+
4+
# Send tools/list request to the MCP server
5+
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | \
6+
dotnet run --project /Users/christianfindlay/Documents/Code/RestClient.Net/Samples/NucliaDbClient.McpServer/NucliaDbClient.McpServer.csproj --no-build 2>/dev/null | \
7+
grep -v "^info:" | \
8+
head -20

0 commit comments

Comments
 (0)