dchu3/base-mcp-server
If you are the rightful owner of base-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
Base blockchain MCP server is a foundational server designed to facilitate communication and data exchange in blockchain networks using the Model Context Protocol (MCP).
base-mcp-server
MCP server for Base that wraps the Blockscout API into agent-friendly tools. It exposes account, transaction, contract, token, log, and router activity queries for both Base Mainnet and Base Sepolia.
Getting Started
npm install
cp .env.example .env
npm run dev
Set BASE_NETWORK to base-mainnet or base-sepolia in .env. Override Blockscout
endpoints or router config through environment variables when needed.
Configuration
Key environment variables (see .env.example for defaults):
BASE_NETWORK:base-mainnetorbase-sepolia(selects the Blockscout base URL).BLOCKSCOUT_MAINNET/BLOCKSCOUT_SEPOLIA: explorer API URLs (override if self-hosted).BLOCKSCOUT_API_KEY: optional Blockscout API key.PORT: health endpoint port (/healthz).LOG_LEVEL:fatal|error|warn|info|debug|trace|silent.- Cache / rate / retry knobs:
CACHE_TTL_MS,CACHE_MAX,RATE_POINTS,RATE_DURATION_S,RETRY_ATTEMPTS,RETRY_MIN_MS,RETRY_MAX_MS. ROUTERS_CONFIG_PATH: JSON file for router overrides (used byrouters set).
Key Commands
npm run dev– start the MCP server in watch mode (stdio transport).npm run build– bundle the project with tsup.npm run start– run the compiled server fromdist/.npm run test– execute Vitest unit tests.npm run lint– lint the TypeScript sources.npm run format– format the codebase via Prettier.
CLI Interface
# Start the MCP server (reads .env)
base-mcp-server start --network base-mainnet --port 7801 --log-level info
# Print known router addresses for the active network
base-mcp-server routers print
# Get a single router address for the active network
base-mcp-server routers get --name uniswap_v3
# Update a router override (requires ROUTERS_CONFIG_PATH)
base-mcp-server routers set --name uniswap_v3 --network base-mainnet --address 0x...
# Probe Blockscout reachability
base-mcp-server health
start also launches an HTTP health check at /healthz on the configured PORT.
The server surfaces tools such as getAccountSummary, getTransactions,
getContractABI, getLogs, and getDexRouterActivity, returning small structured
payloads validated with zod.
search Tool
- Wraps Blockscout
GET /v2/searchand returns the first 10 matches. - Normalizes fields across addresses, tokens, and transactions (
type,name,hash,address,label,match).
getTransactions Tool
- Hits the Blockscout endpoint
GET /v2/addresses/{address}/transactions, so an address is always required. - Filters by direction using Blockscout’s
filter=from|toderived from the MCP-leveldirectionparameter, matching the curl example (filter=to) when you passdirection: 'in'. - Normalizes each transaction record (hash/source/destination/timestamp/status) so the
response shape is consistent even when Blockscout renames fields (
hashvstx_hash,methodvscall_type, etc.). - Surfaces Blockscout’s keyset pagination under a
nextCursorobject. To fetch the next batch of results, pass thatnextCursorback as thecursorinput (the tool merges the opaque keyset params with your latest direction filter).
getContractABI Tool
- Calls
GET /v2/smart-contracts/{address}to fetch the verified ABI plus compiler metadata. - Parses ABI payloads whether Blockscout returns a JSON string (
abi,result, orabi_json) or a pre-parsed array, so agents always receive a normalized ABI array when available. - Surfaces compiler version, EVM version, and verification timestamp fields under a single
metadataobject (verifiedfalls back totrueif the endpoint returns an ABI even when explicit flags are missing).
getTransactionByHash Tool
- Wraps
GET /v2/transactions/{hash}to return a normalized view of a single transaction, including decoded method data when Blockscout has verified the contract ABI. - Normalizes values from both string and object fields (addresses, fees, nested
from/toobjects) so callers always receive plain strings for hash,from,to, and raw input. - Surfaces the extended Blockscout telemetry—gas/fee metrics, layer-1 usage, nonce, confirmations, position, transaction types, and pending status—alongside the original success/fail/pending status flag.
resolveToken Tool
- Hits
GET /v2/tokens/{address}to retrieve token metadata for fungible contracts. - Normalizes Blockscout’s varying field names (
namevstoken_name,symbolvstoken_symbol, etc.) so callers always receive consistentname,symbol,decimals,totalSupply,holders, andtypefields. - Parses numeric strings (decimals, holder count) and gracefully returns
nullwhen the explorer omits a field.
getAccountSummary Tool
- Aggregates
/v2/addresses/{address},/v2/addresses/{address}/token-balances, and/v2/addresses/{address}/countersin parallel to produce an ETH balance, nonce, transaction count, and top ERC-20 balances. - Normalizes balance fields into both wei and ether via
formatWeiToEther, and converts string counters/nonces into numbers, defaulting to zero/null when Blockscout omits a value. - Collapses token-balance payloads from either arrays or
{items}structures and returns the first 20 entries with symbol/name/decimals and optional USD estimates.
getDexRouterActivity Tool
- Calls
/v2/addresses/{router}/transactionswithfilter=toand followsnext_page_paramscursors to gather enough samples for the requested page/pageSize. - Supports
sinceMinutesfiltering by stopping pagination when timestamps are older than the cutoff; transactions are normalized to include decoded method data, sender, value, and optionaldecodedABI parameters. - Returns deterministic pagination (server-side cursor + client-side slicing) so repeated calls with the same inputs produce consistent batches.
getLogs Tool
- If a
transactionHashis provided, hits/v2/transactions/{hash}/logs; otherwise calls/v2/logswith address/topic filters pluspage/page_sizequery params. - Accepts up to four topics, optional block range, and uses response
next_pagecursors when scanning across blocks. - Normalizes log entries to guarantee
topicsarrays, numericblockNumber/logIndex, and unix timestamps even when Blockscout returns ISO strings.
getTokenTransfers Tool
- Wraps
/v2/tokens/{address}/transfers, exposing a simple cursor{blockNumber, index}backed by Blockscout’snext_page_paramsso clients can request the next batch precisely. - Normalizes each transfer’s token metadata, participants, amount, and timestamp by merging
fields like
token.*,contract.*, andtotal.value. - Timestamps accept raw seconds, milliseconds, or ISO strings and are coerced to epoch seconds to keep downstream calculations simple.
Agent connection instructions live in src/prompt.ts; update this file when you need to
adjust the guidance delivered to MCP clients.
Request behavior
- The Blockscout client applies rate limiting (
RATE_POINTSperRATE_DURATION_S) andp-retrybackoff based onRETRY_*settings. - Responses are cached in-memory (LRU) for
CACHE_TTL_MSunless a tool setscache: falsefor dynamic endpoints (transactions, transfers, logs).