Skip to content
Merged
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
17 changes: 17 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ export default tseslint.config(
"@typescript-eslint/no-misused-promises":"off",
"@typescript-eslint/unbound-method":"off"

},
},
{
files: ["packages/mcp/**"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"no-console": "off",
"@typescript-eslint/no-unsafe-argument":"off",
"@typescript-eslint/require-await":"off",
"@typescript-eslint/no-unused-vars":"off",
"@typescript-eslint/no-misused-promises":"off",
"@typescript-eslint/unbound-method":"off"

},
}
);
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export class PolkadotApi implements IPolkadotApi {
try {
// Get filtered chains based on allowed chains
const supportedChains = getFilteredChains(this.allowedChains)

const chainSpecs: Record<KnownChainId, string> = {
polkadot: "",
west: "",
Expand Down
172 changes: 172 additions & 0 deletions packages/mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Polkadot Agent Kit MCP Server

Model Context Protocol (MCP) server for the Polkadot Agent Kit, enabling AI assistants to interact with Polkadot blockchain operations.

## Installation

```bash
npm install @polkadot-agent-kit/mcp
```

## Configuration

The MCP server can be configured through environment variables or client configuration files.

### Environment Variables

| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `PRIVATE_KEY` | Private key for signing transactions | - | Yes |

### Claude Desktop Configuration

Create or update your `claude_desktop_config.json`:

```json
{
"mcpServers": {
"polkadot-agent-kit": {
"command": "npx",
"args": ["@polkadot-agent-kit/mcp"],
"env": {
"PRIVATE_KEY": "your-private-key-here",
}
}
}
}
```

### Cursor Configuration

Create or update your Cursor MCP configuration:

```json
{
"mcpServers": {
"polkadot-agent-kit": {
"command": "npx",
"args": ["@polkadot-agent-kit/mcp"],
"env": {
"PRIVATE_KEY": "your-private-key-here",
}
}
}
}
```

### Custom Client Configuration

Here's how to connect to the MCP server from a custom JavaScript/TypeScript client:

```typescript
import { Client } from "@modelcontextprotocol/sdk/client";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio";

async function main() {
// 1. Initialize the client
const client = new Client({
name: "polkadot-client",
version: "1.0.0"
});

// 2. Configure the transport to connect to the MCP server
const transport = new StdioClientTransport({
command: "npx",
args: ["@polkadot-agent-kit/mcp"],
env: {
PRIVATE_KEY: "your-private-key-here"
}
});

// 3. Connect to the server
await client.connect(transport);
console.log("✅ Connected to MCP server");

// 4. Use the tools
// Example 1: Check balance
const balance = await client.callTool({
name: "check_balance",
arguments: { chain: "polkadot" }
});
console.log("Balance:", balance);

// Example 2: Transfer 0.1 DOT on Polkadot
const transferResult = await client.callTool({
name: "transfer_native",
arguments: {
to: "15oF4uVJwmo4o4KoAc4v98tklqve5eMDU2rgh5M5G4Z2bftF", // Example address, replace with a valid one
amount: "0.1",
chain: "polkadot"
}
});
console.log("Transfer Result:", transferResult);

// 5. Disconnect from the server
await client.close();
console.log("Disconnected from MCP server");
}

main().catch(console.error);
```

## Available Tools

The MCP server exposes a rich set of tools for interacting with the Polkadot ecosystem.

### 💰 Balance

- **`check_balance`**: Checks the native token balance for the current account.
- **Parameters**: `chain` (`polkadot`, `kusama`, `westend`)

### 💸 Transfer

- **`transfer_native`**: Transfers native tokens to another account.
- **Parameters**: `to` (address), `amount`, `chain`

### 🔒 Staking (Nomination Pools)

- **`join_pool`**: Joins a nomination pool with a specified amount.
- **Parameters**: `amount`, `chain`
- **`bond_extra`**: Bonds additional funds to a pool from the wallet balance or rewards.
- **Parameters**: `type` (`FreeBalance` or `Rewards`), `amount` (optional), `chain`
- **`unbond`**: Unbonds tokens from a pool.
- **Parameters**: `amount`, `chain`
- **`withdraw_unbonded`**: Withdraws unbonded tokens after the unbonding period.
- **Parameters**: `slashingSpans`, `chain`
- **`claim_rewards`**: Claims pending staking rewards.
- **Parameters**: `chain`

### 🌐 XCM (Cross-Chain)

- **`xcm_transfer`**: Transfers native assets between chains (e.g., Polkadot to AssetHub).
- **Parameters**: `amount`, `to` (address), `sourceChain`, `destChain`

### 🔁 DeFi (Swap)

- **`swap_tokens`**: Swaps tokens on a DEX like Hydration.
- **Parameters**: `currencyFrom`, `currencyTo`, `amount`, `from` (chain), `to` (chain), `receiver` (address), `dex`

## Development

```bash
# Install dependencies
pnpm install

# Build the package
pnpm build

# Start the MCP server with inspector for debugging
npx -y @modelcontextprotocol/inspector npx -y tsx src/index.ts
```

The inspector will provide a web interface where you can:
- View all available tools
- Test tool calls with different parameters
- See the request/response flow
- Debug any issues with the MCP server

This is especially useful during development to verify that all tools are properly registered and working correctly.

## License

MIT
51 changes: 51 additions & 0 deletions packages/mcp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@polkadot-agent-kit/mcp",
"version": "1.0.0",
"description": "Model Context Protocol server for Polkadot Agent Kit",
"repository": {
"type": "git",
"url": "git+https://github.com/elasticlabs-org/polkadot-agent-kit.git",
"directory": "packages/mcp"
},
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"clean": "rm -rf dist .turbo node_modules",
"compile": "tsc --noEmit",
"build": "rollup -c",
"lint:check": "eslint src",
"lint": "eslint --fix src",
"format:check": "prettier --check src",
"format:write": "prettier --write src",
"start": "node dist/index.mjs"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.13.1",
"@polkadot-agent-kit/common": "workspace:*",
"@polkadot-agent-kit/core": "workspace:*",
"@polkadot-agent-kit/llm": "workspace:*",
"@polkadot-agent-kit/sdk": "workspace:*",
"polkadot-api": "^1.9.13",
"zod": "^3.24.3",
"mcps-logger": "^1.0.0"
},
"devDependencies": {
"@rollup/plugin-typescript": "^12.1.2",
"@rollup/plugin-json": "^6.1.0",
"rollup": "^4.37.0",
"rollup-plugin-dts": "^6.2.1"
}
}
59 changes: 59 additions & 0 deletions packages/mcp/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
import dts from 'rollup-plugin-dts';

const config = [
// ES Module build
{
input: 'src/index.ts',
output: {
file: 'dist/index.mjs',
format: 'es',
sourcemap: true,
},
plugins: [
json(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
declarationMap: false,
}),
],
external: [
'@modelcontextprotocol/sdk',
'@polkadot-agent-kit/common',
'@polkadot-agent-kit/core',
'@polkadot-agent-kit/llm',
'@polkadot-agent-kit/sdk',
'polkadot-api',
'zod',
],
},
// CommonJS build
{
input: 'src/index.ts',
output: {
file: 'dist/index.cjs',
format: 'cjs',
sourcemap: true,
},
plugins: [
json(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
declarationMap: false,
}),
],
external: [
'@modelcontextprotocol/sdk',
'@polkadot-agent-kit/common',
'@polkadot-agent-kit/core',
'@polkadot-agent-kit/llm',
'polkadot-api',
'zod',
],
}
];

export default config;
24 changes: 24 additions & 0 deletions packages/mcp/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { PolkadotAgentKit } from "@polkadot-agent-kit/sdk";

import { PolkadotMCPServer } from "../src/server";
import { createDefaultConfig } from "../src/utils/config";

async function runServer() {
try {
const config = createDefaultConfig();

const polkadotAgent = new PolkadotAgentKit(config.privateKey, {
keyType: "Sr25519",
chains: ["polkadot"],
});

const server = new PolkadotMCPServer(config, polkadotAgent);

await server.start();
} catch (error) {
console.error("❌ Failed to start MCP server:", error);
process.exit(1);
}
}

runServer().catch(console.error);
Loading