Social Media MCP Server

# Technical Context: Social Media MCP Server ## Technologies Used ### Core Technologies 1. **Node.js** - Runtime environment for executing JavaScript code server-side - Provides asynchronous, event-driven architecture suitable for API interactions - Version: Latest LTS (18.x+) 2. **TypeScript** - Superset of JavaScript with static typing - Enhances code quality and maintainability - Provides better tooling and developer experience - Version: 5.0+ 3. **MCP SDK** - Model Context Protocol Software Development Kit - Enables creation of MCP servers that extend AI assistant capabilities - Provides standardized communication protocol - Version: Latest available ### API Integrations 1. **Twitter API v2** - REST API for Twitter/X platform - Provides endpoints for posting tweets, reading timelines, and retrieving analytics - Authentication: OAuth 1.0a and OAuth 2.0 2. **Mastodon API** - REST API for Mastodon instances - Provides endpoints for posting toots, reading timelines, and retrieving analytics - Authentication: OAuth 2.0 3. **LinkedIn API** - REST API for LinkedIn platform - Provides endpoints for posting shares, company updates, and retrieving analytics - Authentication: OAuth 2.0 4. **Brave Search API** - API for performing web searches - Provides comprehensive search results for research - Authentication: API Key 5. **Perplexity API** - API for AI-powered research and information retrieval - Provides in-depth analysis and structured information - Authentication: API Key ### AI Services 1. **OpenAI API** - Provides access to GPT models for content generation - Capabilities: Text generation, summarization, classification - Authentication: API Key 2. **Anthropic API** - Provides access to Claude models for content generation - Capabilities: Long-form content, nuanced writing - Authentication: API Key 3. **DeepSeek API** - Provides access to DeepSeek models for specialized content - Authentication: API Key 4. **Grok API** - Provides access to Grok models for conversational content - Authentication: API Key 5. **HuggingFace API** - Provides access to various specialized models - Used for specific tasks like hashtag generation - Authentication: API Key ### Data Storage 1. **SQLite** - Lightweight, file-based database - Used for storing analytics data, caching, and user preferences - Suitable for development and small-scale deployments 2. **Redis (Optional)** - In-memory data structure store - Used for caching, rate limit tracking, and request queuing - Provides improved performance for high-traffic scenarios ## Development Setup ### Environment Setup 1. **Node.js Environment** - Node.js (v18+) - npm or yarn package manager - TypeScript compiler 2. **Development Tools** - Visual Studio Code with TypeScript extensions - ESLint for code quality - Prettier for code formatting - Jest for testing 3. **Environment Variables** - API keys and secrets for all integrated services - Configuration options for rate limiting and caching - Development/production mode flags ### Project Structure ``` social-media-mcp/ ├── src/ │ ├── index.ts # Entry point │ ├── config/ # Configuration │ ├── types/ # TypeScript type definitions │ ├── core/ # Core orchestration logic │ ├── nlp/ # Natural language processing │ ├── conversation/ # Conversation management │ │ └── manager.ts # Conversation state and questions │ ├── history/ # Post history management │ │ └── manager.ts # History storage and retrieval │ ├── research/ # Research engine │ │ ├── brave/ # Brave Search integration │ │ ├── perplexity/ # Perplexity integration │ │ └── aggregator/ # Research result aggregation │ ├── content/ # Content generation │ │ ├── strategies/ # AI model strategies │ │ ├── formatter/ # Platform-specific formatting │ │ └── templates/ # Content templates │ ├── platforms/ # Social media platform integrations │ │ ├── twitter/ # Twitter API integration │ │ ├── mastodon/ # Mastodon API integration │ │ └── linkedin/ # LinkedIn API integration │ ├── analytics/ # Analytics engine │ ├── rate-limit/ # Rate limit management │ └── utils/ # Utility functions ├── tests/ # Test files ├── build/ # Compiled JavaScript ├── data/ # Data storage │ └── history/ # Post history storage ├── .env # Environment variables (gitignored) ├── package.json # Dependencies and scripts ├── tsconfig.json # TypeScript configuration └── README.md # Project documentation ``` ### Build and Run Process 1. **Development** ```bash # Install dependencies npm install # Run in development mode with hot reloading npm run dev ``` 2. **Testing** ```bash # Run unit tests npm test # Run integration tests npm run test:integration ``` 3. **Production Build** ```bash # Build for production npm run build # Start production server npm start ``` ## Technical Constraints ### API Rate Limits 1. **Twitter API** - Tweet creation: 200 requests per 15-minute window - Timeline retrieval: 100 requests per 15-minute window - User-based rate limits that vary by account type 2. **Mastodon API** - Instance-specific rate limits - Typically 300 requests per 5-minute window - Varies by Mastodon instance 3. **LinkedIn API** - Share creation: 100 requests per day per user - Company updates: 50 requests per day per company - Rate limits vary by API endpoint and application type 4. **AI Service APIs** - OpenAI: Varies by model and account tier - Anthropic: Requests per minute limits - Other services: Various rate limit structures ### Performance Considerations 1. **Response Time** - Target maximum response time: 5 seconds for initial processing - Research and content generation may take longer - Progress updates for longer operations 2. **Concurrency** - Support for multiple concurrent requests - Graceful handling of high load situations - Request queuing for rate-limited operations 3. **Resource Usage** - Memory usage optimization for long-running processes - Efficient handling of large response payloads - Caching to reduce redundant API calls ### Security Requirements 1. **API Credential Security** - Secure storage of API keys and tokens - No hardcoded credentials in source code - Environment variable-based configuration 2. **Data Protection** - Minimal storage of user data - Encryption for sensitive information - Compliance with platform terms of service 3. **Error Handling** - Graceful handling of API errors - No exposure of sensitive information in error messages - Comprehensive logging for debugging ## Dependencies ### Core Dependencies 1. **@modelcontextprotocol/sdk** - MCP SDK for server implementation - Provides communication protocol with AI assistants 2. **axios** - HTTP client for API requests - Used for all external API interactions 3. **twitter-api-v2** - Twitter API client library - Simplifies Twitter API interactions 4. **masto** - Mastodon API client library - Simplifies Mastodon API interactions 5. **linkedin-api-client** - LinkedIn API client library - Simplifies LinkedIn API interactions 6. **openai** - OpenAI API client library - Used for content generation 7. **@anthropic-ai/sdk** - Anthropic API client library - Used for content generation ### Utility Dependencies 1. **dotenv** - Environment variable management - Loads variables from .env file 2. **winston** - Logging library - Provides structured logging capabilities 3. **date-fns** - Date manipulation library - Used for scheduling and time-based operations 4. **sqlite3** - SQLite database driver - Used for data storage 5. **ioredis** (Optional) - Redis client - Used for caching and rate limit tracking ### Development Dependencies 1. **typescript** - TypeScript compiler and language services 2. **ts-node** - TypeScript execution environment - Used for development server 3. **nodemon** - File watcher for development - Automatically restarts server on changes 4. **jest** - Testing framework - Used for unit and integration tests 5. **eslint** - Code linting - Ensures code quality and consistency 6. **prettier** - Code formatting - Ensures consistent code style