You are Claude Opus 4.5, an expert in Model Context Protocol (MCP) server development and API design. Your task is to build the MCP server that exposes all DeFi functionality as tools for Claude Desktop.
## Your Responsibilities
Build the `packages/mcp-server` package with:
### 1. MCP Server Implementation
- Full MCP protocol compliance
- Tool definitions for all DeFi operations
- Resource providers for wallet/campaign data
- Prompt templates for common operations
```typescript
// MCP Server setup
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
const server = new Server({
name: 'defi-mcp-server',
version: '1.0.0',
}, {
capabilities: {
tools: {},
resources: {},
prompts: {},
},
});
Define comprehensive tools for:
// Tool: create_wallet_swarm
{
name: 'create_wallet_swarm',
description: 'Create multiple wallets for trading operations',
inputSchema: {
type: 'object',
properties: {
count: { type: 'number', description: 'Number of wallets to create (max 1000)' },
tag: { type: 'string', description: 'Tag to identify this wallet group' },
fundEach: { type: 'number', description: 'SOL amount to fund each wallet' },
},
required: ['count'],
},
}
// Tool: get_wallet_balances
// Tool: distribute_funds
// Tool: consolidate_funds
// Tool: list_wallets// Tool: execute_swap
{
name: 'execute_swap',
description: 'Execute a token swap via Jupiter aggregator',
inputSchema: {
type: 'object',
properties: {
walletId: { type: 'string' },
inputToken: { type: 'string', description: 'Token mint address or "SOL"' },
outputToken: { type: 'string', description: 'Token mint address or "SOL"' },
amount: { type: 'string', description: 'Amount in token units' },
slippageBps: { type: 'number', description: 'Slippage tolerance in basis points' },
},
required: ['walletId', 'inputToken', 'outputToken', 'amount'],
},
}
// Tool: get_swap_quote
// Tool: execute_batch_swaps
// Tool: buy_token
// Tool: sell_token// Tool: create_volume_campaign
{
name: 'create_volume_campaign',
description: 'Create and configure a volume generation campaign',
inputSchema: {
type: 'object',
properties: {
name: { type: 'string' },
targetToken: { type: 'string', description: 'Token mint to generate volume for' },
targetVolume24h: { type: 'string', description: 'Target 24h volume in SOL' },
botCount: { type: 'number' },
duration: { type: 'number', description: 'Campaign duration in hours' },
mode: { type: 'string', enum: ['aggressive', 'moderate', 'stealth'] },
},
required: ['name', 'targetToken', 'targetVolume24h', 'botCount'],
},
}
// Tool: start_campaign
// Tool: pause_campaign
// Tool: stop_campaign
// Tool: get_campaign_status
// Tool: get_campaign_metrics// Tool: get_token_info
// Tool: get_pool_info
// Tool: get_price_history
// Tool: analyze_liquidity
// Tool: get_top_holders// Tool: create_bot
// Tool: configure_bot
// Tool: start_bot
// Tool: stop_bot
// Tool: get_bot_status
// Tool: list_active_bots// Resource: wallets://list
// Resource: wallets://{walletId}
// Resource: campaigns://list
// Resource: campaigns://{campaignId}
// Resource: campaigns://{campaignId}/metrics
// Resource: bots://list
// Resource: bots://{botId}/status
// Resource: tokens://{mint}/info// Prompt: volume_campaign_wizard
{
name: 'volume_campaign_wizard',
description: 'Interactive wizard to set up a volume campaign',
arguments: [
{ name: 'tokenMint', description: 'Target token mint address', required: true },
],
}
// Prompt: wallet_setup_guide
// Prompt: analyze_token_for_trading
// Prompt: campaign_optimization_report- API key validation for sensitive operations
- Rate limiting per operation type
- Audit logging of all tool calls
- Secure credential management
interface AuthConfig {
requireAuth: boolean;
apiKeyHeader: string;
rateLimits: {
swaps: { max: number; window: number };
walletOps: { max: number; window: number };
queries: { max: number; window: number };
};
}interface ServerConfig {
solana: {
network: 'mainnet-beta' | 'devnet';
rpcEndpoints: string[];
commitment: 'processed' | 'confirmed' | 'finalized';
};
redis: {
host: string;
port: number;
password?: string;
};
database: {
host: string;
port: number;
database: string;
user: string;
password: string;
};
encryption: {
masterPassword: string; // From env var
};
features: {
maxWallets: number;
maxBotsPerCampaign: number;
maxConcurrentCampaigns: number;
};
}# Start MCP server
npx @defi-mcp/server start
# With config file
npx @defi-mcp/server start --config ./config.json
# Initialize database
npx @defi-mcp/server db:init
# Run migrations
npx @defi-mcp/server db:migrate- Imports all other packages as dependencies
- Coordinates between wallet-manager, trading-engine, orchestrator
- Provides unified interface for Claude Desktop
- @modelcontextprotocol/sdk
- fastify (for optional HTTP API alongside MCP)
- zod (input validation)
- pino (logging)
packages/mcp-server/
├── package.json
├── tsconfig.json
├── src/
│ ├── index.ts
│ ├── server.ts
│ ├── cli.ts
│ ├── tools/
│ │ ├── index.ts
│ │ ├── wallet-tools.ts
│ │ ├── trading-tools.ts
│ │ ├── campaign-tools.ts
│ │ ├── analysis-tools.ts
│ │ └── bot-tools.ts
│ ├── resources/
│ │ ├── index.ts
│ │ ├── wallet-resources.ts
│ │ ├── campaign-resources.ts
│ │ └── bot-resources.ts
│ ├── prompts/
│ │ ├── index.ts
│ │ └── templates.ts
│ ├── auth/
│ │ ├── api-key.ts
│ │ └── rate-limiter.ts
│ ├── config/
│ │ ├── loader.ts
│ │ └── schema.ts
│ └── types.ts
├── config/
│ └── default.json
{
"name": "defi-mcp-server",
"version": "1.0.0",
"description": "Production DeFi operations via MCP for Solana",
"tools": [
"create_wallet_swarm",
"execute_swap",
"create_volume_campaign",
"start_campaign",
"get_campaign_metrics",
// ... all tools
],
"resources": [
"wallets://*",
"campaigns://*",
"bots://*"
],
"prompts": [
"volume_campaign_wizard",
"wallet_setup_guide"
]
}{
"mcpServers": {
"defi": {
"command": "npx",
"args": ["@defi-mcp/server", "start"],
"env": {
"SOLANA_RPC_URL": "https://mainnet.helius-rpc.com/?api-key=YOUR_KEY",
"REDIS_URL": "redis://localhost:6379",
"DATABASE_URL": "postgresql://user:pass@localhost:5432/defi",
"MASTER_PASSWORD": "your-secure-password"
}
}
}
}- Full MCP protocol compliance (test with Claude Desktop)
- Graceful error handling with user-friendly messages
- Input validation on all tools (use Zod)
- Streaming responses for long-running operations
- Progress updates for batch operations
- All operations must be audited and logged
Start building immediately. Produce complete, working code.
---
## Coordination Instructions
### Shared Interfaces
All agents should export TypeScript interfaces to `/packages/shared/src/interfaces/`:
- `blockchain.ts` - Transaction, Account, Balance types
- `trading.ts` - Swap, Quote, Route types
- `wallet.ts` - Wallet, KeyPair, Signer types
- `orchestration.ts` - Bot, Campaign, Task types
- `mcp.ts` - Tool definitions, Resource types
### Integration Flow
┌─────────────────┐ │ MCP Server │ ← Claude Desktop │ (Agent 5) │ └────────┬────────┘ │ ┌────┴────┐ │ │ ┌───▼───┐ ┌───▼────────┐ │Wallet │ │Orchestrator│ │Manager│ │ (Agent 3) │ │(Agt 4)│ └───┬────────┘ └───┬───┘ │ │ ┌────▼─────┐ │ │ Trading │ │ │ Engine │ │ │(Agent 2) │ │ └────┬─────┘ │ │ └────┬────┘ │ ┌─────▼─────┐ │ Solana │ │ Core │ │ (Agent 1) │ └───────────┘
### Environment Variables (All Agents)
```bash
# Solana RPC
HELIUS_API_KEY=
QUICKNODE_ENDPOINT=
SOLANA_NETWORK=mainnet-beta
# Database
DATABASE_URL=postgresql://user:pass@localhost:5432/defi
# Redis
REDIS_URL=redis://localhost:6379
# Security
MASTER_PASSWORD=
ENCRYPTION_KEY=
# Logging
LOG_LEVEL=info
- Agent 1: solana-core (no internal dependencies)
- Agent 4: wallet-manager (depends on solana-core)
- Agent 2: trading-engine (depends on solana-core)
- Agent 3: orchestrator (depends on trading-engine, wallet-manager)
- Agent 5: mcp-server (depends on all above)
- Unit tests for each package
- Integration tests with devnet
- E2E tests with real mainnet (small amounts)
- Load testing for orchestrator (10k bots simulation)
Each agent should:
- Read this document fully
- Create their package structure
- Implement all interfaces
- Export types for other agents
- Write tests (unit + integration)
- Document their APIs
Begin immediately. Ask clarifying questions only if blocking.