@trace.market/types 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +6 -5
- package/CHANGELOG.md +23 -0
- package/IMPLEMENTATION.md +8 -13
- package/OPENLCA_INTEGRATION_PLAN.md +253 -0
- package/OPENLCA_MCP_ENRICHER_SPEC.md +416 -0
- package/OPENLCA_MCP_GUIDE.md +158 -0
- package/QUICKSTART.md +1 -10
- package/generate-json.ts +8 -0
- package/mcp-config.example.json +1 -1
- package/mcp-server/1767725715307.conversation.json +3337 -0
- package/mcp-server/README.md +2 -0
- package/mcp-server/docs/AI-integration-notes.md +330 -0
- package/mcp-server/package-lock.json +221 -0
- package/mcp-server/package.json +10 -7
- package/mcp-server/scripts/start-tcp-shim.sh +10 -0
- package/mcp-server/src/ai-service.ts +386 -0
- package/mcp-server/src/food-service.ts +510 -0
- package/mcp-server/src/index.ts +682 -8
- package/mcp-server/src/non-food-service.ts +612 -0
- package/mcp-server/tsconfig.json +17 -0
- package/package.json +6 -3
- package/package1.json +32 -0
- package/src/descriptions.json +836 -0
- package/src/descriptions.ts +722 -0
- package/src/index.d.ts +80 -22
- package/src/openlcaMcpTypes.ts +251 -0
- package/mcp-server/.env.example +0 -9
|
@@ -15,6 +15,7 @@ jobs:
|
|
|
15
15
|
permissions:
|
|
16
16
|
contents: write
|
|
17
17
|
packages: write
|
|
18
|
+
id-token: write # Required for provenance and OIDC auth
|
|
18
19
|
|
|
19
20
|
steps:
|
|
20
21
|
- uses: actions/checkout@v4
|
|
@@ -48,7 +49,7 @@ jobs:
|
|
|
48
49
|
|
|
49
50
|
- name: Publish to NPM
|
|
50
51
|
if: steps.check.outputs.changed == 'true'
|
|
51
|
-
run: npm publish --access public
|
|
52
|
+
run: npm publish --provenance --access public
|
|
52
53
|
env:
|
|
53
54
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
54
55
|
|
|
@@ -62,11 +63,11 @@ jobs:
|
|
|
62
63
|
|
|
63
64
|
- name: Create GitHub Release
|
|
64
65
|
if: steps.check.outputs.changed == 'true'
|
|
65
|
-
uses:
|
|
66
|
-
env:
|
|
67
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
66
|
+
uses: softprops/action-gh-release@v1
|
|
68
67
|
with:
|
|
69
68
|
tag_name: v${{ steps.check.outputs.version }}
|
|
70
|
-
|
|
69
|
+
name: Release v${{ steps.check.outputs.version }}
|
|
71
70
|
draft: false
|
|
72
71
|
prerelease: false
|
|
72
|
+
env:
|
|
73
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.3.0] - 2026-01-19
|
|
6
|
+
|
|
7
|
+
### ⚠ BREAKING CHANGES
|
|
8
|
+
- **Renaming**: `MachineInstance` is renamed to `ToolInstance`. All references to `machineInstance` in processes are renamed to `toolInstance`.
|
|
9
|
+
- **Structure**: `hr` (Human Resources) field moved from `ToolInstance` to `Process` interface. It is now a sibling of `toolInstance`.
|
|
10
|
+
- **Typing**: `Hr.tasks` is now `string[]` (array of strings) instead of `string`.
|
|
11
|
+
- **Typing**: `KnowHow.inputs` is explicitly defined as a JSONata expression string.
|
|
12
|
+
- **Data Model**: Renamed `CartridgeInstance` to `NonFoodInstance` with category `non-food`.
|
|
13
|
+
- **Data Model**: Removed `PackagingProcess` and `StorageProcess`.
|
|
14
|
+
- **Data Model**: Consolidated `ecoLabels` and `qualityAttributes` into a single `labels` array.
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
- Added `hash` field to `ToolInstance`.
|
|
18
|
+
- Added support for ordered steps in `Hr.tasks`.
|
|
19
|
+
- Validation rules in `KnowHow` are now standardized as JSONata.
|
|
20
|
+
|
|
21
|
+
### Documentation (descriptions.json)
|
|
22
|
+
- Renamed root field `description` to `header`.
|
|
23
|
+
- Updated all labels and examples to reflect the new "Tool" terminology and "JSONata" rules.
|
package/IMPLEMENTATION.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## ✅ Completed Setup
|
|
4
4
|
|
|
5
5
|
### 1. Package Configuration
|
|
6
|
-
- **Name
|
|
6
|
+
- **Name**: `@trace.market/types` (new scoped release)
|
|
7
7
|
- **Version**: 0.1.0
|
|
8
8
|
- **License**: MIT (was UNLICENSED)
|
|
9
9
|
- **Repository**: Linked to https://github.com/entin-hun/tm-types
|
|
@@ -52,7 +52,7 @@ Created `.github/workflows/`:
|
|
|
52
52
|
|
|
53
53
|
## 📦 Current Type Definitions
|
|
54
54
|
|
|
55
|
-
All types from `@
|
|
55
|
+
All types from `@trace.market/types@0.0.6` are preserved:
|
|
56
56
|
- Pokedex, ProductInstance, FoodInstance, CartridgeInstance
|
|
57
57
|
- Process types: Milling, Printing, FreezeDrying, Blending, Sale, Harvest
|
|
58
58
|
- Supply chain: Transport, Facility, Location, InputInstance
|
|
@@ -103,22 +103,17 @@ JWT_SECRET="your-secret" node generate-token.js userId role
|
|
|
103
103
|
|
|
104
104
|
## 🔄 Migration Path
|
|
105
105
|
|
|
106
|
-
### For Projects Using `@
|
|
106
|
+
### For Projects Using `@trace.market/types`
|
|
107
107
|
|
|
108
108
|
1. **Update dependencies:**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
```
|
|
109
|
+
```bash
|
|
110
|
+
npm install @trace.market/types@^0.1.0
|
|
111
|
+
```
|
|
113
112
|
|
|
114
113
|
2. **Find & replace imports:**
|
|
115
|
-
|
|
116
|
-
// Old
|
|
117
|
-
import { FoodInstance } from '@fairfooddata/types';
|
|
118
|
-
|
|
119
|
-
// New
|
|
114
|
+
```typescript
|
|
120
115
|
import { FoodInstance } from '@trace.market/types';
|
|
121
|
-
|
|
116
|
+
```
|
|
122
117
|
|
|
123
118
|
3. **Test builds:**
|
|
124
119
|
```bash
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# OpenLCA Integration Plan - Summary
|
|
2
|
+
|
|
3
|
+
## ✅ Completed
|
|
4
|
+
|
|
5
|
+
### 1. **Database Inventory**
|
|
6
|
+
All LCA datasets extracted and catalogued:
|
|
7
|
+
|
|
8
|
+
| Database | Processes | Best For | Size |
|
|
9
|
+
|----------|-----------|----------|------|
|
|
10
|
+
| **BAFU-2025_LCI_DB_17Dec25** | 11,747 | **Textiles, agriculture, construction (PRIMARY)** | 250 MB |
|
|
11
|
+
| exiobase3_monetary_20181212 | 7,504 | Global fallback, input-output | 13 GB |
|
|
12
|
+
| usda_1901009 | 8,434 | US agriculture/food | 378 MB |
|
|
13
|
+
| ELCD 3.2 | 365 | EU reference processes | 864 MB |
|
|
14
|
+
| EcoProfiles_disaggregated | 71 | Foreground detailed models | 9.5 MB |
|
|
15
|
+
| needs_18 | 933 | Building/construction (EU) | 501 MB |
|
|
16
|
+
| bioenergiedat_18 | - | Bioenergy systems | 81 MB |
|
|
17
|
+
| OzLCI2019 | - | Australian processes | 87 MB |
|
|
18
|
+
| Worldsteel 2020 | - | Steel production | 57 MB |
|
|
19
|
+
|
|
20
|
+
### 2. **LCIA Method Identification**
|
|
21
|
+
**EF 3.1 (Environmental Footprint v3.1)** ✅ **RECOMMENDED**
|
|
22
|
+
- **UUID**: `20629e27-b863-4fbe-bbc2-082d3eefd1e5`
|
|
23
|
+
- **Location**: `ecoinvent 3.12 LCIA Methods 2025-12-01`
|
|
24
|
+
- **Impact Categories**: 16 categories
|
|
25
|
+
- Climate change (fossil + biogenic + LULUC)
|
|
26
|
+
- Acidification, eutrophication (freshwater, marine, terrestrial)
|
|
27
|
+
- Ecotoxicity (freshwater, 3 subcategories)
|
|
28
|
+
- Human toxicity (carcinogenic + non-carcinogenic, 3 subcategories each)
|
|
29
|
+
- Land use
|
|
30
|
+
- Water use
|
|
31
|
+
- Material resources (metals/minerals)
|
|
32
|
+
- Ozone depletion
|
|
33
|
+
- Ionising radiation
|
|
34
|
+
- Particulate matter
|
|
35
|
+
- Photochemical oxidant formation
|
|
36
|
+
- Energy resources (non-renewable)
|
|
37
|
+
|
|
38
|
+
**Alternatives Available**:
|
|
39
|
+
- EF v3.0 (UUID: `1a653397-a909-4c2c-80d7-186462c20889`)
|
|
40
|
+
- ReCiPe 2016 v1.03 (midpoint + endpoint)
|
|
41
|
+
- TRACI v2.1 (US EPA)
|
|
42
|
+
- CML v4.8
|
|
43
|
+
- Ecological Scarcity 2021
|
|
44
|
+
|
|
45
|
+
### 3. **Primary Database Selection**
|
|
46
|
+
**BAFU-2025_LCI_DB_17Dec25** (11,747 processes)
|
|
47
|
+
- ✅ Covers **textiles**: Cotton, wool, synthetic fabrics, dyeing, weaving
|
|
48
|
+
- ✅ Covers **agriculture**: Grain, vegetable, fruit, dairy, meat, seed production
|
|
49
|
+
- ✅ Covers **construction**: Bricks, concrete, wood, insulation, glass
|
|
50
|
+
- ✅ Geographic: Swiss/EU focus (high data quality)
|
|
51
|
+
- ✅ Includes emissions to air, water, soil
|
|
52
|
+
- ✅ Compatible with EF 3.1
|
|
53
|
+
|
|
54
|
+
**Fallback Strategy**:
|
|
55
|
+
- If location="USA" → try `usda_1901009` first
|
|
56
|
+
- If sector="global" or not found → `exiobase3_monetary_20181212`
|
|
57
|
+
- If EU/CH → BAFU (primary)
|
|
58
|
+
|
|
59
|
+
### 4. **Input Field Analysis (tm-types → Impacts)**
|
|
60
|
+
|
|
61
|
+
From your `ProductInstance` & `Process` types, minimum fields for impact estimate:
|
|
62
|
+
|
|
63
|
+
| Field | Required? | Source | Enricher Default |
|
|
64
|
+
|-------|-----------|--------|-----------------|
|
|
65
|
+
| `processName` | **YES** | Process.type + process.name | None (must provide) |
|
|
66
|
+
| `amount` | **YES** | quantity from InputInstance | None (must provide) |
|
|
67
|
+
| `unit` | **YES** | Unit from quantity | None (must provide) |
|
|
68
|
+
| `flowType` | Recommended | Process category | Inferred from sector |
|
|
69
|
+
| `location` | Recommended | Facility.location (geo) | "CH" / "EU" |
|
|
70
|
+
| `database` | No | — | Auto-selected by enricher |
|
|
71
|
+
| `lciaMethod` | No | — | "EF 3.1" |
|
|
72
|
+
| `systemBoundary` | No | — | "cradle-to-gate" |
|
|
73
|
+
| `allocation` | No | — | "cut-off" |
|
|
74
|
+
|
|
75
|
+
**Bottom Line**: Your types **mostly have what's needed**. Missing: explicit `unit` might need normalization (e.g., grams → kg).
|
|
76
|
+
|
|
77
|
+
### 5. **MCP Enricher Contract**
|
|
78
|
+
|
|
79
|
+
Created comprehensive TypeScript schema in:
|
|
80
|
+
- **[OPENLCA_MCP_ENRICHER_SPEC.md](/opt/tm-types/OPENLCA_MCP_ENRICHER_SPEC.md)** – Full architecture & logic
|
|
81
|
+
- **[openlcaMcpTypes.ts](/opt/tm-types/src/openlcaMcpTypes.ts)** – Request/response types
|
|
82
|
+
|
|
83
|
+
**Key Endpoints**:
|
|
84
|
+
```
|
|
85
|
+
POST /api/estimate/impacts → EstimateResponse
|
|
86
|
+
GET /api/databases → DatabasesListResponse
|
|
87
|
+
GET /api/lcia-methods → LCIAMethodsListResponse
|
|
88
|
+
POST /api/estimate/processes/search → ProcessSearchResult
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Example Flow**:
|
|
92
|
+
```typescript
|
|
93
|
+
const request: EstimateImpactRequest = {
|
|
94
|
+
processName: "Cotton fabric production",
|
|
95
|
+
amount: 1,
|
|
96
|
+
unit: "m2",
|
|
97
|
+
flowType: "product",
|
|
98
|
+
location: "IN"
|
|
99
|
+
// database, lciaMethod auto-filled by enricher
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const response: EstimateSuccess = {
|
|
103
|
+
status: "success",
|
|
104
|
+
results: {
|
|
105
|
+
lcia: {
|
|
106
|
+
method: "EF v3.1",
|
|
107
|
+
impacts: [
|
|
108
|
+
{ category: "Climate change", value: 2.45, unit: "kg CO2-Eq" },
|
|
109
|
+
{ category: "Water use", value: 0.082, unit: "m3 world Eq deprived" },
|
|
110
|
+
// ... 14 more categories
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 🚀 Next Steps (Implementation)
|
|
120
|
+
|
|
121
|
+
### Phase 1: Enricher Middleware (Week 1)
|
|
122
|
+
1. Build Node.js/Express MCP enricher service (TypeScript)
|
|
123
|
+
2. Implement database selector + fuzzy process matcher
|
|
124
|
+
3. Wire unit conversions + LCIA method selection
|
|
125
|
+
4. Deploy at `/api/lca` endpoint (beside gdt-server)
|
|
126
|
+
|
|
127
|
+
### Phase 2: gdt-server Integration (Week 2)
|
|
128
|
+
1. Confirm gdt-server is running with **BAFU-2025_LCI_DB_17Dec25** as `-db bafu`
|
|
129
|
+
2. Test direct calculation: `POST /api/calculate` (gdt-server REST API)
|
|
130
|
+
3. Implement enricher → gdt-server bridge
|
|
131
|
+
|
|
132
|
+
### Phase 3: tm-types Integration (Week 3)
|
|
133
|
+
1. Add `impacts?: ImpactResult[]` to `Process` interface
|
|
134
|
+
2. Implement `traceMarketToEstimate()` helper to convert ProductInstance → enricher request
|
|
135
|
+
3. Cache impact calculations (Redis or simple in-memory)
|
|
136
|
+
4. Expose `/estimate/impacts` as public endpoint on lca.trace.market
|
|
137
|
+
|
|
138
|
+
### Phase 4: Testing & Optimization (Week 4)
|
|
139
|
+
1. Test with real textiles/agriculture/construction products
|
|
140
|
+
2. Validate EF 3.1 category accuracy
|
|
141
|
+
3. Optimize fuzzy-match performance (process index)
|
|
142
|
+
4. Document API for consumers
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 📋 Database URLs (gdt-server Configuration)
|
|
147
|
+
|
|
148
|
+
To run multiple DBs simultaneously (load-balance or A/B test):
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Primary (textiles, agriculture, construction)
|
|
152
|
+
docker run -p 38081:8080 \
|
|
153
|
+
-v /root/openLCA-data-1.4/databases/BAFU-2025_LCI_DB_17Dec25:/app/data/databases/bafu \
|
|
154
|
+
--name gdt-bafu --rm -d gdt-server -db bafu --readonly
|
|
155
|
+
|
|
156
|
+
# Fallback (US agriculture)
|
|
157
|
+
docker run -p 38082:8080 \
|
|
158
|
+
-v /root/openLCA-data-1.4/databases/usda_1901009:/app/data/databases/usda \
|
|
159
|
+
--name gdt-usda --rm -d gdt-server -db usda --readonly
|
|
160
|
+
|
|
161
|
+
# Global IO
|
|
162
|
+
docker run -p 38083:8080 \
|
|
163
|
+
-v /root/openLCA-data-1.4/databases/exiobase3_monetary_20181212_fixedlcia_July2021:/app/data/databases/exio \
|
|
164
|
+
--name gdt-exio --rm -d gdt-server -db exio --readonly
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Then nginx reverse-proxy:
|
|
168
|
+
```
|
|
169
|
+
/api/bafu/* → :38081
|
|
170
|
+
/api/usda/* → :38082
|
|
171
|
+
/api/global/* → :38083
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 🔧 Enricher Config (Server-Side)
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
const enricherConfig: EnricherConfig = {
|
|
180
|
+
primaryDatabase: "BAFU-2025_LCI_DB_17Dec25",
|
|
181
|
+
secondaryDatabases: {
|
|
182
|
+
usa: "usda_1901009",
|
|
183
|
+
global: "exiobase3_monetary_20181212_fixedlcia_July2021",
|
|
184
|
+
eu: "BAFU-2025_LCI_DB_17Dec25"
|
|
185
|
+
},
|
|
186
|
+
defaultLCIAMethod: "20629e27-b863-4fbe-bbc2-082d3eefd1e5", // EF 3.1
|
|
187
|
+
gdtServerUrl: "http://127.0.0.1:38081",
|
|
188
|
+
fuzzyMatchThreshold: 0.7,
|
|
189
|
+
unitConversions: {
|
|
190
|
+
g: { kg: 0.001, t: 1e-6 },
|
|
191
|
+
kg: { g: 1000, t: 0.001 },
|
|
192
|
+
m2: { m2: 1 },
|
|
193
|
+
kWh: { MJ: 3.6, J: 3.6e6 },
|
|
194
|
+
MJ: { kWh: 0.2778, J: 1e6 }
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 📊 Expected LCIA Results (EF 3.1 Example)
|
|
202
|
+
|
|
203
|
+
For 1 kg cotton fabric (conventional, bleached):
|
|
204
|
+
|
|
205
|
+
| Impact | Value | Unit |
|
|
206
|
+
|--------|-------|------|
|
|
207
|
+
| Climate change | 2.45 | kg CO2-Eq |
|
|
208
|
+
| Water use | 0.082 | m3 world Eq deprived |
|
|
209
|
+
| Acidification | 0.0015 | mol H+-Eq |
|
|
210
|
+
| Eutrophication (terrestrial) | 0.0082 | mol N-Eq |
|
|
211
|
+
| Ecotoxicity (freshwater) | 0.012 | CTUe |
|
|
212
|
+
| Human toxicity (carcinogenic) | 1.2e-6 | CTUh |
|
|
213
|
+
| Land use | 0.0042 | dimensionless |
|
|
214
|
+
| Particulate matter | 0.00045 | disease incidence |
|
|
215
|
+
| Ozone depletion | 5e-8 | kg CFC-11-Eq |
|
|
216
|
+
| Material resources | 0.00015 | kg Sb-Eq |
|
|
217
|
+
| Energy (non-renewable) | 18.5 | MJ |
|
|
218
|
+
| Ionising radiation | 0.082 | kBq U235-Eq |
|
|
219
|
+
| Eutrophication (freshwater) | 0.0003 | kg P-Eq |
|
|
220
|
+
| Eutrophication (marine) | 0.0008 | kg N-Eq |
|
|
221
|
+
| Photochemical oxidant | 0.0022 | kg NMVOC-Eq |
|
|
222
|
+
| Ecotoxicity freshwater (metals) | 0.008 | CTUe |
|
|
223
|
+
|
|
224
|
+
**Single Weighted Score (EF 3.1 Global Reference 2010)**: ~0.042 Pts
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 📁 Files Created
|
|
229
|
+
|
|
230
|
+
1. **[OPENLCA_MCP_ENRICHER_SPEC.md](/opt/tm-types/OPENLCA_MCP_ENRICHER_SPEC.md)**
|
|
231
|
+
- Full architecture, database config, enrichment logic
|
|
232
|
+
- Request/response schemas
|
|
233
|
+
- Required input field analysis
|
|
234
|
+
- Endpoints & implementation details
|
|
235
|
+
|
|
236
|
+
2. **[openlcaMcpTypes.ts](/opt/tm-types/src/openlcaMcpTypes.ts)**
|
|
237
|
+
- TypeScript type definitions
|
|
238
|
+
- Helpers: `traceMarketToEstimate()`, `extractKeyImpacts()`
|
|
239
|
+
- Plugs directly into tm-types
|
|
240
|
+
|
|
241
|
+
3. **[index.d.ts (updated)](/opt/tm-types/src/index.d.ts)**
|
|
242
|
+
- Exports all openLCA MCP types
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## ✨ Key Insights
|
|
247
|
+
|
|
248
|
+
1. **Your products (textiles, smallholder farms, construction) map perfectly to BAFU-2025** – high-quality, granular process data.
|
|
249
|
+
2. **EF 3.1 is ideal** – EU standard, comprehensive impact categories, easy interpretation.
|
|
250
|
+
3. **Minimal additional fields needed** – `processName`, `amount`, `unit` are critical; location helps; enricher fills the rest.
|
|
251
|
+
4. **Fuzzy matching is essential** – users won't have process UUIDs; levenshtein + location boost makes it reliable.
|
|
252
|
+
5. **Multi-DB strategy** – fallback to exiobase3 or USDA if sector-specific DB unavailable; no single DB is exhaustive.
|
|
253
|
+
|