A powerful Model Context Protocol (MCP) server for integrating with the Threads.com API. This server provides comprehensive tools for creating, reading, and managing Threads content programmatically.
π Visit the Website for a better reading experience!
- π Complete Threads API Integration - Full support for Threads.com API v1.0
- π§ MCP Protocol - Standard Model Context Protocol implementation
- π Analytics & Insights - Access engagement metrics and analytics
- π¬ Conversation Management - Create threads, replies, and manage conversations
- π― Type-Safe - Full TypeScript support with Zod schema validation
- β‘ Rate Limiting - Token bucket algorithm to prevent API rate limit violations
- πΎ Caching Layer - In-memory caching with TTL and LRU eviction
- π Webhook Support - Event-based webhooks with automatic retries and signature verification
- β Well Tested - >90% test coverage with Vitest
- π Modern Stack - Built with latest npm packages and best practices
The server provides the following MCP tools:
threads_get_profile- Get authenticated user's profile informationthreads_get_threads- Retrieve user's threads (posts) with paginationthreads_get_thread- Get a specific thread by IDthreads_create_thread- Create new threads with text, images, or videosthreads_reply_to_thread- Reply to existing threads
threads_get_insights- Get analytics for threads or user accountthreads_get_replies- Retrieve replies to a specific threadthreads_get_conversation- Get full conversation threads
Before you begin, you'll need:
- Node.js 18+ - Download here
- pnpm - Install with
npm install -g pnpm - Meta Developer Account - Sign up here
- Threads Account - Your personal Threads account
- OAuth 2.0 Credentials - See OAuth Setup Guide
-
Create a Meta App
- Visit Meta for Developers
- Create a new app and add the Threads API product
- Add OAuth redirect URI:
http://localhost:48810/callback - Get your App ID and App Secret
-
Configure Claude Desktop
- Add to your Claude Desktop config with just your App ID and Secret
- The server will automatically handle OAuth on first run
- A browser will open for you to authorize the app
- Tokens are stored and automatically refreshed!
That's it! No manual OAuth flow needed. π
π For detailed instructions, see the OAuth Setup Guide
pnpm install -g threads-mcp# Clone the repository
git clone https://github.com/PegasusHeavyIndustries/threads-mcp.git
cd threads-mcp
# Install dependencies
pnpm install
# Build the project
pnpm run buildThe simplest way is to let the server handle OAuth automatically:
For Claude Desktop, edit your config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"threads": {
"command": "npx",
"args": ["-y", "@pegasusheavy/threads-mcp"],
"env": {
"THREADS_APP_ID": "your-app-id",
"THREADS_APP_SECRET": "your-app-secret"
}
}
}
}When you start Claude Desktop:
- A browser will automatically open
- Log in and authorize the app
- Done! Tokens are stored and auto-refreshed
If you prefer to use pre-generated tokens:
{
"mcpServers": {
"threads": {
"command": "npx",
"args": ["-y", "@pegasusheavy/threads-mcp"],
"env": {
"THREADS_ACCESS_TOKEN": "your-long-lived-token",
"THREADS_USER_ID": "your-user-id"
}
}
}
}See OAuth Setup Guide for manual OAuth flow instructions.
# If installed globally
threads-mcp
# If running from source
pnpm run devConfigure your MCP client (like Claude Desktop) to use this server:
{
"mcpServers": {
"threads": {
"command": "threads-mcp",
"env": {
"THREADS_ACCESS_TOKEN": "your-access-token",
"THREADS_USER_ID": "your-user-id"
}
}
}
}{
"name": "threads_get_profile",
"arguments": {}
}{
"name": "threads_create_thread",
"arguments": {
"text": "Hello from the Threads MCP Server! π",
"replyControl": "everyone"
}
}{
"name": "threads_get_insights",
"arguments": {
"threadId": "thread-id-here",
"metrics": ["views", "likes", "replies", "reposts"]
}
}{
"name": "threads_reply_to_thread",
"arguments": {
"threadId": "thread-id-to-reply-to",
"text": "Great post!",
"replyControl": "accounts_you_follow"
}
}threads-mcp/
βββ src/
β βββ client/ # Threads API client
β β βββ __tests__/ # Client tests
β β βββ threads-client.ts
β βββ server/ # MCP server implementation
β β βββ __tests__/ # Server tests
β β βββ server.ts
β βββ types/ # TypeScript types & Zod schemas
β β βββ __tests__/ # Type tests
β β βββ threads.ts
β βββ index.ts # Entry point
βββ dist/ # Compiled output
βββ coverage/ # Test coverage reports
βββ tests/ # Integration tests
# Development
pnpm run dev # Run in development mode with tsx
pnpm run build # Compile TypeScript to JavaScript
# Testing
pnpm test # Run tests once
pnpm test:watch # Run tests in watch mode
pnpm test:coverage # Generate coverage report
# Code Quality
pnpm run lint # Lint code with ESLint
pnpm run format # Format code with PrettierThe project has comprehensive test coverage (>90%):
# Run all tests
pnpm test
# Run with coverage
pnpm test:coverage
# Watch mode for development
pnpm test:watch# Lint your code
pnpm run lint
# Format code
pnpm run formatThe core client for interacting with the Threads API.
const client = new ThreadsClient({
accessToken: string;
userId: string;
apiVersion?: string; // Optional, defaults to 'v1.0'
});getProfile(fields?: string[]): Promise<ThreadsUser>getThreads(params?: GetMediaParams): Promise<ThreadsMedia[]>getThread(threadId: string, fields?: string[]): Promise<ThreadsMedia>createThread(params: CreateThreadParams): Promise<CreateThreadResponse>getThreadInsights(threadId: string, params: GetInsightsParams): Promise<ThreadsInsights[]>getUserInsights(params: GetInsightsParams): Promise<ThreadsInsights[]>getReplies(threadId: string, params?: GetRepliesParams): Promise<ThreadsReplies>getConversation(threadId: string, params?: GetRepliesParams): Promise<ThreadsConversation>replyToThread(threadId: string, text: string, replyControl?: string): Promise<CreateThreadResponse>validateToken(): Promise<boolean>
The client includes comprehensive error handling:
import { ThreadsAPIError } from 'threads-mcp';
try {
await client.createThread({ text: 'Hello!' });
} catch (error) {
if (error instanceof ThreadsAPIError) {
console.error('API Error:', error.message);
console.error('Status Code:', error.statusCode);
console.error('Response:', error.response);
}
}Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Write tests for new features (maintain >90% coverage)
- Follow the existing code style
- Update documentation as needed
- Use conventional commits (enforced by Git hooks)
This project uses Husky to enforce code quality:
- pre-commit: Runs linting, formatting, and type checking
- pre-push: Runs full test suite, coverage check, and build verification
- commit-msg: Validates commit message format (conventional commits)
See docs/GIT_HOOKS.md for detailed information about Git hooks.
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2025 Pegasus Heavy Industries LLC
- π Threads API Documentation
- π Report Issues
- π¬ MCP Protocol Documentation
- Built with MCP SDK
- Powered by Threads API
- Type validation with Zod
- Testing with Vitest
Made with β€οΈ by Pegasus Heavy Industries LLC