Skip to main content
Glama

Math Lab: MCP + OpenAI Agents SDK

本项目通过两个适配器使用同一套数学逻辑:

  • 一个用于 Codex、MCP Inspector 或任何兼容客户端的 MCP 服务器。

  • 一个使用 OpenAI Agents SDK 构建的代理,用于自然语言对话。

打包为可安装的 Python 包(pip install -e .),采用 src/ 布局和清晰的分层架构。

结构

pyproject.toml       # Metadata, dependencias y entry points del paquete
src/
└── math_assistant/
    ├── domain/          # Reglas matemáticas puras (sin dependencias externas)
    ├── application/     # Catálogo de capacidades públicas
    ├── infrastructure/  # Adaptadores para MCP (FastMCP) y OpenAI Agents SDK
    └── presentation/    # Interfaz de terminal
tests/
├── unit/            # Prueban dominio y catálogo
└── integration/     # Comprueban que los adaptadores se construyen
run_cli.py           # Entry point: interfaz amigable para aprender y probar
run_mcp.py           # Entry point: STDIO exclusivo para el cliente MCP

依赖始终指向内部:

CLI / MCP / OpenAI SDK  →  application  →  domain

领域层不依赖 FastMCP、OpenAI、API key 或 print。因此可以快速测试,无需网络。

Related MCP server: Explore MCP

安装

python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[dev]"

将你的 OPENAI_API_KEY 复制到根目录下的 .env 文件中(永远不会提交到 git)。

运行友好界面

.\.venv\Scripts\python.exe .\run_cli.py

菜单允许:

  1. 与 OpenAI 代理对话(使用 .env 中的 OPENAI_API_KEY)。

  2. 在本地测试加法、减法、乘法和除法,无需 API 费用。

  3. 查看 MCP 服务器发布的工具。

运行 MCP 服务器

.\.venv\Scripts\python.exe .\run_mcp.py

要使用 MCP Inspector 检查它:

npx @modelcontextprotocol/inspector "C:\ruta\completa\a\math-mcp-lab\.venv\Scripts\python.exe" "C:\ruta\completa\a\math-mcp-lab\run_mcp.py"

使用绝对路径:Inspector 并不总是遵循当前工作目录。

不要在 run_mcp.py 或 MCP 适配器中添加 print():标准输出通道(stdout)保留给协议的 JSON-RPC 消息。友好界面因此位于 run_cli.py 中。

与 Codex 集成

.codex/config.toml(不纳入版本控制,是机器本地配置)将 Codex 指向 MCP 服务器。如果你使用 Codex CLI,请创建你自己的:

[mcp_servers.math]
command = "C:\\ruta\\completa\\a\\math-mcp-lab\\.venv\\Scripts\\python.exe"
args = ["C:\\ruta\\completa\\a\\math-mcp-lab\\run_mcp.py"]
cwd = "C:\\ruta\\completa\\a\\math-mcp-lab"

测试

.\.venv\Scripts\python.exe -m unittest discover -s tests -v

如何添加数学工具

  1. src/math_assistant/domain/operations.py 中创建纯函数及其 docstring。

  2. 将其添加到 src/math_assistant/application/tool_catalog.py 中的 MATH_OPERATIONS

  3. 运行测试。

两个适配器会自动暴露它:FastMCP 将其转换为 MCP 工具,Agents SDK 将其转换为 function tool。

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    A demonstration MCP server that exposes basic arithmetic tools (add, subtract, ping) through FastAPI and shows how to integrate them with OpenAI's tool-calling API for LLM orchestration.
  • F
    license
    Not graded
    quality
    D
    maintenance
    A simple demonstration MCP server built with FastMCP that exposes basic calculator operations (add, subtract, multiply, divide) as tools for MCP clients like GitHub Copilot Agent mode.
  • F
    license
    A
    quality
    D
    maintenance
    A basic MCP server built with the FastMCP framework that provides fundamental mathematical operations like addition, subtraction, multiplication, and division. It serves as a demonstration for integrating math-based tools into MCP-compatible environments like Cursor IDE.
    4

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/matiasn2008/math-mcp-lab'

If you have feedback or need assistance with the MCP directory API, please join our Discord server