Skip to main content
Glama
systemyuri

Asistente Comercial MCP

by systemyuri

πŸ›’ Asistente Comercial MCP

Python Streamlit LangChain Groq Tests

Sistema de agente de IA para anΓ‘lisis comercial de un e-commerce de productos alimenticios.


πŸ“‘ Índice


Related MCP server: mcp-server

πŸ“‹ Problema que Resuelve

El asistente ayuda a equipos comerciales y de atenciΓ³n al cliente a obtener informaciΓ³n rΓ‘pida y verificable sobre:

  • Clientes: BΓΊsqueda, perfil de consumo, identificaciΓ³n de alto valor

  • Productos: Productos mΓ‘s vendidos, anΓ‘lisis por categorΓ­a

  • Ventas: AnΓ‘lisis por regiΓ³n, mΓ©todos de pago

  • AnΓ‘lisis: ClasificaciΓ³n de clientes (VIP, Premium, Regular)

Usuario principal: Equipo comercial y de atenciΓ³n al cliente de un e-commerce.

Necesidad: Obtener informaciΓ³n rΓ‘pida y verificable sobre clientes, ventas, productos y regiones sin necesidad de consultar directamente bases de datos.

Lo que cubre:

  • βœ… BΓΊsqueda de clientes por nombre, apellido o regiΓ³n

  • βœ… Perfil de consumo de clientes

  • βœ… Productos mΓ‘s vendidos

  • βœ… AnΓ‘lisis de ventas por categorΓ­a y regiΓ³n

  • βœ… Preferencias de mΓ©todos de pago

  • βœ… ClasificaciΓ³n de clientes (VIP, Premium, Regular)

Lo que NO cubre:

  • ❌ ModificaciΓ³n de datos (solo lectura)

  • ❌ Procesamiento de pagos

  • ❌ GestiΓ³n de inventario en tiempo real


πŸ—οΈ Arquitectura del Sistema

Diagrama de Componentes

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   USUARIO                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               INTERFAZ WEB (Streamlit)                        β”‚
β”‚       app_streamlit.py                                        β”‚
β”‚       β€’ Chat interactivo                                      β”‚
β”‚       β€’ VisualizaciΓ³n de evidencia                            β”‚
β”‚       β€’ GestiΓ³n de session_id                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               AGENTE LANGCHAIN + GROQ                         β”‚
β”‚       agent_core.py                                           β”‚
β”‚       β€’ InterpretaciΓ³n de intenciΓ³n                           β”‚
β”‚       β€’ SelecciΓ³n de herramientas                             β”‚
β”‚       β€’ Memoria de corto plazo (InMemorySaver)                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           CLIENTE MCP (langchain-mcp-adapters)                β”‚
β”‚           β€’ Descubrimiento de herramientas                    β”‚
β”‚           β€’ InvocaciΓ³n de tools                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               SERVIDOR MCP (FastMCP)                          β”‚
β”‚           mcp_server.py                                       β”‚
β”‚           β€’ ExposiciΓ³n de 8 herramientas personalizadas       β”‚
β”‚           β€’ ValidaciΓ³n de entradas                            β”‚
β”‚           β€’ Respuestas estructuradas                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   BASE DE DATOS (SQLite)                      β”‚
β”‚           data/mcp_laboratorio.db                             β”‚
β”‚           β€’ clientes β€’ ventas β€’ productos                     β”‚
β”‚           β€’ categorias β€’ metodos_pago                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Arquitectura

graph TD
    A[Usuario] --> B[Streamlit UI]
    B --> C[Agente LangChain + Groq]
    C --> D{ΒΏNecesita tool?}
    D -->|SΓ­| E[Cliente MCP]
    D -->|No| F[Respuesta directa]
    E --> G[Servidor MCP FastMCP]
    G --> H[SQLite Database]
    H --> I[Resultado estructurado]
    I --> C
    F --> J[Respuesta final]
    C --> J
    J --> B
    B --> A
    
    style A fill:#B30909,stroke:#fff,stroke-width:2px
    style B fill:#00f,stroke:#fff,stroke-width:2px
    style C fill:#056c5c,stroke:#fff,stroke-width:2px
    style G fill:#f2f,stroke:#fff,stroke-width:2px
    style H fill:#1D7799,stroke:#fff,stroke-width:2px

Flujo de EjecuciΓ³n

  1. Usuario escribe una pregunta en Streamlit

  2. Streamlit envΓ­a la pregunta al agente con session_id

  3. Agente LangChain + Groq interpreta la intenciΓ³n

  4. DecisiΓ³n:

    • Si necesita datos β†’ Invoca tool MCP

    • Si no β†’ Responde directamente

  5. MCP Server ejecuta la tool contra SQLite

  6. Resultado vuelve al agente

  7. Agente sintetiza respuesta con evidencia

  8. Streamlit muestra respuesta, tools usadas y traza

  9. Memoria guarda contexto para siguiente interacciΓ³n

Componentes y Responsabilidades

Capa

TecnologΓ­a

Archivo

Responsabilidad

Interfaz

Streamlit

app_streamlit.py

Recibir preguntas, mostrar respuesta y evidencia

OrquestaciΓ³n

LangChain + Groq

agent_core.py

Interpretar intenciΓ³n, elegir tools, gestionar memoria

MCP

FastMCP

mcp_server.py

Exponer tools personalizadas con contratos claros

Datos

SQLite

data/

Entregar informaciΓ³n y ejecutar operaciones controladas

Memoria

InMemorySaver

agent_core.py

Mantener contexto de la conversaciΓ³n por session_id

πŸ› οΈ TecnologΓ­as Utilizadas

TecnologΓ­a

VersiΓ³n

PropΓ³sito

Python

3.12.9+

Lenguaje base

Streamlit

1.28+

Interfaz web

LangChain

0.3+

OrquestaciΓ³n del agente

Groq

-

Modelo de lenguaje (llama-3.3-70b-versatile)

FastMCP

0.3+

Servidor MCP

SQLite

3.x

Base de datos local

Pandas

2.0+

Procesamiento de datos

Pytest

8.0+

Pruebas unitarias

Pytest-Asyncio

0.23+

Pruebas asΓ­ncronas

πŸ”§ Herramientas MCP

Tool

PropΓ³sito

Entrada

Salida

Riesgo

buscar_clientes

Buscar clientes

texto_busqueda, limite

Lista de clientes

Bajo

perfil_consumo_cliente

Perfil de consumo

cliente_id

MΓ©tricas de consumo

Bajo

clientes_alto_valor

Clientes con alto gasto

gasto_minimo, limite

Top clientes

Bajo

top_productos_vendidos

Productos mΓ‘s vendidos

limite, ordenar_por

Ranking de productos

Bajo

analisis_categoria

Ventas por categorΓ­a

categoria (opcional)

MΓ©tricas por categorΓ­a

Bajo

ventas_por_region

Ventas por regiΓ³n

region (opcional)

MΓ©tricas por regiΓ³n

Bajo

preferencia_metodo_pago

Preferencias de pago

region (opcional)

MΓ©tricas de pago

Bajo

calcular_nivel_cliente

Clasificar cliente

gasto_total, total_ordenes

Nivel y recomendaciΓ³n

Bajo

🧠 Memoria

  • Tipo: Corto plazo (InMemorySaver)

  • Session ID: Identificador ΓΊnico por conversaciΓ³n

  • Ventana: Últimos 6-10 mensajes

  • LimitaciΓ³n: La memoria se pierde al reiniciar el servidor

πŸ” Secretos y ConfiguraciΓ³n

Variables de Entorno Requeridas

Variable

DescripciΓ³n

DΓ³nde obtenerla

GROQ_API_KEY

API Key de Groq

console.groq.com

GROQ_MODEL

Modelo a usar

llama-3.3-70b-versatile

MCP_SERVER_URL

URL del MCP Server

Local: http://127.0.0.1:8000/mcp

ConfiguraciΓ³n Local (.env)

  1. Copia el archivo de ejemplo:

cp .env.example .env
  1. Edita .env con tus valores:

GROQ_API_KEY=gsk_tu_api_key_aqui
GROQ_MODEL=llama-3.3-70b-versatile
MCP_SERVER_URL=http://127.0.0.1:8000/mcp

ConfiguraciΓ³n para Streamlit Cloud (Secrets)

En la interfaz de Streamlit Cloud, agrega estos secretos:

GROQ_API_KEY = "gsk_tu_api_key_aqui"
GROQ_MODEL = "llama-3.1-8b-instant"
MCP_SERVER_URL = "https://tu-mcp-server.onrender.com/mcp"

πŸš€ InstalaciΓ³n Local

  1. Clonar el repositorio

git clone https://github.com/systemyuri/agente-mcp-groq.git
cd agente-mcp-groq
  1. Crear y activar entorno virtual

python -m venv .venv
#source .venv/bin/activate  # Linux/Mac
.venv\Scripts\activate   # Windows
  1. Instalar dependencias

pip install -r requirements.txt
  1. Configurar variables de entorno

cp .env.example .env
# Edita .env con tu GROQ_API_KEY
  1. Preparar datos

# Coloca tus archivos CSV en la carpeta data/
python load_data.py
  1. Ejecutar el MCP Server (Terminal 1)

python mcp_server.py

Salida esperada:

πŸš€ Iniciando MCP Server...
   Base de datos: data/mcp_laboratorio.db
   βœ… Con validaciΓ³n de tipos para parΓ‘metros

πŸ“‹ Tools disponibles:
   - buscar_clientes
   - perfil_consumo_cliente
   - clientes_alto_valor
   - top_productos_vendidos
   - analisis_categoria
   - ventas_por_region
   - preferencia_metodo_pago
   - calcular_nivel_cliente

🌐 Servidor HTTP escuchando en http://127.0.0.1:8000
   Endpoint MCP: http://127.0.0.1:8000/mcp
  1. Ejecutar Streamlit (Terminal 2)

streamlit run app_streamlit.py

πŸ§ͺ Pruebas

El proyecto incluye pruebas unitarias para todas las herramientas MCP y el agente completo.

πŸ“Š Cobertura de Pruebas

Componente

Pruebas

Estado

Tools MCP

9 pruebas

βœ… Todas pasan

Agente LangChain

5 pruebas

βœ… Todas pasan

ConexiΓ³n MCP

1 prueba

βœ… Todas pasan

Total

15 pruebas

βœ… 100% pasan

πŸ”§ Pruebas de Herramientas MCP

Prueba

DescripciΓ³n

Estado

test_buscar_clientes

BΓΊsqueda por regiΓ³n, nombre y validaciΓ³n de tipos

βœ…

test_perfil_consumo_cliente

Perfil de cliente existente e inexistente

βœ…

test_clientes_alto_valor

Filtrado por gasto mΓ­nimo y lΓ­mite

βœ…

test_top_productos_vendidos

Orden por cantidad e ingresos

βœ…

test_analisis_categoria

Todas las categorΓ­as y especΓ­fica

βœ…

test_ventas_por_region

Todas las regiones y especΓ­fica

βœ…

test_preferencia_metodo_pago

Todos los mΓ©todos y por regiΓ³n

βœ…

test_calcular_nivel_cliente

ClasificaciΓ³n VIP, Premium, Regular

βœ…

test_mcp

ConexiΓ³n al MCP Server

βœ…

🧠 Pruebas del Agente

Prueba

DescripciΓ³n

Estado

test_system_prompt

Verifica que el prompt estΓ‘ definido

βœ…

test_agent_creation

CreaciΓ³n del agente LangChain

βœ…

test_simple_query

Consulta simple sin tools

βœ…

test_tool_query

Consulta que usa herramientas MCP

βœ…

test_memory

Memoria entre turnos de conversaciΓ³n

βœ…

test_error_handling

Manejo de errores y casos extremos

βœ…

πŸš€ Ejecutar Pruebas

1. Instalar dependencias de pruebas

pip install pytest pytest-cov pytest-asyncio

2. Asegurar que el MCP Server estΓ‘ corriendo

# En una terminal separada
python mcp_server.py

3. Ejecutar todas las pruebas

python -m pytest tests/ -v --asyncio-mode=auto

4. Ejecutar pruebas con cobertura

python -m pytest tests/ -v --cov=. --cov-report=html --asyncio-mode=auto
# Abrir htmlcov/index.html en el navegador

5. Ejecutar pruebas especΓ­ficas

# Solo herramientas MCP
python -m pytest tests/test_tools.py -v
# Solo agente
python -m pytest tests/test_agent.py -v --asyncio-mode=auto
# Solo conexiΓ³n
python -m pytest tests/test_connection.py -v --asyncio-mode=auto

πŸ“Š Resultado Esperado


============================================= test session starts =============================================
collected 15 items
tests/test_agent.py::test_system_prompt PASSED                                                           [  6%]
tests/test_agent.py::test_agent_creation PASSED                                                          [ 13%]
tests/test_agent.py::test_simple_query PASSED                                                            [ 20%]
tests/test_agent.py::test_tool_query PASSED                                                              [ 26%]
tests/test_agent.py::test_memory PASSED                                                                  [ 33%]
tests/test_agent.py::test_error_handling PASSED                                                          [ 40%]
tests/test_connection.py::test_mcp PASSED                                                                [ 46%]
tests/test_tools.py::test_buscar_clientes PASSED                                                         [ 53%]
tests/test_tools.py::test_perfil_consumo_cliente PASSED                                                  [ 60%]
tests/test_tools.py::test_clientes_alto_valor PASSED                                                     [ 66%]
tests/test_tools.py::test_top_productos_vendidos PASSED                                                  [ 73%]
tests/test_tools.py::test_analisis_categoria PASSED                                                      [ 80%]
tests/test_tools.py::test_ventas_por_region PASSED                                                       [ 86%]
tests/test_tools.py::test_preferencia_metodo_pago PASSED                                                 [ 93%]
tests/test_tools.py::test_calcular_nivel_cliente PASSED                                                  [100%]
=========================================== 15 passed in 3.42s ===========================================

πŸ› SoluciΓ³n de Problemas en Pruebas

Error

SoluciΓ³n

ModuleNotFoundError: No module named 'langchain'

Activar entorno virtual: .venvScriptsactivate

async def functions are not natively supported

Instalar: pip install pytest-asyncio

MCP Server no detectado

Ejecutar python mcp_server.py en otra terminal

Error de conexiΓ³n

Verificar URL en .env: MCP_SERVER_URL=http://127.0.0.1:8000/mcp

🌐 Despliegue

En Streamlit Community Cloud

  1. Sube el cΓ³digo a GitHub


git add .
git commit -m "feat: Asistente Comercial MCP con Groq"
git push origin main
  1. Ve a share.streamlit.io

  2. Conecta tu repositorio

    • Selecciona GitHub

    • Elige el repositorio y rama main

    • Archivo principal: app_streamlit.py

  3. Configura los Secretos
    En la secciΓ³n "Secrets", agrega:

    
    GROQ_API_KEY = "gsk_tu_api_key_aqui"
    GROQ_MODEL = "llama-3.1-8b-instant"
    MCP_SERVER_URL = "https://tu-mcp-server.onrender.com/mcp"
  4. Despliega

    • Haz clic en "Deploy"

    • Espera ~5 minutos

    • Β‘ObtendrΓ‘s tu URL pΓΊblica!

MCP Server Remoto

OpciΓ³n 1: Render.com (Recomendado)

Crea render.yaml:


services:
  - type: web
    name: mcp-server
    env: python
    buildCommand: pip install -r requirements.txt
    startCommand: python mcp_server.py
    envVars:
      - key: GROQ_API_KEY
        sync: false

OpciΓ³n 2: ngrok (Para pruebas rΓ‘pidas)


# Terminal 1
python mcp_server.py
# Terminal 2 (nueva terminal)
ngrok http 8000
# Copia la URL https://xxxx.ngrok.io
# Actualiza MCP_SERVER_URL con esta URL + /mcp

πŸ“ Estructura del Proyecto


agente_mcp_groq/
β”œβ”€β”€ app_streamlit.py            # Interfaz web
β”œβ”€β”€ agent_core.py               # LΓ³gica del agente (Groq, MCP, memoria)
β”œβ”€β”€ mcp_server.py               # Servidor MCP con 8 herramientas
β”œβ”€β”€ load_data.py                # Script para cargar datos
β”œβ”€β”€ check_db.py                 # VerificaciΓ³n de base de datos
β”œβ”€β”€ test_connection.py          # Prueba de conexiΓ³n MCP
β”œβ”€β”€ requirements.txt            # Dependencias
β”œβ”€β”€ README.md                   # DocumentaciΓ³n
β”œβ”€β”€ .gitignore                  # Archivos a ignorar
β”œβ”€β”€ .env.example                # Ejemplo de variables de entorno
β”œβ”€β”€ data/ # Datos
β”‚ β”œβ”€β”€ clientes.csv
β”‚ β”œβ”€β”€ ventas.csv
β”‚ β”œβ”€β”€ productos.csv
β”‚ β”œβ”€β”€ categorias.csv
β”‚ └── metodos_pago.csv
β”œβ”€β”€ tests/ # Pruebas unitarias
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ test_tools.py             # 8 pruebas de herramientas MCP
β”‚ β”œβ”€β”€ test_agent.py             # 5 pruebas del agente
β”‚ └── test_connection.py        # 1 prueba de conexiΓ³n
└── .streamlit/
  └── secrets.toml.example      # Ejemplo de secretos

πŸ”— Enlaces

ProducciΓ³n y Repositorio

DocumentaciΓ³n Oficial


πŸ‘₯ Equipo

  • Desarrollador: David Yurivilca

  • Curso: Estrategias de Integracion

  • Fecha de Entrega: 19/07/2026


πŸ“„ Licencia

MIT - Libre para uso educativo.


πŸ™ Agradecimientos

  • Groq por el modelo de lenguaje de alto rendimiento

  • LangChain por la orquestaciΓ³n del agente

  • FastMCP por el servidor de herramientas

  • Streamlit por la interfaz web

  • GuΓ­a del Curso por la estructura y requisitos

F
license - not found
-
quality - not tested
B
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

View all related MCP servers

Related MCP Connectors

  • Manage your NanoCart store from any AI agent: products, orders, coupons, subscribers, reports.

  • Manage your Savanto store from your AI: catalog, content, prompts, and analytics, by chat.

  • Web search, page extraction and structured commerce, social and business data for AI agents

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/systemyuri/agente-mcp-groq'

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