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
3 changes: 3 additions & 0 deletions typescript/create-onchain-agent/templates/mcp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
build
58 changes: 58 additions & 0 deletions typescript/create-onchain-agent/templates/mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Onchain Claude Desktop Powered by AgentKit

This is a [Model Context Protocol Server](https://modelcontextprotocol.io/quickstart/server) project bootstrapped with `create-onchain-agent`.

It integrates [AgentKit](https://github.com/coinbase/agentkit) to provide Claude Desktop with AI-driven interactions with on-chain capabilities.

## Getting Started

First, install dependencies:

```sh
npm install
```

Then, configure your environment variables in, `claude_desktop_config.json`, if needed. For example, if you are using CDP, you will need to fill in your CDP API key.

Copy the `claude_desktop_config.json` file to your Claude Desktop config directory:

```sh
cp claude_desktop_config.json ~/Library/Application\ Support/Claude/claude_desktop_config.json
```

Build the server:

```sh
npm run build
```

Open Claude Desktop and start prompting Claude to do things onchain! For example, ask it to print your wallet details.

## Configuring Your Agent

You can [modify your configuration](https://github.com/coinbase/agentkit/tree/main/typescript/agentkit#usage) of the agent. By default, your agentkit configuration occurs in the `./src/getAgentKit.ts` file, and agent instantiation + server setup occurs in the `./src/index.ts` file.

---

## Next Steps

- Explore the AgentKit README: [AgentKit Documentation](https://github.com/coinbase/agentkit)
- Learn more about available Wallet Providers & Action Providers.
- Experiment with custom Action Providers for your specific use case.

---

## Learn More

- [Learn more about CDP](https://docs.cdp.coinbase.com/)
- [Learn more about AgentKit](https://docs.cdp.coinbase.com/agentkit/docs/welcome)
- [Learn more about Model Context Protocol](https://modelcontextprotocol.io/quickstart/server)

---

## Contributing

Interested in contributing to AgentKit? Follow the contribution guide:

- [Contribution Guide](https://github.com/coinbase/agentkit/blob/main/CONTRIBUTING.md)
- Join the discussion on [Discord](https://discord.gg/CDP)
26 changes: 26 additions & 0 deletions typescript/create-onchain-agent/templates/mcp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "mcp",
"version": "0.1.0",
"private": true,
"main": "index.js",
"type": "module",
"bin": {
"agentkit": "./build/index.js"
},
"scripts": {
"build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\""
},
"dependencies": {
"@coinbase/agentkit": "^0.3.0",
"@coinbase/agentkit-model-context-protocol": "^0.2.0",
"@modelcontextprotocol/sdk": "^1.6.1",
"@solana/web3.js": "^1.98.0",
"bs58": "^6.0.0",
"viem": "^2.23.7"
},
"devDependencies": {
"@types/node": "^22.13.9",
"tsx": "^4.19.3",
"typescript": "^5.8.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"mcpServers": {
"agentkit": {
"command": "node",
"args": ["{absolutePath}/build/index.js"],
"env": {
"PRIVATE_KEY": "",
"RPC_URL": "",
"CHAIN_ID": "",
"CDP_API_KEY_NAME": "",
"CDP_API_KEY_PRIVATE_KEY": ""
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
ActionProvider,
AgentKit,
cdpApiActionProvider,
erc20ActionProvider,
pythActionProvider,
ViemWalletProvider,
walletActionProvider,
wethActionProvider,
} from "@coinbase/agentkit";
import { createWalletClient, Hex, http } from "viem";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";

/**
* Get the AgentKit instance.
*
* @returns {Promise<AgentKit>} The AgentKit instance
*/
export async function getAgentKit(): Promise<AgentKit> {
try {
// Initialize WalletProvider: https://docs.cdp.coinbase.com/agentkit/docs/wallet-management
let privateKey = process.env.PRIVATE_KEY as Hex;
if (!privateKey) {
privateKey = generatePrivateKey();
}
const account = privateKeyToAccount(privateKey);

const rpcUrl = process.env.RPC_URL as string;
const chainId = process.env.CHAIN_ID as string;
const client = createWalletClient({
account,
// Customize the chain metadata to match your custom chain
chain: {
id: parseInt(chainId),
rpcUrls: {
default: {
http: [rpcUrl],
},
},
name: "Custom Chain",
nativeCurrency: {
name: "Ether",
symbol: "ETH",
decimals: 18,
},
},
transport: http(),
});
const walletProvider = new ViemWalletProvider(client);

// Initialize AgentKit: https://docs.cdp.coinbase.com/agentkit/docs/agent-actions
const actionProviders: ActionProvider[] = [
wethActionProvider(),
pythActionProvider(),
walletActionProvider(),
erc20ActionProvider(),
];
const canUseCdpApi = process.env.CDP_API_KEY_NAME && process.env.CDP_API_KEY_PRIVATE_KEY;
if (canUseCdpApi) {
actionProviders.push(
cdpApiActionProvider({
apiKeyName: process.env.CDP_API_KEY_NAME,
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
}),
);
}
const agentkit = await AgentKit.from({
walletProvider,
actionProviders,
});

return agentkit;
} catch (error) {
console.error("Error initializing agent:", error);
throw new Error("Failed to initialize agent");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"mcpServers": {
"agentkit": {
"command": "node",
"args": ["{absolutePath}/build/index.js"],
"env": {
"CDP_API_KEY_NAME": "",
"CDP_API_KEY_PRIVATE_KEY": "",
"NETWORK_ID": "base-sepolia"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
AgentKit,
cdpApiActionProvider,
cdpWalletActionProvider,
CdpWalletProvider,
erc20ActionProvider,
pythActionProvider,
walletActionProvider,
wethActionProvider,
} from "@coinbase/agentkit";

/**
* Get the AgentKit instance.
*
* @returns {Promise<AgentKit>} The AgentKit instance
*/
export async function getAgentKit(): Promise<AgentKit> {
try {
// Initialize WalletProvider: https://docs.cdp.coinbase.com/agentkit/docs/wallet-management
const walletProvider = await CdpWalletProvider.configureWithWallet({
apiKeyName: process.env.CDP_API_KEY_NAME,
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
networkId: process.env.NETWORK_ID || "base-sepolia",
});

// Initialize AgentKit: https://docs.cdp.coinbase.com/agentkit/docs/agent-actions
const agentkit = await AgentKit.from({
walletProvider,
actionProviders: [
wethActionProvider(),
pythActionProvider(),
walletActionProvider(),
erc20ActionProvider(),
cdpApiActionProvider({
apiKeyName: process.env.CDP_API_KEY_NAME,
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
}),
cdpWalletActionProvider({
apiKeyName: process.env.CDP_API_KEY_NAME,
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
}),
],
});

return agentkit;
} catch (error) {
console.error("Error initializing agent:", error);
throw new Error("Failed to initialize agent");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"mcpServers": {
"agentkit": {
"command": "node",
"args": ["{absolutePath}/build/index.js"],
"env": {
"PRIVY_APP_ID": "",
"PRIVY_APP_SECRET": "",
"PRIVY_WALLET_ID": "",
"PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY": "",
"PRIVY_WALLET_AUTHORIZATION_KEY_ID": "",
"CHAIN_ID": "84532",
"CDP_API_KEY_NAME": "",
"CDP_API_KEY_PRIVATE_KEY": ""
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
ActionProvider,
AgentKit,
cdpApiActionProvider,
erc20ActionProvider,
PrivyWalletConfig,
PrivyWalletProvider,
pythActionProvider,
walletActionProvider,
wethActionProvider,
} from "@coinbase/agentkit";

/**
* Get the AgentKit instance.
*
* @returns {Promise<AgentKit>} The AgentKit instance
*/
export async function getAgentKit(): Promise<AgentKit> {
try {
// Initialize WalletProvider: https://docs.cdp.coinbase.com/agentkit/docs/wallet-management
const config: PrivyWalletConfig = {
appId: process.env.PRIVY_APP_ID as string,
appSecret: process.env.PRIVY_APP_SECRET as string,
walletId: process.env.PRIVY_WALLET_ID as string,
chainId: process.env.CHAIN_ID,
authorizationPrivateKey: process.env.PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY,
authorizationKeyId: process.env.PRIVY_WALLET_AUTHORIZATION_KEY_ID,
};

if (!config.chainId) {
console.log("Warning: CHAIN_ID not set, defaulting to 84532 (base-sepolia)");
config.chainId = "84532";
}
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);

// Initialize AgentKit: https://docs.cdp.coinbase.com/agentkit/docs/agent-actions
const actionProviders: ActionProvider[] = [
wethActionProvider(),
pythActionProvider(),
walletActionProvider(),
erc20ActionProvider(),
];
const canUseCdpApi = process.env.CDP_API_KEY_NAME && process.env.CDP_API_KEY_PRIVATE_KEY;
if (canUseCdpApi) {
actionProviders.push(
cdpApiActionProvider({
apiKeyName: process.env.CDP_API_KEY_NAME,
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
}),
);
}
const agentkit = await AgentKit.from({
walletProvider,
actionProviders,
});

return agentkit;
} catch (error) {
console.error("Error initializing agent:", error);
throw new Error("Failed to initialize agent");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"mcpServers": {
"agentkit": {
"command": "node",
"args": ["{absolutePath}/build/index.js"],
"env": {
"CDP_API_KEY_NAME": "",
"CDP_API_KEY_PRIVATE_KEY": "",
"PRIVATE_KEY": "",
"NETWORK_ID": "base-sepolia"
}
}
}
}
Loading