CosmWasm MCP Server Template

by drewstaylor

1 319 downloads Not rated yet Apache-2.0 license

About

MCP server template for CosmWasm smart contract projects

Details

License
Apache-2.0 license

Explore

- Wraps CosmWasm query and execute entry points
- Generates JSON schemas for AI agents
- Supports stdio, SSE, and HTTP‑streamable transports
- Customizable LLM instructions and tool descriptions
- Works with any CosmWasm contract via template adaptation
- Provides 6 default MCP tools for contract interaction

This project is an MCP server template that can be used with any CosmWasm contract, but to use this template with your own contracts, you'll need to make a few small changes.

To use this template with your own contract, implement the following _mandatory_ changes:

cargo build --release


At the bottom of src/contract.rs (see code), update the deployed contract addresses for the mainnet and testnet deployments of your contract. Or, if you want to remove one of the entries, so there's only a testnet or only a mainnet entry, you'll need to remove the entry from the contracts array in the CwMcp::new() function (see code).

rs
/// Replace with your deployed contract addresses.
/// This helps the query msg and tx msg builders wrap
/// your query and tx messages to the contract into
/// CosmWasm's QueryRequest and CosmosMessage types
/// that can be broadcast by a rpc enabled wallet tool
pub static CONTRACT_MAINNET: &str =
"archway1gaf9nw7n8v5lpjz9caxjpps006kxfcrzcuc8y5qp4clslhven2ns2g0ule";
pub static CONTRACT_TESTNET: &str =
"archway1r8kepegwhldwqanuurc769l2g0qxlsm2sm6t5rhqjzcerxsgshls267f7a";
```

  • If your contract uses any custom types or responses that you think would be beneficial for the AI agent should have access to, there's an example (commented out) in server.rs of how to achieve that (see below snippet from src/server.rs).
/// (Optionally) if your contract provides any custom query response types
/// configure this tool so the MCP agent can access them. Allowing the MCP
/// agent to access the custom query responses enables it to provide smarter
/// advice, and summaries, about exacly what data can be fetched when making
/// a query to the contract.
/// @see: src/query.rs
#[tool(description = LIST_QUERY_RESPONSE_DESCR)]
async fn list_query_responses(&self) -> Result<CallToolResult, Error> {
    let schema = schema_for!(AllQueryResponse);
    let serialized: String = serde_json::to_string(&schema).unwrap_or("".to_string());
    Ok(CallToolResult::success(vec![Content::text(serialized)]))
}

By default, this MCP server provides the following 6 tools and functionality.

1. list_contract_deployments - Lists Ambur core contract addresses (mainnet and testnet)
2. list_nft_collections - Lists Ambur NFTs (mainnet and testnet contract addresses, collection name, and collection description)
3. list_query_entry_points - Lists the queries that can be made to the core Ambur marketplace contract
4. build_query_msg - Build a query to the core Ambur marketplace contract, that can be broadcast by an RPC connected wallet
5. list_tx_entry_points - Lists the transactions that can be made to the core Ambur marketplace contract
6. build_execute_msg - Build a transaction to the core Ambur marketplace contract, that can be signed and broadcast by an RPC connected wallet

MCP server in Rust, for wrapping query and execute entry point messages to be broadcast by a signer. This project template should work with any CosmWasm contract.

Building this project

To build this project requires the nightly build of Rust, this will allow using edition 2024 of rustc.

```sh

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.