Agentic MCP Microservices
使用 MCP 与 Gemini 的企业 BAU 服务
一个可执行的验证性概念(POC),展示 AI 代理如何通过模型上下文协议(MCP)与现有的日常运营(BAU)REST 微服务协同工作。
该演示使用 Google Gemini 来发现 MCP 工具、检索客户与订单信息,并执行一次受控的订单取消操作。BAU 服务保持为独立的 REST API;MCP 提供这些 API 与代理之间的集成边界。
演示
所包含的场景要求代理执行以下操作:
检索
CUST-1001的客户档案。列出该客户的订单。
识别状态为
Processing的订单。使用提供的理由取消
ORD-9002。总结已完成的工作。
预期的工具调用顺序为:
Gemini agent
-> MCP tool discovery over stdio
-> MCP server
-> Customer and Order REST APIs
-> Tool results returned to Gemini
-> Final user-facing summaryRelated MCP server: MCP API Tool Demo
架构
+------------------+ stdio +------------------+ HTTP +----------------------+
| Gemini agent | <----------------> | MCP server | <--------------> | Customer service |
| agent_runner.py | | server.py | | localhost:8001 |
+------------------+ +--------+---------+ +----------------------+
|
| HTTP
v
+----------------------+
| Order service |
| localhost:8002 |
+----------------------+MCP 工具
工具 | 用途 |
| 检索客户档案、等级、状态和信用额度。 |
| 列出与某客户关联的订单。 |
| 当订单状态允许取消时取消该订单。 |
项目结构
.
├── agent/
│ └── agent_runner.py # Gemini agent and MCP client
├── mcp_server/
│ └── server.py # MCP tools and REST integration
├── services/
│ ├── customer_service.py # Mock customer REST API
│ └── order_service.py # Mock order REST API
├── tests/
│ └── test_services.py # Service behavior tests
├── .env.example # Environment variable template
├── requirements.txt # Python dependencies
└── mcp_microservices_poc_blueprint.md
# Detailed design and implementation reference前提条件
Python 3.11 或更高版本
来自 Google AI Studio 的 Gemini API 密钥
Windows PowerShell、macOS/Linux shell 或等效终端
运行代理时能够访问 Gemini API 的网络连接
本项目不需要 Anthropic 或 OpenAI API 密钥。
Windows 快速开始
在项目目录中打开 PowerShell:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
Copy-Item .env.example .env打开 .env,将 your_gemini_api_key_here 替换为你的密钥:
GOOGLE_API_KEY=your_gemini_api_key_here
GEMINI_MODEL=gemini-3.6-flash切勿提交 .env 或将 API 密钥放入源代码中。所选模型必须对你的 Gemini 账户可用。
运行演示
使用三个终端。在每个终端中激活 .venv。
终端 1:客户服务
python services/customer_service.py运行于 http://localhost:8001。
终端 2:订单服务
python services/order_service.py运行于 http://localhost:8002。
终端 3:Gemini 代理
python agent/agent_runner.py代理将 MCP 服务器作为子进程启动,发现其工具,并执行示例工作流。
验证本地服务
在两个服务运行期间执行以下命令:
Invoke-RestMethod http://localhost:8001/health
Invoke-RestMethod http://localhost:8002/health
Invoke-RestMethod http://localhost:8001/api/v1/customers/CUST-1001
Invoke-RestMethod http://localhost:8002/api/v1/orders/customer/CUST-1001运行测试
在虚拟环境激活状态下:
python -m pytest -q测试覆盖了不区分大小写的客户查找、客户不存在、取消处理中的订单,以及防止取消已发货订单的保护逻辑。
配置
变量 | 描述 | 默认值 |
| Gemini 认证密钥。 | 必填 |
| 代理使用的 Gemini 模型。 |
|
| 客户服务基础 URL。 |
|
| 订单服务基础 URL。 |
|
范围与限制
这是一个本地、刻意保持小规模的 POC,旨在使集成模式易于检查和运行。
客户和订单记录存储在内存中,服务重启时会被重置。
服务未实现身份验证或授权。
在真实系统中,取消操作应受到审批和业务策略控制的保护。
MCP 使用 stdio 进行本地进程集成。部署架构应使用经过身份验证的网络传输。
下游错误以工具文本形式返回以便查看;生产系统应使用结构化错误、重试、追踪和指标。
示例代理会发起真实的 Gemini API 请求,需要有效的密钥。
故障排查
GOOGLE_API_KEY is not set
确认项目目录中存在 .env 且包含有效密钥。从项目目录运行代理。
Gemini 模型返回 404 NOT_FOUND
在 .env 中将 GEMINI_MODEL 设置为你的账户已启用的模型。本 POC 中的默认值为 gemini-3.6-flash。
MCP 启动或工具发现失败
确认依赖已安装到当前激活的虚拟环境中:
python -m pip install -r requirements.txt本项目将 MCP 固定在 1.x API 范围内,因为服务器实现使用了 FastMCP。
MCP 工具出现连接错误
确认两个 REST 服务正在端口 8001 和 8002 上运行。如果端口已被占用,请更新服务端口以及 .env 中对应的 URL。
延伸阅读
This server cannot be installed
Maintenance
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
- AlicenseNot gradedqualityCmaintenanceAn MCP server that enables AI agents to interact with the commercetools Composable Commerce platform. It provides tools for managing products, categories, orders, carts, and customer data through secure read and write operations.13MIT
- FlicenseNot gradedqualityBmaintenanceDemo MCP server that exposes order and customer data as read-only tools for AI assistants, simulating a business API or internal data source.
- AlicenseNot gradedqualityCmaintenanceMCP server that bridges AI agents with external tools, APIs, databases, and services, enabling standardized tool execution and resource access.MIT
- FlicenseNot gradedqualityBmaintenanceMCP server that enables AI platforms to search products, customers, and warehouses, and prepare and submit sales orders to a fixed ERP endpoint with per-session bearer authentication.
Related MCP Connectors
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
MCP server exposing the Backtest360 engine API as tools for AI agents.
MCP server for secureFlows: token-free URL builders and integration-linting tools for AI agents.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/sganapa/agentic-mcp-microservices'
If you have feedback or need assistance with the MCP directory API, please join our Discord server