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
9 changes: 9 additions & 0 deletions typescript/lib/mcp-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Welcome to Vibekit's MCP tools directory! Model Context Protocol (MCP) tools are standardized interfaces that allow agents to easily interact with on-chain data, execute DeFi operations, and integrate with external services. This directory contains the MCP building blocks that give DeFi agents their superpowers.

## 📦 Available MCP Servers

This directory includes the following production-ready MCP servers:

- **[Uniswap MCP Server](./uniswap-mcp-server/)** - Token swaps, quotes, routing, and transaction generation for Uniswap v2/v3
- **[CoinGecko MCP Server](./coingecko-mcp-server/)** - Cryptocurrency price data and charts
- **[Allora MCP Server](./allora-mcp-server/)** - Allora network price prediction data
- **[DeFiSafety Implementation](./defisafety-implementation/)** - DeFi protocol safety evaluation tools

## 🛠️ Building Your MCP Tool

By contributing new MCP tools, you're expanding the possibilities for all Vibekit agents. Your tools can enable new DeFi strategies, integrate additional protocols, or enhance existing capabilities. This guide will walk you through the process of creating and contributing your own MCP tools to the ecosystem. Before submitting a pull request for your work, please review the guidelines in [`CONTRIBUTIONS.md`](https://github.com/EmberAGI/arbitrum-vibekit/blob/main/CONTRIBUTIONS.md) to ensure best practices are followed.
Expand Down
29 changes: 29 additions & 0 deletions typescript/lib/mcp-tools/uniswap-mcp-server/COMPATIBILITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Compatibility Notes

## Uniswap SDK and Ethers Version Compatibility

The Uniswap MCP Server uses the latest Uniswap SDK packages which require **ethers v6**. However, the vibekit codebase currently uses **ethers v5**.

### Current Status

- **Uniswap SDK packages**: Latest versions (require ethers v6)
- **Vibekit codebase**: Uses ethers v5
- **Status**: Code structure is complete, but SDK integration needs ethers v6 compatibility layer or migration

### Options for Resolution

1. **Use ethers v6 adapter**: Create an adapter layer to bridge ethers v5 and v6
2. **Upgrade to ethers v6**: Migrate the entire vibekit codebase to ethers v6 (larger change)
3. **Use older Uniswap SDK versions**: Find versions compatible with ethers v5 (may have limited features)

### Recommended Approach

For production use, we recommend:
1. Testing the current implementation with ethers v6 in an isolated environment
2. Creating an adapter layer if needed
3. Or waiting for vibekit to migrate to ethers v6

### Installation

The packages may show peer dependency warnings during installation. This is expected due to the ethers version mismatch. The code structure is complete and ready for testing once the ethers compatibility is resolved.

113 changes: 113 additions & 0 deletions typescript/lib/mcp-tools/uniswap-mcp-server/INTEGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Uniswap MCP Server - Integration Guide

This guide shows how to integrate the Uniswap MCP server into your Vibekit agent.

## Quick Integration

### 1. Add to MCP Registry

Add the Uniswap MCP server to your agent's `mcp.json` file:

```json
{
"mcpServers": {
"uniswap": {
"type": "stdio",
"command": "node",
"args": [
"./typescript/lib/mcp-tools/uniswap-mcp-server/dist/index.js"
],
"env": {
"ETHEREUM_RPC_URL": "$env:ETHEREUM_RPC_URL",
"ARBITRUM_RPC_URL": "$env:ARBITRUM_RPC_URL",
"DEFAULT_SLIPPAGE": "0.5",
"GAS_MULTIPLIER": "1.2"
}
}
}
}
```

### 2. Reference in Skills

In your skill files (`.md` files in `skills/` directory), reference the Uniswap server:

```markdown
---
skill:
id: swap-tokens
name: 'Token Swap Skill'
description: 'Execute token swaps on Uniswap'
tags: [defi, swap]

mcp:
servers:
- name: uniswap
allowedTools:
- uniswap__getSwapQuote
- uniswap__getBestRoute
- uniswap__generateSwapTransaction
- uniswap__validateSwapFeasibility
- uniswap__processSwapIntent
---

You can help users swap tokens on Uniswap using the available tools...
```

### 3. Environment Variables

Set the required environment variables:

```bash
export ETHEREUM_RPC_URL="https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY"
export ARBITRUM_RPC_URL="https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY"
export DEFAULT_SLIPPAGE="0.5" # Optional
export GAS_MULTIPLIER="1.2" # Optional
```

## Tool Namespacing

Tools are automatically namespaced as `{server_name}__{tool_name}`:

- `uniswap__getSwapQuote`
- `uniswap__getBestRoute`
- `uniswap__generateSwapTransaction`
- `uniswap__validateSwapFeasibility`
- `uniswap__processSwapIntent`

## HTTP Transport (Alternative)

For HTTP/StreamableHTTP transport:

```json
{
"mcpServers": {
"uniswap": {
"transport": {
"type": "http",
"url": "http://localhost:3012/mcp"
}
}
}
}
```

Then start the server separately:

```bash
cd typescript/lib/mcp-tools/uniswap-mcp-server
pnpm start
```

## Testing Integration

1. Start your agent with the MCP server configured
2. Check agent logs for MCP server connection status
3. Test a tool call from your agent

## Troubleshooting

- **Server not found**: Check the path in `args` is correct relative to your agent's working directory
- **Connection failed**: Verify environment variables are set correctly
- **Tool not available**: Check the tool name includes the namespace prefix (`uniswap__`)

193 changes: 193 additions & 0 deletions typescript/lib/mcp-tools/uniswap-mcp-server/QUICK_START.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Uniswap MCP Server - Quick Start Guide

This guide will help you quickly get started with the Uniswap MCP Server for agents.

## Prerequisites

- Node.js >= 18.0.0
- pnpm package manager
- RPC endpoints for Ethereum and Arbitrum

## Setup

1. **Install dependencies:**

```bash
cd typescript/lib/mcp-tools/uniswap-mcp-server
pnpm install
```

2. **Configure environment:**

Create a `.env` file:

```env
ETHEREUM_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
ARBITRUM_RPC_URL=https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY
DEFAULT_SLIPPAGE=0.5
```

3. **Build the server:**

```bash
pnpm build
```

## Basic Usage Examples

### Example 1: Get a Swap Quote

```typescript
// Agent calls the MCP tool
const quote = await mcpClient.callTool({
name: 'getSwapQuote',
arguments: {
tokenIn: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
tokenOut: '0xA0b86991c6218b36c1d19D4a2e9Eb0c3606eB48', // USDC
amount: '1000000000000000000', // 1 ETH
chainId: 1,
slippageTolerance: 0.5
}
});

console.log(`Expected output: ${quote.expectedAmountOut} USDC`);
console.log(`Price impact: ${quote.priceImpact}%`);
```

### Example 2: Process Natural Language Intent

```typescript
// Agent processes user intent
const swapPlan = await mcpClient.callTool({
name: 'processSwapIntent',
arguments: {
intent: 'Swap 1 ETH to USDC with minimal slippage',
chainId: 1,
userAddress: '0x742d35Cc6634C4532895c05b22629ce5b3c28da4'
}
});

// The tool returns a complete swap plan
console.log('Token in:', swapPlan.tokenIn);
console.log('Token out:', swapPlan.tokenOut);
console.log('Amount:', swapPlan.amount);
console.log('Quote:', swapPlan.quote);
console.log('Transaction:', swapPlan.transaction);
console.log('Validation:', swapPlan.validation);
```

### Example 3: Validate Before Swapping

```typescript
// Always validate before executing
const validation = await mcpClient.callTool({
name: 'validateSwapFeasibility',
arguments: {
tokenIn: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
tokenOut: '0xA0b86991c6218b36c1d19D4a2e9Eb0c3606eB48',
amount: '1000000000000000000',
chainId: 1,
userAddress: '0x742d35Cc6634C4532895c05b22629ce5b3c28da4',
slippageTolerance: 0.5
}
});

if (!validation.isValid) {
console.error('Swap not feasible:', validation.errors);
return;
}

if (validation.warnings.length > 0) {
console.warn('Warnings:', validation.warnings);
}

if (validation.requiresApproval) {
console.log('Approval needed. Current allowance:', validation.currentAllowance);
}
```

### Example 4: Generate and Execute Transaction

```typescript
// Step 1: Get the best route
const route = await mcpClient.callTool({
name: 'getBestRoute',
arguments: {
tokenIn: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
tokenOut: '0xA0b86991c6218b36c1d19D4a2e9Eb0c3606eB48',
amount: '1000000000000000000',
chainId: 1
}
});

// Step 2: Generate transaction
const tx = await mcpClient.callTool({
name: 'generateSwapTransaction',
arguments: {
route: route.route,
amountIn: '1000000000000000000',
slippageTolerance: 0.5,
recipient: '0x742d35Cc6634C4532895c05b22629ce5b3c28da4',
chainId: 1
}
});

// Step 3: Execute transaction (using your wallet provider)
await wallet.sendTransaction({
to: tx.to,
data: tx.data,
value: tx.value,
gasLimit: tx.gasEstimate
});
```

## Common Token Addresses

### Ethereum Mainnet
- ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`
- WETH: `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`
- USDC: `0xA0b86991c6218b36c1d19D4a2e9Eb0c3606eB48`
- USDT: `0xdAC17F958D2ee523a2206206994597C13D831ec7`
- DAI: `0x6B175474E89094C44Da98b954EedeAC495271d0F`

### Arbitrum One
- ETH: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`
- WETH: `0x82aF49447D8a07e3bd95BD0d56f35241523fBab1`
- USDC: `0xaf88d065e77c8cC2239327C5EDb3A432268e5831`
- USDT: `0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9`
- DAI: `0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1`

## Best Practices

1. **Always validate before executing**: Use `validateSwapFeasibility` to check all conditions
2. **Check price impact**: High price impact (>5%) may indicate low liquidity
3. **Handle approvals**: Check if token approval is needed before swapping
4. **Use appropriate slippage**: Default 0.5% is usually safe, adjust based on volatility
5. **Monitor gas estimates**: Large gas estimates may indicate complex routes

## Troubleshooting

### "No route found"
- Check that both tokens are valid ERC20 contracts
- Verify there's liquidity for the token pair
- Try a smaller amount

### "Insufficient balance"
- Check user's token balance
- For native ETH, ensure sufficient ETH balance

### "Approval required"
- User needs to approve the Universal Router to spend their tokens
- Use the ERC20 `approve` function first

### "High price impact"
- Consider splitting the swap into smaller amounts
- Try a different route or DEX
- Wait for better liquidity conditions

## Next Steps

- Read the full [README.md](./README.md) for detailed documentation
- Explore the source code to understand the implementation
- Integrate into your agent using the MCP client

Loading