Crates.io | agenterra |
lib.rs | agenterra |
version | 0.2.1 |
created_at | 2025-06-20 02:01:42.211835+00 |
updated_at | 2025-07-09 02:00:14.914037+00 |
description | Generate production-ready MCP (Model Context Protocol) servers and clients from OpenAPI specs |
homepage | https://github.com/clafollett/agenterra |
repository | https://github.com/clafollett/agenterra |
max_upload_size | |
id | 1719042 |
size | 1,350,076 |
Generate production-ready MCP (Model Context Protocol) servers and clients from OpenAPI specs with minimal configuration.
Agenterra transforms your OpenAPI specifications into fully-functional MCP servers and clients with type-safe Rust code, ready for integration with AI tools and workflows. Perfect for:
cargo install
supportAgenterra generates code with security features built-in. Every generated server and client includes comprehensive protection against modern attack vectors.
Key Security Features:
See Security Features for complete details.
# Clone the repository
git clone https://github.com/clafollett/agenterra.git
cd agenterra
# Generate MCP server from a local file without install:
cargo run -- scaffold mcp server --schema-path ./tests/fixtures/openapi/petstore.openapi.v3.json --project-name petstore-server --base-url https://petstore3.swagger.io
# Generate MCP server from a remote URL without install:
cargo run -- scaffold mcp server --schema-path https://petstore3.swagger.io/api/v3/openapi.json --project-name petstore-remote
# Generate MCP client without install:
cargo run -- scaffold mcp client --project-name petstore-client
# Or install the CLI
cargo install --path .
# Generate your MCP server from a local file
agenterra scaffold mcp server --schema-path ./tests/fixtures/openapi/petstore.openapi.v3.json --project-name petstore-server --base-url https://petstore3.swagger.io
# Generate MCP server from a remote URL
agenterra scaffold mcp server --schema-path https://petstore3.swagger.io/api/v3/openapi.json --project-name petstore-remote
# Generate MCP client
agenterra scaffold mcp client --project-name petstore-client
Note: After the single-crate refactor, you can now install directly from the project root with
cargo install --path .
# Install latest version
cargo install --git https://github.com/clafollett/agenterra.git agenterra
# Install specific version. Example: v0.1.0
cargo install --git https://github.com/clafollett/agenterra.git --tag v<VERSION> agenterra
chmod +x agenterra
# Generate your MCP server from a local file
./agenterra scaffold mcp server --schema-path ./tests/fixtures/openapi/petstore.openapi.v3.json --project-name petstore-server --base-url https://petstore3.swagger.io
# Generate MCP server from a remote URL
./agenterra scaffold mcp server --schema-path https://petstore3.swagger.io/api/v3/openapi.json --project-name petstore-remote
# Generate MCP client
./agenterra scaffold mcp client --project-name petstore-client
Add this to your VS Code settings (File > Preferences > Settings > Open Settings JSON):
{
"mcp": {
"servers": {
"petstore": {
"command": "cargo",
"args": ["run", "--manifest-path", "/path/to/petstore-server/Cargo.toml"]
}
}
}
}
Add this to your Cursor settings (File > Preferences > Settings > Extensions > MCP):
{
"mcpServers": {
"petstore": {
"command": "cargo",
"args": ["run", "--manifest-path", "/path/to/petstore-server/Cargo.toml"],
"disabled": false,
"alwaysAllowed": ["listPets", "showPetById"],
"disabledTools": ["deletePet"]
}
}
}
Test your MCP server with the MCP Inspector:
# Test STDIO mode (default)
npx @modelcontextprotocol/inspector cargo run --manifest-path=/path/to/petstore-server/Cargo.toml
# Test SSE mode
npx @modelcontextprotocol/inspector cargo run --manifest-path=/path/to/petstore-server/Cargo.toml -- --transport sse
# Or install globally
npm install -g @modelcontextprotocol/inspector
modelcontextprotocol-inspector cargo run --manifest-path=/path/to/petstore-server/Cargo.toml
When running in SSE mode, the server exposes HTTP endpoints:
# Start server in SSE mode
cargo run -- --transport sse --sse-addr 127.0.0.1:8080
# Test SSE endpoint with curl
curl -N -H "Accept: text/event-stream" http://localhost:8080/sse
# Send MCP messages via POST
curl -X POST http://localhost:8080/message \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}'
Agenterra is designed to scaffold a well-structured MCP servers from OpenAPI specs. This is a great starting point, not necessarily a Best Practice
. Wrapping an OpenAPI spec under an MCP facade is convenient, but not always the βproperβ way to build MCPs. For robust, agent-friendly tools, consider how your server can best expose business logic, aggregate data, and provide clear, useful tool contracts.
Considerations:
Postman now offers robust support for the Model Context Protocol (MCP), including:
When should you use Agenterra?
When should you use Postman?
Summary:
Agenterra is built for extensibility, automation, and code quality. Here's how the core pieces fit together:
Core Modules:
openapi
: Loads and validates OpenAPI specs (YAML/JSON, local or URL)generator
: Orchestrates code generation from the parsed OpenAPI modeltemplate
: Handles Tera-based templates for idiomatic Rust codecli
: Command-line interface for scaffolding, configuration, and workflowCode Generation Flow:
OpenAPI Spec (local file or URL)
β
βΌ
[openapi module]
β
βΌ
[generator module]
β
βΌ
[template module]
β
βΌ
Generated Rust MCP Server (Axum, etc.)
Generated servers and clients support multiple transport modes:
# STDIO mode (default) - for direct process communication
./my-server
# SSE mode - for HTTP-based communication
./my-server --transport sse --sse-addr 127.0.0.1:8080
# With custom keep-alive interval
./my-server --transport sse --sse-addr 0.0.0.0:9000 --sse-keep-alive 60
# Configuration via command-line arguments only
./my-server --transport sse --sse-addr 127.0.0.1:8080
# STDIO mode (default) - connects to server process
./my-client --server /path/to/server
# SSE mode - connects to HTTP endpoint
./my-client --transport sse --sse-url http://localhost:8080
Generated MCP clients include a sophisticated SQLite-powered resource caching system:
Features:
Configuration Options:
// Resource cache configuration
let cache_config = CacheConfig {
default_ttl: Duration::from_secs(3600),
max_size_mb: 100,
auto_cleanup: true,
};
// Database connection configuration (separate from cache config)
let db_config = DatabaseConfig {
database_path: PathBuf::from("cache.db"),
pool_max_connections: 10,
pool_connection_timeout: Some(Duration::from_secs(5)),
pool_max_lifetime: Some(Duration::from_secs(300)),
};
We welcome contributions from the community! To keep Agenterra high-quality and maintainable, please follow these guidelines:
<type>/issue-<number>/<description>
(e.g., docs/issue-57/update-readme
).cargo test
and integration tests).cargo test --test e2e_mcp_test
For more details, see CONTRIBUTING.md if available.
Here's how to work productively with Agenterra as a contributor or advanced user:
cargo test
cargo test --test e2e_mcp_test
tests/e2e_mcp_test.rs
for integration coverage.cargo build --release
docs/TEMPLATES.md
for template developmenttemplates/
directory# Download the Petstore OpenAPI spec
curl -o petstore.json https://petstore3.swagger.io/api/v3/openapi.json
# Generate the MCP server
agenterra scaffold mcp server --schema-path petstore.json --project-name petstore-server
# Generate the MCP client
agenterra scaffold mcp client --project-name petstore-client
# Build and run the server
cd petstore-server
cargo run
Agenterra is configured through command-line arguments. By default, projects are created in the current directory (like cargo new
):
# Generate MCP server (creates ./my_server/)
agenterra scaffold mcp server --schema-path your_api.json --project-name my_server
# Generate MCP client (creates ./my_client/)
agenterra scaffold mcp client --project-name my_client
# Specify a parent directory with --output-dir
agenterra scaffold mcp server --schema-path api.json --project-name my_server --output-dir ~/projects
# Creates: ~/projects/my_server/
Environment Variables:
AGENTERRA_OUTPUT_DIR
- Default parent directory for generated projectsAGENTERRA_TEMPLATE_DIR
- Custom template directory locationAgenterra uses Tera templates for code generation. Templates are embedded in the binary for easy distribution and can be managed using the built-in template commands.
Built-in Server Templates:
rust
- Rust MCP server using Axum web frameworkBuilt-in Client Templates:
rust
- Rust MCP client with REPL interface and SQLite resource cachingManaging Templates:
# List all available embedded templates
agenterra templates list
# Show detailed information about a specific template
agenterra templates info mcp/server/rust
# Export all templates to a directory
agenterra templates export ./my-templates
# Export a single template
agenterra templates export ./my-templates --template mcp/server/rust
Custom Templates:
--template-dir
when scaffoldingtemplates/mcp/server/
or templates/mcp/client/
docs/TEMPLATES.md
Project Structure: Each generated project includes a detailed README.md with template-specific project structure documentation, usage examples, and configuration options.
MIT License - see LICENSE for details.