Back to Data
Instagram Analytics
Integrates with Instagram's API and web scraping tools to enable social media analytics, account management, and content strategy insights.
Last updated: 1/27/2026
README
# Instagram MCP Server
A Model Context Protocol (MCP) server for fetching Instagram posts using Chrome's existing login session.
## Features
- Modular architecture with clear separation of concerns
- Type-safe implementation using TypeScript
- Improved error handling and logging
- Configurable through environment variables
- JSON-RPC 2.0 compliant communication
- Automatic media downloading and metadata generation
- SEO-friendly description generation
## Architecture
The server follows a modular architecture with the following structure:
```
src/
āāā core/ # Core MCP functionality
ā āāā mcp/ # MCP server implementation
ā ā āāā server.ts # Server class
ā ā āāā stdio.ts # StdioServerTransport
ā ā āāā index.ts # Barrel exports
ā āāā types/ # Core type definitions
ā ā āāā mcp.ts # MCP types
ā āāā utils/ # Utility functions
ā āāā config.ts # Configuration management
ā āāā errors.ts # Error handling
āāā features/ # Feature modules
ā āāā instagram/ # Instagram feature
ā āāā types.ts # Instagram types
ā āāā utils/ # Feature utilities
ā ā āāā media.ts # Media handling
ā ā āāā post.ts # Post processing
ā ā āāā seo.ts # SEO generation
ā āāā instagram.service.ts # Instagram service
āāā services/ # Shared services
ā āāā browser/ # Browser service
ā āāā types.ts # Browser types
ā āāā browser.service.ts # Browser service
āāā index.ts # Entry point
āāā server.ts # Main server class
```
## Configuration
The server requires the following environment variables:
- `CHROME_USER_DATA_DIR`: Path to Chrome user data directory containing login session
Additional configuration options are available through the config manager:
- Browser settings (viewport, timeouts)
- Instagram settings (delays, batch sizes)
- Save directory and file paths
## Usage
1. Install dependencies:
```bash
npm install
```
2. Build the server:
```bash
npm run build
```
3. Run the server:
```bash
CHROME_USER_DATA_DIR=/path/to/chrome/profile npm start
```
## Available Tools
### get_instagram_posts
Fetches recent posts from an Instagram profile.
Parameters:
- `username` (required): Instagram username to fetch posts from
- `limit` (optional): Number of posts to fetch (1-50) or "all"
- `saveDir` (optional): Directory to save media files and metadata
- `delayBetweenPosts` (optional): Milliseconds to wait between processing posts
Example:
```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "call_tool",
"params": {
"name": "get_instagram_posts",
"arguments": {
"username": "example",
"limit": 10
}
}
}
```
## Error Handling
The server uses standardized error codes and messages:
- `INVALID_REQUEST`: Invalid request format or parameters
- `INVALID_PARAMS`: Missing or invalid parameters
- `METHOD_NOT_FOUND`: Unknown method or tool
- `INTERNAL_ERROR`: Server-side errors
## Development
1. Start in development mode:
```bash
npm run dev
```
2. Run linter:
```bash
npm run lint
```
## Improvements Over Original
1. **Modular Architecture**
- Clear separation of concerns
- Better code organization
- Easier to maintain and extend
2. **Type Safety**
- Comprehensive TypeScript types
- Better error catching
- Improved IDE support
3. **Error Handling**
- Standardized error codes
- Better error messages
- Proper error propagation
4. **Configuration**
- Centralized configuration
- Environment variable validation
- Type-safe config access
5. **Code Quality**
- Consistent coding style
- Better documentation
- Improved logging
6. **Testing Support**
- Modular design enables testing
- Dependency injection ready
- Clear interfaces
## License
MIT
Installation
Add this MCP to your configuration:
{
"mcpServers": {
"instagram-analytics": {
// See GitHub repository for configuration
}
}
}See the GitHub repository for full installation instructions.