Skip to main content
Glama
mcgiverdev

MCP API Server

by mcgiverdev
README.md
# MCP API Server

Servidor MCP (Model Context Protocol) con arquitectura modular que permite conectarse a APIs externas.

## Estructura del Proyecto

```
src/
├── config/          # Configuración
│   ├── api.ts       # Configuración de API
│   └── env.ts       # Variables de entorno
├── services/        # Servicios de negocio
│   ├── httpClient.ts     # Cliente HTTP base
│   ├── userService.ts    # Servicio de usuarios
│   ├── weatherService.ts # Servicio de clima
│   └── companyService.ts # Servicio de empresas
├── tools/           # Herramientas MCP
│   ├── weatherTool.ts        # Herramienta de clima
│   ├── userCreateTool.ts     # Crear usuarios
│   ├── userListTool.ts       # Listar usuarios
│   ├── companyCreateTool.ts  # Crear empresas
│   └── companyListTool.ts    # Listar empresas
├── types/           # Tipos TypeScript
│   ├── api.ts       # Tipos base de API
│   └── company.ts   # Tipos de empresas
└── main.ts          # Punto de entrada
```

## Características

- ✅ Arquitectura modular y escalable
- ✅ Cliente HTTP reutilizable
- ✅ Validación con Zod
- ✅ Tipos TypeScript completos
- ✅ Manejo de errores robusto
- ✅ Configuración por variables de entorno

## Herramientas Disponibles

### Clima
- `obtener-clima`: Obtiene información del clima

### Usuarios
- `crear-usuario`: Crea un nuevo usuario
- `listar-usuarios`: Lista todos los usuarios

### Empresas (API Externa)
- `crear-empresa`: Crea una nueva empresa vía API
  - **Tamaños permitidos**: `small`, `medium`, `large`
- `listar-empresas`: Lista empresas desde la API

## Scripts Disponibles

```bash
# Construir el proyecto
npm run build

# Ejecutar en modo desarrollo
npm run dev

# Ejecutar el servidor
npm start

# Abrir inspector MCP
npm run inspector
```

## Variables de Entorno

```bash
API_BASE_URL=https://api.ejemplo.com  # URL base de la API
API_TIMEOUT=30000                     # Timeout en milisegundos
NODE_ENV=development                  # Entorno de ejecución
```

## Uso con Inspector MCP

1. Ejecutar el inspector: `npm run inspector`
2. El servidor se iniciará en modo debug
3. Se abrirá automáticamente el navegador con la interfaz

## Agregar Nuevos Servicios

Para agregar un nuevo servicio (ej: productos):

1. **Crear tipos** en `src/types/product.ts`
2. **Crear servicio** en `src/services/productService.ts`
3. **Crear herramientas** en `src/tools/productCreateTool.ts`, etc.
4. **Registrar herramientas** en `src/main.ts`
5. **Actualizar configuración** si es necesario

## Estructura de API Externa

El servidor está configurado para trabajar con APIs que sigan este formato:

### GET Response
```json
{
  "data": [...],
  "links": {
    "first": "string",
    "last": "string",
    "prev": "string", 
    "next": "string"
  },
  "meta": {
    "current_page": 0,
    "from": 0,
    "last_page": 0,
    "per_page": 0,
    "to": 0,
    "total": 0
  }
}
```

### POST Request
```json
{
  "field1": "value1",
  "field2": "value2"
}
```

TDQS

C2.7/5.0

Scored across 5 tools

Disambiguation4/5

The tools are mostly distinct, with clear separation between company and user operations. However, 'obtener-clima' (get weather) is an outlier that could cause confusion about the server's primary domain, as it doesn't relate to the company/user management focus of the other tools.

Naming Consistency4/5

Four of the five tools follow a consistent Spanish verb_noun pattern (crear-empresa, crear-usuario, listar-empresas, listar-usuarios). 'obtener-clima' also follows this pattern but uses a different verb ('obtener' vs 'crear/listar'), which is a minor deviation that maintains readability.

Tool Count3/5

Five tools is a reasonable count, but the inclusion of 'obtener-clima' makes the scope feel borderline. The core company/user management domain has good coverage with four tools, but the weather tool seems out of place, suggesting either an incomplete or overly broad scope.

Completeness2/5

For the apparent company/user management domain, there are significant gaps. While create and list operations exist for both entities, there are no update, delete, or get-by-id tools, which are essential for full CRUD coverage. The weather tool adds confusion rather than addressing these gaps.

Maintenance

ActivityInactive
ResponsivenessNo issues