mirror of
https://github.com/hoshikawa2/agent_platform_oci.git
synced 2026-07-09 22:04:21 +00:00
First commit
This commit is contained in:
6
mcp/servers/telecom_mcp_server/Dockerfile
Normal file
6
mcp/servers/telecom_mcp_server/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM python:3.11-slim
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY main.py .
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8100"]
|
||||
22
mcp/servers/telecom_mcp_server/README_FASTMCP.md
Normal file
22
mcp/servers/telecom_mcp_server/README_FASTMCP.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# FastMCP mode
|
||||
|
||||
This folder keeps the original FastAPI mock server in `main.py` and adds an official FastMCP server in `main_fastmcp.py`.
|
||||
|
||||
Run legacy mock HTTP contract:
|
||||
|
||||
```bash
|
||||
uvicorn main:app --host 0.0.0.0 --port 8001
|
||||
```
|
||||
|
||||
Run FastMCP Streamable HTTP:
|
||||
|
||||
```bash
|
||||
python main_fastmcp.py
|
||||
```
|
||||
|
||||
In the framework, point `config/mcp_servers.yaml` to the FastMCP endpoint and set:
|
||||
|
||||
```yaml
|
||||
transport: fastmcp
|
||||
endpoint: http://localhost:8001/mcp
|
||||
```
|
||||
86
mcp/servers/telecom_mcp_server/main.py
Normal file
86
mcp/servers/telecom_mcp_server/main.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
from typing import Any
|
||||
|
||||
app = FastAPI(title="Telecom MCP Server Example")
|
||||
|
||||
class ToolCall(BaseModel):
|
||||
tool_name: str
|
||||
arguments: dict[str, Any] = {}
|
||||
|
||||
TOOLS = {
|
||||
"consultar_fatura": {
|
||||
"description": "Consulta dados resumidos de fatura por msisdn/invoice_id.",
|
||||
"input_schema": {"msisdn": "string", "invoice_id": "string"},
|
||||
},
|
||||
"consultar_pagamentos": {
|
||||
"description": "Consulta histórico de pagamentos do cliente.",
|
||||
"input_schema": {"msisdn": "string"},
|
||||
},
|
||||
"consultar_plano": {
|
||||
"description": "Consulta plano ativo e atributos comerciais.",
|
||||
"input_schema": {"msisdn": "string", "asset_id": "string"},
|
||||
},
|
||||
"listar_servicos": {
|
||||
"description": "Lista serviços ativos e adicionais VAS.",
|
||||
"input_schema": {"msisdn": "string"},
|
||||
},
|
||||
}
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"status": "ok", "server": "telecom_mcp_server"}
|
||||
|
||||
@app.get("/mcp/tools/list")
|
||||
async def list_tools():
|
||||
return {"tools": [{"name": name, **cfg} for name, cfg in TOOLS.items()]}
|
||||
|
||||
@app.post("/mcp/tools/call")
|
||||
async def call_tool(call: ToolCall):
|
||||
name = call.tool_name
|
||||
args = call.arguments or {}
|
||||
if name not in TOOLS:
|
||||
return {"ok": False, "error": f"Tool não encontrada: {name}"}
|
||||
|
||||
if name == "consultar_fatura":
|
||||
result = {
|
||||
"invoice_id": args.get("invoice_id") or "INV-EXEMPLO-001",
|
||||
"msisdn": args.get("msisdn") or "11999999999",
|
||||
"valor_total": 249.90,
|
||||
"vencimento": "2026-06-10",
|
||||
"status": "ABERTA",
|
||||
"itens": [
|
||||
{"descricao": "Plano Controle 50GB", "valor": 149.90},
|
||||
{"descricao": "Roaming internacional", "valor": 50.00},
|
||||
{"descricao": "Serviços digitais", "valor": 50.00},
|
||||
],
|
||||
}
|
||||
elif name == "consultar_pagamentos":
|
||||
result = {
|
||||
"msisdn": args.get("msisdn") or "11999999999",
|
||||
"pagamentos": [
|
||||
{"data": "2026-05-10", "valor": 199.90, "status": "CONFIRMADO"},
|
||||
{"data": "2026-04-10", "valor": 189.90, "status": "CONFIRMADO"},
|
||||
],
|
||||
}
|
||||
elif name == "consultar_plano":
|
||||
result = {
|
||||
"msisdn": args.get("msisdn") or "11999999999",
|
||||
"asset_id": args.get("asset_id") or "ASSET-001",
|
||||
"plano": "Controle 50GB",
|
||||
"internet_gb": 50,
|
||||
"roaming": "Américas incluso",
|
||||
"status": "ATIVO",
|
||||
}
|
||||
elif name == "listar_servicos":
|
||||
result = {
|
||||
"msisdn": args.get("msisdn") or "11999999999",
|
||||
"servicos": [
|
||||
{"nome": "Caixa Postal", "status": "ATIVO", "valor": 0.0},
|
||||
{"nome": "TIM Segurança", "status": "ATIVO", "valor": 19.90},
|
||||
],
|
||||
}
|
||||
else:
|
||||
result = {}
|
||||
|
||||
return {"ok": True, "result": result, "metadata": {"server": "telecom", "tool": name}}
|
||||
67
mcp/servers/telecom_mcp_server/main_fastmcp.py
Normal file
67
mcp/servers/telecom_mcp_server/main_fastmcp.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
mcp = FastMCP("telecom_mcp_server")
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def consultar_fatura(msisdn: str | None = None, invoice_id: str | None = None) -> dict[str, Any]:
|
||||
"""Consulta dados resumidos de fatura por msisdn/invoice_id."""
|
||||
return {
|
||||
"invoice_id": invoice_id or "INV-EXEMPLO-001",
|
||||
"msisdn": msisdn or "11999999999",
|
||||
"valor_total": 249.90,
|
||||
"vencimento": "2026-06-10",
|
||||
"status": "ABERTA",
|
||||
"itens": [
|
||||
{"descricao": "Plano Controle 50GB", "valor": 149.90},
|
||||
{"descricao": "Roaming internacional", "valor": 50.00},
|
||||
{"descricao": "Serviços digitais", "valor": 50.00},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def consultar_pagamentos(msisdn: str | None = None) -> dict[str, Any]:
|
||||
"""Consulta histórico de pagamentos do cliente."""
|
||||
return {
|
||||
"msisdn": msisdn or "11999999999",
|
||||
"pagamentos": [
|
||||
{"data": "2026-05-10", "valor": 199.90, "status": "CONFIRMADO"},
|
||||
{"data": "2026-04-10", "valor": 189.90, "status": "CONFIRMADO"},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def consultar_plano(msisdn: str | None = None, asset_id: str | None = None) -> dict[str, Any]:
|
||||
"""Consulta plano ativo e atributos comerciais."""
|
||||
return {
|
||||
"msisdn": msisdn or "11999999999",
|
||||
"asset_id": asset_id or "ASSET-001",
|
||||
"plano": "Controle 50GB",
|
||||
"internet_gb": 50,
|
||||
"roaming": "Américas incluso",
|
||||
"status": "ATIVO",
|
||||
}
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def listar_servicos(msisdn: str | None = None) -> dict[str, Any]:
|
||||
"""Lista serviços ativos e adicionais VAS."""
|
||||
return {
|
||||
"msisdn": msisdn or "11999999999",
|
||||
"servicos": [
|
||||
{"nome": "Caixa Postal", "status": "ATIVO", "valor": 0.0},
|
||||
{"nome": "TIM Segurança", "status": "ATIVO", "valor": 19.90},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mcp.settings.host = "0.0.0.0"
|
||||
mcp.settings.port = 8001
|
||||
mcp.run(transport="streamable-http")
|
||||
4
mcp/servers/telecom_mcp_server/requirements.txt
Normal file
4
mcp/servers/telecom_mcp_server/requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
fastapi>=0.115.0
|
||||
uvicorn[standard]>=0.30.0
|
||||
pydantic>=2.8.0
|
||||
mcp>=1.9.0
|
||||
Reference in New Issue
Block a user