MCP HubMCP Hub
duhlink

instagram-server-next-mcp

by: duhlink

instagram server next mcp

14created 14/12/2024
Visit
Instagram
Next

πŸ“ŒOverview

Purpose: To provide a Model Context Protocol (MCP) server for fetching Instagram posts utilizing Chrome's existing login session.

Overview: The Instagram MCP Server is designed to efficiently retrieve Instagram posts by leveraging a modular architecture and TypeScript for type safety. It supports JSON-RPC 2.0 for seamless communication and includes robust error handling.

Key Features:

  • Modular Architecture: Promotes clear separation of concerns, enhancing maintainability and extensibility of the code.

  • Type Safety with TypeScript: Provides comprehensive type definitions for improved error catching and better integration with development tools.

  • Error Handling: Implements standardized error codes and informative messages to facilitate troubleshooting.

  • Configurable via Environment Variables: Allows users to adjust settings for Chrome user data and other parameters easily.

  • JSON-RPC 2.0 Compliance: Supports efficient and standardized communication protocols.

  • Automatic Media Handling: Includes features for downloading media and generating associated metadata, along with an SEO-friendly description generation.


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/                      
β”‚   β”œβ”€β”€ mcp/                  
β”‚   β”‚   β”œβ”€β”€ server.ts        
β”‚   β”‚   β”œβ”€β”€ stdio.ts         
β”‚   β”‚   └── index.ts         
β”‚   β”œβ”€β”€ types/               
β”‚   β”‚   └── mcp.ts          
β”‚   └── utils/               
β”‚       β”œβ”€β”€ config.ts        
β”‚       └── errors.ts        
β”œβ”€β”€ features/                 
β”‚   └── instagram/           
β”‚       β”œβ”€β”€ types.ts         
β”‚       β”œβ”€β”€ utils/           
β”‚       β”‚   β”œβ”€β”€ media.ts     
β”‚       β”‚   β”œβ”€β”€ post.ts      
β”‚       β”‚   └── seo.ts       
β”‚       └── instagram.service.ts 
β”œβ”€β”€ services/                 
β”‚   └── browser/             
β”‚       β”œβ”€β”€ types.ts         
β”‚       └── browser.service.ts 
β”œβ”€β”€ index.ts                 
└── server.ts                

Configuration

The server requires the following environment variable:

  • CHROME_USER_DATA_DIR: Path to Chrome user data directory containing login session

Usage

  1. Install dependencies:

    npm install
    
  2. Build the server:

    npm run build
    
  3. Run the server:

    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

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:

    npm run dev
    
  2. Run linter:

    npm run lint
    

Improvements Over Original

  1. Modular Architecture: Clear separation of concerns and easier maintenance.
  2. Type Safety: Comprehensive TypeScript types and improved error catching.
  3. Error Handling: Standardized error codes and better messages.
  4. Configuration: Centralized and type-safe configuration.
  5. Code Quality: Consistent coding style and improved logging.
  6. Testing Support: Modular design for easier testing.

License

MIT