@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.
@@ -0,0 +1,151 @@
1
+ # Trace Market Types MCP Server
2
+
3
+ This MCP server provides intelligent type management and data validation for the Trace Market food supply chain platform.
4
+
5
+ ## Features
6
+
7
+ ### For Authenticated Users (Admin/User Role)
8
+ - **Create types from natural language**: Describe a type in plain English and get TypeScript definitions
9
+ - **Add/modify type definitions**: Directly add or update TypeScript type definitions
10
+ - **Track changes**: All type modifications are version controlled
11
+
12
+ ### For All Users (Including Anonymous)
13
+ - **List types**: Browse all available type definitions
14
+ - **Get type details**: View detailed field information for any type
15
+ - **Validate data**: Check if data conforms to type specifications
16
+ - **Query data**: Filter and search based on type structure
17
+ - **Generate reports**: Create custom reports in JSON, Markdown, or HTML
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ cd mcp-server
23
+ npm install
24
+ npm run build
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ 1. Copy `.env.example` to `.env`
30
+ 2. Set `JWT_SECRET` to a secure random string
31
+ 3. (Optional) Configure database URL for data persistence
32
+ 4. (Optional) Add LLM API keys for better natural language processing
33
+
34
+ ## Authentication
35
+
36
+ Generate a JWT token for authenticated operations:
37
+
38
+ ```javascript
39
+ const jwt = require('jsonwebtoken');
40
+ const token = jwt.sign(
41
+ { userId: 'user123', role: 'user' }, // or role: 'admin'
42
+ 'your-jwt-secret',
43
+ { expiresIn: '24h' }
44
+ );
45
+ ```
46
+
47
+ ## MCP Tools
48
+
49
+ ### `list_types`
50
+ List all available type definitions with optional filtering.
51
+ - **Auth required**: No
52
+ - **Parameters**:
53
+ - `filter` (optional): Search string to filter type names
54
+
55
+ ### `get_type_definition`
56
+ Get detailed definition of a specific type.
57
+ - **Auth required**: No
58
+ - **Parameters**:
59
+ - `typeName` (required): Name of the type
60
+
61
+ ### `validate_data`
62
+ Validate data against a type definition.
63
+ - **Auth required**: No
64
+ - **Parameters**:
65
+ - `typeName` (required): Type to validate against
66
+ - `data` (required): Data object to validate
67
+
68
+ ### `create_type_from_description`
69
+ Generate TypeScript type from natural language description.
70
+ - **Auth required**: Yes (user or admin)
71
+ - **Parameters**:
72
+ - `description` (required): Natural language description
73
+ - `authToken` (required): JWT authentication token
74
+
75
+ ### `add_type_definition`
76
+ Add a new type definition to the repository.
77
+ - **Auth required**: Yes (user or admin)
78
+ - **Parameters**:
79
+ - `typeDefinition` (required): TypeScript code
80
+ - `authToken` (required): JWT authentication token
81
+
82
+ ### `query_data`
83
+ Query and filter data based on type structure.
84
+ - **Auth required**: No
85
+ - **Parameters**:
86
+ - `typeName` (required): Type to query
87
+ - `query` (optional): Query filters
88
+
89
+ ### `generate_report`
90
+ Generate custom reports from type data.
91
+ - **Auth required**: No
92
+ - **Parameters**:
93
+ - `reportType` (required): 'summary', 'detailed', or 'impact'
94
+ - `data` (required): Data to include in report
95
+ - `format` (optional): 'json', 'markdown', or 'html'
96
+
97
+ ## Usage with GitHub Copilot
98
+
99
+ Add this MCP server to your Copilot configuration:
100
+
101
+ ```json
102
+ {
103
+ "mcpServers": {
104
+ "tm-types": {
105
+ "command": "node",
106
+ "args": ["/path/to/tm-types/mcp-server/dist/index.js"],
107
+ "env": {
108
+ "JWT_SECRET": "your-secret-key"
109
+ }
110
+ }
111
+ }
112
+ }
113
+ ```
114
+
115
+ Then in Copilot, you can:
116
+ - Ask to list all types: "Show me all available types"
117
+ - Create new types: "Create a new type for tracking organic certification with fields for certifier, issue date, and expiry date"
118
+ - Validate data: "Check if this data matches the FoodInstance type"
119
+ - Generate reports: "Create a summary report of this product's carbon footprint"
120
+
121
+ ## Integration with Transcription/Chatbots
122
+
123
+ The MCP server supports non-authenticated access for data queries and report generation, making it perfect for:
124
+ - Voice-driven data entry (transcription → validation)
125
+ - Chatbot interfaces for supply chain data
126
+ - Public dashboards and reports
127
+ - API integrations
128
+
129
+ Example chatbot flow:
130
+ 1. User speaks: "What's the carbon footprint of this coconut drink?"
131
+ 2. Transcription service converts to text
132
+ 3. Chatbot queries MCP: `generate_report` with reportType='impact'
133
+ 4. MCP returns formatted report
134
+ 5. Chatbot presents results to user
135
+
136
+ ## Development
137
+
138
+ ```bash
139
+ # Watch mode
140
+ npm run dev
141
+
142
+ # Build
143
+ npm run build
144
+
145
+ # Start server
146
+ npm start
147
+ ```
148
+
149
+ ## License
150
+
151
+ MIT
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Generate JWT tokens for authenticated MCP operations
5
+ * Usage: node generate-token.js [userId] [role]
6
+ */
7
+
8
+ import jwt from 'jsonwebtoken';
9
+ import readline from 'readline';
10
+
11
+ const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key-change-in-production';
12
+
13
+ const rl = readline.createInterface({
14
+ input: process.stdin,
15
+ output: process.stdout
16
+ });
17
+
18
+ function generateToken(userId, role, expiresIn = '24h') {
19
+ return jwt.sign(
20
+ { userId, role },
21
+ JWT_SECRET,
22
+ { expiresIn }
23
+ );
24
+ }
25
+
26
+ async function main() {
27
+ const args = process.argv.slice(2);
28
+
29
+ if (args.length >= 2) {
30
+ const [userId, role] = args;
31
+ const token = generateToken(userId, role);
32
+ console.log('\nGenerated JWT Token:');
33
+ console.log(token);
34
+ console.log('\nDecoded payload:');
35
+ console.log(jwt.decode(token));
36
+ process.exit(0);
37
+ }
38
+
39
+ console.log('=== JWT Token Generator ===\n');
40
+
41
+ rl.question('Enter User ID: ', (userId) => {
42
+ rl.question('Enter Role (user/admin): ', (role) => {
43
+ rl.question('Expiration (default: 24h): ', (expiry) => {
44
+ const expiresIn = expiry || '24h';
45
+ const token = generateToken(userId, role, expiresIn);
46
+
47
+ console.log('\n=== Generated Token ===');
48
+ console.log(token);
49
+ console.log('\n=== Decoded Payload ===');
50
+ console.log(jwt.decode(token));
51
+ console.log('\n=== Usage Example ===');
52
+ console.log('In MCP tool call, include:');
53
+ console.log(JSON.stringify({ authToken: token }, null, 2));
54
+
55
+ rl.close();
56
+ });
57
+ });
58
+ });
59
+ }
60
+
61
+ main();