| 1 | using System.Text; |
| 2 | using System.Text.Encodings.Web; |
| 3 | using System.Text.Json; |
| 4 | using System.Text.Json.Serialization; |
| 5 | using WebcamCaptureMcp; |
| 6 | using ExportMcpManifest; |
| 7 | using McpToolManifest; |
| 8 | using Tool = ModelContextProtocol.Protocol.Tool; |
| 9 | |
| 10 | var tools = ToolCatalog.Build(); |
| 11 | var cliArgs = Environment.GetCommandLineArgs().Skip(1).ToArray(); |
| 12 | |
| 13 | if (cliArgs.Contains("--write", StringComparer.Ordinal)) |
| 14 | { |
| 15 | var root = Directory.GetCurrentDirectory(); |
| 16 | var jsonPath = Path.Combine(root, "mcp-tools.manifest.json"); |
| 17 | var mdDir = Path.Combine(root, "docs"); |
| 18 | var mdPath = Path.Combine(mdDir, "MCP-TOOLS.md"); |
| 19 | Directory.CreateDirectory(mdDir); |
| 20 | |
| 21 | WriteJsonFile(jsonPath, tools); |
| 22 | var md = McpToolsDocMarkdown.Build(tools.Select(t => (t.Name!, t.Description!))); |
| 23 | File.WriteAllText(mdPath, md, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); |
| 24 | |
| 25 | Console.Error.WriteLine($"Wrote {jsonPath}"); |
| 26 | Console.Error.WriteLine($"Wrote {mdPath}"); |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | if (cliArgs.Contains("--md-only", StringComparer.Ordinal)) |
| 31 | { |
| 32 | Console.WriteLine(McpToolsDocMarkdown.Build(tools.Select(t => (t.Name!, t.Description!))).TrimEnd()); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | var doc = new McpToolManifestDocument |
| 37 | { |
| 38 | SchemaVersion = 1, |
| 39 | McpId = "webcam-capture-mcp", |
| 40 | Title = "Webcam Capture MCP", |
| 41 | Tools = tools.Select(t => new McpToolManifestTool { Name = t.Name, Description = t.Description }).ToList() |
| 42 | }; |
| 43 | |
| 44 | Console.WriteLine(JsonSerializer.Serialize(doc, new JsonSerializerOptions |
| 45 | { |
| 46 | WriteIndented = true, |
| 47 | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, |
| 48 | Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping |
| 49 | })); |
| 50 | |
| 51 | static void WriteJsonFile(string path, List<Tool> tools) |
| 52 | { |
| 53 | var doc = new McpToolManifestDocument |
| 54 | { |
| 55 | SchemaVersion = 1, |
| 56 | McpId = "webcam-capture-mcp", |
| 57 | Title = "Webcam Capture MCP", |
| 58 | Tools = tools.Select(t => new McpToolManifestTool { Name = t.Name, Description = t.Description }).ToList() |
| 59 | }; |
| 60 | |
| 61 | File.WriteAllText( |
| 62 | path, |
| 63 | JsonSerializer.Serialize(doc, new JsonSerializerOptions |
| 64 | { |
| 65 | WriteIndented = true, |
| 66 | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, |
| 67 | Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping |
| 68 | }) + Environment.NewLine, |
| 69 | new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); |
| 70 | } |
| 71 | |