Skip to content

Commit 65bac33

Browse files
authored
add verbose mode
1 parent 5b0435f commit 65bac33

File tree

11 files changed

+110
-8
lines changed

11 files changed

+110
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ If you built from source (Option 2):
8787
"REGION": "your_dataworks_open_api_region_id_here",
8888
"ALIBABA_CLOUD_ACCESS_KEY_ID": "your_alibaba_cloud_access_key_id",
8989
"ALIBABA_CLOUD_ACCESS_KEY_SECRET": "your_alibaba_cloud_access_key_secret",
90-
"NODE_ENV": "development_or_product"
90+
"NODE_ENV": "development_or_product",
91+
"VERBOSE": "true"
9192
},
9293
"disabled": false,
9394
"autoApprove": []

build/mcp/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function createMcpServer(actions, agent, dataWorksOpenApis, options) {
2323
const { result = {} } = zodToMCPShape(convertInputSchemaToSchema(action?.inputSchema));
2424
paramsSchema = result;
2525
}
26-
console.log(paramsSchema);
26+
console.log('active tool', action.name);
2727
server.tool(action.name, action.description || '', paramsSchema, async (params) => {
2828
try {
2929
// Execute the action handler with the params directly

build/openApiClient/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import OpenApi from '@alicloud/openapi-client';
22
import Credential from '@alicloud/credentials';
3+
import { getEnvInfo, isVerboseMode } from '../utils/common.js';
34
class OpenApiClient {
45
/**
56
* use ak and sk to init a client
@@ -32,6 +33,11 @@ class OpenApiClient {
3233
// 使用特定方式调用
3334
// import DataWorksPublic20240518 from '@alicloud/dataworks-public20240518';
3435
// return new DataWorksPublic20240518.default(apiConfig);
36+
const verbose = isVerboseMode();
37+
if (verbose) {
38+
console.debug('apiConfig endpoint', apiConfig.endpoint);
39+
console.debug('env info', getEnvInfo());
40+
}
3541
// 使用泛化方式调用
3642
// https://help.aliyun.com/zh/sdk/developer-reference/generalized-call-node-js
3743
return new OpenApi.default(apiConfig);

build/tools/callTool.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// import * as DataWorksPublic20240518Classes from '@alicloud/dataworks-public20240518';
33
import OpenApi from '@alicloud/openapi-client';
44
import Util from '@alicloud/tea-util';
5+
import { isVerboseMode, getEnvInfo } from '../utils/common.js';
56
/**
67
* Get detailed and latest information about any topic using Perplexity AI.
78
* @param agent Aliyun Open API instance
@@ -76,7 +77,8 @@ async function callTool(agent, apiKey, input, dataWorksOpenApis) {
7677
return (res?.statusCode === 200 && res?.body) ? res?.body : res;
7778
}
7879
catch (error) {
79-
throw new Error(`Call tool failed: ${error.message}, api key: ${apiKey}, api request configs: ${JSON.stringify(apiRequestConfigs)}, query: ${JSON.stringify(query)}, body: ${JSON.stringify(body)}`);
80+
const verbose = isVerboseMode();
81+
throw new Error(`Call tool failed: ${error.message}, api key: ${apiKey}, api request configs: ${JSON.stringify(apiRequestConfigs)}, query: ${JSON.stringify(query)}, body: ${JSON.stringify(body)}${verbose ? `, env info: ${getEnvInfo()}` : ''}`);
8082
}
8183
}
8284
;

build/utils/common.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 是 undefined 或 null
3+
* @param value
4+
* @returns
5+
*/
6+
export function isEmpty(value) {
7+
return value === undefined || value === null;
8+
}
9+
/**
10+
* 不是undefined null 空字串
11+
* @param input
12+
* @returns {boolean}
13+
*/
14+
export function isEmptyStr(input) {
15+
return (input === null || input === undefined || input === '');
16+
}
17+
export function isVerboseMode() {
18+
let verbose = false;
19+
try {
20+
const env = process?.env || {};
21+
verbose = env.VERBOSE === 'true';
22+
}
23+
catch (e) {
24+
console.error(e);
25+
}
26+
return verbose;
27+
}
28+
export function getEnvInfo() {
29+
let envInfoStr = '';
30+
try {
31+
const env = process?.env || {};
32+
envInfoStr = JSON.stringify(env);
33+
}
34+
catch (e) {
35+
console.error(e);
36+
}
37+
return envInfoStr;
38+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "alibabacloud-dataworks-mcp-server",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "DataWorks MCP Server: Export the DataWorks Open API to MCP Server, allowing clients that can run MCP Server to use DataWorks Open API through AI.",
55
"main": "build/index.js",
66
"module": "build/index.js",
@@ -37,7 +37,7 @@
3737
"author": "DataWorks",
3838
"license": "Apache-2.0",
3939
"dependencies": {
40-
"@alicloud/credentials": "^2.4.2",
40+
"@alicloud/credentials": "2.4.2",
4141
"@alicloud/dataworks-public20240518": "^6.0.2",
4242
"@alicloud/openapi-client": "^0.4.13",
4343
"@alicloud/openapi-util": "^0.3.2",
@@ -61,6 +61,9 @@
6161
"tailwindcss": "^3.0.0",
6262
"typescript": "^5.7.3"
6363
},
64+
"resolutions": {
65+
"@alicloud/credentials": "2.4.2"
66+
},
6467
"packageManager": "[email protected]",
6568
"publishConfig": {
6669
"registry": "https://registry.npmjs.org"

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mcp/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function createMcpServer(
3737
paramsSchema = result;
3838
}
3939

40-
console.log(paramsSchema);
40+
console.log('active tool', action.name);
4141

4242
server.tool(
4343
action.name,

src/openApiClient/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Credential from '@alicloud/credentials';
33
import Util from '@alicloud/tea-util';
44
import tea from '@alicloud/tea-typescript';
55
import typeClient from '@alicloud/openapi-client';
6+
import { getEnvInfo, isVerboseMode } from '../utils/common.js';
67

78
type Error = { message: string; };
89

@@ -55,6 +56,12 @@ class OpenApiClient {
5556
// import DataWorksPublic20240518 from '@alicloud/dataworks-public20240518';
5657
// return new DataWorksPublic20240518.default(apiConfig);
5758

59+
const verbose = isVerboseMode();
60+
if (verbose) {
61+
console.debug('apiConfig endpoint', apiConfig.endpoint);
62+
console.debug('env info', getEnvInfo());
63+
}
64+
5865
// 使用泛化方式调用
5966
// https://help.aliyun.com/zh/sdk/developer-reference/generalized-call-node-js
6067
return new OpenApi.default(apiConfig);

src/tools/callTool.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Util from '@alicloud/tea-util';
66
import tea from '@alicloud/tea-typescript';
77
import { OpenApiClientInstance } from "../openApiClient/index.js";
88
import { AlibabaCloudOpenApiInterface, ApiMethod, IAlibabaCloudOpenApiResponse } from '../types/apibabaCloudApi.js';
9+
import { isVerboseMode, getEnvInfo } from '../utils/common.js';
910

1011
/**
1112
* Get detailed and latest information about any topic using Perplexity AI.
@@ -94,7 +95,8 @@ async function callTool(
9495
return (res?.statusCode === 200 && res?.body) ? res?.body : res;
9596

9697
} catch (error: any) {
97-
throw new Error(`Call tool failed: ${error.message}, api key: ${apiKey}, api request configs: ${JSON.stringify(apiRequestConfigs)}, query: ${JSON.stringify(query)}, body: ${JSON.stringify(body)}`);
98+
const verbose = isVerboseMode();
99+
throw new Error(`Call tool failed: ${error.message}, api key: ${apiKey}, api request configs: ${JSON.stringify(apiRequestConfigs)}, query: ${JSON.stringify(query)}, body: ${JSON.stringify(body)}${verbose ? `, env info: ${getEnvInfo()}` : ''}`);
98100
}
99101
};
100102

src/utils/common.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* 是 undefined 或 null
3+
* @param value
4+
* @returns
5+
*/
6+
export function isEmpty(value: any) {
7+
return value === undefined || value === null;
8+
}
9+
10+
11+
/**
12+
* 不是undefined null 空字串
13+
* @param input
14+
* @returns {boolean}
15+
*/
16+
export function isEmptyStr(input: any) {
17+
return (input === null || input === undefined || input === '');
18+
}
19+
20+
export function isVerboseMode() {
21+
let verbose: boolean = false;
22+
try {
23+
const env = process?.env || {};
24+
verbose = env.VERBOSE === 'true';
25+
} catch (e) {
26+
console.error(e);
27+
}
28+
return verbose;
29+
}
30+
31+
export function getEnvInfo() {
32+
let envInfoStr: string = '';
33+
try {
34+
const env = process?.env || {};
35+
envInfoStr = JSON.stringify(env);
36+
} catch (e) {
37+
console.error(e);
38+
}
39+
return envInfoStr;
40+
}

0 commit comments

Comments
 (0)