SendGrid MCP服务器
模型上下文协议(MCP)服务器,提供对SendGrid营销API的访问,用于电子邮件营销和联系人管理。https://docs.sendgrid.com/api-reference/how-to-use-the-sendgrid-v3-api
演示
在这个演示中,我们要求Cline SendGrid代理创建一个新的联系人列表,将我的电子邮件添加到其中,自动生成“失落的城市”事实模板,并将电子邮件发送到列表中。在这个过程中,Cline会自动意识到它需要知道我们拥有的已验证发件人,以及要使用哪个取消订阅组。一封漂亮的电子邮件被发送到我的收件箱,让我对《失落的城市》感到高兴!
关于API支持的重要说明
此服务器仅支持SendGrid的v3 API,不支持遗留功能。这包括:
- 仅限动态模板-不支持旧模板
- 针对所有联系人和联系人列表操作营销API v3
- 单次发送API,用于批量电子邮件发送
可用工具
联系人管理
list_contacts
列出您SendGrid帐户中的所有联系人。
// No parameters requiredadd_contact
将联系人添加到您的SendGrid营销联系人中。
{
email: string; // Required: Contact email address
first_name?: string; // Optional: Contact first name
last_name?: string; // Optional: Contact last name
custom_fields?: object; // Optional: Custom field values
}删除联系人
从您的SendGrid帐户中删除联系人。
{
emails: string[]; // Required: Array of email addresses to delete
}get_contacts_by_list
获取SendGrid列表中的所有联系人。
{
list_id: string; // Required: ID of the contact list
}列表管理
list_contact_lists
列出您SendGrid帐户中的所有联系人列表。
// No parameters requiredcreate_contact_list
在SendGrid中创建新的联系人列表。
{
name: string; // Required: Name of the contact list
}delete_list
从SendGrid中删除联系人列表。
{
list_id: string; // Required: ID of the contact list to delete
}add_contacts_to_list
将联系人添加到现有的SendGrid列表中。
{
list_id: string; // Required: ID of the contact list
emails: string[]; // Required: Array of email addresses to add
}remove_contacts_from_list
从SendGrid列表中删除联系人,但不删除。
{
list_id: string; // Required: ID of the contact list
emails: string[]; // Required: Array of email addresses to remove
}电子邮件发送
send_邮件
使用SendGrid发送电子邮件。
{
to: string; // Required: Recipient email address
subject: string; // Required: Email subject line
text: string; // Required: Plain text content
from: string; // Required: Verified sender email address
html?: string; // Optional: HTML content
template_id?: string; // Optional: Dynamic template ID
dynamic_template_data?: object; // Optional: Template variables
}send_to_list
使用SendGrid单次发送向联系人列表发送电子邮件。
{
name: string; // Required: Name of the single send
list_ids: string[]; // Required: Array of list IDs to send to
subject: string; // Required: Email subject line
html_content: string; // Required: HTML content
plain_content: string; // Required: Plain text content
sender_id: number; // Required: ID of the verified sender
suppression_group_id?: number; // Required if custom_unsubscribe_url not provided
custom_unsubscribe_url?: string; // Required if suppression_group_id not provided
}模板管理(仅限动态模板)
create_template
创建新的动态电子邮件模板。
{
name: string; // Required: Name of the template
subject: string; // Required: Default subject line
html_content: string; // Required: HTML content with handlebars syntax
plain_content: string; // Required: Plain text content with handlebars syntax
}list_templates
列出所有动态电子邮件模板。
// No parameters requiredget_template
按ID检索模板。
{
template_id: string; // Required: ID of the template to retrieve
}delete_template
删除动态模板。
{
template_id: string; // Required: ID of the template to delete
}分析和验证
get_stats
获取SendGrid电子邮件统计信息。
{
start_date: string; // Required: Start date (YYYY-MM-DD)
end_date?: string; // Optional: End date (YYYY-MM-DD)
aggregated_by?: 'day' | 'week' | 'month'; // Optional: Aggregation period
}validate_email
使用SendGrid验证电子邮件地址。
{
email: string; // Required: Email address to validate
}账户管理
列表_验证_发件人
列出所有已验证的发件人身份。
// No parameters required列表_压缩_组
列出所有取消订阅组。
// No parameters required安装
git clone https://github.com/Garoth/sendgrid-mcp.git
cd sendgrid-mcp
npm install配置
- 获取SendGrid API密钥:
- 登录您的SendGrid帐户 - 前往“设置”>“API密钥” - 创建具有完全访问权限的新API密钥 - 安全地保存API密钥,因为它不会再次显示
- 将其添加到VSCode设置中的Cline MCP设置文件中(例如~/.config/Code/User/globalStorage/saoudrizwan.claude dev/settings/Cline_MCP_settings.json):
{
"mcpServers": {
"sendgrid": {
"command": "node",
"args": ["/path/to/sendgrid-mcp/build/index.js"],
"env": {
"SENDGRID_API_KEY": "your-api-key-here"
},
"disabled": false,
"autoApprove": [
"list_contacts",
"list_contact_lists",
"list_templates",
"list_single_sends",
"get_single_send",
"list_verified_senders",
"list_suppression_groups",
"get_stats",
"validate_email"
]
}
}
}注意:为了安全起见,修改数据的工具(如发送电子邮件或删除联系人)被故意排除在autoApprove之外。
发展
设置测试
测试使用真实的API调用来确保准确的响应。要运行测试,请执行以下操作:
- 复制示例环境文件:
cp .env.example .env- 编辑
.env并添加您的SendGrid API密钥:
SENDGRID_API_KEY=your-api-key-here注: .env 文件被标记为gitignore,以防止提交敏感信息。
- 运行测试:
npm test建筑
npm run build重要提示
- 向列表发送电子邮件时,您必须提供suppression_group_id或custom_unsubcribe_url以遵守电子邮件规定
- 发件人电子邮件地址必须经过SendGrid验证,然后才能用于发送电子邮件
- 所有模板都创建为支持车把语法的动态模板(例如,{{variable_name}})
- 单一发送API用于所有批量电子邮件操作,因为它提供了更好的跟踪和管理功能
- SendGrid API是“最终一致的”-数据更改(如添加联系人或更新列表)可能不会在进行后立即出现
许可证
麻省理工学院
SendGrid徽标版权/归Twilio所有
