NCM代码属性查询工具

一个基于FastAPI的API服务,用于查询Mercosul共同命名法(NCM)代码及其相关属性信息。

  • by TulioCMP
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 tuliocmp/fastapi-mcp-server

使用说明

FastAPI NCM属性工具

该应用程序提供了一个基于FastAPI的API,用于检索NCM(南方共同市场命名法)代码及其相关属性的信息。

特性

  • 按代码或描述搜索NCM代码
  • 检索特定NCM代码的所有属性及其可能值
  • 带有适当文档的RESTful API端点
  • 用于AI交互的MCP服务器集成

数据库结构

该应用程序使用具有以下主要表的PostgreSQL数据库:

  • ncm:包含NCM代码和说明
  • ncm_attributes:包含与NCM代码关联的属性
  • attribute:包含属性定义

API终点

NCM属性

  • GET /ncm/{ncm_code}/attributes:获取特定NCM代码的所有属性
  • GET /ncm/search?query={search_term}:按代码或描述搜索NCM代码

MCP工具

  • get_ncm_attributes_tool:MCP工具,用于获取NCM代码的属性

示例用法

import requests

# Search for NCM codes
response = requests.get("http://localhost:8000/ncm/search?query=1234")
results = response.json()

# Get attributes for a specific NCM code
response = requests.get("http://localhost:8000/ncm/1234.56.78/attributes")
attributes = response.json()

建筑

该应用程序遵循干净的架构,包括:

  • 模型:表示数据库表的SQLAlchemy模型
  • 仓库:处理数据库操作
  • 服务:实现业务逻辑
  • 模式:用于请求/响应验证的Pydantic模型
  • API路线:用于HTTP交互的FastAPI端点

运行应用程序

# Run the application
uvicorn main:app --reload --host 0.0.0.0 --port 8000

# Access the API documentation
# Open in browser: http://localhost:8000/docs
``` # fastapi-mcp-server
# fastapi-mcp-server