instagram-server-next-mcp
by: duhlink
instagram server next mcp
π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
-
Install dependencies:
npm install
-
Build the server:
npm run build
-
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 fromlimit
(optional): Number of posts to fetch (1-50) or "all"saveDir
(optional): Directory to save media files and metadatadelayBetweenPosts
(optional): Milliseconds to wait between processing posts
Error Handling
The server uses standardized error codes and messages:
INVALID_REQUEST
: Invalid request format or parametersINVALID_PARAMS
: Missing or invalid parametersMETHOD_NOT_FOUND
: Unknown method or toolINTERNAL_ERROR
: Server-side errors
Development
-
Start in development mode:
npm run dev
-
Run linter:
npm run lint
Improvements Over Original
- Modular Architecture: Clear separation of concerns and easier maintenance.
- Type Safety: Comprehensive TypeScript types and improved error catching.
- Error Handling: Standardized error codes and better messages.
- Configuration: Centralized and type-safe configuration.
- Code Quality: Consistent coding style and improved logging.
- Testing Support: Modular design for easier testing.
License
MIT