条纹税和发票API MCP服务器
模型上下文协议(MCP)服务器,与条纹税和发票API交互以检索和修改税务设置、计算和发票数据。
安装
先决条件
- Node.js(v16或更高版本)
- npm(v6或更高版本)
- 具有API访问权限的Stripe帐户
安装步骤
- 克隆存储库:
git clone
cd stripe-tax-api-mcp-server- 安装依赖项:
npm install(你可能需要跑步 npm install @modelcontextprotocol/sdk 也)
- 配置环境变量:
cp .env.example .env- 编辑
.env文件添加您的Stripe API密钥:
STRIPE_API_KEY=sk_test_your_test_key_here⚠️ 重要:示例文件中包含的测试API密钥已过期。您必须从您的Stripe帐户提供您自己的有效API密钥。
- 启动服务器:
npm start配置选项
可以使用环境变量配置服务器:
- 条纹API密钥:
- 在中设置API密钥 .env 文件为 STRIPE_API_KEY - 或者,您可以在调用每个工具时提供API密钥 - 对于生产使用,请使用仅具有税收相关权限的受限API密钥 - 在开发过程中,您可以使用Stripe仪表板中的测试API密钥
Claude Desktop的特殊安装步骤
- 编辑claude_desktop_config.json文件(克劳德->设置->开发人员->编辑配置)
- 粘贴此内容:
"stripe-tax": {
"command": "node",
"args": [
"/
/stripe-tax-mcp-server"
],
"env": {
"STRIPE_API_KEY": ""
}
}使用示例
此MCP服务器提供与Stripe Tax API交互的工具,用于设置、计算和产品税代码关联。
工具
1. getTaxSettings
从Stripe检索当前税务设置。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。
示例:
{
"name": "getTaxSettings",
"arguments": {}
}API密钥示例:
{
"name": "getTaxSettings",
"arguments": {
"apiKey": "sk_test_your_stripe_key"
}
}响应:
{
"default_tax_jurisdiction": "US",
"head_office": {
"address": {
"country": "US",
"line1": "123 Main St",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105"
}
},
"tax_id": {
"type": "us_ein",
"value": "12-3456789"
},
"status": {
"active": true
}
}2.更新TaxSettings
更新Stripe中的税务设置。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。settings:包含要更新的税务设置的对象
- default_tax_jurisdiction:税务计算的默认国家 - head_office:公司地址信息 - tax_id:税务识别信息
使用环境变量API键的示例:
{
"name": "updateTaxSettings",
"arguments": {
"settings": {
"default_tax_jurisdiction": "CA",
"tax_id": {
"type": "ca_bn",
"value": "123456789"
}
}
}
}带有显式API键的示例:
{
"name": "updateTaxSettings",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"settings": {
"default_tax_jurisdiction": "CA",
"tax_id": {
"type": "ca_bn",
"value": "123456789"
}
}
}
}3.retrieveTax计算
通过ID从Stripe检索税务计算。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。calculationId:要检索的税务计算的ID
使用环境变量API键的示例:
{
"name": "retrieveTaxCalculation",
"arguments": {
"calculationId": "taxcalc_12345"
}
}带有显式API键的示例:
{
"name": "retrieveTaxCalculation",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"calculationId": "taxcalc_12345"
}
}响应:
{
"id": "taxcalc_12345",
"object": "tax.calculation",
"amount_total": 1090,
"currency": "usd",
"customer_details": {
"address": {
"country": "US",
"line1": "123 Main St",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105"
},
"address_source": "shipping",
"tax_ids": []
},
"line_items_subtotal_amount": 1000,
"shipping_cost_subtotal_amount": 0,
"tax_amount_exclusive": 90,
"tax_amount_inclusive": 0,
"tax_breakdown": [
{
"amount": 60,
"jurisdiction": "California",
"sourcing": "destination",
"tax_type": "sales_tax"
},
{
"amount": 30,
"jurisdiction": "San Francisco",
"sourcing": "destination",
"tax_type": "local_tax"
}
],
"tax_date": "2023-01-15",
"expires_at": 1673913600
}4.创建税务计算
在Stripe中创建新的税务计算。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。params:包含税务计算参数的对象:
- currency:计算货币(例如“美元”) - customer_details:客户信息,包括地址和可选税务ID - line_items:包含金额和可选税码的行项目数组
使用环境变量API键的示例:
{
"name": "createTaxCalculation",
"arguments": {
"params": {
"currency": "usd",
"customer_details": {
"address": {
"country": "US",
"line1": "123 Main St",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105"
},
"address_source": "shipping",
"tax_ids": [
{
"type": "us_ein",
"value": "12-3456789"
}
]
},
"line_items": [
{
"amount": 1000,
"reference": "product_123",
"tax_code": "txcd_30060006",
"tax_behavior": "exclusive"
}
]
}
}
}带有显式API键的示例:
{
"name": "createTaxCalculation",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"params": {
"currency": "usd",
"customer_details": {
"address": {
"country": "US",
"line1": "123 Main St",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105"
},
"address_source": "shipping",
"tax_ids": [
{
"type": "us_ein",
"value": "12-3456789"
}
]
},
"line_items": [
{
"amount": 1000,
"reference": "product_123",
"tax_code": "txcd_30060006",
"tax_behavior": "exclusive"
}
]
}
}
}响应:
{
"id": "taxcalc_12345",
"object": "tax.calculation",
"amount_total": 1090,
"currency": "usd",
"customer_details": {
"address": {
"country": "US",
"line1": "123 Main St",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105"
},
"tax_ids": [
{
"type": "us_ein",
"value": "12-3456789"
}
]
},
"line_items_subtotal_amount": 1000,
"shipping_cost_subtotal_amount": 0,
"tax_amount_exclusive": 90,
"tax_amount_inclusive": 0,
"tax_breakdown": [
{
"amount": 60,
"jurisdiction": "California",
"sourcing": "destination",
"tax_type": "sales_tax"
},
{
"amount": 30,
"jurisdiction": "San Francisco",
"sourcing": "destination",
"tax_type": "local_tax"
}
],
"tax_date": "2023-01-15",
"expires_at": 1673913600
}5.列出税务计算行项目
根据Stripe的ID从Stripe检索用于税务计算的行项目。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。calculationId:用于检索行项目的税务计算IDlimit(可选):要返回的最大行项目数starting_after(可选):分页光标,用于从上一个列表继续ending_before(可选):分页光标,用于返回此ID之前的结果
使用环境变量API键的示例:
{
"name": "listTaxCalculationLineItems",
"arguments": {
"calculationId": "taxcalc_12345",
"limit": 3
}
}带有显式API键的示例:
{
"name": "listTaxCalculationLineItems",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"calculationId": "taxcalc_12345",
"limit": 3
}
}响应:
{
"object": "list",
"url": "/v1/tax/calculations/taxcalc_12345/line_items",
"has_more": false,
"data": [
{
"id": "li_1NpJD42eZvKYlo2CxyzABC",
"object": "tax.calculation_line_item",
"amount": 1000,
"amount_tax": 100,
"livemode": false,
"product": "prod_12345",
"quantity": 1,
"reference": "product_123",
"tax_behavior": "exclusive",
"tax_breakdown": [
{
"amount": 70,
"jurisdiction": "California",
"sourcing": "destination",
"tax_rate_details": {
"percentage_decimal": "0.07",
"tax_type": "sales_tax"
},
"taxability_reason": "standard",
"taxable_amount": 1000
},
{
"amount": 30,
"jurisdiction": "San Francisco",
"sourcing": "destination",
"tax_rate_details": {
"percentage_decimal": "0.03",
"tax_type": "local_tax"
},
"taxability_reason": "standard",
"taxable_amount": 1000
}
],
"tax_code": "txcd_30060006",
"taxable_amount": 1000
}
]
}6.更新产品税码
在Stripe中更新产品以将税码与之关联。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。productId:要更新的产品的IDtaxCode:与产品关联的税码(例如,“txcd_30060006”)
使用环境变量API键的示例:
{
"name": "updateProductTaxCode",
"arguments": {
"productId": "prod_123456",
"taxCode": "txcd_30060006"
}
}带有显式API键的示例:
{
"name": "updateProductTaxCode",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"productId": "prod_123456",
"taxCode": "txcd_30060006"
}
}响应:
{
"id": "prod_123456",
"object": "product",
"active": true,
"created": 1681234567,
"description": "Premium Widget",
"images": [],
"tax_code": "txcd_30060006",
"name": "Widget Pro",
"updated": 1681234789
}7.获取产品税码
从Stripe检索产品及其关联的税码。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。productId:要检索的产品的ID
使用环境变量API键的示例:
{
"name": "getProductTaxCode",
"arguments": {
"productId": "prod_123456"
}
}带有显式API键的示例:
{
"name": "getProductTaxCode",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"productId": "prod_123456"
}
}响应:
{
"product": {
"id": "prod_123456",
"object": "product",
"active": true,
"created": 1681234567,
"description": "Premium Widget",
"images": [],
"tax_code": "txcd_30060006",
"name": "Widget Pro",
"updated": 1681234789
},
"tax_code": "txcd_30060006",
"has_tax_code": true
}8.发票清单
从Stripe检索发票列表。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。limit(可选):要返回的最大发票数customer(可选):要筛选的客户IDstatus(可选):要筛选的发票状态(“草稿”、“未结”、“已付款”、“无法收回”、“作废”)starting_after(可选):分页光标,用于从上一个列表继续ending_before(可选):分页光标,用于返回此ID之前的结果
使用环境变量API键的示例:
{
"name": "listInvoices",
"arguments": {
"limit": 5,
"customer": "cus_123456"
}
}带有显式API键的示例:
{
"name": "listInvoices",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"limit": 5,
"status": "paid"
}
}响应:
{
"object": "list",
"url": "/v1/invoices",
"has_more": true,
"data": [
{
"id": "in_1234567890",
"object": "invoice",
"account_country": "US",
"account_name": "Your Company",
"amount_due": 10000,
"amount_paid": 10000,
"amount_remaining": 0,
"customer": "cus_123456",
"currency": "usd",
"status": "paid",
"total": 10000,
"subtotal": 9500,
"tax": 500
},
{
"id": "in_0987654321",
"object": "invoice",
"account_country": "US",
"account_name": "Your Company",
"amount_due": 5000,
"amount_paid": 5000,
"amount_remaining": 0,
"customer": "cus_123456",
"currency": "usd",
"status": "paid",
"total": 5000,
"subtotal": 4750,
"tax": 250
}
]
}9.检索语音
按ID从Stripe检索特定发票。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。invoiceId:要检索的发票的ID
使用环境变量API键的示例:
{
"name": "retrieveInvoice",
"arguments": {
"invoiceId": "in_1234567890"
}
}带有显式API键的示例:
{
"name": "retrieveInvoice",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"invoiceId": "in_1234567890"
}
}响应:
{
"id": "in_1234567890",
"object": "invoice",
"account_country": "US",
"account_name": "Your Company",
"amount_due": 10000,
"amount_paid": 10000,
"amount_remaining": 0,
"customer": "cus_123456",
"currency": "usd",
"status": "paid",
"total": 10000,
"subtotal": 9500,
"tax": 500,
"lines": {
"object": "list",
"data": [
{
"id": "il_1234567890",
"object": "line_item",
"amount": 9500,
"currency": "usd",
"description": "Premium Plan",
"quantity": 1,
"tax_amounts": [
{
"amount": 500,
"inclusive": false,
"tax_rate": "txr_1234567890"
}
]
}
],
"has_more": false,
"url": "/v1/invoices/in_1234567890/lines"
}
}10.检索语音行项目
从Stripe检索发票的行项目。
参数:
apiKey(可选):您的Stripe API密钥。如果未提供,将使用环境变量中的API键。invoiceId:用于检索行项目的发票IDlimit(可选):要返回的最大行项目数starting_after(可选):分页光标,用于从上一个列表继续ending_before(可选):分页光标,用于返回此ID之前的结果
使用环境变量API键的示例:
{
"name": "retrieveInvoiceLineItems",
"arguments": {
"invoiceId": "in_1234567890",
"limit": 10
}
}带有显式API键的示例:
{
"name": "retrieveInvoiceLineItems",
"arguments": {
"apiKey": "sk_test_your_stripe_key",
"invoiceId": "in_1234567890",
"limit": 10
}
}响应:
{
"object": "list",
"url": "/v1/invoices/in_1234567890/lines",
"has_more": false,
"data": [
{
"id": "il_1234567890",
"object": "line_item",
"amount": 9500,
"currency": "usd",
"description": "Premium Plan",
"quantity": 1,
"tax_amounts": [
{
"amount": 500,
"inclusive": false,
"tax_rate": "txr_1234567890"
}
]
}
]
}资源
服务器提供以下资源:
stripe-tax://info:关于条纹税的一般信息stripe-tax://documentation:参考条纹税文件和条纹发票文件
鼓励
服务器提供以下提示:
get-tax-settings:检索税务设置的提示update-tax-settings:更新税务设置的提示retrieve-tax-calculation:按ID检索税务计算的提示create-tax-calculation:创建新税务计算的提示list-tax-calculation-line-items:按ID检索税务计算行项目的提示update-product-tax-code:使用税码更新产品的提示get-product-tax-code:检索产品税码的提示list-invoices:使用可选筛选器列出发票的提示retrieve-invoice:按ID检索特定发票的提示retrieve-invoice-line-items:检索特定发票行项目的提示
常见故障排除
API身份验证问题
问题:使用工具时出现“身份验证失败”错误。
解决方案:
- 请确保API密钥有效且格式正确
- 检查API密钥是否具有所需的权限
- 对于受限密钥,确保它们可以访问税务端点
速率限制
问题:API请求因速率限制错误而被拒绝。
解决方案:
- 实现重试逻辑的指数回退
- 降低API调用频率
- 如果您需要更高的限额,请考虑升级您的Stripe帐户
数据验证错误
问题:服务器拒绝您的税务设置更新。
解决方案:
- 确保所有必填字段都以正确的格式提供
- 检查国家代码是否为有效的ISO代码(例如“US”、“CA”、“GB”)
- 验证税务ID类型是否与给定司法管辖区的预期格式匹配
API关键问题
问题:“未提供API密钥”错误消息。
解决方案:
- 确保您已创建
.env与您的文件STRIPE_API_KEY集 - 或者在调用方法时直接提供API密钥
- 验证API密钥是否具有条纹税操作的权限
连接问题
问题:无法连接到MCP服务器。
解决方案:
- 验证服务器是否正在运行(检查控制台输出)
- 检查您的客户端是否正确实现了MCP协议
- 尝试使用MCP检查器工具调试连接
- 确保你的路径
claude_desktop_config.json是正确的
安全考虑
- 从不 在代码中对Stripe API密钥进行硬编码
- 通过使用环境变量
.env用于存储API密钥的文件 - 在生产中,只使用所需权限的受限API密钥
- 考虑实施API密钥轮换以增强安全性
- 添加
.env到你的.gitignore文件,以防止意外提交API密钥
