diff --git a/docs-mcp/README.md b/docs-mcp/README.md index 716f82fd7..97b9a71b4 100644 --- a/docs-mcp/README.md +++ b/docs-mcp/README.md @@ -34,6 +34,21 @@ Alternatively, you can add a `.vscode/mcp.json` file to your workspace: } ``` +You can also add the `--database` parameter with a path to the database file to use: + +```json +{ + "servers": { + "duende-mcp": { + "type": "stdio", + "command": "dnx", + "args": ["Duende.Documentation.Mcp", "--yes", "--", "--database", "/path/to/database.db"], + "env": {} + } + } +} +``` + Open GitHub Copilot and select Agent Mode to work with the MCP server. ### JetBrains Rider @@ -64,6 +79,19 @@ Set the working directory to a path on your machine where the Duende Documentati index. Not setting the working directory will result in the MCP server failing to start because it cannot create the database file. +Alternatively, you can add the `--database` parameter with a path to the database file to use: + +```json +{ + "mcpServers": { + "duende-mcp": { + "command": "dnx", + "args": ["Duende.Documentation.Mcp", "--yes", "--", "--database", "/path/to/database.db"] + } + } +} +``` + ## Tools and Example Prompts The Duende Documentation MCP Server has several tools available: diff --git a/docs-mcp/src/Documentation.Mcp/Program.cs b/docs-mcp/src/Documentation.Mcp/Program.cs index 1dc172c04..e4b44d675 100644 --- a/docs-mcp/src/Documentation.Mcp/Program.cs +++ b/docs-mcp/src/Documentation.Mcp/Program.cs @@ -20,9 +20,24 @@ builder.Logging.AddConsole(consoleLogOptions => consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace; }); +// Determine database path +var databasePath = "mcp.db"; +if (args.Length > 0) +{ + var dbParameterIndex = args.IndexOf("--database"); + if (dbParameterIndex >= 0 && args.Length > dbParameterIndex + 1) + { + var dbPathParameter = args[dbParameterIndex + 1].Replace("\"", "", StringComparison.OrdinalIgnoreCase); + if (Path.IsPathFullyQualified(dbPathParameter)) + { + databasePath = dbPathParameter; + } + } +} + // Setup services builder.Services.AddHttpClient(); -builder.Services.AddSqlite("Data Source=mcp.db;Cache=Shared"); +builder.Services.AddSqlite("Data Source=" + databasePath + ";Cache=Shared"); builder.Services.AddHostedService(); builder.Services.AddHostedService(); @@ -73,6 +88,8 @@ async Task EnsureDb(IServiceProvider services, ILogger logger) await using var db = scope.ServiceProvider.GetRequiredService(); if (db.Database.IsRelational()) { + logger.LogInformation("Using database: {DatabasePath}", databasePath); + logger.LogInformation("Updating database..."); await db.Database.MigrateAsync(); logger.LogInformation("Updated database");