API施工估算
使用构建的用于施工估算管理的RESTful API后端。NET核心9.0和实体框架核心。此演示应用程序提供了用于管理客户端、估算和发票的完整CRUD操作。
特性
- 客户管理 -创建和管理客户信息
- 估算管理 -通过状态跟踪生成和跟踪施工估算
- 发票管理 -创建与估算关联的发票或独立发票
- MCP服务器 -通过模型上下文协议进行自然语言交互的AI集成
- SQLite数据库 -轻量级的基于文件的数据库,易于设置
- Swagger用户界面 -交互式API文档和测试界面
- RESTful设计 -清晰直观的API端点
- 样品数据 -自动播种演示数据以供测试
技术栈
- .NET Core 9.0 -现代跨平台框架
- 实体框架核心9.0 -ORM用于数据库操作
- SQLite -嵌入式数据库
- Swagger/OpenAPI -API文件
- 清洁建筑 -将关注点与核心层、数据层和API层分离
项目结构
ConstructionEstimation/
├── src/
│ ├── ConstructionEstimation.Api/ # Web API project
│ │ ├── Controllers/ # API controllers
│ │ ├── Program.cs # Application entry point
│ │ └── appsettings.json # Configuration
│ ├── ConstructionEstimation.Core/ # Domain models
│ │ └── Models/ # Client, Estimate, Invoice
│ ├── ConstructionEstimation.Data/ # Data access layer
│ │ ├── AppDbContext.cs # EF Core context
│ │ └── DbSeeder.cs # Sample data seeder
│ └── ConstructionEstimation.McpServer/ # MCP server for AI integration
│ ├── Tools/ # MCP tool implementations
│ └── Program.cs # MCP server entry point
└── ConstructionEstimation.sln # Solution file入门指南
先决条件
- .NET 9.0 SDK 或以后
安装
- 克隆存储库:
git clone
cd mcp-estimates- 恢复依赖关系:
dotnet restore- 运行应用程序:
对于HTTPS(推荐):
dotnet run --project src/ConstructionEstimation.Api --launch-profile httpsAPI将于 https://localhost:7052 (HTTPS)和 http://localhost:5125 (HTTP)。
仅适用于HTTP:
dotnet run --project src/ConstructionEstimation.Api --launch-profile httpAPI将于 http://localhost:5125 (仅限HTTP)。
- 打开浏览器并导航到:
https://localhost:7052您将看到带有交互式API文档的Swagger UI。
API终点
客户
| 方法 | 端点 | 描述 |
|---|---|---|
| 得到 | /api/clients | 获取所有客户 |
| 得到 | /api/clients/{id} | 按ID获取客户端 |
| 职位 | /api/clients | 创建新客户端 |
| PUT | /api/clients/{id} | 更新客户端 |
| 删除 | /api/clients/{id} | 删除客户端 |
估计
| 方法 | 端点 | 描述 |
|---|---|---|
| 得到 | /api/estimates | 获取所有估计值 |
| 得到 | /api/estimates?clientId={id} | 按客户获取估算 |
| 得到 | /api/estimates/{id} | 按ID获取估计值 |
| 职位 | /api/estimates | 创建新估算 |
| PUT | /api/estimates/{id} | 更新估算 |
| 删除 | /api/estimates/{id} | 删除估算 |
发票
| 方法 | 端点 | 描述 |
|---|---|---|
| 得到 | /api/invoices | 获取所有发票 |
| 得到 | /api/invoices?clientId={id} | 按客户获取发票 |
| 得到 | /api/invoices?estimateId={id} | 按估算获取发票 |
| 得到 | /api/invoices/{id} | 按ID获取发票 |
| 职位 | /api/invoices | 创建新发票 |
| PUT | /api/invoices/{id} | 更新发票 |
| 删除 | /api/invoices/{id} | 删除发票 |
数据模型
客户端
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "ABC Construction",
"email": "contact@abc.com",
"phone": "555-1234",
"address": "123 Main St",
"city": "Springfield",
"state": "IL",
"zipCode": "62701",
"createdAt": "2025-10-28T10:00:00Z",
"updatedAt": "2025-10-28T10:00:00Z"
}估计
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"clientId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"estimateNumber": "EST-2025-001",
"title": "Kitchen Remodel",
"description": "Complete kitchen renovation including cabinets, countertops, and appliances",
"totalAmount": 25000.0,
"status": "Draft",
"validUntil": "2025-12-31T00:00:00Z",
"createdAt": "2025-10-28T10:00:00Z",
"updatedAt": "2025-10-28T10:00:00Z"
}估计状态值: Draft, Sent, Approved, Rejected
发票
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"estimateId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"clientId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"invoiceNumber": "INV-2025-001",
"description": "First payment for kitchen remodel",
"amount": 12500.0,
"status": "Sent",
"dueDate": "2025-11-15T00:00:00Z",
"paidDate": null,
"createdAt": "2025-10-28T10:00:00Z",
"updatedAt": "2025-10-28T10:00:00Z"
}发票状态值: Draft, Sent, Paid, Overdue
使用示例
创建客户端
curl -X POST https://localhost:7052/api/clients \
-H "Content-Type: application/json" \
-d '{
"name": "ABC Construction",
"email": "contact@abc.com",
"phone": "555-1234",
"address": "123 Main St",
"city": "Springfield",
"state": "IL",
"zipCode": "62701"
}'创建估算
curl -X POST https://localhost:7052/api/estimates \
-H "Content-Type: application/json" \
-d '{
"clientId": "{client-id}",
"estimateNumber": "EST-2025-001",
"title": "Kitchen Remodel",
"description": "Complete kitchen renovation",
"totalAmount": 25000.00,
"status": "Draft",
"validUntil": "2025-12-31T00:00:00Z"
}'创建发票
curl -X POST https://localhost:7052/api/invoices \
-H "Content-Type: application/json" \
-d '{
"clientId": "{client-id}",
"estimateId": "{estimate-id}",
"invoiceNumber": "INV-2025-001",
"description": "First payment",
"amount": 12500.00,
"status": "Sent",
"dueDate": "2025-11-15T00:00:00Z"
}'发展
构建解决方案
dotnet build运行测试
dotnet test数据库
该应用程序使用SQLite和Entity Framework Core。数据库文件(construction_estimation.db)在首次运行时自动创建,并存储在API项目目录中。
要重置数据库,只需删除 .db 文件并重新启动应用程序。
配置
配置通过以下方式管理 appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=construction_estimation.db"
}
}许可证
这是一个为演示目的而创建的演示项目。
MCP服务器(AI集成)
该项目包括 模型上下文协议(MCP)服务器 这使得像克劳德这样的人工智能助手能够与您的建筑估算数据进行交互。
什么是MCP?
模型上下文协议(MCP)是一种标准协议,允许AI助手安全地连接到您的数据和工具。使用MCP服务器,您可以使用自然语言:
- 查询客户信息
- 创建和管理估算
- 查看财务摘要
- 获取有关项目的统计信息
MCP服务器设置
先决条件
- Claude桌面版 安装
- .NET 9.0 SDK
配置Claude桌面
- 打开您的Claude Desktop配置文件:
macOS:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json窗户:
code %APPDATA%\Claude\claude_desktop_config.json- 添加构造估计器MCP服务器:
{
"mcpServers": {
"construction-estimator": {
"command": "dotnet",
"args": [
"run",
"--project",
"/ABSOLUTE/PATH/TO/mcp-estimates/src/ConstructionEstimation.McpServer"
]
}
}
}重要提示: 替换 /ABSOLUTE/PATH/TO/mcp-estimates 使用项目目录的实际绝对路径。
- 完全重新启动Claude Desktop(退出并重新打开,不要只是关闭窗口)
- 寻找🔨 Claude Desktop中的(锤子)图标,查看可用工具
可用的MCP工具
MCP服务器公开了11个用于AI交互的工具:
客户管理
- list_clients -获取所有客户的基本信息
- get_client_details -获取详细的客户信息,包括估算和发票
估算管理
- list_估计值 -使用可选的客户端筛选器获取所有估计值
- get_estimate_details -获取详细的估算信息
- 创建_估计 -为客户创建新的估算
- 更新_估计 -更新现有估算(标题、描述、金额、状态、有效期)
- get_estimate_statistics -获取有关估计的统计数据
发票和财务
- list_invoices -使用可选过滤器获取所有发票
- get_client_financial_summary -获取全面的财务摘要
架构与开发
- get_database_schema -获取OpenAPI/JSON schema格式的完整数据库模式,用于前端开发
- get_api_routes -使用完整的请求/响应模型从实时Swagger端点获取完整的REST API路由(API必须正在运行)
AI查询示例
配置后,您可以向Claude提出以下问题:
- “显示系统中的所有客户端”
- “史密斯住宅的财务摘要是什么?”
- “为马丁内斯家庭住宅进行价值15000美元的甲板翻修估算”
- “更新估算EST-2025-001,将状态更改为已批准,并将金额增加到28000美元”
- “我所有估计的统计数据是什么?”
- “显示所有未付发票”
- “获取数据库架构,以便我可以构建前端UI”
- “获取API路由,这样我就可以构建前端应用程序”
- “显示所有可用的REST端点及其请求和响应格式”
独立运行MCP服务器
您也可以直接测试MCP服务器:
cd src/ConstructionEstimation.McpServer
dotnet run服务器在stdin上监听JSON-RPC消息,并在stdout上做出响应。
MCP服务器故障排除
服务器未出现在Claude Desktop中:
- 验证中的路径
claude_desktop_config.json绝对正确 - 检查克劳德桌面日志:
tail -f ~/Library/Logs/Claude/mcp*.log- 确保完全退出并重新启动Claude Desktop
工具调用失败:
- 检查Claude日志目录中的MCP服务器日志
- 验证数据库文件是否存在并且可以访问
- 确保。NET 9.0已安装:
dotnet --version
贡献
这是一个演示项目。请随意分叉和修改以供自己使用。
