First commit

This commit is contained in:
2026-06-19 22:17:09 -03:00
commit 239203ee2a
533 changed files with 75195 additions and 0 deletions

View 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", "8200"]

View 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
```

View File

@@ -0,0 +1,84 @@
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Any
app = FastAPI(title="Retail MCP Server Example")
class ToolCall(BaseModel):
tool_name: str
arguments: dict[str, Any] = {}
TOOLS = {
"consultar_pedido": {
"description": "Consulta pedido de varejo por order_id/customer_id.",
"input_schema": {"order_id": "string", "customer_id": "string"},
},
"consultar_entrega": {
"description": "Consulta entrega e rastreamento do pedido.",
"input_schema": {"order_id": "string"},
},
"solicitar_troca": {
"description": "Simula abertura de solicitação de troca.",
"input_schema": {"order_id": "string", "reason": "string"},
},
"solicitar_devolucao": {
"description": "Simula abertura de solicitação de devolução.",
"input_schema": {"order_id": "string", "reason": "string"},
},
}
@app.get("/health")
async def health():
return {"status": "ok", "server": "retail_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_pedido":
result = {
"order_id": args.get("order_id") or "PED-1001",
"customer_id": args.get("customer_id") or "CLIENTE-001",
"status": "EM_TRANSPORTE",
"valor_total": 349.90,
"itens": [
{"sku": "LIV-001", "descricao": "Livro de Arquitetura de IA", "quantidade": 1, "valor": 199.90},
{"sku": "CAB-USB", "descricao": "Cabo USB-C", "quantidade": 1, "valor": 150.00},
],
}
elif name == "consultar_entrega":
result = {
"order_id": args.get("order_id") or "PED-1001",
"transportadora": "Entrega Express",
"codigo_rastreio": "BR123456789",
"previsao_entrega": "2026-06-03",
"eventos": [
{"data": "2026-05-28", "descricao": "Pedido coletado"},
{"data": "2026-05-29", "descricao": "Em trânsito para o centro de distribuição"},
],
}
elif name == "solicitar_troca":
result = {
"protocolo": "TROCA-2026-001",
"order_id": args.get("order_id") or "PED-1001",
"status": "ABERTO",
"orientacao": "Aguarde instruções de postagem no e-mail cadastrado.",
}
elif name == "solicitar_devolucao":
result = {
"protocolo": "DEV-2026-001",
"order_id": args.get("order_id") or "PED-1001",
"status": "ABERTO",
"orientacao": "Solicitação registrada para análise conforme política de devolução.",
}
else:
result = {}
return {"ok": True, "result": result, "metadata": {"server": "retail", "tool": name}}

View File

@@ -0,0 +1,59 @@
from __future__ import annotations
from typing import Any
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("retail_mcp_server")
@mcp.tool()
def consultar_pedido(customer_id: str | None = None, order_id: str | None = None) -> dict[str, Any]:
"""Consulta dados resumidos de um pedido."""
return {
"customer_id": customer_id or "CUST-001",
"order_id": order_id or "ORD-001",
"status": "EM_TRANSPORTE",
"valor_total": 399.90,
"itens": [{"sku": "SKU-001", "nome": "Produto exemplo", "quantidade": 1}],
}
@mcp.tool()
def consultar_entrega(order_id: str | None = None) -> dict[str, Any]:
"""Consulta rastreio e previsão de entrega."""
return {
"order_id": order_id or "ORD-001",
"transportadora": "Entrega Express",
"previsao": "2026-06-20",
"status": "EM_ROTA",
}
@mcp.tool()
def solicitar_troca(order_id: str | None = None, motivo: str | None = None) -> dict[str, Any]:
"""Abre solicitação de troca para um pedido."""
return {
"order_id": order_id or "ORD-001",
"protocolo": "TROCA-123456",
"motivo": motivo or "Não informado",
"status": "ABERTA",
}
@mcp.tool()
def solicitar_devolucao(order_id: str | None = None, motivo: str | None = None) -> dict[str, Any]:
"""Abre solicitação de devolução para um pedido."""
return {
"order_id": order_id or "ORD-001",
"protocolo": "DEV-123456",
"motivo": motivo or "Não informado",
"status": "ABERTA",
}
if __name__ == "__main__":
mcp.settings.host = "0.0.0.0"
mcp.settings.port = 8002
mcp.run(transport="streamable-http")

View File

@@ -0,0 +1,4 @@
fastapi>=0.115.0
uvicorn[standard]>=0.30.0
pydantic>=2.8.0
mcp>=1.9.0

View 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"]

View 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
```

View 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}}

View 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")

View File

@@ -0,0 +1,4 @@
fastapi>=0.115.0
uvicorn[standard]>=0.30.0
pydantic>=2.8.0
mcp>=1.9.0