@tiangong-lca/mcp-server 0.0.9 → 0.0.11

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.
@@ -8,7 +8,7 @@ const redis = new Redis({
8
8
  url: redis_url,
9
9
  token: redis_token,
10
10
  });
11
- function getTokenType(bearerKey) {
11
+ export function getTokenType(bearerKey) {
12
12
  const jwtPattern = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
13
13
  if (jwtPattern.test(bearerKey)) {
14
14
  try {
@@ -2,16 +2,19 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { regBomCalculationTool } from '../tools/bom_calculation.js';
3
3
  import { regFlowSearchTool } from '../tools/flow_hybrid_search.js';
4
4
  import { regProcessSearchTool } from '../tools/process_hybrid_search.js';
5
- export function initializeServer(bearerKey) {
5
+ import { getTokenType } from './auth_middleware.js';
6
+ export function initializeServer(bearerKey, xApiKey) {
6
7
  const server = new McpServer({
7
8
  name: 'TianGong-LCA-MCP-Server',
8
9
  version: '1.0.0',
9
10
  });
10
- regFlowSearchTool(server, bearerKey);
11
- regProcessSearchTool(server, bearerKey);
11
+ regFlowSearchTool(server, bearerKey, xApiKey);
12
+ regProcessSearchTool(server, bearerKey, xApiKey);
12
13
  regBomCalculationTool(server);
13
14
  return server;
14
15
  }
15
16
  export function getServer(bearerKey) {
16
- return initializeServer(bearerKey);
17
+ const tokenType = bearerKey ? getTokenType(bearerKey) : '';
18
+ console.log('Token type:', tokenType);
19
+ return initializeServer(tokenType !== 'supabase' ? undefined : bearerKey, tokenType !== 'supabase' ? bearerKey : undefined);
17
20
  }
@@ -4,15 +4,22 @@ import { supabase_anon_key, supabase_base_url, x_region } from '../_shared/confi
4
4
  const input_schema = {
5
5
  query: z.string().min(1).describe('Queries from user'),
6
6
  };
7
- async function searchFlows({ query }, bearerKey) {
7
+ async function searchFlows({ query }, bearerKey, xApiKey) {
8
8
  const url = `${supabase_base_url}/functions/v1/flow_hybrid_search`;
9
+ const headers = {
10
+ 'Content-Type': 'application/json',
11
+ Authorization: `Bearer ${bearerKey || supabase_anon_key}`,
12
+ ...(xApiKey && { 'x-api-key': xApiKey }),
13
+ 'x-region': x_region,
14
+ };
15
+ console.error('Headers:', headers);
9
16
  try {
10
17
  const response = await fetch(url, {
11
18
  method: 'POST',
12
19
  headers: {
13
20
  'Content-Type': 'application/json',
14
- Authorization: `Bearer ${supabase_anon_key}`,
15
- ...(bearerKey && { 'x-api-key': bearerKey }),
21
+ Authorization: `Bearer ${bearerKey || supabase_anon_key}`,
22
+ ...(xApiKey && { 'x-api-key': xApiKey }),
16
23
  'x-region': x_region,
17
24
  },
18
25
  body: JSON.stringify(cleanObject({
@@ -30,11 +37,11 @@ async function searchFlows({ query }, bearerKey) {
30
37
  throw error;
31
38
  }
32
39
  }
33
- export function regFlowSearchTool(server, bearerKey) {
40
+ export function regFlowSearchTool(server, bearerKey, xApiKey) {
34
41
  server.tool('Search_flows_Tool', 'Search LCA flows data.', input_schema, async ({ query }) => {
35
42
  const result = await searchFlows({
36
43
  query,
37
- }, bearerKey);
44
+ }, bearerKey, xApiKey);
38
45
  return {
39
46
  content: [
40
47
  {
@@ -4,15 +4,15 @@ import { supabase_anon_key, supabase_base_url, x_region } from '../_shared/confi
4
4
  const input_schema = {
5
5
  query: z.string().min(1).describe('Queries from user'),
6
6
  };
7
- async function searchProcesses({ query }, bearerKey) {
7
+ async function searchProcesses({ query }, bearerKey, xApiKey) {
8
8
  const url = `${supabase_base_url}/functions/v1/process_hybrid_search`;
9
9
  try {
10
10
  const response = await fetch(url, {
11
11
  method: 'POST',
12
12
  headers: {
13
13
  'Content-Type': 'application/json',
14
- Authorization: `Bearer ${supabase_anon_key}`,
15
- ...(bearerKey && { 'x-api-key': bearerKey }),
14
+ Authorization: `Bearer ${bearerKey || supabase_anon_key}`,
15
+ ...(xApiKey && { 'x-api-key': xApiKey }),
16
16
  'x-region': x_region,
17
17
  },
18
18
  body: JSON.stringify(cleanObject({
@@ -30,11 +30,11 @@ async function searchProcesses({ query }, bearerKey) {
30
30
  throw error;
31
31
  }
32
32
  }
33
- export function regProcessSearchTool(server, bearerKey) {
33
+ export function regProcessSearchTool(server, bearerKey, xApiKey) {
34
34
  server.tool('Search_processes_Tool', 'Search LCA processes data.', input_schema, async ({ query }) => {
35
35
  const result = await searchProcesses({
36
36
  query,
37
- }, bearerKey);
37
+ }, bearerKey, xApiKey);
38
38
  return {
39
39
  content: [
40
40
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiangong-lca/mcp-server",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "TianGong LCA MCP Server",
5
5
  "license": "MIT",
6
6
  "author": "Nan LI",