-
Notifications
You must be signed in to change notification settings - Fork 91
Adds mcp-server generator #1985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add support for generating MCP server bindings from Soroban contracts: - Implement MCP server code generator with TypeScript template - Add support for Buffer and array inputs in type validation - Include transaction simulation and submission capabilities - Add comprehensive error handling for Horizon responses
Fix the "Bad union switch: 1" error that was occurring when handling transaction responses from the Stellar network. The following changes were made: 1. Simplified submitTransaction function in helper.ts to immediately return success with the transaction hash without waiting for confirmation 2. Improved error handling in index.ts to properly handle XDR parsing errors These changes resolve the JSON parsing errors in the Claude app while still allowing users to track their transactions via the transaction hash and Stellar Explorer.
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
…nsaction building parameters - Use SAC client instead of TransactionBuilder - Return XDR directly - Simplify response format [Author] Cursor Agent
…ies - Add proper environment variable handling - Add dotenv configuration [Author] Cursor Agent
…ate_tool [Author] Cursor Agent - Added import tracking in type_to_zod for type-specific converters - Updated generate_tool to track imports for parameter conversions - Fixed method calls to use instance methods instead of static methods - Refactored converter selection to track imports
…ursor Agent - Fixed import replacement in index.ts template - Aligned imports with helper.ts usage
…e formatted strings in variables to ensure proper lifetimes - Fix temporary value dropped while borrowed errors
@JoseCToscano Awesome work, could you create this as a plugin? https://developers.stellar.org/docs/tools/cli/plugins |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces an MCP server generator for Soroban smart contracts by adding a new command to the Soroban CLI and providing a TypeScript-based server template.
- Updated the command handling to pass global arguments to the new MCP server command.
- Added multiple new files for the MCP server generator including the core generator implementation in Rust and a full TypeScript project template with build scripts and helper functions.
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
cmd/soroban-cli/src/commands/contract/mod.rs | Updated the bindings command to pass global arguments correctly. |
cmd/soroban-cli/src/commands/contract/bindings/mcp_server.rs | Added the new MCP server command implementation and error handling. |
cmd/soroban-cli/src/commands/contract/bindings.rs | Integrated the new MCP server command into the existing bindings module. |
cmd/crates/soroban-spec-typescript/src/mcp_server_template/* | Added TypeScript project template files, including build configurations, a runtime server implementation, helpers, documentation, and configuration management. |
cmd/crates/soroban-spec-typescript/src/lib.rs & Cargo.toml | Integrated and referenced the new MCP server generator module. |
Comments suppressed due to low confidence (3)
cmd/crates/soroban-spec-typescript/src/mcp_server_template/src/index.ts:50
- [nitpick] The placeholder 'INSERT_TOOLS_HERE' should be replaced with the actual tool registrations or accompanied by clear instructions to ensure the server starts without runtime errors.
INSERT_TOOLS_HERE
cmd/crates/soroban-spec-typescript/src/mcp_server_template/README.md:53
- [nitpick] Replace the 'INSERT_TOOL_LIST_HERE' placeholder with either the generated list of contract tools or a note detailing that this section will be auto-populated to improve clarity for users setting up the MCP server.
INSERT_TOOL_LIST_HERE
cmd/crates/soroban-spec-typescript/src/mcp_server_template/package.json:2
- [nitpick] Update the 'INSERT_NAME_HERE' placeholder in package.json with the actual package name to ensure consistency and clarity in the generated project output.
"name": "INSERT_NAME_HERE",
@JoseCToscano this is amazing! Thanks for this! After some internal discussion, we came to the conclusion that we want to keep the CLI core as small as possible, pushing features like this as external plugins. This allows for a faster development cycle, without diverging too much from the native experience. Could you please extract this work into its own executable, and make it available as a plugin instead? Here is the documentation around CLI plugins. |
MCP Server Generator for Soroban Smart Contracts
Overview
This PR adds a new MCP (Model Context Protocol)[https://modelcontextprotocol.io/introduction] server generator to the Soroban CLI. The generator creates a TypeScript-based server that provides a standardized interface for interacting with Soroban smart contracts, supporting both SAC (Stellar Asset Contract) and regular (WASM) contracts.
This will create the mcp server configuration for the XLM SAC with the relevant functions formated as tools a MCP client can call.
For instance generating the mcp server for (DoMath)[https://github.com/kalepail/do-math] will create something like this

Key Features
Technical Details
New Files Added
cmd/crates/soroban-spec-typescript/src/mcp_server.rs
Template Files:
.env.example
: Environment configuration templateREADME.md
: Documentation and setup instructionsbuild.ts
: Production build script to enable runing the mcp-server as standalone built JSpackage.json
: Project dependencies and scriptsconfig.ts
: Server configuration managementhelper.ts
: Utility functionsindex.ts
: Server implementationTransaction Handling Architecture
Dual-Mode Operation
The MCP server implements a dual-mode operation pattern that mirrors the Stellar SDK's behavior while providing AI-friendly interfaces:
Read-Only Operations
Write Operations
Integration with Stellar-MCP
The generator is designed to work seamlessly with the stellar-mcp project, which provides:
Security and AI Agency
This architecture supports the emerging paradigm of Autonomous AI Agents by:
This separation of concerns allows AI agents to construct valid transactions while maintaining security through controlled signing processes, making it an ideal foundation for autonomous financial operations.
Key Implementation Features
Smart Type Handling
Operation Modes
Configuration Management
Build System
Usage Example
Next Steps
Breaking Changes
None. This is a new feature that doesn't affect existing functionality.
Dependencies Added
@modelcontextprotocol/sdk
: ^1.0.0@stellar/stellar-sdk
: ^13.0.0sac-sdk
: ^0.3.6zod
: ^3.22.0dotenv
: ^16.4.7Development Dependencies Added
@types/node
: ^20.0.0typescript
: ^5.0.0tsx
: ^4.7.0esbuild
: ^0.20.2