这是一个提供与freee会计软件API集成的Model Context Protocol (MCP)服务器,使AI助手能够与会计数据进行交互。
git clone https://github.com/knishioka/freee-mcp.git
cd freee-mcp
npm install
npm run build
cp .env.example .env
.env文件,填写您的freee API凭证:FREEE_CLIENT_ID=your_client_id_here
FREEE_CLIENT_SECRET=your_client_secret_here
FREEE_REDIRECT_URI=urn:ietf:wg:oauth:2.0:oob
TOKEN_STORAGE_PATH=./tokens.json
urn:ietf:wg:oauth:2.0:oob)确保服务器已构建(参见安装步骤3)
找到配置文件:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json选择您的配置方法:
选项A:使用tokens.json(推荐在运行setup-auth后使用)
{
"mcpServers": {
"freee": {
"command": "node",
"args": ["/absolute/path/to/freee-mcp/dist/index.js"],
"env": {
"FREEE_CLIENT_ID": "your_client_id_here",
"FREEE_CLIENT_SECRET": "your_client_secret_here",
"TOKEN_STORAGE_PATH": "/absolute/path/to/freee-mcp/tokens.json",
"FREEE_DEFAULT_COMPANY_ID": "123456" // 可选:设置默认公司ID
}
}
}
}
选项B:使用环境变量存储令牌
{
"mcpServers": {
"freee": {
"command": "node",
"args": ["/absolute/path/to/freee-mcp/dist/index.js"],
"env": {
"FREEE_CLIENT_ID": "your_client_id_here",
"FREEE_CLIENT_SECRET": "your_client_secret_here",
"FREEE_ACCESS_TOKEN": "your_access_token",
"FREEE_REFRESH_TOKEN": "your_refresh_token",
"FREEE_COMPANY_ID": "your_company_id"
}
}
}
}
重启Claude Desktop以应用配置。
验证服务器是否运行,检查Claude中是否可用freee工具。尝试询问“有哪些可用的freee工具?”
对于其他MCP客户端,根据需要调整配置格式:
运行交互式设置脚本:
npm run setup-auth
此脚本会:
.env文件加载凭证tokens.json中的现有令牌tokens.json或显示环境变量运行此脚本后,请使用上述Claude Desktop配置中的选项A。
如果您已有令牌,可以直接将其设置在Claude Desktop配置中。使用上述Claude Desktop配置中的选项B,并填写实际的令牌值。
使用工具:freee_get_auth_url
使用工具:freee_get_access_token with code: "your_auth_code"
注意:授权码很快就会过期,因此这种方法经常失败。
freee MCP支持多个公司。当您进行身份验证时,服务器会自动获取与您的freee账户关联的所有公司的访问权限。
为了避免每次API调用都需要指定companyId,您可以设置一个默认公司ID:
{
"env": {
"FREEE_DEFAULT_COMPANY_ID": "123456" // 您的默认公司ID
}
}
要查找您的公司ID,请在身份验证后使用freee_get_companies工具。
如果没有设置默认公司ID,则必须为每个API调用指定companyId:
// 已设置默认公司ID:
使用工具:freee_get_deals
// 未设置默认公司ID:
使用工具:freee_get_deals with companyId: 123456
freee_get_auth_url - 获取OAuth授权URLfreee_get_access_token - 交换授权码以获取访问令牌freee_set_company_token - 手动设置公司的令牌freee_get_companies - 列出可访问的公司freee_get_company - 获取公司详情freee_get_deals - 列出交易freee_get_deal - 获取交易详情freee_create_deal - 创建新交易freee_get_account_items - 列出账目项目freee_get_partners - 列出合作伙伴freee_create_partner - 创建新的合作伙伴freee_get_sections - 列出部门freee_get_tags - 列出标签freee_get_invoices - 列出发票freee_create_invoice - 创建新的发票freee_get_trial_balance - 获取试算平衡报告freee_get_profit_loss - 获取损益表 - 适合获取营业利润!freee_get_balance_sheet - 获取资产负债表freee_get_cash_flow - 获取现金流量表避免检索大量单独的交易,而是使用损益API (freee_get_profit_loss),通过一次API调用即可获取包括营业利润在内的财务数据。
# 示例:获取2024财年的营业利润
使用工具:freee_get_profit_loss
参数:
- fiscalYear: 2024
- startMonth: 4 # 财年起点
- endMonth: 3 # 财年终点
此API返回预聚合的信息,包括:
# 2024年4月至6月的营业利润
使用工具:freee_get_profit_loss
参数:
- fiscalYear: 2024
- startMonth: 4
- endMonth: 6
# 当前期间(FY2024)
使用工具:freee_get_profit_loss
参数:
- fiscalYear: 2024
- startMonth: 4
- endMonth: 9
# 上一期间(FY2023)
使用工具:freee_get_profit_loss
参数:
- fiscalYear: 2023
- startMonth: 4
- endMonth: 9
使用工具:freee_get_profit_loss
参数:
- fiscalYear: 2024
- startMonth: 4
- endMonth: 12
- breakdownDisplayType: "partner" # 按合作伙伴细分
| 方法 | API调用 | 数据处理 | 对速率限制的影响 |
|---|---|---|---|
| 单个交易聚合 | 数千到数万次 | 需要在客户端侧进行聚合 | 高风险(可能会达到限制) |
| 损益API | 1次调用 | 服务器侧预聚合 | 极低风险 |
freee_get_profit_loss → 1次API调用 → 占用0.03%的速率限制npm run build
npm run dev
npm run lint
npm run typecheck
服务器自动管理OAuth令牌:
TOKEN_STORAGE_PATH指定的文件中服务器提供详细的错误消息:
.env文件或tokens.json此项目使用Gitleaks来防止意外暴露敏感数据:
npm run gitleaks以本地检查秘密可用命令:
npm run gitleaks # 扫描秘密(非阻塞)
npm run gitleaks:ci # 扫描秘密(CI模式,发现时阻塞)
有关详细的安全最佳实践、OAuth实现指南以及针对Claude Desktop的具体考虑,请参阅我们的MCP认证指南。
指南涵盖:
MIT
对于以下问题: