@tiangong-lca/mcp-server 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -32,17 +32,17 @@ npx -y supergateway \
32
32
 
33
33
  ```bash
34
34
  # Build MCP server image using Dockerfile (optional)
35
- docker build -t linancn/tiangong-lca-mcp-server:0.0.1 .
35
+ docker build -t linancn/tiangong-lca-mcp-server:0.0.5 .
36
36
 
37
37
  # Pull MCP server image
38
- docker pull linancn/tiangong-lca-mcp-server:0.0.1
38
+ docker pull linancn/tiangong-lca-mcp-server:0.0.5
39
39
 
40
40
  # Start MCP server using Docker
41
41
  docker run -d \
42
42
  --name tiangong-lca-mcp-server \
43
- --publish 3001:80 \
43
+ --publish 9278:9278 \
44
44
  --env-file .env \
45
- linancn/tiangong-lca-mcp-server:0.0.1
45
+ linancn/tiangong-lca-mcp-server:0.0.5
46
46
  ```
47
47
 
48
48
  ## Development
@@ -90,7 +90,7 @@ npm install -g supergateway
90
90
  # Launch the SSE Server (If the parameter --baseUrl is configured, it should be set to a valid IP address or domain name)
91
91
  npx dotenv -e .env -- \
92
92
  npx -y supergateway \
93
- --stdio "npx -y -p tiangong-lca-mcp-server-0.0.3.tgz tiangong-lca-mcp-stdio" \
93
+ --stdio "npx -y -p tiangong-lca-mcp-server-0.0.5.tgz tiangong-lca-mcp-stdio" \
94
94
  --port 3001 \
95
95
  --ssePath /sse \
96
96
  --messagePath /message
@@ -0,0 +1,74 @@
1
+ import { createClient } from '@supabase/supabase-js';
2
+ import { Redis } from '@upstash/redis';
3
+ import decodeApiKey from './decode_api_key.js';
4
+ const supabase_base_url = process.env.SUPABASE_BASE_URL ?? '';
5
+ const supabase_anon_key = process.env.SUPABASE_ANON_KEY ?? '';
6
+ const supabase = createClient(supabase_base_url, supabase_anon_key);
7
+ const redis_url = process.env.UPSTASH_REDIS_URL ?? '';
8
+ const redis_token = process.env.UPSTASH_REDIS_TOKEN ?? '';
9
+ const redis = new Redis({
10
+ url: redis_url,
11
+ token: redis_token,
12
+ });
13
+ export async function authenticateRequest(bearerKey) {
14
+ const credentials = decodeApiKey(bearerKey);
15
+ if (credentials) {
16
+ const { email = '', password = '' } = credentials;
17
+ const userIdFromRedis = await redis.get('lca_' + email);
18
+ if (!userIdFromRedis) {
19
+ const { data, error } = await supabase.auth.signInWithPassword({
20
+ email: email,
21
+ password: password,
22
+ });
23
+ console.error(email, password, data, error);
24
+ if (error) {
25
+ return {
26
+ isAuthenticated: false,
27
+ response: 'Unauthorized',
28
+ };
29
+ }
30
+ if (data.user.role !== 'authenticated') {
31
+ return {
32
+ isAuthenticated: false,
33
+ response: 'You are not an authenticated user.',
34
+ };
35
+ }
36
+ else {
37
+ await redis.setex('lca_' + email, 3600, data.user.id);
38
+ return {
39
+ isAuthenticated: true,
40
+ response: data.user.id,
41
+ };
42
+ }
43
+ }
44
+ return {
45
+ isAuthenticated: true,
46
+ response: String(userIdFromRedis),
47
+ };
48
+ }
49
+ const { data: authData } = await supabase.auth.getUser(bearerKey);
50
+ if (authData.user?.role === 'authenticated') {
51
+ return {
52
+ isAuthenticated: true,
53
+ response: authData.user?.id,
54
+ };
55
+ }
56
+ if (!authData || !authData.user) {
57
+ return {
58
+ isAuthenticated: false,
59
+ response: 'User Not Found',
60
+ };
61
+ }
62
+ else {
63
+ if (authData.user.role !== 'authenticated') {
64
+ return {
65
+ isAuthenticated: false,
66
+ response: 'Forbidden',
67
+ };
68
+ }
69
+ }
70
+ return {
71
+ isAuthenticated: true,
72
+ response: authData.user.id,
73
+ };
74
+ }
@@ -1,4 +1,4 @@
1
- export const base_url = process.env.BASE_URL ?? '';
1
+ export const supabase_base_url = process.env.SUPABASE_BASE_URL ?? '';
2
2
  export const supabase_anon_key = process.env.SUPABASE_ANON_KEY ?? '';
3
3
  export const x_api_key = process.env.X_API_KEY ?? '';
4
4
  export const x_region = process.env.X_REGION ?? '';
@@ -0,0 +1,16 @@
1
+ function decodeApiKey(apiKey) {
2
+ if (!apiKey)
3
+ return null;
4
+ try {
5
+ const jsonString = atob(apiKey);
6
+ const credentials = JSON.parse(jsonString);
7
+ if (!credentials.email || !credentials.password) {
8
+ return null;
9
+ }
10
+ return credentials;
11
+ }
12
+ catch (_error) {
13
+ return null;
14
+ }
15
+ }
16
+ export default decodeApiKey;
@@ -5,19 +5,19 @@ import { regOpenLcaLciaTool } from '../tools/openlca_ipc_lcia.js';
5
5
  import { regOpenLcaListLCIAMethodsTool } from '../tools/openlca_ipc_lcia_methods_list.js';
6
6
  import { regOpenLcaListSystemProcessTool } from '../tools/openlca_ipc_process_list.js';
7
7
  import { regProcessSearchTool } from '../tools/process_hybrid_search.js';
8
- export function initializeServer() {
8
+ export function initializeServer(bearerKey) {
9
9
  const server = new McpServer({
10
10
  name: 'TianGong-MCP-Server',
11
11
  version: '1.0.0',
12
12
  });
13
- regFlowSearchTool(server);
14
- regProcessSearchTool(server);
13
+ regFlowSearchTool(server, bearerKey);
14
+ regProcessSearchTool(server, bearerKey);
15
15
  regBomCalculationTool(server);
16
16
  regOpenLcaLciaTool(server);
17
17
  regOpenLcaListSystemProcessTool(server);
18
18
  regOpenLcaListLCIAMethodsTool(server);
19
19
  return server;
20
20
  }
21
- export function getServer() {
22
- return initializeServer();
21
+ export function getServer(bearerKey) {
22
+ return initializeServer(bearerKey);
23
23
  }