Skip to content

Commit 976c3ac

Browse files
get the mcp up and running
1 parent 4687a05 commit 976c3ac

File tree

4 files changed

+165
-20
lines changed

4 files changed

+165
-20
lines changed

Samples/NucliaDbClient.McpServer/NucliaDbClient.McpServer.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
44
<TargetFramework>net9.0</TargetFramework>
5-
<NoWarn>CA1303;CA2000</NoWarn>
5+
<NoWarn>CA1303;CA2000;CA2007;IDE0005</NoWarn>
66
</PropertyGroup>
77
<ItemGroup>
8+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
89
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
910
<PackageReference Include="ModelContextProtocol" Version="0.4.0-preview.2" />
1011
<PackageReference Include="Urls" Version="1.0.0" />
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Hosting;
3+
using Microsoft.Extensions.Logging;
4+
using ModelContextProtocol.Server;
25
using NucliaDB.Mcp;
36

7+
var builder = Host.CreateApplicationBuilder(args);
8+
9+
// Configure logging to stderr to not interfere with stdio MCP protocol
10+
builder.Logging.AddConsole(consoleLogOptions =>
11+
{
12+
consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;
13+
});
14+
415
// Get the NucliaDB base URL from environment or use default
516
var nucleaBaseUrl =
617
Environment.GetEnvironmentVariable("NUCLIA_BASE_URL") ?? "http://localhost:8080/api/v1";
718

8-
// Create a simple HTTP client factory
9-
var services = new ServiceCollection();
10-
1119
// Configure HttpClient with base URL
12-
services.AddHttpClient(
13-
"default",
20+
builder.Services.AddHttpClient(
21+
string.Empty,
1422
client =>
1523
{
1624
client.BaseAddress = new Uri(nucleaBaseUrl);
@@ -19,13 +27,13 @@
1927
);
2028

2129
// Add the NucliaDB tools to DI
22-
services.AddSingleton<NucliaDbTools>();
23-
24-
var serviceProvider = services.BuildServiceProvider();
30+
builder.Services.AddSingleton<NucliaDbTools>();
2531

26-
// TODO: Wire up MCP server when ModelContextProtocol API stabilizes
27-
Console.WriteLine("NucliaDB MCP Server - MCP tools generated successfully!");
28-
Console.WriteLine($"Configured for NucliaDB at: {nucleaBaseUrl}");
29-
Console.WriteLine("Ready to integrate with ModelContextProtocol when API is stable.");
32+
// Add MCP server with stdio transport and tools from assembly
33+
builder.Services
34+
.AddMcpServer()
35+
.WithStdioServerTransport()
36+
.WithToolsFromAssembly();
3037

31-
await Task.CompletedTask.ConfigureAwait(false);
38+
var host = builder.Build();
39+
await host.RunAsync();

Samples/NucliaDbClient.McpServer/run-for-claude.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,41 @@
33
# Add the NucliaDB MCP server to Claude Code
44
# This allows Claude Code to interact with NucliaDB via the Model Context Protocol
55

6+
set -e
7+
68
# Get the absolute path to the project directory
79
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
810
PROJECT_PATH="$SCRIPT_DIR/NucliaDbClient.McpServer.csproj"
911

12+
# Find the dotnet executable
13+
DOTNET_PATH=$(which dotnet)
14+
15+
echo "Configuring NucliaDB MCP server for Claude Code..."
16+
echo " Script directory: $SCRIPT_DIR"
17+
echo " Project path: $PROJECT_PATH"
18+
echo " Dotnet path: $DOTNET_PATH"
19+
echo ""
20+
1021
# Add the MCP server to Claude Code configuration
11-
claude mcp add nuclia-db dotnet run --project "$PROJECT_PATH" --env NUCLIA_BASE_URL=http://localhost:8080/api/v1
22+
# The command structure is: claude mcp add [options] <name> [--env KEY=value] -- <command> [args...]
23+
claude mcp add --transport stdio nucliadb-mcp --env NUCLIA_BASE_URL=http://localhost:8080/api/v1 -- "$DOTNET_PATH" run --project "$PROJECT_PATH" --no-build
1224

13-
echo "NucliaDB MCP server added to Claude Code!"
1425
echo ""
15-
echo "Make sure NucliaDB is running before using the MCP tools:"
16-
echo " cd $SCRIPT_DIR && ./start-mcp-server.sh"
26+
echo "✓ NucliaDB MCP server added to Claude Code!"
27+
echo ""
28+
echo "Next steps:"
29+
echo " 1. Make sure NucliaDB is running:"
30+
echo " cd $SCRIPT_DIR && docker-compose up -d"
31+
echo ""
32+
echo " 2. Verify the MCP server is configured:"
33+
echo " claude mcp list"
34+
echo ""
35+
echo " 3. Test the connection:"
36+
echo " The server should appear as 'nucliadb-mcp' with a ✓ or ✗ status"
1737
echo ""
18-
echo "You can verify the server is configured by running:"
19-
echo " claude-code mcp list"
38+
echo "Available MCP tools:"
39+
echo " - Knowledge box management (get, create, delete)"
40+
echo " - Search (full-text, semantic, catalog)"
41+
echo " - Ask (question-answering)"
42+
echo " - Resources (CRUD operations)"
43+
echo " - And 100+ more NucliaDB API operations!"

0 commit comments

Comments
 (0)