MCPServerCSharp

MCPServerCSharp

🚀 使用 C# 和 Firebird 的 MCP 服务器

本项目是一个支持自定义工具的 Modular Command Platform (MCP) 服务器,采用 C# 编写。其一大特色功能是能够在 Firebird 数据库中执行动态查询,同时支持过滤和记录限制。

🚀 快速开始

本项目是一个支持自定义工具的 Modular Command Platform (MCP) 服务器,由 C# 编写而成。借助它,你可以在 Firebird 数据库中执行动态查询,并进行过滤和记录限制。

✨ 主要特性

  • 支持在 Firebird 数据库中执行动态查询。
  • 可对查询结果进行过滤和记录限制。
  • 支持自定义工具。

📦 安装指南

⚙️ 安装依赖项

使用以下命令安装 NuGet 包:

dotnet add package ModelContextProtocol --prerelease

🔧 appsettings.json 文件

在项目根目录中创建一个 appsettings.json 文件,并添加以下内容:

{
"ConnectionStrings": {
"FirebirdDb": "Database=C:\\你的数据文件名.fdb;User=SYSDBA;Password=masterkey;Dialect=3;Charset=NONE;"
}
}

📝 请根据你的数据库文件的实际路径修改 C:\\你的数据文件名.fdb

📂 推荐的项目结构如下:

src/
├── MCPServer/
│ ├── Factory/
│ │ └── FbConnectionFactory.cs
│ ├── Tools/
│ │ └── FbQueries.cs
│ ├── Program.cs
│ └── appsettings.json

💻 使用示例

🔍 ListTable

[McpTool, Description("列出 Firebird 表中的所有记录")]
public Liststring, object>> ListTable(string tableName, string filter = "", int limitRecords = 0)

此工具可以从 Firebird 数据库表中返回记录,支持以下功能:

  • 🔍 条件过滤(通过 SQL)
  • 🔢 记录数限制(使用 FIRST

{DF1F6239-E983-45A0-87E3-645291A6D2C7}

基础用法

{
"tool": "ListTable",
"args": {
"tableName": "CUSTOMERS",
"filter": "STATUS = 'ACTIVE'",
"limitRecords": 10
}
}

🔧 技术细节

📦 所用技术

  • NPX
  • C# (.NET 9 框架)
  • MCP(Modular Command Platform)
  • FirebirdSql.Data.FirebirdClient
  • 依赖注入(通过 Host.CreateApplicationBuilder 实现)
  • 配置文件(通过 appsettings.json 实现)

🏡 运行 MCP 服务器

使用以下命令运行 MCP 服务器:

npx @modelcontextprotocol/inspector dotnet run

{58D6C0FD-B032-48FC-9F16-8769A9403E82}

  • 0 关注
  • 0 收藏,18 浏览
  • system 提出于 2025-09-23 13:57

相似服务问题

相关AI产品