Azure APIM集成工具

一个用于Azure APIM集成的FastMCP服务器实现,提供基本的计算工具。

  • by rmoreirao
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 rmoreirao/BasicAzureApimMCP

使用说明

BasicAzureApimMCP

带有Azure APIM集成基本工具的FastMCP服务器实现。

特性

  • 求和工具:一个简单的MCP工具,将两个数字加在一起
    • 支持整数和浮点数
    • 带有明确错误消息的输入验证
    • 与mypy严格模式兼容的类型提示

安装

pip install -e .

发展:

pip install -e ".[dev]"

用法

运行服务器

from basic_mcp.server import mcp

# Run the MCP server
mcp.run()

或者从命令行:

python -m basic_mcp.server

使用求和工具

可通过FastMCP接口使用求和工具:

import asyncio
from basic_mcp.server import mcp

async def example():
    # Get the tool
    tool = await mcp.get_tool("sum")
    
    # Call the tool function directly
    result = tool.fn(2.0, 3.0)
    print(f"2 + 3 = {result}")  # Output: 2 + 3 = 5.0

asyncio.run(example())

示例

# Basic addition
sum(2, 3)  # Returns 5.0

# Float addition
sum(2.5, 3.7)  # Returns 6.2

# Negative numbers
sum(-5, 10)  # Returns 5.0

# Zero values
sum(0, 0)  # Returns 0.0

# Very large numbers (note: limited precision)
sum(1e308, 1e308)  # Returns 2e+308

输入验证

求和工具验证输入并提高 ValueError 对于无效类型:

sum("2", 3)  # Raises ValueError: must be a numeric type
sum(None, 3)  # Raises ValueError: must be a numeric type
sum(True, 3)  # Raises ValueError: must be a numeric type

发展

运行测试

# Set PYTHONPATH and run all tests
export PYTHONPATH=src:$PYTHONPATH
pytest tests/ -v

项目结构

BasicAzureApimMCP/
├── src/
│   └── basic_mcp/
│       ├── __init__.py
│       ├── server.py          # FastMCP server instance
│       └── tools/
│           ├── __init__.py
│           └── sum_tool.py    # Sum tool implementation
├── tests/
│   ├── test_sum_tool.py       # Unit tests
│   └── test_sum_integration.py # Integration tests
├── pyproject.toml
├── requirements.txt
└── README.md

需求

  • Python>=3.10
  • fastmcp>=0.1.0

许可证

有关详细信息,请参阅LICENSE文件。

BasicAzureApimMCP

执行MCP检查器

“灰烬” npx@modelcontextprotocol/检查器 '''