Skip to content

Commit cf59433

Browse files
authored
feat: add polkadot upgrade workflow tools and prompts (#33)
* feat: add polkadot upgrade workflow tools and prompts - Add list_polkadot_releases tool to discover available SDK releases - Add find_runtime_pallets tool to analyze project runtime configurations - Add polkadot_upgrade prompt for systematic release impact analysis - Enhance fetch_and_analyze_release with PR labels and structured output - Add GitHub API authentication support via GITHUB_TOKEN env var - Use zeroize crate for secure token handling - Add comprehensive test coverage for runtime discovery * fix: make substrate node integration test skip when binary unavailable - Add is_available() method to check for substrate-node binary - Skip test gracefully with informative message when binary not found - Prevents test failure in CI/environments without substrate-node installed * fix: make substrate node test fail with clear error when binary missing - Change from skipping to panicking when substrate-node not found - Provide clear error message about requirement to install substrate-node - Ensures CI/developers are aware of the dependency requirement * refactor: simplify fetch_and_analyze_release naming - Remove '_enhanced' suffix from fetch_and_analyze_release_enhanced - Update all references to use simplified name - No functional changes, just naming consistency * fmt Signed-off-by: Michael Assaf <[email protected]> * feat: enhance polkadot upgrade prompt with parallel sub-agent architecture - Add comprehensive workflow documentation with agent coordination - Implement three-agent system: Main Orchestrator, Compilation, and Analysis agents - Add evidence-based impact categorization (MUST/OPTIONAL/INHERITED/DON'T KNOW) - Include detailed tracking tables and structured reporting - Add mermaid diagrams for workflow visualization - Enhance prompt template with specific sub-agent instructions - Normalize release input to handle different git tag formats - Add comprehensive README documenting the upgrade analysis process * feat: enhance polkadot upgrade prompt with parallel sub-agent architecture - Add ULTRATHINK directive for improved analysis - Implement batch processing for PR analysis (10 parallel agents per batch) - Create dedicated analysis directory structure for individual PR reports - Update tracking table to include total PR count and link to analysis files - Add force parameter to fetch_and_analyze_release for cache control - Implement cache loading functionality to avoid redundant downloads - Improve compilation sub-agent requirements and constraints - Clarify single PR analysis requirement for each sub-agent - Add structured report writing to designated analysis files * optimize prompt, use dyn for mock github api client, add caching for fetch and analyze release Signed-off-by: Michael Assaf <[email protected]> * remove compilation sub agent from workflow * pay close attention to template code in pr changes * send logs to stderr --------- Signed-off-by: Michael Assaf <[email protected]>
1 parent de51df6 commit cf59433

File tree

13 files changed

+2055
-579
lines changed

13 files changed

+2055
-579
lines changed

Cargo.lock

Lines changed: 65 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ scale-value = { version = "0.16", features = ["from-string"] }
4242
scale-info = "2.11"
4343
sp-core = "33.0"
4444
tokio-util = "0.7.16"
45+
zeroize = "1.8"
46+
ignore = "0.4.23"
47+
async-trait = "0.1"
4548

4649
[dev-dependencies]
4750
rmcp = { version = "0.6.3", features = ["transport-io", "client"] }
51+
tempfile = "3.22.0"

README.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22

33
An MCP (Model Context Protocol) server that provides tools for working with Substrate-based blockchains.
44

5-
65
## Installation
76

87
### Option 1: Install from GitHub
8+
99
```bash
1010
cargo install --locked --git https://github.com/Moonsong-Labs/substrate-mcp
1111
```
1212

1313
### Option 2: Build locally (Requires cargo)
14+
1415
```bash
1516
cargo build --release
1617
```
18+
1719
The binary will be available at `./target/release/substrate-mcp`
1820

1921
## Prerequisites
2022

2123
For the `subxt_execute` tool, install the subxt CLI:
24+
2225
```bash
2326
cargo install subxt-cli
2427
```
@@ -51,14 +54,51 @@ If you built the server locally instead of installing it, use the full path:
5154

5255
Alternatively, you can add using cli:
5356

54-
```claude mcp add substrate /path/to/substrate-mcp/target/release/substrate-mcp```
57+
```
58+
claude mcp add substrate /path/to/substrate-mcp/target/release/substrate-mcp
59+
```
60+
61+
## Configuration
62+
63+
### GitHub API Rate Limits
64+
65+
Some tools (like `fetch_and_analyze_release` and `list_polkadot_releases`) make requests to the GitHub API. Without authentication, you're limited to 60 requests per hour. For higher rate limits (5,000 requests/hour), set a GitHub token:
66+
67+
```bash
68+
export GITHUB_TOKEN="your_github_personal_access_token"
69+
```
70+
71+
To generate a token:
72+
73+
1. Go to [GitHub Settings > Personal access tokens](https://github.com/settings/tokens)
74+
2. Click "Generate new token" > "Generate new token (classic)"
75+
3. No special permissions required - just create a basic token
76+
4. Copy the token and set it in your environment
77+
78+
For Claude Code, you can set environment variables in your configuration:
79+
80+
```json
81+
{
82+
"mcpServers": {
83+
"substrate-mcp": {
84+
"command": "substrate-mcp",
85+
"env": {
86+
"GITHUB_TOKEN": "your_github_personal_access_token"
87+
}
88+
}
89+
}
90+
}
91+
```
5592

5693
## Available Tools
5794

5895
### Release Analysis
96+
5997
- **`fetch_and_analyze_release`** - Fetches and analyzes a Polkadot SDK release - downloads PRDocs and generates summaries (manifest, crate changes, audience breakdown)
98+
- **`list_polkadot_releases`** - List all available Polkadot SDK releases from the polkadot-sdk repository. Helps discover valid release identifiers before using other tools. Supports filtering by release type (stable, legacy, or all)
6099

61100
### Chain Exploration
101+
62102
- **`subxt_execute`** - Use subxt to decode and explore Substrate blockchain data. Useful for: analyzing chain metadata structure, generating type-safe Rust code for chain interactions, exploring available pallets/calls/storage/events, decoding extrinsics and storage values, and understanding runtime APIs
63103
- **`filter_metadata`** - Filter and search chain metadata to discover available pallets, storage entries, calls, events, constants, and errors. Supports partial name matching for easy discovery
64104
- **`query_extrinsics`** - Query extrinsics from blocks. Supports filtering by pallet, call name, and signer address. Returns decoded transaction data including signer, call info, and arguments
@@ -67,8 +107,8 @@ Alternatively, you can add using cli:
67107
- **`list_pallet_storage`** - List all storage entries available in a specific pallet. Use this to discover what storage items are available before querying them
68108

69109
### Extrinsic Operations
70-
- **`submit_dev_extrinsic`** - Submit a generic extrinsic to a Substrate chain using dev accounts. Supports any pallet call with arbitrary arguments. Use dev account names like 'alice', 'bob', 'charlie', etc. for signing
71110

111+
- **`submit_dev_extrinsic`** - Submit a generic extrinsic to a Substrate chain using dev accounts. Supports any pallet call with arbitrary arguments. Use dev account names like 'alice', 'bob', 'charlie', etc. for signing
72112

73113
## Available Prompts
74114

@@ -77,30 +117,46 @@ The Substrate MCP server provides several specialized prompts for Substrate deve
77117
### Polkadot SDK Release Analysis
78118

79119
#### release_comparison
80-
**Description**: List changes between two polkadot-sdk release versions
120+
121+
**Description**: List changes between two polkadot-sdk release versions
81122
**Arguments**:
123+
82124
- `current_version` (required): Version currently being used
83125
- `target_version` (required): Version dev wants to compare with (must be greater than current)
84126
- `specific_changes` (optional): What specific changes to look for (e.g: was there any change in `pallet_treasury` ?)
85127

86128
#### analyze_release
87-
**Description**: Analyze how specific release(s) impact your current project
129+
130+
**Description**: Analyze how specific release(s) impact your current project
88131
**Arguments**:
132+
89133
- `release` (required): The release version(s) to analyze. Examples: 'stable2503-7' for single release, 'stable2502,stable2503' for comparison
90134
- `focus` (optional): Specific aspect to focus on (e.g., 'breaking changes', 'migrations', 'security'). Leave empty for comprehensive analysis
91135

136+
#### polkadot_upgrade
137+
138+
**Description**: User and agent discovery and discussion on what is needed to upgrade polkadot version in your substrate client and runtime
139+
**Arguments**:
140+
141+
- `release` (required): Release name/version to analyze
142+
- `focus` (optional): Specific area to focus analysis on
143+
92144
### Development & Scaffolding
93145

94146
#### scaffold_pallet
95-
**Description**: Generate pallet structure and implementation templates
147+
148+
**Description**: Generate pallet structure and implementation templates
96149
**Arguments**:
150+
97151
- `pallet_description` (required): Description for the pallet
98152

99153
### Security Analysis
100154

101155
#### security_review
102-
**Description**: Security review covering code security, economic threats, and performance analysis
156+
157+
**Description**: Security review covering code security, economic threats, and performance analysis
103158
**Arguments**:
159+
104160
- `target` (required): Target component/pallet/system to review
105161

106162
This prompt combines code security audit, economic security assessment, threat modeling, and weight analysis into a comprehensive security review. NOTE: This prompt is designed to be used during development as a tool to provide an extra layer of analysis. It is not meant to replace professional security audits.

src/service/mod.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ mod utils;
2020
use utils::catch_panic_as_mcp_error;
2121

2222
use crate::service::prompts::{
23-
analyze_release, get_started, release_comparison, scaffold_pallet, security_review,
23+
analyze_release, get_started, polkadot_upgrade, release_comparison, scaffold_pallet,
24+
security_review,
2425
};
2526

2627
#[cfg(test)]
@@ -58,6 +59,24 @@ impl SubstrateService {
5859
catch_panic_as_mcp_error(tools::handle_fetch_and_analyze_release(properties)).await
5960
}
6061

62+
#[tool(
63+
description = "List all available Polkadot SDK releases from the polkadot-sdk repository. Helps discover valid release identifiers before using other tools."
64+
)]
65+
pub(crate) async fn list_polkadot_releases(&self) -> Result<CallToolResult, McpError> {
66+
catch_panic_as_mcp_error(tools::handle_list_polkadot_releases()).await
67+
}
68+
69+
// TODO: Support old runtime definition macro
70+
#[tool(
71+
description = "Find and analyze runtime pallets configured in a given project directory. Scans for #[frame_support::runtime] attributes to discover all pallets used in your runtime(s)."
72+
)]
73+
pub(crate) async fn find_runtime_pallets(
74+
&self,
75+
Parameters(properties): Parameters<tools::FindRuntimePalletsProperties>,
76+
) -> Result<CallToolResult, McpError> {
77+
catch_panic_as_mcp_error(tools::handle_find_runtime_pallets(properties)).await
78+
}
79+
6180
#[tool(
6281
description = "Use subxt to decode and explore Substrate blockchain data. Useful for: analyzing chain metadata structure, generating type-safe Rust code for chain interactions, exploring available pallets/calls/storage/events, decoding extrinsics and storage values, and understanding runtime APIs. The 'explore' subcommand provides interactive browsing of chain state. Common investigations: System.LastRuntimeUpgrade (find runtime upgrades), Staking.ActiveEra (current era info), Democracy.ReferendumCount (governance activity). Outputs human-readable decoded values by default. Particularly valuable when building applications that need to interact with Substrate chains or when investigating chain functionality. Pass '--help' to any subcommand to learn more."
6382
)]
@@ -172,6 +191,18 @@ impl SubstrateService {
172191
prompts::security_review::generate_prompt(args).await
173192
}
174193

194+
/// User and agent discussion and issue creation workflow to track PRs in a polkadot release upgrade
195+
#[prompt(
196+
name = "polkadot_upgrade",
197+
description = "User and agent discovery and discussion on what is needed to upgrade polkadot version in your substrate client and runtime"
198+
)]
199+
async fn polkadot_upgrade(
200+
&self,
201+
Parameters(args): Parameters<polkadot_upgrade::PolkadotUpgradeArgs>,
202+
) -> Vec<PromptMessage> {
203+
prompts::polkadot_upgrade::generate_prompt(args).await
204+
}
205+
175206
#[prompt(
176207
name = "get_started",
177208
description = "Get started on polkadot and substrate systems"

src/service/prompts/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
pub(crate) mod analyze_release;
88
pub(crate) mod common;
99
pub(crate) mod get_started;
10+
pub(crate) mod polkadot_upgrade;
1011
pub(crate) mod release_comparison;
1112
pub(crate) mod scaffold_pallet;
1213
pub(crate) mod security_review;

0 commit comments

Comments
 (0)