OpenLCA_Impact_Assessment_Tool
Perform life cycle impact assessments by analyzing product systems and impact methods using OpenLCA within the TianGong-LCA-MCP Server environment.
Instructions
Calculate life cycle impact assessment using OpenLCA.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| impactMethod | Yes | OpenLCA impact method ID | |
| serverUrl | No | OpenLCA IPC server URL | http://localhost:8080 |
| systemProcess | Yes | OpenLCA product system ID |
Implementation Reference
- src/tools/openlca_ipc_lcia.ts:5-9 (schema)Defines the Zod input schema for the OpenLCA_Impact_Assessment_Tool, specifying parameters for product system ID, impact method ID, and optional server URL.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'), };
- src/tools/openlca_ipc_lcia.ts:11-63 (handler)Core handler function that executes the LCA impact assessment by connecting to OpenLCA IPC server, fetching product system and impact method, performing calculation, and returning JSON results.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); }
- src/tools/openlca_ipc_lcia.ts:65-87 (registration)Registers the 'OpenLCA_Impact_Assessment_Tool' with the MCP server, providing name, description, input schema, and handler wrapper that calls the core calculateLcaImpacts function.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, }, ], }; }, ); }
- src/_shared/init_server.ts:24-24 (registration)Top-level call to register the OpenLCA_Impact_Assessment_Tool during server initialization.regOpenLcaLciaTool(server);
- src/_shared/init_server_http_local.ts:15-15 (registration)Top-level call to register the OpenLCA_Impact_Assessment_Tool in local HTTP server initialization.regOpenLcaLciaTool(server);