Skip to content

Commit 5da2a60

Browse files
authored
fix: fetch is not enable when node < 18 (#171)
1 parent 2c72864 commit 5da2a60

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"license": "MIT",
4444
"dependencies": {
4545
"@modelcontextprotocol/sdk": "^1.11.4",
46+
"axios": "^1.11.0",
4647
"zod": "^3.25.16",
4748
"zod-to-json-schema": "^3.24.5"
4849
},

src/utils/generate.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2+
import axios from "axios";
23
import { getServiceIdentifier, getVisRequestServer } from "./env";
34

45
/**
@@ -15,19 +16,20 @@ export async function generateChartUrl(
1516
): Promise<string> {
1617
const url = getVisRequestServer();
1718

18-
const response = await fetch(url, {
19-
method: "POST",
20-
headers: {
21-
"Content-Type": "application/json",
22-
},
23-
body: JSON.stringify({
19+
const response = await axios.post(
20+
url,
21+
{
2422
type,
2523
...options,
2624
source: "mcp-server-chart",
27-
}),
28-
});
29-
30-
const { success, errorMessage, resultObj } = await response.json();
25+
},
26+
{
27+
headers: {
28+
"Content-Type": "application/json",
29+
},
30+
},
31+
);
32+
const { success, errorMessage, resultObj } = response.data;
3133

3234
if (!success) {
3335
throw new Error(errorMessage);
@@ -57,20 +59,21 @@ export async function generateMap(
5759
): Promise<ResponseResult> {
5860
const url = getVisRequestServer();
5961

60-
const response = await fetch(url, {
61-
method: "POST",
62-
headers: {
63-
"Content-Type": "application/json",
64-
},
65-
body: JSON.stringify({
66-
source: "mcp-server-chart",
62+
const response = await axios.post(
63+
url,
64+
{
6765
serviceId: getServiceIdentifier(),
6866
tool,
6967
input,
70-
}),
71-
});
72-
73-
const { success, errorMessage, resultObj } = await response.json();
68+
source: "mcp-server-chart",
69+
},
70+
{
71+
headers: {
72+
"Content-Type": "application/json",
73+
},
74+
},
75+
);
76+
const { success, errorMessage, resultObj } = response.data;
7477

7578
if (!success) {
7679
throw new Error(errorMessage);

0 commit comments

Comments
 (0)