@jorgeceballos/mcp-server-oci
Version:
Model Context Protocol server for Oracle Cloud Infrastructure
95 lines (86 loc) • 2.92 kB
JavaScript
#!/usr/bin/env node
// Servidor MCP dedicado para usar con el inspector
// Este script crea un servidor MCP muy básico que funciona con el inspector
// sin problemas de comunicación
const { McpServer } = require('@modelcontextprotocol/sdk/server/mcp.js');
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
const { z } = require('zod');
async function main() {
try {
// Crear un servidor MCP básico
const server = new McpServer({
name: 'OCI Server (Inspector Mode)',
version: '1.0.0'
});
// Registrar una herramienta de ejemplo
server.tool(
'list_compartments',
'Lists all compartments available in your Oracle Cloud Infrastructure account',
async (extra) => {
try {
// En modo inspector, devolver un resultado de ejemplo
return {
content: [{
text: JSON.stringify([
{
id: "ocid1.compartment.oc1..example1",
name: "Example Compartment 1",
description: "Example compartment for testing",
timeCreated: "2024-05-01T12:00:00.000Z"
},
{
id: "ocid1.compartment.oc1..example2",
name: "Example Compartment 2",
description: "Another example compartment",
timeCreated: "2024-05-02T12:00:00.000Z"
}
], null, 2),
type: "text"
}]
};
} catch (error) {
throw error;
}
}
);
// Herramienta list_instances
server.tool(
'list_instances',
{ compartmentId: z.string().describe('The OCID of the compartment to list instances from') },
async (args, extra) => {
try {
return {
content: [{
text: JSON.stringify([
{
id: "ocid1.instance.oc1..example1",
displayName: "Example Instance 1",
shape: "VM.Standard2.1",
lifecycleState: "RUNNING",
timeCreated: "2024-05-01T12:00:00.000Z",
availabilityDomain: "ABcd:US-ASHBURN-AD-1",
faultDomain: "FAULT-DOMAIN-1"
}
], null, 2),
type: "text"
}]
};
} catch (error) {
throw error;
}
}
);
// Crear transporte stdio para la interfaz de línea de comandos
const transport = new StdioServerTransport();
// Conectar el servidor al transporte
await server.connect(transport);
} catch (error) {
process.stderr.write(`Error en el servidor MCP: ${error.message}\n`);
process.exit(1);
}
}
// Iniciar el servidor
main().catch(error => {
process.stderr.write(`Error fatal: ${error.message}\n`);
process.exit(1);
});