Skip to content

Commit a2daeba

Browse files
refactor: use wallet address from env variable instead of parameter (#40)
1 parent e6dcffd commit a2daeba

File tree

5 files changed

+24
-34
lines changed

5 files changed

+24
-34
lines changed

.github/workflows/publish-docker.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ jobs:
4242
with:
4343
context: .
4444
push: true
45-
tags: |
46-
iexechub/mcp-server:latest
47-
iexechub/mcp-server:v${{ steps.version.outputs.version }}
45+
tags: iexechub/mcp-server:v${{ steps.version.outputs.version }}
4846
cache-from: type=gha
4947
cache-to: type=gha,mode=max
5048

src/tools/dataProtectorCore/getUserVoucher.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
22
import { getIexecProvider } from "../../utils/provider.js";
3+
import { readWalletPrivateKey } from "../../utils/readWalletKeystore.js";
4+
import { Wallet } from "ethers";
35

46
export const getUserVoucher = {
57
name: "get_user_voucher",
68
description: "Get the user's iExec voucher information (balance, expiration, sponsors, etc.)",
79
inputSchema: {
810
type: "object",
911
properties: {
10-
wallet: { type: "string" }
12+
query: { type: "string" },
1113
},
12-
required: ["wallet"],
14+
required: [],
1315
},
14-
handler: async (params: any) => {
15-
const { wallet } = params;
16+
handler: async () => {
1617

17-
if (!wallet || !wallet.match(/^0x[a-fA-F0-9]{40}$/)) {
18-
throw new McpError(ErrorCode.InvalidParams, "Invalid or missing wallet address");
19-
}
18+
const privateKey = await readWalletPrivateKey();
19+
const wallet = new Wallet(privateKey);
2020

2121
try {
22+
2223
const iexecResponse = await getIexecProvider();
2324
if (!iexecResponse.success || !iexecResponse.data) {
2425
throw new Error(iexecResponse.error || "Failed to initialize iExec SDK");
2526
}
2627

2728
const iexec = iexecResponse.data.iexec;
2829

29-
const userVoucher = await iexec.voucher.showUserVoucher(wallet);
30+
const userVoucher = await iexec.voucher.showUserVoucher(wallet.address);
3031

3132
return {
3233
address: userVoucher.address,
@@ -41,7 +42,7 @@ export const getUserVoucher = {
4142
} catch (error: any) {
4243
if (error.message.includes("No Voucher found")) {
4344
return {
44-
message: `No voucher found for wallet ${wallet}. Go to iExec discord to claim your voucher: https://discord.com/invite/aXH5ym5H4k`
45+
message: `No voucher found for wallet ${wallet.address}. Go to iExec discord to claim your voucher: https://discord.com/invite/aXH5ym5H4k`
4546
};
4647
}
4748
throw new McpError(ErrorCode.InternalError, error.message);

src/tools/dataProtectorCore/getWalletBalance.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
22
import { getIexecProvider } from "../../utils/provider.js";
3+
import { readWalletPrivateKey } from "../../utils/readWalletKeystore.js";
4+
import { Wallet } from "ethers";
35

46
export const getWalletBalance = {
57
name: "get_wallet_balance",
68
description: "Get the RLC balance of a wallet address using iExec SDK",
79
inputSchema: {
810
type: "object",
911
properties: {
10-
wallet: { type: "string" }
12+
query: { type: "string" }
1113
},
12-
required: ["wallet"],
14+
required: [],
1315
},
14-
handler: async (params: any) => {
15-
const { wallet } = params;
16-
17-
if (!wallet || !wallet.match(/^0x[a-fA-F0-9]{40}$/)) {
18-
throw new McpError(ErrorCode.InvalidParams, "Invalid or missing wallet address");
19-
}
16+
handler: async () => {
17+
const privateKey = await readWalletPrivateKey();
18+
const wallet = new Wallet(privateKey);
2019

2120
try {
2221
const iexecResponse = await getIexecProvider();
@@ -26,15 +25,15 @@ export const getWalletBalance = {
2625

2726
const iexec = iexecResponse.data.iexec;
2827

29-
const balance = await iexec.account.checkBalance(wallet);
28+
const balance = await iexec.account.checkBalance(wallet.address);
3029
const stakeRLC = Number(balance.stake) * 1e-9;
3130
const lockedRLC = Number(balance.locked) * 1e-9;
3231

33-
const { nRLC } = await iexec.wallet.checkBalances(wallet);
32+
const { nRLC } = await iexec.wallet.checkBalances(wallet.address);
3433
const onChainRLC = Number(nRLC) * 1e-9;
3534

3635
return {
37-
wallet,
36+
wallet: wallet.address,
3837
onChainRLC,
3938
stakeRLC,
4039
lockedRLC

src/tools/web3mail/fetchMyContacts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export const fetchMyContacts = {
88
inputSchema: {
99
type: "object",
1010
properties: {
11+
query: { type: "string" },
1112
},
13+
required: [],
1214
},
1315
handler: async () => {
1416
try {

src/tools/web3mail/sendEmail.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
2-
import { getWeb3Provider, IExecWeb3mail, WorkflowError } from '@iexec/web3mail';
2+
import { getWeb3Provider, IExecWeb3mail } from '@iexec/web3mail';
33
import { readWalletPrivateKey } from '../../utils/readWalletKeystore.js';
44

55
export const sendEmail = {
@@ -58,21 +58,11 @@ export const sendEmail = {
5858
if (contentType !== undefined) sendEmailParams.contentType = contentType;
5959
if (label !== undefined) sendEmailParams.label = label;
6060
if (useVoucher !== undefined) sendEmailParams.useVoucher = useVoucher;
61-
console.error("Send email params:", sendEmailParams);
6261
const response = await web3mail.sendEmail(sendEmailParams);
63-
6462
return response;
6563
} catch (error: any) {
6664
console.error("Error sending email:", error);
6765
throw new McpError(ErrorCode.InternalError, error);
68-
if (error instanceof WorkflowError) {
69-
if (error.isProtocolError) {
70-
throw new McpError(ErrorCode.InternalError, error.message);
71-
} else {
72-
throw new McpError(ErrorCode.InvalidParams, error.message);
73-
}
74-
}
75-
throw new McpError(ErrorCode.InternalError, error.message);
7666
}
7767
},
7868
};

0 commit comments

Comments
 (0)