16
README.md
16
README.md
@@ -2,6 +2,22 @@
|
|||||||
|
|
||||||
Servidor MCP (Model Context Protocol) para consultar la API del Instituto Nacional de Estadística (INE) de España. Implementa soporte completo para JSON-RPC sobre HTTP y SSE (Server-Sent Events), optimizado para su uso con VS Code AI Toolkit.
|
Servidor MCP (Model Context Protocol) para consultar la API del Instituto Nacional de Estadística (INE) de España. Implementa soporte completo para JSON-RPC sobre HTTP y SSE (Server-Sent Events), optimizado para su uso con VS Code AI Toolkit.
|
||||||
|
|
||||||
|
## ⚠️ Importante: Datos Disponibles
|
||||||
|
|
||||||
|
**Este servidor solo proporciona acceso a las estadísticas del INE.** El INE NO incluye datos de criminalidad.
|
||||||
|
|
||||||
|
**Tipos de datos disponibles:**
|
||||||
|
- 📊 Demografía y población
|
||||||
|
- 💰 Economía (IPC, PIB, mercado laboral)
|
||||||
|
- 🏢 Empresas y comercio
|
||||||
|
- 🏘️ Vivienda y construcción
|
||||||
|
- 📚 Educación y sociedad
|
||||||
|
- 🌾 Agricultura y medio ambiente
|
||||||
|
|
||||||
|
Para estadísticas de criminalidad en España, consulta el [Portal Estadístico de Criminalidad del Ministerio del Interior](https://estadisticasdecriminalidad.ses.mir.es/).
|
||||||
|
|
||||||
|
Ver la [guía completa de datos disponibles](./DATOS_DISPONIBLES.md) para más información.
|
||||||
|
|
||||||
## 🌟 Características
|
## 🌟 Características
|
||||||
|
|
||||||
- ✅ **Protocolo MCP completo**: Soporte para JSON-RPC y SSE
|
- ✅ **Protocolo MCP completo**: Soporte para JSON-RPC y SSE
|
||||||
|
|||||||
@@ -895,7 +895,7 @@ app.post('/mcp/v1', async (req: Request, res: Response) => {
|
|||||||
console.log(`MCP tools/call: ${name}`, args);
|
console.log(`MCP tools/call: ${name}`, args);
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return res.status(400).json({
|
return res.status(200).json({
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
error: {
|
error: {
|
||||||
code: -32602,
|
code: -32602,
|
||||||
|
|||||||
@@ -84,46 +84,340 @@ async function handleToolCall(name: string, args: any): Promise<any> {
|
|||||||
const tools = [
|
const tools = [
|
||||||
{
|
{
|
||||||
name: 'ine_datos_tabla',
|
name: 'ine_datos_tabla',
|
||||||
description: 'Obtiene datos de una tabla específica del INE',
|
description: 'Obtiene datos de una tabla específica del INE. Permite filtrar por periodos, nivel de detalle y variables.',
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
idTabla: { type: 'string', description: 'ID de la tabla' },
|
idTabla: { type: 'string', description: 'ID de la tabla (ej: 50902)' },
|
||||||
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES', description: 'Idioma' },
|
||||||
nult: { type: 'number' },
|
nult: { type: 'number', description: 'Número de últimos periodos' },
|
||||||
det: { type: 'number', enum: [0, 1, 2] },
|
det: { type: 'number', enum: [0, 1, 2], description: 'Nivel de detalle' },
|
||||||
tip: { type: 'string', enum: ['A', 'M', 'AM'] }
|
tip: { type: 'string', enum: ['A', 'M', 'AM'], description: 'Tipo: A=amigable, M=metadatos, AM=ambos' },
|
||||||
|
tv: { type: 'string', description: 'Filtro de variables (formato: id_variable:id_valor)' },
|
||||||
|
date: { type: 'string', description: 'Rango de fechas (formato: aaaammdd:aaaammdd)' }
|
||||||
},
|
},
|
||||||
required: ['idTabla']
|
required: ['idTabla']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'ine_datos_serie',
|
name: 'ine_datos_serie',
|
||||||
description: 'Obtiene datos de una serie temporal',
|
description: 'Obtiene datos de una serie temporal específica del INE.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idSerie: { type: 'string', description: 'Código de la serie (ej: IPC251856)' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
nult: { type: 'number', description: 'Número de últimos periodos' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2], description: 'Nivel de detalle' },
|
||||||
|
tip: { type: 'string', enum: ['A', 'M', 'AM'], description: 'Tipo de respuesta' },
|
||||||
|
date: { type: 'string', description: 'Rango de fechas' }
|
||||||
|
},
|
||||||
|
required: ['idSerie']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_datos_metadata_operacion',
|
||||||
|
description: 'Obtiene datos de series usando filtros de metadata de una operación.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idOperacion: { type: 'string', description: 'Código de operación (ej: IPC)' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
p: { type: 'number', description: 'Periodicidad (1=mensual, 3=trimestral, 12=anual)' },
|
||||||
|
nult: { type: 'number', description: 'Número de últimos periodos' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
tip: { type: 'string', enum: ['A', 'M', 'AM'] },
|
||||||
|
g1: { type: 'string', description: 'Filtro 1 (formato: id_variable:id_valor)' },
|
||||||
|
g2: { type: 'string', description: 'Filtro 2' },
|
||||||
|
g3: { type: 'string', description: 'Filtro 3' },
|
||||||
|
g4: { type: 'string', description: 'Filtro 4' },
|
||||||
|
g5: { type: 'string', description: 'Filtro 5' }
|
||||||
|
},
|
||||||
|
required: ['idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_operaciones_disponibles',
|
||||||
|
description: 'Lista todas las operaciones estadísticas disponibles en el INE.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
geo: { type: 'number', enum: [0, 1], description: '0=nacional, 1=geográfico' },
|
||||||
|
page: { type: 'number', description: 'Página (500 elementos por página)' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_operacion',
|
||||||
|
description: 'Obtiene información detallada de una operación estadística.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idOperacion: { type: 'string', description: 'Código de operación' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] }
|
||||||
|
},
|
||||||
|
required: ['idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_variables',
|
||||||
|
description: 'Lista todas las variables estadísticas disponibles.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
page: { type: 'number' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_variables_operacion',
|
||||||
|
description: 'Obtiene las variables utilizadas en una operación específica.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idOperacion: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
page: { type: 'number' }
|
||||||
|
},
|
||||||
|
required: ['idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_valores_variable',
|
||||||
|
description: 'Obtiene todos los valores posibles de una variable.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idVariable: { type: 'string', description: 'ID de la variable' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
clasif: { type: 'number', description: 'ID de clasificación' }
|
||||||
|
},
|
||||||
|
required: ['idVariable']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_valores_variable_operacion',
|
||||||
|
description: 'Obtiene valores de una variable en el contexto de una operación.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idVariable: { type: 'string' },
|
||||||
|
idOperacion: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] }
|
||||||
|
},
|
||||||
|
required: ['idVariable', 'idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_tablas_operacion',
|
||||||
|
description: 'Lista todas las tablas de una operación estadística.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idOperacion: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
geo: { type: 'number', enum: [0, 1] },
|
||||||
|
tip: { type: 'string', enum: ['A'] }
|
||||||
|
},
|
||||||
|
required: ['idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_grupos_tabla',
|
||||||
|
description: 'Obtiene los grupos de selección que definen una tabla.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idTabla: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' }
|
||||||
|
},
|
||||||
|
required: ['idTabla']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_valores_grupos_tabla',
|
||||||
|
description: 'Obtiene los valores de un grupo específico de una tabla.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idTabla: { type: 'string' },
|
||||||
|
idGrupo: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] }
|
||||||
|
},
|
||||||
|
required: ['idTabla', 'idGrupo']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_serie',
|
||||||
|
description: 'Obtiene información completa de una serie temporal.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idSerie: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
tip: { type: 'string', enum: ['A', 'M', 'AM'] }
|
||||||
|
},
|
||||||
|
required: ['idSerie']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_series_operacion',
|
||||||
|
description: 'Lista todas las series de una operación.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idOperacion: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
tip: { type: 'string', enum: ['A', 'M', 'AM'] },
|
||||||
|
page: { type: 'number' }
|
||||||
|
},
|
||||||
|
required: ['idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_valores_serie',
|
||||||
|
description: 'Obtiene las variables y valores que definen una serie.',
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
idSerie: { type: 'string' },
|
idSerie: { type: 'string' },
|
||||||
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
nult: { type: 'number' },
|
|
||||||
det: { type: 'number', enum: [0, 1, 2] }
|
det: { type: 'number', enum: [0, 1, 2] }
|
||||||
},
|
},
|
||||||
required: ['idSerie']
|
required: ['idSerie']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'ine_operaciones_disponibles',
|
name: 'ine_series_tabla',
|
||||||
description: 'Lista todas las operaciones estadísticas',
|
description: 'Obtiene todas las series de una tabla específica.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idTabla: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
tip: { type: 'string', enum: ['A', 'M', 'AM'] },
|
||||||
|
tv: { type: 'string', description: 'Filtro de variables' }
|
||||||
|
},
|
||||||
|
required: ['idTabla']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_serie_metadata_operacion',
|
||||||
|
description: 'Busca series usando filtros de metadata en una operación.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idOperacion: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
p: { type: 'number', description: 'Periodicidad' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
tip: { type: 'string', enum: ['A', 'M', 'AM'] },
|
||||||
|
g1: { type: 'string' },
|
||||||
|
g2: { type: 'string' },
|
||||||
|
g3: { type: 'string' },
|
||||||
|
g4: { type: 'string' },
|
||||||
|
g5: { type: 'string' }
|
||||||
|
},
|
||||||
|
required: ['idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_periodicidades',
|
||||||
|
description: 'Lista todas las periodicidades disponibles (mensual, trimestral, etc.).',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_publicaciones',
|
||||||
|
description: 'Lista todas las publicaciones estadísticas disponibles.',
|
||||||
inputSchema: {
|
inputSchema: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
geo: { type: 'number', enum: [0, 1] },
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
page: { type: 'number' }
|
tip: { type: 'string', enum: ['A'] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_publicaciones_operacion',
|
||||||
|
description: 'Obtiene las publicaciones de una operación específica.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idOperacion: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
tip: { type: 'string', enum: ['A'] }
|
||||||
|
},
|
||||||
|
required: ['idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_publicacion_fecha_publicacion',
|
||||||
|
description: 'Obtiene las fechas de publicación para una publicación dada.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idPublicacion: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] },
|
||||||
|
tip: { type: 'string', enum: ['A'] }
|
||||||
|
},
|
||||||
|
required: ['idPublicacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_clasificaciones',
|
||||||
|
description: 'Lista todas las clasificaciones estadísticas disponibles.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_clasificaciones_operacion',
|
||||||
|
description: 'Obtiene las clasificaciones utilizadas en una operación.',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idOperacion: { type: 'string' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' }
|
||||||
|
},
|
||||||
|
required: ['idOperacion']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ine_valores_hijos',
|
||||||
|
description: 'Obtiene valores hijos en una estructura jerárquica (ej: provincias de una comunidad).',
|
||||||
|
inputSchema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
idVariable: { type: 'string', description: 'ID de la variable' },
|
||||||
|
idValor: { type: 'string', description: 'ID del valor padre' },
|
||||||
|
idioma: { type: 'string', enum: ['ES', 'EN'], default: 'ES' },
|
||||||
|
det: { type: 'number', enum: [0, 1, 2] }
|
||||||
|
},
|
||||||
|
required: ['idVariable', 'idValor']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Agregar el resto de herramientas según sea necesario
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Referencia en una nueva incidencia
Block a user