feat: scaffold OpenNest.Mcp project with session state

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 15:46:02 -04:00
parent a9af5effc5
commit d02dfb92e9
4 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
using System.Collections.Generic;
namespace OpenNest.Mcp
{
public class NestSession
{
public Nest Nest { get; set; }
public List<Plate> Plates { get; } = new();
public List<Drawing> 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<Plate> AllPlates()
{
var all = new List<Plate>();
if (Nest != null)
all.AddRange(Nest.Plates);
all.AddRange(Plates);
return all;
}
public List<Drawing> AllDrawings()
{
var all = new List<Drawing>();
if (Nest != null)
all.AddRange(Nest.Drawings);
all.AddRange(Drawings);
return all;
}
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>OpenNest.Mcp</RootNamespace>
<AssemblyName>OpenNest.Mcp</AssemblyName>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OpenNest.Core\OpenNest.Core.csproj" />
<ProjectReference Include="..\OpenNest.Engine\OpenNest.Engine.csproj" />
<ProjectReference Include="..\OpenNest.IO\OpenNest.IO.csproj" />
<PackageReference Include="ModelContextProtocol" Version="0.*-*" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.*" />
</ItemGroup>
</Project>

15
OpenNest.Mcp/Program.cs Normal file
View File

@@ -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<NestSession>();
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithToolsFromAssembly(typeof(Program).Assembly);
var app = builder.Build();
await app.RunAsync();

View File

@@ -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