Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Make sure to replace `<path to dist/index.js>` with the path to the `dist/index.
"command": "node",
"args": ["<path to dist/index.js>"],
"env": {
"AKASH_MNEMONIC": "<your mnemonic here>",
"AKASH_MNEMONIC": "<your mnemonic here>", // OR "AKASH_PRIVATE_KEY": "<your 64-character-hex-string>"
"AKASH_RPC_URL": "https://rpc.akashnet.net:443" // optional, defaults to https://rpc.akashnet.net:443
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/AkashMCP.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import type { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import type { SigningStargateClient } from '@cosmjs/stargate';
import { loadWalletAndClient, loadCertificate } from './utils/index.js';
import { SERVER_CONFIG } from './config.js';
Expand All @@ -22,7 +22,7 @@ import type { ToolContext } from './types/index.js';
import type { CertificatePem } from '@akashnetwork/akashjs/build/certificates/certificate-manager/CertificateManager.js';

class AkashMCP extends McpServer {
private wallet: DirectSecp256k1HdWallet | null = null;
private wallet: DirectSecp256k1HdWallet | DirectSecp256k1Wallet | null = null;
private client: SigningStargateClient | null = null;
private certificate: CertificatePem | null = null;

Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const SERVER_CONFIG = {
environment: process.env.NODE_ENV || 'development',
rpcEndpoint: process.env.RPC_ENDPOINT || 'https://rpc.akashnet.net:443',
mnemonic: process.env.AKASH_MNEMONIC || '',
privateKey: process.env.AKASH_PRIVATE_KEY || '',
} as const;

export type ServerConfig = typeof SERVER_CONFIG;
4 changes: 2 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { z } from 'zod';
import type { SigningStargateClient } from '@cosmjs/stargate';
import type { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import type { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import type { ReadResourceCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
import type { CertificatePem } from '@akashnetwork/akashjs/build/certificates/certificate-manager/CertificateManager.js';

// Tool related types
export interface ToolContext {
client: SigningStargateClient;
wallet: DirectSecp256k1HdWallet;
wallet: DirectSecp256k1HdWallet | DirectSecp256k1Wallet;
certificate: CertificatePem;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/load-certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import path from 'path';
import { fileURLToPath } from 'url';
import * as cert from '@akashnetwork/akashjs/build/certificates/index.js';
import { certificateManager } from '@akashnetwork/akashjs/build/certificates/certificate-manager/index.js';
import type { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import type { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import type { SigningStargateClient } from '@cosmjs/stargate';
import type { CertificatePem } from '@akashnetwork/akashjs/build/certificates/certificate-manager/CertificateManager.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export async function loadCertificate(
wallet: DirectSecp256k1HdWallet,
wallet: DirectSecp256k1HdWallet | DirectSecp256k1Wallet,
client: SigningStargateClient
): Promise<CertificatePem> {
const accounts = await wallet.getAccounts();
Expand Down
18 changes: 14 additions & 4 deletions src/utils/load-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { GasPrice, SigningStargateClient } from '@cosmjs/stargate';
import { getAkashTypeRegistry } from '@akashnetwork/akashjs/build/stargate/index.js';
import { DirectSecp256k1HdWallet, Registry } from '@cosmjs/proto-signing';
import { DirectSecp256k1HdWallet, DirectSecp256k1Wallet, Registry } from '@cosmjs/proto-signing';
import { SERVER_CONFIG } from '../config.js';

export async function loadWalletAndClient() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(SERVER_CONFIG.mnemonic, {
prefix: 'akash',
});
let wallet: DirectSecp256k1HdWallet | DirectSecp256k1Wallet;

if (SERVER_CONFIG.mnemonic) {
wallet = await DirectSecp256k1HdWallet.fromMnemonic(SERVER_CONFIG.mnemonic, {
prefix: 'akash',
});
} else if (SERVER_CONFIG.privateKey) {
const privateKeyBytes = Uint8Array.from(Buffer.from(SERVER_CONFIG.privateKey, 'hex'));
wallet = await DirectSecp256k1Wallet.fromKey(privateKeyBytes, 'akash');
} else {
throw new Error('Either AKASH_MNEMONIC or AKASH_PRIVATE_KEY must be provided');
}

const registry = getAkashTypeRegistry();

const client = await SigningStargateClient.connectWithSigner(SERVER_CONFIG.rpcEndpoint, wallet, {
Expand Down
Loading