Tweek MCP Server

Tweek MCP Server

An MCP server that integrates with the Tweek API to manage calendars, tasks, and custom colors. It enables users to perform full task CRUD operations, list accessible calendars, and fetch color preferences through secure authentication.

Category
访问服务器

README

Tweek MCP Server

A Model Context Protocol (MCP) server that integrates with the Tweek API to manage calendars, tasks, and custom colors. Built with TypeScript and ESM modules.

Features

  • Secure Authentication: Interactive sign-in with automatic token refresh
  • Calendar Management: List calendars with role-based access
  • Task CRUD: Create, read, update, and delete tasks with validation
  • Custom Colors: Fetch user-specific color preferences
  • Pagination Support: Forward-only pagination with nextDocId
  • Error Handling: Structured error mapping with retry logic for transient failures
  • Token Security: Encrypted token storage with file permissions (mode 600)

Prerequisites

  • Node 20+
  • PNPM 10+
  • Tweek API key (obtain from Tweek)

Installation

# Install dependencies
pnpm install

# Build the project
pnpm build

Quick Start

1. Configure Environment

Set your Tweek API key (required):

export TWEEK_API_KEY="your-api-key-here"

See Configuration for all available environment variables.

2. First-Time Authentication

Before starting the server, you need to authenticate once:

pnpm auth:signin

You'll be prompted to enter your Tweek email and password:

Enter your Tweek email: user@example.com
Enter your Tweek password: ********
✅ Authentication successful! Tokens saved.

Your credentials are used only in memory and never persisted. The command exchanges them for tokens and securely saves them to ~/.tweek-mcp/tokens.json (or your configured TWEEK_TOKENS_PATH).

Alternative Authentication Methods

Non-interactive (for automation/CI):

echo "your-password" | pnpm auth:signin --email user@example.com --password-stdin

Import existing refresh token:

pnpm auth:import --refresh-token "your-refresh-token"

3. Start the Server

pnpm start

The server will:

  • Load tokens from the token file
  • Automatically refresh the idToken if needed
  • Start listening for MCP requests

For development with auto-reload:

pnpm dev

Configuration

Configure via environment variables:

Variable Required Default Description
TWEEK_API_KEY ✅ Yes - Your Tweek API key
TWEEK_API_BASE No https://tweek.so/api/v1 Tweek API base URL
TWEEK_TOKENS_PATH No ~/.tweek-mcp/tokens.json Path to token storage file
TWEEK_REQUEST_TIMEOUT_MS No 30000 HTTP request timeout (milliseconds)
TWEEK_TOKEN_REFRESH_BUFFER_SEC No 60 Proactive token refresh window (seconds)
TWEEK_ENCRYPTION_KEY No - 32-byte key for AES-GCM token encryption

Example Configuration

export TWEEK_API_KEY="ak_live_..."
export TWEEK_TOKENS_PATH="/secure/volume/tweek-tokens.json"
export TWEEK_ENCRYPTION_KEY="your-32-byte-encryption-key-here"
export TWEEK_REQUEST_TIMEOUT_MS="45000"
export TWEEK_TOKEN_REFRESH_BUFFER_SEC="120"

MCP Tools

The server exposes the following MCP tools:

Calendars

listCalendars()

List all calendars accessible to the authenticated user.

Returns:

interface ListCalendarsResponse {
  calendars: Calendar[]
}

interface Calendar {
  id: string
  name: string
  role: 'ROLE_OWNER' | 'ROLE_EDITOR' | 'ROLE_VIEWER'
  color?: string
  // ... other calendar fields
}

Tasks

listTasks({ calendarId, startAt?, dateFrom?, dateTo? })

List tasks with optional pagination and date filtering.

Parameters:

  • calendarId (required): Calendar ID
  • startAt (optional): Pagination cursor from previous response
  • dateFrom (optional): ISO 8601 date to filter tasks from
  • dateTo (optional): ISO 8601 date to filter tasks to

Returns:

interface ListTasksResponse {
  pageSize: number
  nextDocId?: string
  data: Task[]
}

getTask({ taskId })

Retrieve a single task by ID.

createTask({ task })

Create a new task.

Parameters:

  • task.calendarId (required): Calendar ID
  • task.text (required): Task title
  • task.date (optional): ISO 8601 date
  • task.freq (optional): Recurrence frequency (0-7)
  • task.checklist (optional): Array of checklist items
  • ... see Tweek API docs for all fields

Returns:

interface CreateTaskResponse {
  id: string
}

updateTask({ taskId, patch })

Update an existing task.

Returns: Full updated task object

deleteTask({ taskId })

Delete a task.

Returns:

interface DeleteTaskResponse {
  success: true
}

Custom Colors

getCustomColors()

Fetch custom colors for the authenticated user. The userId is automatically extracted from the idToken.

Returns:

interface GetCustomColorsResponse {
  colors: Color[]
}

interface Color {
  id: string
  hex: string
  name?: string
}

Input Validation

The server validates task inputs:

  • freq: Must be integer 0-7 (Tweek recurrence enum)
  • notifyAt, date, isoDate, dtStart: Must be valid ISO 8601 date/datetime
  • calendarId: Required non-empty string on creation
  • checklist: Each item must have non-empty text field

Connecting MCP Clients

Claude Desktop

Add to your Claude Desktop configuration (claude_desktop_config.json):

{
  "mcpServers": {
    "tweek": {
      "command": "node",
      "args": ["/path/to/tweek-mcp/dist/index.js"],
      "env": {
        "TWEEK_API_KEY": "your-api-key-here"
      }
    }
  }
}

Other MCP Clients

The server uses standard MCP JSON-RPC over stdio. Configure your client to:

  1. Run node dist/index.js (or pnpm start)
  2. Pass TWEEK_API_KEY in environment
  3. Ensure token file exists at configured path

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run linter
pnpm lint

# Build TypeScript
pnpm build

# Development mode (auto-reload)
pnpm dev

Project Structure

src/
├── auth/           # Authentication (AuthManager, TokenStore, IdentityClient)
├── cli/            # CLI commands (auth signin/import)
├── config/         # Configuration loading
├── http/           # HTTP client with retry logic
├── logging/        # Structured logging
├── tests/          # Test suite
├── tools/          # MCP tools (calendars, tasks, colors, validation)
├── tweek/          # Tweek API client and types
└── index.ts        # Server bootstrap

Troubleshooting

Error: "Tweek tokens not found"

Problem: Server cannot find the token file.

Solution: Run authentication first:

pnpm auth:signin

Error: "UNAUTHENTICATED"

Problem: Tokens are expired or invalid.

Solution: Re-authenticate:

pnpm auth:signin

Error: "Permission denied" on token file

Problem: Token file permissions are incorrect.

Solution: The server automatically sets mode 600. If issues persist, manually fix:

chmod 600 ~/.tweek-mcp/tokens.json

Tokens Not Refreshing

Problem: Token refresh fails silently.

Solution: Check logs for refresh errors. Verify your refresh token is still valid by re-authenticating.

Connection Timeouts

Problem: Requests timing out to Tweek API.

Solution: Increase timeout:

export TWEEK_REQUEST_TIMEOUT_MS="60000"

Container Deployments

For Docker or containerized environments:

  1. Mount a persistent volume for tokens:

    docker run -v /secure/volume:/tokens \
      -e TWEEK_TOKENS_PATH=/tokens/tweek.json \
      -e TWEEK_API_KEY=your-key \
      tweek-mcp
    
  2. Consider using TWEEK_ENCRYPTION_KEY for additional security

  3. Pre-authenticate using auth:import with a refresh token

Security

  • Tokens stored with file permissions 600 (user-only access)
  • Optional AES-GCM encryption for token file
  • Credentials never logged or persisted
  • Sensitive headers redacted from logs
  • Automatic token refresh before expiry

Testing

Comprehensive test suite with:

  • Unit tests for validation, retry logic, encryption
  • Integration tests for HTTP client and auth flows
  • CLI end-to-end tests
  • Contract tests for MCP tools
# Run all tests
pnpm test

# Run specific test file
pnpm test src/tests/validation.test.ts

# Run tests matching pattern
pnpm test -- -t "should validate task input"

Contributing

  1. Follow the existing code style (enforced by ESLint)
  2. Add tests for new features
  3. Ensure pnpm lint and pnpm test pass
  4. Update documentation as needed

License

MIT

Resources

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选