@locofy/mcp 1.0.6 → 1.0.8
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,31 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
/**
|
|
4
|
+
* Get the PROJECT_ID
|
|
5
|
+
* If PROJECT_ID is not found in the workspacePath/.locofy/config.json, return the environment variable value
|
|
6
|
+
* @param workspacePath
|
|
7
|
+
* @returns The PROJECT_ID value
|
|
8
|
+
*/
|
|
9
|
+
export async function getProjectID(workspacePath) {
|
|
10
|
+
const projectIDKey = 'PROJECT_ID';
|
|
11
|
+
const configPath = path.join(workspacePath, '.locofy/config.json');
|
|
12
|
+
if (fs.existsSync(configPath)) {
|
|
13
|
+
try {
|
|
14
|
+
const configData = fs.readFileSync(configPath, 'utf8');
|
|
15
|
+
const config = JSON.parse(configData);
|
|
16
|
+
if (config[projectIDKey]) {
|
|
17
|
+
console.log(`found ${projectIDKey} in config file, returning value ${config[projectIDKey]}`);
|
|
18
|
+
return config[projectIDKey];
|
|
19
|
+
}
|
|
20
|
+
if (config[projectIDKey.toLowerCase()]) {
|
|
21
|
+
console.log(`found ${projectIDKey.toLowerCase()} in config file, returning value ${config[projectIDKey.toLowerCase()]}`);
|
|
22
|
+
return config[projectIDKey.toLowerCase()];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error('Error reading config file:', error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
console.log(`PROJECT_ID was not found in config file, returning environment variable value ${process.env.PROJECT_ID}`);
|
|
30
|
+
return process.env.PROJECT_ID;
|
|
31
|
+
}
|
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import axios from 'axios';
|
|
5
|
+
import { getProjectID } from '../helpers/helpers.js';
|
|
5
6
|
/**
|
|
6
7
|
* PullComponents tool
|
|
7
8
|
* - Returns a hardcoded representation of a directory structure
|
|
@@ -19,10 +20,13 @@ export async function runPullComponentsTool(args) {
|
|
|
19
20
|
// clean the component names, remove extensions
|
|
20
21
|
componentNames = componentNames.map(name => name.replace(/\.[^/.]+$/, ''));
|
|
21
22
|
const workspacePath = decodeURIComponent(args.workspacePath);
|
|
22
|
-
const projectID =
|
|
23
|
+
const projectID = await getProjectID(workspacePath);
|
|
24
|
+
if (!projectID || projectID.length === 0) {
|
|
25
|
+
throw new Error('PROJECT_ID is not set');
|
|
26
|
+
}
|
|
23
27
|
const personalAccessToken = process.env.PERSONAL_ACCESS_TOKEN;
|
|
24
|
-
if (!
|
|
25
|
-
throw new Error('
|
|
28
|
+
if (!personalAccessToken) {
|
|
29
|
+
throw new Error('PERSONAL_ACCESS_TOKEN is not set');
|
|
26
30
|
}
|
|
27
31
|
try {
|
|
28
32
|
const result = await fetchDirectoryStructure(componentNames, projectID, personalAccessToken);
|
|
@@ -77,10 +81,11 @@ export async function runPullComponentsTool(args) {
|
|
|
77
81
|
}
|
|
78
82
|
async function fetchDirectoryStructure(componentNames, projectID, personalAccessToken) {
|
|
79
83
|
const encodedNames = componentNames.map(name => encodeURIComponent(name)).join(',');
|
|
80
|
-
let baseURL = 'https://codegen-api.locofy.ai/mcp/generators/';
|
|
81
|
-
if (process.env.IS_DEV === 'true') {
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
+
// let baseURL = 'https://codegen-api.locofy.ai/mcp/generators/';
|
|
85
|
+
// if (process.env.IS_DEV === 'true') {
|
|
86
|
+
// baseURL = 'https://codegen-api.locofy.dev/mcp/generators/';
|
|
87
|
+
// }
|
|
88
|
+
const baseURL = 'https://codegen-api.locofy.dev/mcp/generators/';
|
|
84
89
|
const url = baseURL + projectID + '?name=' + encodedNames;
|
|
85
90
|
const headers = {
|
|
86
91
|
'Accept': '*/*',
|
package/build/tools/pullFiles.js
CHANGED
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import axios from 'axios';
|
|
5
|
+
import { getProjectID } from '../helpers/helpers.js';
|
|
5
6
|
/**
|
|
6
7
|
* PullFiles tool
|
|
7
8
|
* - Returns a hardcoded representation of a directory structure
|
|
@@ -19,10 +20,13 @@ export async function runPullFilesTool(args) {
|
|
|
19
20
|
// clean the file names, remove extensions
|
|
20
21
|
fileNames = fileNames.map(name => name.replace(/\.[^/.]+$/, ''));
|
|
21
22
|
const workspacePath = decodeURIComponent(args.workspacePath);
|
|
22
|
-
const projectID =
|
|
23
|
+
const projectID = await getProjectID(workspacePath);
|
|
24
|
+
if (!projectID || projectID.length === 0) {
|
|
25
|
+
throw new Error('PROJECT_ID is not set');
|
|
26
|
+
}
|
|
23
27
|
const personalAccessToken = process.env.PERSONAL_ACCESS_TOKEN;
|
|
24
|
-
if (!
|
|
25
|
-
throw new Error('
|
|
28
|
+
if (!personalAccessToken) {
|
|
29
|
+
throw new Error('PERSONAL_ACCESS_TOKEN is not set');
|
|
26
30
|
}
|
|
27
31
|
try {
|
|
28
32
|
const result = await fetchDirectoryStructure(fileNames, projectID, personalAccessToken);
|
|
@@ -77,10 +81,11 @@ export async function runPullFilesTool(args) {
|
|
|
77
81
|
}
|
|
78
82
|
async function fetchDirectoryStructure(fileNames, projectID, personalAccessToken) {
|
|
79
83
|
const encodedNames = fileNames.map(name => encodeURIComponent(name)).join(',');
|
|
80
|
-
let baseURL = 'https://codegen-api.locofy.ai/mcp/generators/';
|
|
81
|
-
if (process.env.IS_DEV === 'true') {
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
+
// let baseURL = 'https://codegen-api.locofy.ai/mcp/generators/';
|
|
85
|
+
// if (process.env.IS_DEV === 'true') {
|
|
86
|
+
// baseURL = 'https://codegen-api.locofy.dev/mcp/generators/';
|
|
87
|
+
// }
|
|
88
|
+
const baseURL = 'https://codegen-api.locofy.dev/mcp/generators/';
|
|
84
89
|
const url = baseURL + projectID + '?name=' + encodedNames;
|
|
85
90
|
const headers = {
|
|
86
91
|
'Accept': '*/*',
|