code-mode-alchemy-mcp
Gives Claude access to Alchemy blockchain APIs by loading all API specs at startup and providing two tools: search and execute. Enables querying NFTs, token balances, transactions, and more via natural language.
README
code-mode-alchemy-mcp
An MCP (Model Context Protocol) server that gives Claude access to Alchemy's blockchain APIs. Instead of defining 88+ individual tools, it loads all Alchemy API specs at startup and exposes just two tools — search and execute — keeping context usage minimal (~1,000 tokens vs. thousands).
Inspired by Cloudflare's Code Mode MCP pattern.
How It Works
At startup, the server fetches 10 Alchemy API specifications (6 REST OpenAPI + 4 JSON-RPC OpenRPC) and indexes all their endpoints. Claude can then:
- Search — find relevant endpoints by keyword
- Execute — run JavaScript code in a sandboxed environment against those endpoints
Claude → search("NFT owner") → finds getNFTsForOwner endpoint
Claude → execute(code) → runs against Alchemy API, returns data
Loaded Specifications
REST (OpenAPI):
nft— NFT operations (mint, transfer, ownership queries)portfolio— Wallet portfolio dataprices— Token pricing informationnotify— Webhook notificationstransactions— Transaction history and detailsaccounts— Account management
JSON-RPC (OpenRPC):
transfers— Token transfer history (alchemy_getAssetTransfers)token— Token metadata and balances (alchemy_getTokenBalances, etc.)transaction-simulation— Simulate transactions before sendingbundler— ERC-4337 bundler operations
Prerequisites
- Node.js 18+
- An Alchemy API key
Installation
git clone https://github.com/your-username/code-mode-alchemy-mcp
cd code-mode-alchemy-mcp
npm install
npm run build
Configuration
Copy the example environment file:
cp .env.example .env
Set your values in .env:
ALCHEMY_API_KEY=your_key_here
ALCHEMY_NETWORK=eth-mainnet
Supported Networks
Any network string Alchemy supports in their URL format, e.g.:
eth-mainneteth-sepoliapolygon-mainnetarb-mainnetopt-mainnetbase-mainnet
Add to Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"alchemy": {
"command": "node",
"args": ["/absolute/path/to/code-mode-alchemy-mcp/dist/index.js"],
"env": {
"ALCHEMY_API_KEY": "your_key_here",
"ALCHEMY_NETWORK": "eth-mainnet"
}
}
}
}
Restart Claude Desktop. You should see the Alchemy MCP server connected.
Tools
search(query, limit?)
Searches across all loaded endpoint metadata (summaries, descriptions, paths, tags) and returns the most relevant endpoints.
| Parameter | Type | Default | Description |
|---|---|---|---|
query |
string | required | Keywords to search for |
limit |
number | 8 | Max results to return (max 20) |
Example queries:
"NFT owner"— find endpoints for fetching NFTs by owner"token balance"— find token balance endpoints"asset transfers"— find transfer history endpoints"simulate transaction"— find simulation endpoints
execute(code)
Runs JavaScript code in a sandboxed Node.js VM with access to the Alchemy API. Execution is isolated with a 30-second timeout.
Available in the sandbox:
| Name | Type | Description |
|---|---|---|
request(url, params?, options?) |
function | Simplified API caller. Replaces {apiKey} and {network} in the URL automatically. |
fetch |
function | Raw Fetch API for custom requests |
ALCHEMY_API_KEY |
string | Your API key |
ALCHEMY_NETWORK |
string | Your configured network |
console.log |
function | Output captured and returned |
console.error |
function | Errors captured and returned |
REST example:
const data = await request(
"https://{network}.g.alchemy.com/nft/v3/{apiKey}/getNFTsForOwner",
{ owner: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", withMetadata: true }
);
return data;
JSON-RPC example:
const data = await request(
"https://{network}.g.alchemy.com/v2/{apiKey}",
{
jsonrpc: "2.0",
method: "alchemy_getTokenBalances",
params: ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"],
id: 1
},
{ method: "POST" }
);
return data;
Usage Examples
NFTs for a wallet
"Show me all NFTs owned by 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
Claude will:
- Call
search("NFT owner")→ findsgetNFTsForOwner - Call
execute(...)→ fetches and returns NFT data
Token balances
"What ERC-20 tokens does this address hold: 0x..."
Claude will:
- Call
search("token balances")→ findsalchemy_getTokenBalances - Call
execute(...)→ returns token list with balances
Transaction history
"Show recent transactions for vitalik.eth"
Claude will:
- Call
search("asset transfers")→ findsalchemy_getAssetTransfers - Call
execute(...)→ returns transfer history
Simulate a transaction
"What would happen if I sent 1 ETH from 0x... to 0x...?"
Claude will:
- Call
search("simulate transaction")→ finds simulation endpoint - Call
execute(...)→ returns simulation result
Development
# Run in development mode (no build step needed)
npm run dev
# Build for production
npm run build
# Run the compiled server
npm start
Project Structure
code-mode-alchemy-mcp/
├── src/
│ └── index.ts # Everything: spec loading, search, sandbox, MCP server
├── dist/
│ ├── index.js # Compiled output (run this)
│ └── index.d.ts # TypeScript declarations
├── .env.example # Environment variable template
├── package.json
└── tsconfig.json
Architecture
Claude Desktop
│
│ MCP (stdio)
▼
MCP Server
│
├── Startup: fetch 10 specs → index all endpoints
│
├── search(query)
│ └── score & rank endpoints by keyword match
│
└── execute(code)
└── vm.runInNewContext() with 30s timeout
└── request() helper → Alchemy REST/RPC APIs
Why two tools instead of 88+?
Defining every Alchemy endpoint as a separate MCP tool would consume thousands of tokens just in tool definitions, before Claude even starts reasoning. This pattern loads specs once, searches them dynamically, and executes code — using ~1,000 tokens of tool definitions regardless of how many endpoints Alchemy adds.
Security Notes
- Code in
execute()runs in a Node.jsvmsandbox with no access to the filesystem, environment, orrequire - The API key is injected by the sandbox via placeholder replacement — it is never returned in search results or exposed to user-visible output
- Execution is limited to 30 seconds to prevent runaway code
References
- Cloudflare Code Mode MCP — the pattern this is based on
- Cloudflare Agents API Reference
- Alchemy OpenAPI Specs
- Model Context Protocol
- Alchemy API Docs
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。