A Model Context Protocol (MCP) implementation for the Rule.io marketing automation platform.
You can install the mcp-rule package directly with the Universal Executor (uvx):
uvx mcp-ruleFor development, you can install from the source code:
git clone https://github.com/swesam/mcp-rule.git
cd mcp-rule
pip install -e .This MCP implementation provides a standardized interface to Rule.io's API, allowing you to:
- Manage subscribers (create, read, update, delete)
- Work with tags
- Access campaigns
- Create and use custom fields
- Track transactions
- Set up automations
You can use the Rule.io client directly in your Python code:
from mcp_rule import RuleClient
# Initialize the client with your API key
client = RuleClient(api_key="your_api_key_here")
# List subscribers
subscribers = client.get_subscribers(limit=10)
for subscriber in subscribers:
print(f"{subscriber.email} - Created: {subscriber.created}")
# Create a new subscriber
new_subscriber = client.create_subscriber(
email="new@example.com",
tags=["new_user", "newsletter"],
fields={"first_name": "John", "last_name": "Doe"}
)
# Get tags
tags = client.get_tags()
for tag in tags:
print(f"{tag.name} - Subscribers: {tag.subscriber_count}")The primary purpose of this package is to provide a Model Context Protocol implementation for Rule.io. Here's how to use it with MCP:
import asyncio
import json
from mcp import ContextRequest, ContextRequestMetadata, get_provider
async def example():
# Get the Rule MCP provider
provider = get_provider("rule")
# Set up metadata with your API key
metadata = ContextRequestMetadata(api_key="your_api_key_here")
# Create a request to list subscribers
request = ContextRequest(
method="GET",
path="/subscribers",
query_params={"limit": "10"},
metadata=metadata,
)
# Send the request
response = await provider.handle_request(request)
# Parse and use the response
result = json.loads(response.body)
subscribers = result.get("subscribers", [])
for subscriber in subscribers:
print(f"{subscriber['email']}")
# Run the example
asyncio.run(example())The following MCP endpoints are available:
GET /subscribers- List subscribersGET /subscribers/{subscriber_id}- Get a specific subscriberPOST /subscribers- Create a new subscriberPUT /subscribers/{subscriber_id}- Update a subscriberDELETE /subscribers/{subscriber_id}- Delete a subscriber
GET /tags- List tagsPOST /tags- Create a new tag
GET /campaigns- List campaigns
GET /fields- List custom fieldsPOST /fields- Create a new custom field
Check out the examples directory for complete usage examples:
basic_usage.py- Direct API client usagemcp_usage.py- MCP interface usage
For more information about the Rule.io API, see:
For details on the Model Context Protocol (MCP), visit:
[ ] Add more detailed error handling [ ] Implement more MCP endpoints [ ] Publish to a package registry (e.g., PyPI) [ ] Add unit tests for existing functionality
MIT