Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions MCP/MCPserver/MCPserver/javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Instagram MCP Server

This MCP (Model Content Protocol) server provides access to Instagram API functionality.

## Features

- STDIO transport mode support
- Dynamic configuration through environment variables
- Automatic tool generation from API documentation
- Docker support for easy deployment
- Node.js based implementation

## Prerequisites

- Node.js 18.0.0 or higher
- npm package manager

## Installation

### Option 1: Local Installation

1. Install dependencies:
```bash
npm install
```

2. Set up environment variables:
```bash
export API_BASE_URL="https://api.example.com"
export BEARER_TOKEN="your-token-here" # If using Bearer auth
export API_KEY="your-api-key" # If using API key auth
export BASIC_AUTH="base64-encoded" # If using Basic auth
```

### Option 2: Using Docker

Build and run using Docker:
```bash
docker build -t instagram-mcp .
docker run -e API_BASE_URL="https://api.example.com" instagram-mcp
```

## Running the Server

### STDIO Mode (Default)

Run the server in STDIO mode for use with MCP clients:
```bash
npm start
```

Or directly:
```bash
node index.js
```

## Configuration

### Environment Variables

| Variable | Description | Required |
|----------|-------------|----------|
| `API_BASE_URL` | Base URL for the API | Yes |
| `BEARER_TOKEN` | Bearer token for authentication | No |
| `API_KEY` | API key for authentication | No |
| `BASIC_AUTH` | Base64 encoded basic auth credentials | No |
| `TRANSPORT` | Transport mode (stdio) | No (default: stdio) |

## Available Tools

This server provides 23 tools organized in 11 categories:
- `tags_tag_name`
- `users_self`
- `users_user_id`
- `users`
- `locations_location_id`
- `media_media_id_comments`
- `tags`
- `locations`
- `media_media_id`
- `media`
- `general`

## MCP Client Configuration

### Claude Desktop

Add to your Claude Desktop configuration:

```json
{
"mcpServers": {
"instagram": {
"command": "node",
"args": ["/path/to/index.js"],
"env": {
"API_BASE_URL": "https://api.example.com",
"BEARER_TOKEN": "your-token-here"
}
}
}
}
```

### Using MCP Inspector

Test the server using MCP Inspector:
```bash
npx @modelcontextprotocol/inspector node index.js
```

## Development

### Project Structure

```
.
├── index.js # Entry point
├── config.js # Configuration management
├── package.json # Node.js dependencies
├── tools/ # API tool implementations
│ ├── index.js # Tool registry
│ └── ...
└── README.md # This file
```

### Adding Custom Tools

Tools are exported from individual files in the `tools/` directory and imported in `tools/index.js`.

## Troubleshooting

### Common Issues

1. **Import errors**: Ensure all dependencies are installed with `npm install`
2. **Authentication errors**: Verify your API credentials are correct
3. **Connection errors**: Check the API_BASE_URL and network connectivity

### Logging

The server logs to stderr by default. Check console output for debugging information.

## License

Generated by CodeGlide MCP Generator

40 changes: 40 additions & 0 deletions MCP/MCPserver/MCPserver/javascript/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* API configuration for github.com/instagram/mcp-server
*/

export class APIConfig {
constructor(baseUrl = '', bearerToken = '', apiKey = '', basicAuth = '', port = '') {
this.baseUrl = baseUrl;
this.bearerToken = bearerToken;
this.apiKey = apiKey;
this.basicAuth = basicAuth;
this.port = port;
}
}

/**
* Load API configuration from environment variables
* @returns {APIConfig} Configuration object
*/
export function loadApiConfig() {
// Check port environment variable
const port = process.env.PORT || process.env.port || '';

const baseUrl = process.env.API_BASE_URL || '';

// Check transport environment variable
const transport = process.env.TRANSPORT || process.env.transport || '';

// For STDIO mode (not HTTP/HTTPS), API_BASE_URL is required
if (!['http', 'HTTP', 'https', 'HTTPS'].includes(transport) && !baseUrl) {
throw new Error('API_BASE_URL environment variable not set');
}

return new APIConfig(
baseUrl,
process.env.BEARER_TOKEN || '',
process.env.API_KEY || '',
process.env.BASIC_AUTH || '',
port
);
}
99 changes: 99 additions & 0 deletions MCP/MCPserver/MCPserver/javascript/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env node
/**
* Instagram MCP Server
* Version: 1.0.0
*/

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import { loadApiConfig } from './config.js';

// Import all tools
import * as tools from './tools/index.js';

const transport = process.env.TRANSPORT || process.env.transport || 'stdio';

async function main() {
try {
const config = loadApiConfig();

if (transport.toLowerCase() === 'http' || transport.toLowerCase() === 'https') {
// HTTP/HTTPS Mode
const port = config.port;
if (!port) {
console.error('PORT environment variable is required for HTTP/HTTPS mode');
process.exit(1);
}

console.error(`Starting Instagram MCP Server in ${transport.toUpperCase()} mode on port ${port}`);

// HTTP mode not yet fully implemented for JavaScript
console.error('HTTP/HTTPS mode not yet implemented for JavaScript MCP servers');
console.error('Please use STDIO mode or switch to Python/Go implementation');
process.exit(1);
} else {
// STDIO Mode (default)
console.error('Starting Instagram MCP Server in STDIO mode');

const server = new Server(
{
name: 'Instagram',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
}
);

// Register tool handlers
server.setRequestHandler(ListToolsRequestSchema, async () => {
const toolList = Object.keys(tools)
.filter(name => typeof tools[name] === 'function')
.map(name => ({
name: name,
description: tools[name].description || `Call ${name} API endpoint`,
inputSchema: {
type: "object",
properties: tools[name].schema || {},
},
}));

return { tools: toolList };
});

server.setRequestHandler(CallToolRequestSchema, async (request) => {
const toolName = request.params.name;
const toolFunc = tools[toolName];

if (!toolFunc) {
throw new Error(`Unknown tool: ${toolName}`);
}

const result = await toolFunc(request.params.arguments || {});

return {
content: [
{
type: "text",
text: result,
},
],
};
});

const transport = new StdioServerTransport();
await server.connect(transport);

console.error('Instagram MCP Server running in STDIO mode');
console.error(`Registered ${Object.keys(tools).filter(name => typeof tools[name] === 'function').length} tools`);
}
} catch (error) {
console.error('Failed to start server:', error);
process.exit(1);
}
}

main();
20 changes: 20 additions & 0 deletions MCP/MCPserver/MCPserver/javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "instagram",
"version": "1.0.0",
"description": "Instagram MCP Server",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js"
},
"keywords": ["mcp", "server", "instagram"],
"author": "",
"license": "MIT",
"dependencies": {
"@modelcontextprotocol/sdk": "^0.5.0",
"axios": "^1.6.0"
},
"engines": {
"node": ">=18.0.0"
}
}
Loading