Initialize cs-mic-mcp project with core structure and dependencies
This commit is contained in:
parent
c90b220f82
commit
309407133c
13 changed files with 308 additions and 0 deletions
15
src/.idea/.idea.cs-mic-mcp/.idea/.gitignore
generated
vendored
Normal file
15
src/.idea/.idea.cs-mic-mcp/.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/.idea.cs-mic-mcp.iml
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
4
src/.idea/.idea.cs-mic-mcp/.idea/encodings.xml
generated
Normal file
4
src/.idea/.idea.cs-mic-mcp/.idea/encodings.xml
generated
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
src/.idea/.idea.cs-mic-mcp/.idea/indexLayout.xml
generated
Normal file
8
src/.idea/.idea.cs-mic-mcp/.idea/indexLayout.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
src/.idea/.idea.cs-mic-mcp/.idea/misc.xml
generated
Normal file
6
src/.idea/.idea.cs-mic-mcp/.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="2710000" />
|
||||
</component>
|
||||
</project>
|
||||
6
src/.idea/.idea.cs-mic-mcp/.idea/vcs.xml
generated
Normal file
6
src/.idea/.idea.cs-mic-mcp/.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
16
src/cs-mic-mcp.sln
Normal file
16
src/cs-mic-mcp.sln
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs-mic-mcp", "cs-mic-mcp\cs-mic-mcp.csproj", "{09B4A809-D9D3-445C-977B-0FDA6E903F03}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{09B4A809-D9D3-445C-977B-0FDA6E903F03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{09B4A809-D9D3-445C-977B-0FDA6E903F03}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{09B4A809-D9D3-445C-977B-0FDA6E903F03}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{09B4A809-D9D3-445C-977B-0FDA6E903F03}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
55
src/cs-mic-mcp/Program.cs
Normal file
55
src/cs-mic-mcp/Program.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using cs_mic_mcp.Resources;
|
||||
using cs_mic_mcp.Tools;
|
||||
|
||||
namespace cs_mic_mcp;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services
|
||||
.AddMcpServer()
|
||||
//.WithStdioServerTransport()
|
||||
.WithHttpTransport()
|
||||
.WithTools<MathTools>()
|
||||
.WithResources<DocumentationResources>();
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddDefaultPolicy(policy =>
|
||||
{
|
||||
policy
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.WithExposedHeaders("Mcp-Session-Id");
|
||||
});
|
||||
});
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
//builder.Services.AddControllers();
|
||||
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
//builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseCors();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
//app.MapOpenApi();
|
||||
}
|
||||
|
||||
//app.UseAuthorization();
|
||||
|
||||
|
||||
//app.MapControllers();
|
||||
app.MapMcp("/mcp");
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
14
src/cs-mic-mcp/Properties/launchSettings.json
Normal file
14
src/cs-mic-mcp/Properties/launchSettings.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5017",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/cs-mic-mcp/Resources/DocumentationResources.cs
Normal file
29
src/cs-mic-mcp/Resources/DocumentationResources.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System.ComponentModel;
|
||||
using cs_mic_mcp.Tools;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace cs_mic_mcp.Resources;
|
||||
|
||||
/// <summary>
|
||||
/// Provides resources related to documentation for the cs-mic-mcp application.
|
||||
/// Includes methods for accessing function references supported by the cs-mic expression parser.
|
||||
/// </summary>
|
||||
[McpServerResourceType]
|
||||
public class DocumentationResources
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves a formatted list of functions supported by the cs-mic expression parser.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A string containing function names and their expected arguments, formatted as lines of text.
|
||||
/// </returns>
|
||||
[McpServerResource]
|
||||
[Description("Reference for functions supported by cs-mic expressions.")]
|
||||
public static string GetFunctions()
|
||||
{
|
||||
var functions = string.Join(Environment.NewLine,
|
||||
MathTools.standardLibraryFunctions.Select(MathTools.PrintFunctionInfo));
|
||||
|
||||
return functions;
|
||||
}
|
||||
}
|
||||
120
src/cs-mic-mcp/Tools/MathTools.cs
Normal file
120
src/cs-mic-mcp/Tools/MathTools.cs
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using ModelContextProtocol.Server;
|
||||
using CSMic;
|
||||
using CapyKit.Extensions;
|
||||
|
||||
namespace cs_mic_mcp.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// Provides tools for evaluating mathematical expressions and searching for supported functions.
|
||||
/// This class interacts with the cs-mic expression parser to perform deterministic evaluations
|
||||
/// and function searches. It is designed to be used as part of the McpServer infrastructure.
|
||||
/// </summary>
|
||||
[McpServerToolType]
|
||||
public class MathTools
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of standard library functions supported by the cs-mic expression parser.
|
||||
/// These functions represent instances of <see cref="ICodedFunction"/> and are dynamically
|
||||
/// determined at runtime by inspecting the relevant assembly for compatible types. The collection
|
||||
/// is intended to provide the list of mathematical or computational functions available for use
|
||||
/// when evaluating expressions or searching for specific operations.
|
||||
/// </summary>
|
||||
internal static IEnumerable<ICodedFunction> standardLibraryFunctions;
|
||||
|
||||
/// <summary>
|
||||
/// Provides tools for evaluating mathematical expressions and searching for available mathematical
|
||||
/// functions using the cs-mic expression parser library. This class is intended to simplify tasks
|
||||
/// related to mathematical computations and function discovery.
|
||||
/// </summary>
|
||||
static MathTools()
|
||||
{
|
||||
MathTools.standardLibraryFunctions = typeof(CSMic.StandardLibrary.Initializer).Assembly
|
||||
.GetTypes()
|
||||
.Where(type => !type.IsAbstract && typeof(ICodedFunction).IsAssignableFrom(type))
|
||||
.Select(Activator.CreateInstance)
|
||||
.OfType<ICodedFunction>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates a mathematical expression deterministically using the cs-mic expression parser.
|
||||
/// This method computes the result of the expression and returns it as a string.
|
||||
/// </summary>
|
||||
/// <param name="expression">
|
||||
/// A string containing the mathematical expression to be evaluated.
|
||||
/// The expression should conform to the syntax and function definitions supported by the cs-mic library.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A string representing the result of the evaluated expression. If the result is a numeric value,
|
||||
/// it is formatted using the invariant culture.
|
||||
/// </returns>
|
||||
[McpServerTool]
|
||||
[Description(
|
||||
"Evaluate mathematical expressions deterministically using cs-mic, an expression parser. Use this tool instead of calculating arithmetic operations yourself. See the cs-mic function reference resource for supported functions.")]
|
||||
public static string Calculate(string expression)
|
||||
{
|
||||
var inputInterpreter = new InputInterpreter();
|
||||
CSMic.StandardLibrary.Initializer.InitializeAll(inputInterpreter);
|
||||
inputInterpreter.Interpret(expression);
|
||||
var result =
|
||||
inputInterpreter.StringValue.IfNullOrWhiteSpace(
|
||||
inputInterpreter.NumericValue.ToString(CultureInfo.InvariantCulture));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches for mathematical functions that match the provided expression within the cs-mic standard library.
|
||||
/// This method allows users to determine whether a function exists and understand its syntax or arguments.
|
||||
/// </summary>
|
||||
/// <param name="expression">
|
||||
/// A string representing the search term. It can match either the function name or any of its expected argument names,
|
||||
/// and the comparison is case-insensitive.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of strings, each providing information about a matching function, including its name
|
||||
/// and expected arguments.
|
||||
/// </returns>
|
||||
[McpServerTool]
|
||||
[Description(
|
||||
"Search the functions supported by cs-mic. Use this when you need to know whether a mathematical function exists or what syntax it uses. If the search expression is empty, all functions are returned.")]
|
||||
public static IEnumerable<string> Search(string expression)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(expression))
|
||||
{
|
||||
foreach (var function in MathTools.standardLibraryFunctions)
|
||||
{
|
||||
yield return PrintFunctionInfo(function);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
expression = expression.ToLower().Trim();
|
||||
foreach (var function in MathTools.standardLibraryFunctions.Where(f =>
|
||||
f.Name.Contains(expression, StringComparison.InvariantCultureIgnoreCase) ||
|
||||
f.ExpectedArguments.Any(ea =>
|
||||
ea.Name.Contains(expression, StringComparison.InvariantCultureIgnoreCase))))
|
||||
{
|
||||
yield return PrintFunctionInfo(function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a string representation of a mathematical function, including its name and expected arguments.
|
||||
/// The output describes the function in a readable format, where the function name is followed by a list of
|
||||
/// argument names if applicable.
|
||||
/// </summary>
|
||||
/// <param name="function">
|
||||
/// An object representing the mathematical function whose details are to be formatted. The function should include
|
||||
/// its name and a collection of expected arguments.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A string containing the function name followed by its expected arguments, separated by commas. If the function
|
||||
/// has no arguments, the string will only contain the function name.
|
||||
/// </returns>
|
||||
internal static string PrintFunctionInfo(ICodedFunction function)
|
||||
{
|
||||
return $"{function.Name}({string.Join(", ", function.ExpectedArguments.Select(ea => ea.Name))})";
|
||||
}
|
||||
}
|
||||
8
src/cs-mic-mcp/appsettings.Development.json
Normal file
8
src/cs-mic-mcp/appsettings.Development.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/cs-mic-mcp/appsettings.json
Normal file
9
src/cs-mic-mcp/appsettings.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
18
src/cs-mic-mcp/cs-mic-mcp.csproj
Normal file
18
src/cs-mic-mcp/cs-mic-mcp.csproj
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>cs_mic_mcp</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CapyKit" Version="1.0.4" />
|
||||
<PackageReference Include="CSMic" Version="2.1.0" />
|
||||
<PackageReference Include="CSMic.StandardLibrary" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.10" />
|
||||
<PackageReference Include="ModelContextProtocol.AspNetCore" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in a new issue