keyid-agent-kit-mcp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseKeyID Agent Kit — MCP Email Tools for AI Agents
KeyID Agent Kit — 面向AI Agent的MCP邮箱工具
What It Does
功能介绍
- Provisions a real email address for your AI agent automatically
- Exposes 27 MCP tools: send, receive, reply, forward, search, contacts, drafts, webhooks, auto-reply, signatures, forwarding rules, metrics
- Runs as a stdio MCP server — compatible with Claude Desktop, Cursor, and any MCP client
- Uses Ed25519 keypairs for identity — auto-generated if not provided
- 自动为你的AI Agent分配真实邮箱地址
- 开放27款MCP工具:发送邮件、接收邮件、回复、转发、搜索、联系人管理、草稿、Webhook、自动回复、签名、转发规则、数据统计
- 作为标准输入输出(stdio)MCP服务器运行 — 兼容Claude Desktop、Cursor及所有MCP客户端
- 使用Ed25519密钥对进行身份验证 — 未提供时自动生成
Installation
安装步骤
bash
npm install @keyid/agent-kitbash
npm install @keyid/agent-kitor
或
yarn add @keyid/agent-kit
yarn add @keyid/agent-kit
or run directly without installing
或无需安装直接运行
npx @keyid/agent-kit
undefinednpx @keyid/agent-kit
undefinedConfiguration
配置说明
Environment Variables
环境变量
| Variable | Description | Default |
|---|---|---|
| Ed25519 public key (hex) | Auto-generated on first run |
| Ed25519 private key (hex) | Auto-generated on first run |
| API base URL | |
Important: Save the auto-generated keys after first run so your agent keeps the same email address across sessions. The keys are printed to stderr on first launch.
| 变量名 | 说明 | 默认值 |
|---|---|---|
| Ed25519公钥(十六进制格式) | 首次运行时自动生成 |
| Ed25519私钥(十六进制格式) | 首次运行时自动生成 |
| API基础地址 | |
**重要提示:**首次运行后请保存自动生成的密钥,这样你的Agent在不同会话中就能保留同一个邮箱地址。密钥会在首次启动时输出到标准错误流(stderr)。
Claude Desktop Setup
Claude Desktop配置
Edit (macOS) or (Windows):
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonjson
{
"mcpServers": {
"keyid": {
"command": "npx",
"args": ["@keyid/agent-kit"],
"env": {
"KEYID_PUBLIC_KEY": "$KEYID_PUBLIC_KEY",
"KEYID_PRIVATE_KEY": "$KEYID_PRIVATE_KEY"
}
}
}
}编辑macOS下的或Windows下的:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonjson
{
"mcpServers": {
"keyid": {
"command": "npx",
"args": ["@keyid/agent-kit"],
"env": {
"KEYID_PUBLIC_KEY": "$KEYID_PUBLIC_KEY",
"KEYID_PRIVATE_KEY": "$KEYID_PRIVATE_KEY"
}
}
}
}Cursor Setup
Cursor配置
In at project root or global Cursor settings:
.cursor/mcp.jsonjson
{
"mcpServers": {
"keyid": {
"command": "npx",
"args": ["@keyid/agent-kit"],
"env": {
"KEYID_PUBLIC_KEY": "$KEYID_PUBLIC_KEY",
"KEYID_PRIVATE_KEY": "$KEYID_PRIVATE_KEY"
}
}
}
}在项目根目录的或全局Cursor设置文件中添加:
.cursor/mcp.jsonjson
{
"mcpServers": {
"keyid": {
"command": "npx",
"args": ["@keyid/agent-kit"],
"env": {
"KEYID_PUBLIC_KEY": "$KEYID_PUBLIC_KEY",
"KEYID_PRIVATE_KEY": "$KEYID_PRIVATE_KEY"
}
}
}
}First Run — Get Your Email Address
首次运行 — 获取邮箱地址
bash
undefinedbash
undefinedRun once to generate keys and register the agent
运行一次以生成密钥并注册Agent
npx @keyid/agent-kit
npx @keyid/agent-kit
Keys are printed to stderr — save them!
密钥会输出到stderr — 请保存好!
Then set them in your environment or config
之后在环境变量或配置文件中设置密钥
export KEYID_PUBLIC_KEY=<hex-from-output>
export KEYID_PRIVATE_KEY=<hex-from-output>
undefinedexport KEYID_PUBLIC_KEY=<输出的十六进制公钥>
export KEYID_PRIVATE_KEY=<输出的十六进制私钥>
undefinedAll 27 Tools Reference
27款工具完整参考
Identity & Auth
身份与认证
keyid_provision — Register agent, get assigned email address
keyid_get_email — Get the current active email addresskeyid_provision — 注册Agent,获取分配的邮箱地址
keyid_get_email — 获取当前激活的邮箱地址Messages
邮件管理
keyid_get_inbox — Fetch inbox; supports search query, filtering, pagination
keyid_send — Send email (to, subject, body, HTML, scheduled time, display name)
keyid_reply — Reply to a message by message_id
keyid_forward — Forward a message to another address
keyid_update_message — Mark read/unread, star/unstar
keyid_get_unread_count — Get count of unread messageskeyid_get_inbox — 获取收件箱;支持搜索查询、筛选、分页
keyid_send — 发送邮件(支持收件人、主题、正文、HTML格式、定时发送、显示名称)
keyid_reply — 通过message_id回复邮件
keyid_forward — 将邮件转发至其他地址
keyid_update_message — 标记已读/未读、星标/取消星标
keyid_get_unread_count — 获取未读邮件数量Threads & Drafts
会话与草稿
keyid_list_threads — List conversation threads
keyid_get_thread — Get a thread with all its messages
keyid_create_draft — Save a draft
keyid_send_draft — Send a previously saved draftkeyid_list_threads — 列出对话会话
keyid_get_thread — 获取包含所有邮件的会话详情
keyid_create_draft — 保存草稿
keyid_send_draft — 发送已保存的草稿Settings
设置管理
keyid_get_auto_reply — Get current auto-reply/vacation responder config
keyid_set_auto_reply — Enable/disable auto-reply with custom message
keyid_get_signature — Get email signature
keyid_set_signature — Set email signature text/HTML
keyid_get_forwarding — Get forwarding rules
keyid_set_forwarding — Add or update forwarding to another addresskeyid_get_auto_reply — 获取当前自动回复/休假回复配置
keyid_set_auto_reply — 启用/禁用自动回复并设置自定义内容
keyid_get_signature — 获取邮箱签名
keyid_set_signature — 设置邮箱签名的文本/HTML内容
keyid_get_forwarding — 获取转发规则
keyid_set_forwarding — 添加或更新邮件转发地址Contacts
联系人管理
keyid_list_contacts — List all saved contacts
keyid_create_contact — Create a contact (name, email, notes)
keyid_delete_contact — Delete a contact by IDkeyid_list_contacts — 列出所有已保存的联系人
keyid_create_contact — 创建联系人(姓名、邮箱、备注)
keyid_delete_contact — 通过ID删除联系人Webhooks
Webhook
keyid_list_webhooks — List configured webhooks
keyid_create_webhook — Register a webhook URL for inbound events
keyid_get_webhook_deliveries — View delivery history and failureskeyid_list_webhooks — 列出已配置的Webhook
keyid_create_webhook — 注册用于接收入站事件的Webhook地址
keyid_get_webhook_deliveries — 查看Webhook投递历史与失败记录Lists & Metrics
列表与统计
keyid_manage_list — Add/remove addresses from allow or blocklist
keyid_get_metrics — Query usage metrics (sent, received, bounces)keyid_manage_list — 在允许列表或阻止列表中添加/移除地址
keyid_get_metrics — 查询使用统计(发送、接收、退信数量)Real Code Examples
实际代码示例
Programmatic MCP Client (Node.js)
程序化MCP客户端(Node.js)
javascript
import { spawn } from 'child_process';
import { createInterface } from 'readline';
// Start the MCP server as a child process
const server = spawn('npx', ['@keyid/agent-kit'], {
env: {
...process.env,
KEYID_PUBLIC_KEY: process.env.KEYID_PUBLIC_KEY,
KEYID_PRIVATE_KEY: process.env.KEYID_PRIVATE_KEY,
},
stdio: ['pipe', 'pipe', 'inherit'],
});
// Send a JSON-RPC request
function sendRequest(method, params = {}) {
const request = {
jsonrpc: '2.0',
id: Date.now(),
method,
params,
};
server.stdin.write(JSON.stringify(request) + '\n');
}
// Read responses
const rl = createInterface({ input: server.stdout });
rl.on('line', (line) => {
const response = JSON.parse(line);
console.log('Response:', JSON.stringify(response, null, 2));
});
// Initialize MCP session
sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'my-app', version: '1.0.0' },
});javascript
import { spawn } from 'child_process';
import { createInterface } from 'readline';
// 启动MCP服务器作为子进程
const server = spawn('npx', ['@keyid/agent-kit'], {
env: {
...process.env,
KEYID_PUBLIC_KEY: process.env.KEYID_PUBLIC_KEY,
KEYID_PRIVATE_KEY: process.env.KEYID_PRIVATE_KEY,
},
stdio: ['pipe', 'pipe', 'inherit'],
});
// 发送JSON-RPC请求
function sendRequest(method, params = {}) {
const request = {
jsonrpc: '2.0',
id: Date.now(),
method,
params,
};
server.stdin.write(JSON.stringify(request) + '\n');
}
// 读取响应
const rl = createInterface({ input: server.stdout });
rl.on('line', (line) => {
const response = JSON.parse(line);
console.log('Response:', JSON.stringify(response, null, 2));
});
// 初始化MCP会话
sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'my-app', version: '1.0.0' },
});Call a Tool via MCP JSON-RPC
通过MCP JSON-RPC调用工具
javascript
// After initialization, call tools/call
function callTool(toolName, toolArgs) {
const request = {
jsonrpc: '2.0',
id: Date.now(),
method: 'tools/call',
params: {
name: toolName,
arguments: toolArgs,
},
};
server.stdin.write(JSON.stringify(request) + '\n');
}
// Get inbox
callTool('keyid_get_inbox', { limit: 10 });
// Send an email
callTool('keyid_send', {
to: 'colleague@example.com',
subject: 'Hello from my AI agent',
body: 'This email was sent by an AI agent using KeyID.',
});
// Reply to a message
callTool('keyid_reply', {
message_id: 'msg_abc123',
body: 'Thanks, I will review this today.',
});
// Search inbox
callTool('keyid_get_inbox', {
query: 'from:alice@company.com subject:report',
unread_only: true,
});
// Set auto-reply
callTool('keyid_set_auto_reply', {
enabled: true,
subject: 'Out of Office',
body: 'I am currently unavailable. My AI agent will respond shortly.',
});
// Create a contact
callTool('keyid_create_contact', {
name: 'Alice Smith',
email: 'alice@company.com',
notes: 'Project lead for Q1 initiative',
});
// Schedule an email
callTool('keyid_send', {
to: 'team@company.com',
subject: 'Weekly Update',
body: 'Here is the weekly status...',
scheduled_at: '2026-03-25T09:00:00Z',
});
// Set email signature
callTool('keyid_set_signature', {
signature: 'Best regards,\nAI Agent\npowered by KeyID.ai',
});
// Get metrics
callTool('keyid_get_metrics', {
period: '7d',
});javascript
// 初始化完成后,调用工具/call
function callTool(toolName, toolArgs) {
const request = {
jsonrpc: '2.0',
id: Date.now(),
method: 'tools/call',
params: {
name: toolName,
arguments: toolArgs,
},
};
server.stdin.write(JSON.stringify(request) + '\n');
}
// 获取收件箱
callTool('keyid_get_inbox', { limit: 10 });
// 发送邮件
callTool('keyid_send', {
to: 'colleague@example.com',
subject: 'Hello from my AI agent',
body: 'This email was sent by an AI agent using KeyID.',
});
// 回复邮件
callTool('keyid_reply', {
message_id: 'msg_abc123',
body: 'Thanks, I will review this today.',
});
// 搜索收件箱
callTool('keyid_get_inbox', {
query: 'from:alice@company.com subject:report',
unread_only: true,
});
// 设置自动回复
callTool('keyid_set_auto_reply', {
enabled: true,
subject: 'Out of Office',
body: 'I am currently unavailable. My AI agent will respond shortly.',
});
// 创建联系人
callTool('keyid_create_contact', {
name: 'Alice Smith',
email: 'alice@company.com',
notes: 'Project lead for Q1 initiative',
});
// 定时发送邮件
callTool('keyid_send', {
to: 'team@company.com',
subject: 'Weekly Update',
body: 'Here is the weekly status...',
scheduled_at: '2026-03-25T09:00:00Z',
});
// 设置邮箱签名
callTool('keyid_set_signature', {
signature: 'Best regards,\nAI Agent\npowered by KeyID.ai',
});
// 获取统计数据
callTool('keyid_get_metrics', {
period: '7d',
});Using with the MCP SDK (if building a custom client)
与MCP SDK配合使用(自定义客户端开发)
javascript
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
const transport = new StdioClientTransport({
command: 'npx',
args: ['@keyid/agent-kit'],
env: {
KEYID_PUBLIC_KEY: process.env.KEYID_PUBLIC_KEY,
KEYID_PRIVATE_KEY: process.env.KEYID_PRIVATE_KEY,
},
});
const client = new Client(
{ name: 'my-email-agent', version: '1.0.0' },
{ capabilities: {} }
);
await client.connect(transport);
// List available tools
const tools = await client.listTools();
console.log('Available tools:', tools.tools.map(t => t.name));
// Get email address
const emailResult = await client.callTool({
name: 'keyid_get_email',
arguments: {},
});
console.log('Agent email:', emailResult.content[0].text);
// Check unread
const unread = await client.callTool({
name: 'keyid_get_unread_count',
arguments: {},
});
console.log('Unread count:', unread.content[0].text);
// Send email
await client.callTool({
name: 'keyid_send',
arguments: {
to: 'recipient@example.com',
subject: 'Automated report',
body: 'Your daily report is attached.',
html: '<p>Your <strong>daily report</strong> is attached.</p>',
},
});
await client.close();javascript
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
const transport = new StdioClientTransport({
command: 'npx',
args: ['@keyid/agent-kit'],
env: {
KEYID_PUBLIC_KEY: process.env.KEYID_PUBLIC_KEY,
KEYID_PRIVATE_KEY: process.env.KEYID_PRIVATE_KEY,
},
});
const client = new Client(
{ name: 'my-email-agent', version: '1.0.0' },
{ capabilities: {} }
);
await client.connect(transport);
// 列出可用工具
const tools = await client.listTools();
console.log('Available tools:', tools.tools.map(t => t.name));
// 获取邮箱地址
const emailResult = await client.callTool({
name: 'keyid_get_email',
arguments: {},
});
console.log('Agent email:', emailResult.content[0].text);
// 查看未读数量
const unread = await client.callTool({
name: 'keyid_get_unread_count',
arguments: {},
});
console.log('Unread count:', unread.content[0].text);
// 发送邮件
await client.callTool({
name: 'keyid_send',
arguments: {
to: 'recipient@example.com',
subject: 'Automated report',
body: 'Your daily report is attached.',
html: '<p>Your <strong>daily report</strong> is attached.</p>',
},
});
await client.close();Webhook Integration
Webhook集成
javascript
import express from 'express';
const app = express();
app.use(express.json());
// Endpoint to receive KeyID webhook events
app.post('/keyid-webhook', (req, res) => {
const event = req.body;
if (event.type === 'message.received') {
const { from, subject, body, message_id } = event.data;
console.log(`New email from ${from}: ${subject}`);
// Trigger your agent logic here
handleIncomingEmail({ from, subject, body, message_id });
}
res.json({ ok: true });
});
app.listen(3000);
// Register the webhook via the MCP tool
// (call this once via your agent)
// callTool('keyid_create_webhook', {
// url: 'https://your-server.com/keyid-webhook',
// events: ['message.received'],
// });javascript
import express from 'express';
const app = express();
app.use(express.json());
// 接收KeyID Webhook事件的端点
app.post('/keyid-webhook', (req, res) => {
const event = req.body;
if (event.type === 'message.received') {
const { from, subject, body, message_id } = event.data;
console.log(`New email from ${from}: ${subject}`);
// 在此触发你的Agent逻辑
handleIncomingEmail({ from, subject, body, message_id });
}
res.json({ ok: true });
});
app.listen(3000);
// 通过MCP工具注册Webhook
// (通过你的Agent调用一次即可)
// callTool('keyid_create_webhook', {
// url: 'https://your-server.com/keyid-webhook',
// events: ['message.received'],
// });Common Patterns
常见使用模式
Pattern: Agent with Persistent Identity
模式:具备持久身份的Agent
javascript
// Generate and store keys once, reuse forever
import { writeFileSync, readFileSync, existsSync } from 'fs';
import { generateKeyPairSync } from 'crypto'; // or use @noble/ed25519
const KEY_FILE = '.keyid-keys.json';
function loadOrCreateKeys() {
if (existsSync(KEY_FILE)) {
return JSON.parse(readFileSync(KEY_FILE, 'utf8'));
}
// Let @keyid/agent-kit auto-generate on first run,
// then save what it prints to stderr
// Or pre-generate using @noble/ed25519:
// const privKey = randomBytes(32);
// const pubKey = await ed.getPublicKeyAsync(privKey);
return null; // will auto-generate
}javascript
// 生成并存储密钥一次,永久复用
import { writeFileSync, readFileSync, existsSync } from 'fs';
import { generateKeyPairSync } from 'crypto'; // 或使用@noble/ed25519
const KEY_FILE = '.keyid-keys.json';
function loadOrCreateKeys() {
if (existsSync(KEY_FILE)) {
return JSON.parse(readFileSync(KEY_FILE, 'utf8'));
}
// 让@keyid/agent-kit在首次运行时自动生成密钥,
// 然后保存输出到stderr的密钥
// 或使用@noble/ed25519预先生成:
// const privKey = randomBytes(32);
// const pubKey = await ed.getPublicKeyAsync(privKey);
return null; // 将自动生成
}Pattern: Email-Triggered Agent Loop
模式:邮件触发的Agent循环
javascript
// Poll inbox and process new messages
async function agentEmailLoop(client) {
while (true) {
const result = await client.callTool({
name: 'keyid_get_inbox',
arguments: { unread_only: true, limit: 5 },
});
const messages = JSON.parse(result.content[0].text);
for (const msg of messages) {
// Process with your LLM/agent logic
const agentResponse = await processWithAgent(msg);
// Reply
await client.callTool({
name: 'keyid_reply',
arguments: {
message_id: msg.id,
body: agentResponse,
},
});
// Mark as read
await client.callTool({
name: 'keyid_update_message',
arguments: { message_id: msg.id, read: true },
});
}
// Wait 60 seconds before next poll
await new Promise(r => setTimeout(r, 60_000));
}
}javascript
// 轮询收件箱并处理新邮件
async function agentEmailLoop(client) {
while (true) {
const result = await client.callTool({
name: 'keyid_get_inbox',
arguments: { unread_only: true, limit: 5 },
});
const messages = JSON.parse(result.content[0].text);
for (const msg of messages) {
// 使用你的大语言模型/Agent逻辑处理邮件
const agentResponse = await processWithAgent(msg);
// 回复邮件
await client.callTool({
name: 'keyid_reply',
arguments: {
message_id: msg.id,
body: agentResponse,
},
});
// 标记为已读
await client.callTool({
name: 'keyid_update_message',
arguments: { message_id: msg.id, read: true },
});
}
// 等待60秒后再次轮询
await new Promise(r => setTimeout(r, 60_000));
}
}Pattern: Draft-Review-Send Workflow
模式:草稿-审核-发送工作流
javascript
// Create draft, review, then send
const draft = await client.callTool({
name: 'keyid_create_draft',
arguments: {
to: 'client@example.com',
subject: 'Proposal',
body: draftBody,
},
});
const draftId = JSON.parse(draft.content[0].text).id;
// Human or agent reviews...
// Then send:
await client.callTool({
name: 'keyid_send_draft',
arguments: { draft_id: draftId },
});javascript
// 创建草稿,审核后发送
const draft = await client.callTool({
name: 'keyid_create_draft',
arguments: {
to: 'client@example.com',
subject: 'Proposal',
body: draftBody,
},
});
const draftId = JSON.parse(draft.content[0].text).id;
// 人工或Agent审核...
// 然后发送:
await client.callTool({
name: 'keyid_send_draft',
arguments: { draft_id: draftId },
});Troubleshooting
故障排除
Agent gets a new email address every run
Agent每次运行都获取新邮箱地址
Cause: Keys not persisted between runs.
Fix: Save and from first run output and set them in your config or environment.
Fix: Save
KEYID_PUBLIC_KEYKEYID_PRIVATE_KEY原因: 密钥未在会话间持久化存储。
解决方法: 保存首次运行输出的和,并在配置或环境变量中设置。
解决方法: 保存首次运行输出的
KEYID_PUBLIC_KEYKEYID_PRIVATE_KEYMCP server not appearing in Claude Desktop
MCP服务器未在Claude Desktop中显示
Fix: Restart Claude Desktop after editing config. Verify JSON is valid (no trailing commas). Check that is in your PATH.
npx解决方法: 编辑配置后重启Claude Desktop。验证JSON格式有效(无尾随逗号)。检查是否在系统PATH中。
npxTool calls return errors
工具调用返回错误
Fix: Ensure the agent is provisioned first — call before other tools, or call to confirm the agent has an address.
keyid_provisionkeyid_get_email解决方法: 确保Agent已完成注册 — 在调用其他工具前先调用,或调用确认Agent已获取邮箱地址。
keyid_provisionkeyid_get_emailEmails not being received
无法接收邮件
Fix: Check to ensure the sender isn't blocklisted. Check for bounce data.
keyid_manage_listkeyid_get_metrics解决方法: 调用确认发件人未被加入阻止列表。调用查看退信数据。
keyid_manage_listkeyid_get_metricsConnection drops / server crashes
连接断开/服务器崩溃
Fix: The server uses stdio — make sure nothing else is writing to stdout in the same process. Restart the MCP server process.
解决方法: 服务器使用stdio传输 — 确保同一进程中没有其他程序写入stdout。重启MCP服务器进程。
Keys auto-generated but not shown
密钥自动生成但未显示
Cause: stderr may be suppressed by your MCP client.
Fix: Run directly in a terminal first to capture the key output before adding to your MCP config.
Fix: Run
npx @keyid/agent-kit原因: MCP客户端可能抑制了stderr输出。
解决方法: 先在终端中直接运行以捕获密钥输出,再添加到MCP配置中。
解决方法: 先在终端中直接运行
npx @keyid/agent-kitProtocol Details
协议细节
- Transport: stdio (JSON-RPC over stdin/stdout)
- MCP Protocol Version:
2024-11-05 - Auth: Ed25519 keypair — public key becomes agent identity, private key signs requests
- Compatibility: Claude Desktop, Cursor, any MCP-compatible client
- 传输方式: stdio(通过stdin/stdout传输JSON-RPC)
- MCP协议版本:
2024-11-05 - 认证方式: Ed25519密钥对 — 公钥作为Agent身份标识,私钥用于签名请求
- 兼容性: Claude Desktop、Cursor及所有兼容MCP的客户端