本项目旨在创建一个与 Google Calendar 集成的工具,借助 Model Context Protocol (MCP) 以及自然语言处理能力,让你能在 Claude 中轻松管理和查询日历事件。
mkdir google-calendar-mcp
cd google-calendar-mcp
npm init -y
npm install @modelcontextprotocol/sdk googleapis google-auth-library zod
npm install -D @types/node typescript
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "./build",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
{
"type": "module",
"scripts": {
"build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\""
}
}
创建 OAuth 应用:
设置 OAuth 作用域:
https://www.googleapis.com/auth/calendar.readonly
, https://www.googleapis.com/auth/calendar
创建一个 .env
文件(不要提交到版本控制系统):
GOOGLE_CLIENT_ID=your_client_id_here
GOOGLE_CLIENT_SECRET=your_client_secret_here
GOOGLE_REDIRECT_URI=http://localhost
GOOGLE_REFRESH_TOKEN=your_refresh_token_here
mkdir src
在 src/index.ts
中导入必要的模块:
import { GoogleCalendar } from '@modelcontextprotocol/google-calendar';
创建一个 MCP 工具类:
export class GoogleCalendarMCP extends Tool {
private calendar: Calendar;
constructor() {
super('google_calendar', 'Google Calendar Management');
this.calendar = new Calendar({
client_id: process.env.GOOGLE_CLIENT_ID,
client_secret: process.env.GOOGLE_CLIENT_SECRET,
redirect_uri: process.env.GOOGLE_REDIRECT_URI,
refresh_token: process.env.GOOGLE_REFRESH_TOKEN
});
}
// 实现其他工具方法,如 listEvents, createEvent 等
}
npm run build
list_events
:列出指定时间段内的日历事件create_event
:创建新的日历事件update_event
:更新现有日历事件delete_event
:删除日历事件find_free_time
:查找可用的时间段本项目借助 Model Context Protocol (MCP) 实现与 Google Calendar 的集成,通过自然语言处理技术,允许用户在 Claude 中管理和查询日历事件。项目使用 Node.js 作为运行环境,依赖 @modelcontextprotocol/sdk
、googleapis
、google-auth-library
和 zod
等库。
如遇问题,请按照以下步骤处理: