From d02dfb92e92d44c0ae18e0a69148794835aa594d Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sun, 8 Mar 2026 15:46:02 -0400 Subject: [PATCH] feat: scaffold OpenNest.Mcp project with session state Co-Authored-By: Claude Opus 4.6 --- OpenNest.Mcp/NestSession.cs | 61 ++++++++++++++++++++++++++++++++ OpenNest.Mcp/OpenNest.Mcp.csproj | 18 ++++++++++ OpenNest.Mcp/Program.cs | 15 ++++++++ OpenNest.sln | 14 ++++++++ 4 files changed, 108 insertions(+) create mode 100644 OpenNest.Mcp/NestSession.cs create mode 100644 OpenNest.Mcp/OpenNest.Mcp.csproj create mode 100644 OpenNest.Mcp/Program.cs diff --git a/OpenNest.Mcp/NestSession.cs b/OpenNest.Mcp/NestSession.cs new file mode 100644 index 0000000..2dbd993 --- /dev/null +++ b/OpenNest.Mcp/NestSession.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; + +namespace OpenNest.Mcp +{ + public class NestSession + { + public Nest Nest { get; set; } + public List Plates { get; } = new(); + public List Drawings { get; } = new(); + + public Plate GetPlate(int index) + { + if (Nest != null && index < Nest.Plates.Count) + return Nest.Plates[index]; + + var adjustedIndex = index - (Nest?.Plates.Count ?? 0); + if (adjustedIndex >= 0 && adjustedIndex < Plates.Count) + return Plates[adjustedIndex]; + + return null; + } + + public Drawing GetDrawing(string name) + { + if (Nest != null) + { + foreach (var d in Nest.Drawings) + { + if (d.Name == name) + return d; + } + } + + foreach (var d in Drawings) + { + if (d.Name == name) + return d; + } + + return null; + } + + public List AllPlates() + { + var all = new List(); + if (Nest != null) + all.AddRange(Nest.Plates); + all.AddRange(Plates); + return all; + } + + public List AllDrawings() + { + var all = new List(); + if (Nest != null) + all.AddRange(Nest.Drawings); + all.AddRange(Drawings); + return all; + } + } +} diff --git a/OpenNest.Mcp/OpenNest.Mcp.csproj b/OpenNest.Mcp/OpenNest.Mcp.csproj new file mode 100644 index 0000000..c99afd8 --- /dev/null +++ b/OpenNest.Mcp/OpenNest.Mcp.csproj @@ -0,0 +1,18 @@ + + + + Exe + net8.0-windows + OpenNest.Mcp + OpenNest.Mcp + + + + + + + + + + + diff --git a/OpenNest.Mcp/Program.cs b/OpenNest.Mcp/Program.cs new file mode 100644 index 0000000..c924f9f --- /dev/null +++ b/OpenNest.Mcp/Program.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using ModelContextProtocol.Server; +using OpenNest.Mcp; + +var builder = Host.CreateApplicationBuilder(args); + +builder.Services.AddSingleton(); +builder.Services + .AddMcpServer() + .WithStdioServerTransport() + .WithToolsFromAssembly(typeof(Program).Assembly); + +var app = builder.Build(); +await app.RunAsync(); diff --git a/OpenNest.sln b/OpenNest.sln index 6972af1..42a267c 100644 --- a/OpenNest.sln +++ b/OpenNest.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenNest.Gpu", "OpenNest.Gp EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenNest.IO", "OpenNest.IO\OpenNest.IO.csproj", "{1EFCF5FB-7ADE-4044-B55D-60F6F75C3A8B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenNest.Mcp", "OpenNest.Mcp\OpenNest.Mcp.csproj", "{61CC6F65-8B70-408A-B49A-F4E5F34FFD01}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -83,6 +85,18 @@ Global {1EFCF5FB-7ADE-4044-B55D-60F6F75C3A8B}.Release|x64.Build.0 = Release|Any CPU {1EFCF5FB-7ADE-4044-B55D-60F6F75C3A8B}.Release|x86.ActiveCfg = Release|Any CPU {1EFCF5FB-7ADE-4044-B55D-60F6F75C3A8B}.Release|x86.Build.0 = Release|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Debug|x64.ActiveCfg = Debug|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Debug|x64.Build.0 = Debug|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Debug|x86.ActiveCfg = Debug|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Debug|x86.Build.0 = Debug|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Release|Any CPU.Build.0 = Release|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Release|x64.ActiveCfg = Release|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Release|x64.Build.0 = Release|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Release|x86.ActiveCfg = Release|Any CPU + {61CC6F65-8B70-408A-B49A-F4E5F34FFD01}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE