Skip to main content
Glama

project_execute

Execute Python commands on a project TCP server to run code within the Visum Thinker context for structured problem-solving tasks.

Instructions

Execute a command on a project TCP server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdYesProject ID to execute command on
codeYesPython code to execute in the Visum context
descriptionYesDescription of what the code does

Implementation Reference

  • Registration of the 'project_execute' MCP tool, including input schema (Zod) and inline handler function that delegates execution to ProjectServerManager.executeCommand and formats the MCP response.
    server.tool( "project_execute", "Execute a command on a project TCP server", { projectId: z.string().describe("Project ID to execute command on"), code: z.string().describe("Python code to execute in the Visum context"), description: z.string().describe("Description of what the code does") }, async ({ projectId, code, description }) => { try { const result = await serverManager.executeCommand(projectId, code, description); if (result.success) { return { content: [ { type: "text", text: `⚔ **Comando Eseguito**\n\nāœ… ${description}\n\nšŸ“Š **Risultato:**\n\`\`\`json\n${JSON.stringify(result.result, null, 2)}\n\`\`\`\n\nā±ļø **Performance:**\n- Tempo risposta: ${result.responseTimeMs}ms\n- Esecuzione VisumPy: ${result.executionTimeMs}ms` } ] }; } else { return { content: [ { type: "text", text: `āŒ **Errore Esecuzione**\n\n${result.error}` } ] }; } } catch (error) { return { content: [ { type: "text", text: `āŒ **Errore:** ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
  • Core handler logic in ProjectServerManager: forwards the Python code as a 'query' command to the project's TCP server via sendCommandToServer.
    async executeCommand(projectId: string, code: string, description: string): Promise<any> { return await this.sendCommandToServer(projectId, { type: 'query', code, description }); }
  • TCP client implementation: Establishes TCP connection to the project-specific server (spawned by project_open), sends JSON command with code, receives and parses JSON response.
    async sendCommandToServer(projectId: string, command: any): Promise<any> { const serverInfo = this.activeServers.get(projectId); if (!serverInfo) { throw new Error('Server progetto non trovato'); } return new Promise((resolve, reject) => { const client = createConnection(serverInfo.port, 'localhost'); let buffer = ''; client.on('connect', () => { const message = JSON.stringify({ ...command, requestId: Date.now() }); client.write(message + '\n'); }); client.on('data', (data: any) => { buffer += data.toString(); // Dividi per newlines per separare i messaggi const messages = buffer.split('\n'); buffer = messages.pop() || ''; // Mantieni l'ultimo pezzo (potrebbe essere incompleto) for (const message of messages) { if (message.trim()) { try { // Rimuovi backslash-n letterali che il server TCP Python aggiunge const cleanedResponse = message.replace(/\\n$/g, ''); const response = JSON.parse(cleanedResponse); // Ignora il messaggio di welcome, aspetta la risposta vera if (response.type === 'project_welcome') { continue; } // Risposta al comando ricevuta (query_result, save_result, error, etc.) if (response.type === 'query_result' || response.type === 'save_result' || response.type === 'error' || response.type === 'shutdown_ack' || response.result !== undefined) { client.end(); resolve(response); return; } } catch (error) { // Ignora messaggi malformati, continua ad aspettare console.error('WARN: Messaggio TCP non parsabile:', message); } } } }); client.on('error', (error: any) => { reject(error); }); setTimeout(() => { client.end(); reject(new Error('Timeout comando server')); }, 300000); // 5 minuti timeout per operazioni pesanti su reti grandi }); }

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/multiluca2020/visum-thinker-mcp-server'

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