@trace.market/types 0.1.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/build-mcp.yml +36 -0
- package/.github/workflows/publish.yml +72 -0
- package/IMPLEMENTATION.md +199 -0
- package/QUICKSTART.md +238 -0
- package/README.md +144 -0
- package/mcp-config.example.json +13 -0
- package/mcp-server/.env.example +9 -0
- package/mcp-server/README.md +151 -0
- package/mcp-server/generate-token.js +61 -0
- package/mcp-server/package-lock.json +1206 -0
- package/mcp-server/package.json +26 -0
- package/mcp-server/src/index.ts +516 -0
- package/package.json +31 -0
- package/src/ENov +261 -0
- package/src/index.d.ts +187 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Build MCP Server
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- 'mcp-server/**'
|
|
9
|
+
pull_request:
|
|
10
|
+
paths:
|
|
11
|
+
- 'mcp-server/**'
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- uses: actions/setup-node@v4
|
|
21
|
+
with:
|
|
22
|
+
node-version: '20'
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
working-directory: ./mcp-server
|
|
26
|
+
run: npm install
|
|
27
|
+
|
|
28
|
+
- name: Build MCP server
|
|
29
|
+
working-directory: ./mcp-server
|
|
30
|
+
run: npm run build
|
|
31
|
+
|
|
32
|
+
- name: Upload build artifacts
|
|
33
|
+
uses: actions/upload-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
name: mcp-server-dist
|
|
36
|
+
path: mcp-server/dist/
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
name: Publish to NPM
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- 'src/**'
|
|
9
|
+
- 'package.json'
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
contents: write
|
|
17
|
+
packages: write
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0
|
|
23
|
+
|
|
24
|
+
- uses: actions/setup-node@v4
|
|
25
|
+
with:
|
|
26
|
+
node-version: '20'
|
|
27
|
+
registry-url: 'https://registry.npmjs.org'
|
|
28
|
+
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: npm install
|
|
31
|
+
|
|
32
|
+
- name: Validate types
|
|
33
|
+
run: npm run validate
|
|
34
|
+
|
|
35
|
+
- name: Check if version changed
|
|
36
|
+
id: check
|
|
37
|
+
run: |
|
|
38
|
+
git fetch --tags
|
|
39
|
+
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
40
|
+
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
|
|
41
|
+
echo "Version $CURRENT_VERSION already exists"
|
|
42
|
+
echo "changed=false" >> $GITHUB_OUTPUT
|
|
43
|
+
else
|
|
44
|
+
echo "New version $CURRENT_VERSION"
|
|
45
|
+
echo "changed=true" >> $GITHUB_OUTPUT
|
|
46
|
+
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
- name: Publish to NPM
|
|
50
|
+
if: steps.check.outputs.changed == 'true'
|
|
51
|
+
run: npm publish --access public
|
|
52
|
+
env:
|
|
53
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
54
|
+
|
|
55
|
+
- name: Create Git tag
|
|
56
|
+
if: steps.check.outputs.changed == 'true'
|
|
57
|
+
run: |
|
|
58
|
+
git config user.name "GitHub Actions"
|
|
59
|
+
git config user.email "actions@github.com"
|
|
60
|
+
git tag "v${{ steps.check.outputs.version }}"
|
|
61
|
+
git push origin "v${{ steps.check.outputs.version }}"
|
|
62
|
+
|
|
63
|
+
- name: Create GitHub Release
|
|
64
|
+
if: steps.check.outputs.changed == 'true'
|
|
65
|
+
uses: actions/create-release@v1
|
|
66
|
+
env:
|
|
67
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
68
|
+
with:
|
|
69
|
+
tag_name: v${{ steps.check.outputs.version }}
|
|
70
|
+
release_name: Release v${{ steps.check.outputs.version }}
|
|
71
|
+
draft: false
|
|
72
|
+
prerelease: false
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# Implementation Summary
|
|
2
|
+
|
|
3
|
+
## ✅ Completed Setup
|
|
4
|
+
|
|
5
|
+
### 1. Package Configuration
|
|
6
|
+
- **Name changed**: `@fairfooddata/types` → `@trace.market/types`
|
|
7
|
+
- **Version**: 0.1.0
|
|
8
|
+
- **License**: MIT (was UNLICENSED)
|
|
9
|
+
- **Repository**: Linked to https://github.com/entin-hun/tm-types
|
|
10
|
+
- **Scripts**: Added validation, versioning, and publishing workflows
|
|
11
|
+
|
|
12
|
+
### 2. MCP Server Created
|
|
13
|
+
Location: `mcp-server/`
|
|
14
|
+
|
|
15
|
+
**Features Implemented:**
|
|
16
|
+
|
|
17
|
+
#### For Authenticated Users (Admin/User)
|
|
18
|
+
- ✅ `create_type_from_description` - Natural language type creation
|
|
19
|
+
- ✅ `add_type_definition` - Direct TypeScript type addition
|
|
20
|
+
- ✅ JWT-based authentication with role checking
|
|
21
|
+
|
|
22
|
+
#### For All Users (Including Anonymous)
|
|
23
|
+
- ✅ `list_types` - Browse all type definitions
|
|
24
|
+
- ✅ `get_type_definition` - View detailed type information
|
|
25
|
+
- ✅ `validate_data` - Check data against types
|
|
26
|
+
- ✅ `query_data` - Query with filters
|
|
27
|
+
- ✅ `generate_report` - Create reports in JSON/Markdown/HTML
|
|
28
|
+
|
|
29
|
+
### 3. CI/CD Pipelines
|
|
30
|
+
Created `.github/workflows/`:
|
|
31
|
+
- **publish.yml** - Automatic npm publishing on version changes
|
|
32
|
+
- **build-mcp.yml** - MCP server build verification
|
|
33
|
+
|
|
34
|
+
**Publishing Flow:**
|
|
35
|
+
1. Developer updates version in package.json
|
|
36
|
+
2. Push to main branch
|
|
37
|
+
3. GitHub Actions validates TypeScript
|
|
38
|
+
4. If version changed, publishes to npm
|
|
39
|
+
5. Creates git tag and GitHub release
|
|
40
|
+
|
|
41
|
+
### 4. Documentation
|
|
42
|
+
- **README.md** - Main package documentation
|
|
43
|
+
- **mcp-server/README.md** - MCP server guide
|
|
44
|
+
- **QUICKSTART.md** - Step-by-step setup instructions
|
|
45
|
+
- **mcp-config.example.json** - Example Copilot configuration
|
|
46
|
+
|
|
47
|
+
### 5. Tooling
|
|
48
|
+
- **generate-token.js** - JWT token generator for auth operations
|
|
49
|
+
- **.env.example** - Environment configuration template
|
|
50
|
+
- **tsconfig.json** - TypeScript configuration
|
|
51
|
+
- **.gitignore** - Proper exclusions for dist/, node_modules/, .env
|
|
52
|
+
|
|
53
|
+
## 📦 Current Type Definitions
|
|
54
|
+
|
|
55
|
+
All types from `@fairfooddata/types@0.0.6` are preserved:
|
|
56
|
+
- Pokedex, ProductInstance, FoodInstance, CartridgeInstance
|
|
57
|
+
- Process types: Milling, Printing, FreezeDrying, Blending, Sale, Harvest
|
|
58
|
+
- Supply chain: Transport, Facility, Location, InputInstance
|
|
59
|
+
- Environmental: CarbonImpact, WaterImpact
|
|
60
|
+
- Supporting: Price, KnowHow, MachineInstance, etc.
|
|
61
|
+
|
|
62
|
+
## 🚀 Usage
|
|
63
|
+
|
|
64
|
+
### Install Package
|
|
65
|
+
```bash
|
|
66
|
+
npm install @trace.market/types
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Configure MCP in Copilot
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"mcpServers": {
|
|
73
|
+
"tm-types": {
|
|
74
|
+
"command": "node",
|
|
75
|
+
"args": ["/path/to/tm-types/mcp-server/dist/index.js"],
|
|
76
|
+
"env": {
|
|
77
|
+
"JWT_SECRET": "your-secret-key"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Generate Auth Token
|
|
85
|
+
```bash
|
|
86
|
+
cd mcp-server
|
|
87
|
+
JWT_SECRET="your-secret" node generate-token.js userId role
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Example Copilot Interactions
|
|
91
|
+
|
|
92
|
+
**List types (no auth):**
|
|
93
|
+
> "Show me all food-related types"
|
|
94
|
+
|
|
95
|
+
**Create new type (auth required):**
|
|
96
|
+
> "Create an OrganicCertification type with certifier, issueDate, expiryDate fields. Token: [paste]"
|
|
97
|
+
|
|
98
|
+
**Validate data (no auth):**
|
|
99
|
+
> "Check if this is a valid FoodInstance: {category: 'food', bio: true, quantity: 1000}"
|
|
100
|
+
|
|
101
|
+
**Generate report (no auth):**
|
|
102
|
+
> "Generate an impact report for this product data"
|
|
103
|
+
|
|
104
|
+
## 🔄 Migration Path
|
|
105
|
+
|
|
106
|
+
### For Projects Using `@fairfooddata/types`
|
|
107
|
+
|
|
108
|
+
1. **Update dependencies:**
|
|
109
|
+
```bash
|
|
110
|
+
npm uninstall @fairfooddata/types
|
|
111
|
+
npm install @trace.market/types
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
2. **Find & replace imports:**
|
|
115
|
+
```typescript
|
|
116
|
+
// Old
|
|
117
|
+
import { FoodInstance } from '@fairfooddata/types';
|
|
118
|
+
|
|
119
|
+
// New
|
|
120
|
+
import { FoodInstance } from '@trace.market/types';
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
3. **Test builds:**
|
|
124
|
+
```bash
|
|
125
|
+
npm run build # or quasar build, etc.
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Affected Projects
|
|
129
|
+
- tm-editor (version 0.0.9)
|
|
130
|
+
- tm-marketplace (version 0.0.6)
|
|
131
|
+
- tm-list (version 0.0.4)
|
|
132
|
+
- tm-savedvalues (version 0.0.6)
|
|
133
|
+
- tm-package-page buy (version 0.0.6)
|
|
134
|
+
|
|
135
|
+
## 🎯 Key Benefits
|
|
136
|
+
|
|
137
|
+
1. **Self-Service**: No dependency on ex-developer's npm account
|
|
138
|
+
2. **Automation**: Hourly updates possible with CI/CD
|
|
139
|
+
3. **Natural Language**: Non-technical users can add types via Copilot
|
|
140
|
+
4. **Public Access**: Anonymous users can query/validate data
|
|
141
|
+
5. **Transcription-Ready**: Works with chatbots and voice interfaces
|
|
142
|
+
6. **Version Control**: All changes tracked in git
|
|
143
|
+
7. **Authenticated Writes**: Only authorized users modify types
|
|
144
|
+
|
|
145
|
+
## 📝 Next Steps
|
|
146
|
+
|
|
147
|
+
### Immediate
|
|
148
|
+
1. Set up npm account and generate NPM_TOKEN
|
|
149
|
+
2. Add NPM_TOKEN to GitHub repository secrets
|
|
150
|
+
3. Generate production JWT_SECRET
|
|
151
|
+
4. Test first publish: `npm version patch && git push`
|
|
152
|
+
|
|
153
|
+
### Near Term
|
|
154
|
+
1. Migrate tm-editor to use @trace.market/types
|
|
155
|
+
2. Migrate other projects (tm-marketplace, tm-list, etc.)
|
|
156
|
+
3. Document new types that need to be added
|
|
157
|
+
4. Set up user authentication system for MCP
|
|
158
|
+
|
|
159
|
+
### Future Enhancements
|
|
160
|
+
1. Integrate real LLM API for better natural language processing
|
|
161
|
+
2. Add database persistence for type change history
|
|
162
|
+
3. Create web UI for type browsing
|
|
163
|
+
4. Add TypeScript code generation from types
|
|
164
|
+
5. Implement real-time collaboration on type definitions
|
|
165
|
+
|
|
166
|
+
## 🧪 Testing Checklist
|
|
167
|
+
|
|
168
|
+
- [x] Package builds successfully
|
|
169
|
+
- [x] MCP server compiles
|
|
170
|
+
- [x] Token generation works
|
|
171
|
+
- [x] Type definitions validate
|
|
172
|
+
- [ ] First npm publish
|
|
173
|
+
- [ ] MCP integration with Copilot
|
|
174
|
+
- [ ] Anonymous type queries
|
|
175
|
+
- [ ] Authenticated type creation
|
|
176
|
+
- [ ] CI/CD pipeline execution
|
|
177
|
+
|
|
178
|
+
## 📚 Documentation Files
|
|
179
|
+
|
|
180
|
+
- `/README.md` - Main package README
|
|
181
|
+
- `/QUICKSTART.md` - Setup and usage guide
|
|
182
|
+
- `/mcp-server/README.md` - MCP server documentation
|
|
183
|
+
- `/mcp-config.example.json` - Example MCP configuration
|
|
184
|
+
- `/.github/workflows/` - CI/CD documentation
|
|
185
|
+
- `/mcp-server/.env.example` - Environment setup
|
|
186
|
+
|
|
187
|
+
## 🔐 Security Notes
|
|
188
|
+
|
|
189
|
+
- JWT_SECRET must be strong and kept confidential
|
|
190
|
+
- Tokens expire after 24 hours by default
|
|
191
|
+
- Anonymous users have read-only access
|
|
192
|
+
- Type modifications require authentication
|
|
193
|
+
- All changes logged via git history
|
|
194
|
+
|
|
195
|
+
## Support & Contact
|
|
196
|
+
|
|
197
|
+
- Repository: https://github.com/entin-hun/tm-types
|
|
198
|
+
- Issues: https://github.com/entin-hun/tm-types/issues
|
|
199
|
+
- npm: https://www.npmjs.com/package/@trace.market/types (pending first publish)
|
package/QUICKSTART.md
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Quick Start Guide
|
|
2
|
+
|
|
3
|
+
## Setup Steps
|
|
4
|
+
|
|
5
|
+
### 1. Install Dependencies
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Root package (types)
|
|
9
|
+
npm install
|
|
10
|
+
|
|
11
|
+
# MCP Server
|
|
12
|
+
cd mcp-server
|
|
13
|
+
npm install
|
|
14
|
+
npm run build
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 2. Configure Environment
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd mcp-server
|
|
21
|
+
cp .env.example .env
|
|
22
|
+
# Edit .env and set a strong JWT_SECRET
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 3. Generate Auth Token
|
|
26
|
+
|
|
27
|
+
For authenticated operations (creating/modifying types):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
node mcp-server/generate-token.js yourUserId user
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or interactively:
|
|
34
|
+
```bash
|
|
35
|
+
node mcp-server/generate-token.js
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 4. Add to Copilot
|
|
39
|
+
|
|
40
|
+
Add this to your MCP settings (in VS Code or Copilot configuration):
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"mcpServers": {
|
|
45
|
+
"tm-types": {
|
|
46
|
+
"command": "node",
|
|
47
|
+
"args": ["/absolute/path/to/tm-types/mcp-server/dist/index.js"],
|
|
48
|
+
"env": {
|
|
49
|
+
"JWT_SECRET": "your-secret-from-env-file"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage Examples
|
|
57
|
+
|
|
58
|
+
### List All Types (No Auth Required)
|
|
59
|
+
|
|
60
|
+
In Copilot:
|
|
61
|
+
```
|
|
62
|
+
Show me all available types in the tm-types system
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Or direct MCP call:
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"tool": "list_types",
|
|
69
|
+
"arguments": {}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Get Type Definition (No Auth Required)
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
What fields does the FoodInstance type have?
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Validate Data (No Auth Required)
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
Check if this data is valid for FoodInstance type:
|
|
83
|
+
{
|
|
84
|
+
"category": "food",
|
|
85
|
+
"bio": true,
|
|
86
|
+
"quantity": 1000
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Create Type from Description (Auth Required)
|
|
91
|
+
|
|
92
|
+
First, generate a token:
|
|
93
|
+
```bash
|
|
94
|
+
TOKEN=$(node mcp-server/generate-token.js myUserId user | grep "eyJ" | xargs)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then in Copilot:
|
|
98
|
+
```
|
|
99
|
+
Create a new type called "OrganicCertification" with fields for:
|
|
100
|
+
- certifier name (string)
|
|
101
|
+
- certification number (string)
|
|
102
|
+
- issue date (timestamp)
|
|
103
|
+
- expiry date (timestamp)
|
|
104
|
+
- certification body (string)
|
|
105
|
+
- certificate URL (string)
|
|
106
|
+
|
|
107
|
+
Use auth token: [paste token here]
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Generate Report (No Auth Required)
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
Generate a summary report for this product data:
|
|
114
|
+
{
|
|
115
|
+
"name": "Coconut Drink",
|
|
116
|
+
"carbon": 0.5,
|
|
117
|
+
"water": 100
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Publishing Types to NPM
|
|
122
|
+
|
|
123
|
+
### First Time Setup
|
|
124
|
+
|
|
125
|
+
1. Create NPM account at https://www.npmjs.com/
|
|
126
|
+
2. Generate access token: https://www.npmjs.com/settings/your-username/tokens
|
|
127
|
+
3. Add token to GitHub secrets as `NPM_TOKEN`
|
|
128
|
+
|
|
129
|
+
### Publishing Process
|
|
130
|
+
|
|
131
|
+
The CI/CD is configured to automatically publish when:
|
|
132
|
+
To switch from `@fairfooddata/types` to `@trace.market/types`:
|
|
133
|
+
1. You push to main branch
|
|
134
|
+
2. The version in package.json has changed
|
|
135
|
+
3. TypeScript validation passes
|
|
136
|
+
|
|
137
|
+
**To publish a new version:**
|
|
138
|
+
npm install @trace.market/types
|
|
139
|
+
```bash
|
|
140
|
+
# 1. Update version
|
|
141
|
+
npm version patch # or minor, or major
|
|
142
|
+
|
|
143
|
+
# 2. Push changes
|
|
144
|
+
git push origin main
|
|
145
|
+
|
|
146
|
+
# 3. GitHub Actions will automatically:
|
|
147
|
+
# - Validate types
|
|
148
|
+
import { FoodInstance } from '@trace.market/types';
|
|
149
|
+
# - Create git tag
|
|
150
|
+
# - Create GitHub release
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Manual Publishing (if needed)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Migrating Projects
|
|
157
|
+
|
|
158
|
+
- Check npm registry: `npm view @trace.market/types`
|
|
159
|
+
### 1. Update package.json
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
npm uninstall @fairfooddata/types
|
|
163
|
+
npm install @trace.market/types
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 2. Update Imports
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Old
|
|
170
|
+
import { FoodInstance } from '@fairfooddata/types';
|
|
171
|
+
|
|
172
|
+
// New
|
|
173
|
+
import { FoodInstance } from '@trace.market/types';
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 3. Run Find & Replace
|
|
177
|
+
|
|
178
|
+
In VS Code:
|
|
179
|
+
- Find: `@fairfooddata/types`
|
|
180
|
+
- Replace: `@trace.market/types`
|
|
181
|
+
- Replace in all files across workspace
|
|
182
|
+
|
|
183
|
+
## Adding New Types
|
|
184
|
+
|
|
185
|
+
### Method 1: Natural Language (Recommended)
|
|
186
|
+
|
|
187
|
+
1. Generate auth token
|
|
188
|
+
2. Use Copilot to describe the type
|
|
189
|
+
3. Review generated code
|
|
190
|
+
4. Add to repository using `add_type_definition` tool
|
|
191
|
+
|
|
192
|
+
### Method 2: Manual Edit
|
|
193
|
+
|
|
194
|
+
1. Edit `src/index.d.ts`
|
|
195
|
+
2. Add your type definition
|
|
196
|
+
3. Run `npm run validate` to check
|
|
197
|
+
4. Commit and push
|
|
198
|
+
|
|
199
|
+
### Method 3: Pull Request
|
|
200
|
+
|
|
201
|
+
1. Fork repository
|
|
202
|
+
2. Add type definitions
|
|
203
|
+
3. Create PR
|
|
204
|
+
4. Team reviews and merges
|
|
205
|
+
|
|
206
|
+
## Testing MCP Server Locally
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# Terminal 1: Start MCP server
|
|
210
|
+
cd mcp-server
|
|
211
|
+
npm start
|
|
212
|
+
|
|
213
|
+
# Terminal 2: Test with stdio
|
|
214
|
+
echo '{"method":"tools/list"}' | node dist/index.js
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Troubleshooting
|
|
218
|
+
|
|
219
|
+
### "Authentication required" error
|
|
220
|
+
- Generate a valid JWT token
|
|
221
|
+
- Make sure JWT_SECRET matches in .env and token generation
|
|
222
|
+
- Check token hasn't expired (default 24h)
|
|
223
|
+
|
|
224
|
+
### Types not updating
|
|
225
|
+
- Clear node_modules cache: `rm -rf node_modules package-lock.json && npm install`
|
|
226
|
+
- Check npm registry: `npm view @trace.market/types`
|
|
227
|
+
- Verify version number incremented
|
|
228
|
+
|
|
229
|
+
### MCP server not responding
|
|
230
|
+
- Check it built successfully: `ls mcp-server/dist/`
|
|
231
|
+
- Verify Node.js version: `node --version` (should be 18+)
|
|
232
|
+
- Check environment variables are set
|
|
233
|
+
|
|
234
|
+
## Support
|
|
235
|
+
|
|
236
|
+
- GitHub Issues: https://github.com/entin-hun/tm-types/issues
|
|
237
|
+
- Documentation: See README files
|
|
238
|
+
- Example usage: Check tm-editor, tm-marketplace projects
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @trace.market/types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for the Trace Market food supply chain traceability platform.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides comprehensive TypeScript types for food traceability data, including:
|
|
8
|
+
- **Product instances**: Food items, cartridges, and other products
|
|
9
|
+
- **Process tracking**: Milling, printing, freeze-drying, blending, sales, and harvests
|
|
10
|
+
- **Supply chain data**: Transport, facilities, locations, and impacts
|
|
11
|
+
- **Blockchain integration**: NFT metadata and token references
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @trace.market/types
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import {
|
|
23
|
+
FoodInstance,
|
|
24
|
+
ProductInstance,
|
|
25
|
+
Pokedex,
|
|
26
|
+
SaleProcess,
|
|
27
|
+
Impact
|
|
28
|
+
} from '@trace.market/types';
|
|
29
|
+
|
|
30
|
+
const product: FoodInstance = {
|
|
31
|
+
category: 'food',
|
|
32
|
+
type: 'coconut-drink',
|
|
33
|
+
bio: true,
|
|
34
|
+
quantity: 1000,
|
|
35
|
+
ownerId: 'plantsoul',
|
|
36
|
+
process: {
|
|
37
|
+
type: 'blending',
|
|
38
|
+
timestamp: Date.now(),
|
|
39
|
+
facility: {
|
|
40
|
+
label: 'PlantSoul Factory',
|
|
41
|
+
location: {
|
|
42
|
+
type: 'Point',
|
|
43
|
+
coordinates: [19.0402, 47.4979]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
temperatureRange: { min: 4, max: 8 },
|
|
47
|
+
inputInstances: [],
|
|
48
|
+
impacts: [
|
|
49
|
+
{
|
|
50
|
+
category: 'carbon',
|
|
51
|
+
ownerId: 'plantsoul',
|
|
52
|
+
format: 'CO2e',
|
|
53
|
+
quantity: 0.5
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Available Types
|
|
61
|
+
|
|
62
|
+
### Core Types
|
|
63
|
+
- `Pokedex`: Main container for NFT metadata and product instances
|
|
64
|
+
- `ProductInstance`: Union type for all product categories
|
|
65
|
+
- `FoodInstance`: Food products with nutrition and process data
|
|
66
|
+
- `CartridgeInstance`: Printer cartridge tracking
|
|
67
|
+
|
|
68
|
+
### Process Types
|
|
69
|
+
- `Process`: Union of all process types
|
|
70
|
+
- `GenericProcess`: Base process interface
|
|
71
|
+
- `MillingProcess`: Grain/seed processing
|
|
72
|
+
- `PrintingProcess`: 3D printing operations
|
|
73
|
+
- `FreezeDryingProcess`: Freeze-drying operations
|
|
74
|
+
- `BlendingProcess`: Mixing ingredients
|
|
75
|
+
- `SaleProcess`: Sales transactions
|
|
76
|
+
- `HarvestProcess`: Agricultural harvesting
|
|
77
|
+
|
|
78
|
+
### Supply Chain
|
|
79
|
+
- `InputInstance`: Local or transported inputs
|
|
80
|
+
- `Transport`: Transportation tracking
|
|
81
|
+
- `Facility`: Processing facilities and locations
|
|
82
|
+
- `Location`: GeoJSON point coordinates
|
|
83
|
+
|
|
84
|
+
### Environmental Impact
|
|
85
|
+
- `Impact`: Union of impact types
|
|
86
|
+
- `CarbonImpact`: CO2 emissions
|
|
87
|
+
- `WaterImpact`: Water usage
|
|
88
|
+
|
|
89
|
+
### Supporting Types
|
|
90
|
+
- `Price`: Pricing information
|
|
91
|
+
- `KnowHow`: Proprietary process knowledge
|
|
92
|
+
- `MachineInstance`: Equipment tracking
|
|
93
|
+
- `TemperatureRange`: Storage/process temperatures
|
|
94
|
+
- `FallbackFoodNutrient`: Nutrition data
|
|
95
|
+
- `ID`: Registry identifiers
|
|
96
|
+
|
|
97
|
+
## MCP Server
|
|
98
|
+
|
|
99
|
+
This package includes an MCP (Model Context Protocol) server for intelligent type management. See [mcp-server/README.md](./mcp-server/README.md) for details.
|
|
100
|
+
|
|
101
|
+
### Key Features
|
|
102
|
+
- **Natural language type creation**: Describe types in plain English
|
|
103
|
+
- **Automatic validation**: Check data against type definitions
|
|
104
|
+
- **Custom reports**: Generate formatted reports from your data
|
|
105
|
+
- **Authentication support**: Secure type management for authorized users
|
|
106
|
+
- **Public API**: Anonymous access for queries and reports
|
|
107
|
+
|
|
108
|
+
## Contributing
|
|
109
|
+
|
|
110
|
+
This is a self-managed repository for the Trace Market team. To add or modify types:
|
|
111
|
+
|
|
112
|
+
1. **For authenticated users**: Use the MCP server's `create_type_from_description` tool
|
|
113
|
+
2. **Manual method**: Edit `src/index.d.ts` and submit a pull request
|
|
114
|
+
3. **Automated**: CI/CD will validate and publish on merge to main
|
|
115
|
+
|
|
116
|
+
### Versioning
|
|
117
|
+
|
|
118
|
+
We use semantic versioning:
|
|
119
|
+
- **Patch** (0.0.x): Documentation, comments, minor fixes
|
|
120
|
+
- **Minor** (0.x.0): New types, backward-compatible changes
|
|
121
|
+
- **Major** (x.0.0): Breaking changes to existing types
|
|
122
|
+
|
|
123
|
+
Update the version in `package.json` before committing changes that should trigger a new npm release.
|
|
124
|
+
|
|
125
|
+
## CI/CD
|
|
126
|
+
|
|
127
|
+
- **Automatic publishing**: Pushes to main trigger npm publish if version changed
|
|
128
|
+
- **Validation**: TypeScript compilation runs on all commits
|
|
129
|
+
- **MCP server builds**: Automatic builds on changes to mcp-server/
|
|
130
|
+
|
|
131
|
+
## Repository
|
|
132
|
+
|
|
133
|
+
- **GitHub**: https://github.com/entin-hun/tm-types
|
|
134
|
+
- **npm**: https://www.npmjs.com/package/@trace.market/types (coming soon)
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|
|
139
|
+
|
|
140
|
+
## Related Projects
|
|
141
|
+
|
|
142
|
+
- [tm-editor](../tm-editor): Visual editor for creating product instances
|
|
143
|
+
- [tm-marketplace](../tm-marketplace): NFT marketplace for traced products
|
|
144
|
+
- [tm-package-page](../tm-package-page%20buy): Consumer-facing product pages
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Environment variables for MCP server
|
|
2
|
+
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
|
|
3
|
+
|
|
4
|
+
# Optional: Database connection if you want to persist data
|
|
5
|
+
# DATABASE_URL=postgresql://user:password@localhost:5432/tm_types
|
|
6
|
+
|
|
7
|
+
# Optional: External LLM API for better natural language processing
|
|
8
|
+
# OPENAI_API_KEY=sk-...
|
|
9
|
+
# ANTHROPIC_API_KEY=sk-ant-...
|