Skip to main content
Glama
linancn

TianGong-LCA-MCP Server

by linancn
openlca_ipc_lcia.ts2.4 kB
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import * as o from 'olca-ipc'; import { z } from 'zod'; const input_schema = { productSystem: z.string().min(1).describe('OpenLCA product system ID'), impactMethod: z.string().min(1).describe('OpenLCA impact method ID'), serverUrl: z.string().default('http://localhost:8080').describe('OpenLCA IPC server URL'), }; async function calculateLcaImpacts({ productSystem, impactMethod, serverUrl = 'http://localhost:8080', }: { productSystem: string; impactMethod: string; serverUrl?: string; }): Promise<string> { if (!productSystem) { throw new Error('No productSystem provided'); } if (!impactMethod) { throw new Error('No impactMethod provided'); } const client = o.IpcClient.on(serverUrl); const selectedProductSystem = await client.get(o.RefType.ProductSystem, productSystem); if (!selectedProductSystem) throw new Error('Product system not found'); // Get impact method const selectedMethod = await client.get(o.RefType.ImpactMethod, impactMethod); if (!selectedMethod) throw new Error('Impact method not found'); // Calculate the system console.log('Calculating LCA impacts...'); const setup = o.CalculationSetup.of({ target: selectedProductSystem as o.Ref, impactMethod: selectedMethod as o.Ref, }); const result = await client.calculate(setup); const state = await result.untilReady(); if (state.error) { throw new Error(`Calculation failed: ${state.error}`); } // Query the result const impacts = await result.getTotalImpacts(); const resultsObj = impacts.map((impact) => ({ name: impact.impactCategory?.name, value: impact.amount, unit: impact.impactCategory?.refUnit, })); // Dispose the result result.dispose(); return JSON.stringify(resultsObj); } export function regOpenLcaLciaTool(server: McpServer) { server.tool( 'OpenLCA_Impact_Assessment_Tool', 'Calculate life cycle impact assessment using OpenLCA.', input_schema, async ({ productSystem, impactMethod, serverUrl }) => { const result = await calculateLcaImpacts({ productSystem: productSystem, impactMethod: impactMethod, serverUrl: serverUrl, }); return { content: [ { type: 'text', text: result, }, ], }; }, ); }

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/linancn/tiangong-lca-mcp'

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