Content
# Facebook MCP Server
A comprehensive Model Context Protocol (MCP) server for managing Facebook features, including Profiles, Pages, Posts, and Engagement. This server integrates with the Facebook Graph API and provides a seamless way for AI agents (like Claude Desktop) to interact with Facebook.
## Features
- **OAuth 2.0 Authentication:** No need to hardcode long-lived access tokens. The server includes a built-in OAuth flow to authenticate directly with Facebook.
- **Profile Management:** Fetch profile details for the authenticated user or specific user IDs.
- **Page Management:** List managed pages and fetch page insights.
- **Content Publishing:** Publish posts to feeds or pages, and delete objects.
- **Engagement:** Read feeds, fetch comments, and reply to comments.
- **Docker Support:** Easily containerized and run with Docker Compose.
## Prerequisites
Before running the server, you need to create a Facebook App on the Meta for Developers portal.
1. Go to [Meta for Developers](https://developers.facebook.com/).
2. Create a new App (choose "Other" -> "Consumer" or "Business" depending on your needs).
3. Add the **Facebook Login** product to your app.
4. In the Facebook Login settings, add your redirect URI to the "Valid OAuth Redirect URIs" list. By default, it should be: `http://localhost:3000/auth/facebook/callback`.
5. Get your **App ID** and **App Secret** from the App Dashboard -> Settings -> Basic.
## Installation
### Local Setup
1. Clone or copy the project files to your desired directory.
2. Install dependencies:
```bash
npm install
```
3. Copy `.env.example` to `.env` and fill in your credentials:
```bash
cp .env.example .env
```
Edit `.env`:
```env
FACEBOOK_APP_ID=your_actual_app_id
FACEBOOK_APP_SECRET=your_actual_app_secret
PORT=3000
REDIRECT_URI=http://localhost:3000/auth/facebook/callback
```
## Running the Server
### Option 1: Local Node.js
1. Build the project:
```bash
npm run build
```
2. Start the server:
```bash
npm start
```
### Option 2: Docker
1. Make sure your `.env` file is filled out.
2. Run with Docker Compose:
```bash
docker-compose up --build
```
This will build the image and start the server, exposing the port specified in your `.env` file (default 3000) for the authentication callback.
## Connecting to Claude Desktop
Add the server to your Claude Desktop configuration file (usually located at `%APPDATA%\Claude\claude_desktop_config.json` on Windows or `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS).
### For Local Execution:
```json
{
"mcpServers": {
"facebook": {
"command": "node",
"args": ["f:/MCP_Server/Facebook_MCP_server/dist/index.js"],
"env": {
"FACEBOOK_APP_ID": "your_app_id",
"FACEBOOK_APP_SECRET": "your_app_secret",
"REDIRECT_URI": "http://localhost:3000/auth/facebook/callback",
"PORT": "3000"
}
}
}
}
```
*(Adjust the path to `index.js` as necessary)*
### For Docker Execution:
If running via Docker, the server reads the `.env` file from the directory. You can use the `docker` command in Claude config if you have Claude configured to run docker commands, or simply run the container in the background and connect via network if supported (though stdio is the standard for Claude Desktop).
## Authentication Flow
Once the server is connected to Claude Desktop:
1. Ask Claude to "Authenticate with Facebook" or use the `fb_authenticate` tool.
2. Claude will provide a login URL.
3. Open the URL in your browser, log in to Facebook, and authorize the application.
4. You will be redirected to a page that says "Authentication Successful!".
5. The server automatically saves the access token in a local `.fb_token.json` file.
6. You can now start using all other tools!
## Available Tools
### Auth
- `fb_authenticate`: Returns the URL to start the OAuth login process.
### Profile
- `fb_get_profile`: Get profile details (ID, Name, etc.). Can accept `userId` and `fields`.
### Pages
- `fb_get_pages`: List Facebook Pages managed by the authenticated user.
- `fb_get_page_insights`: Get metrics (like impressions) for a specific page.
### Publishing
- `fb_publish_post`: Publish a message or link to a feed/page.
- `fb_delete_object`: Delete a post or comment by ID.
### Engagement
- `fb_get_feed`: Get posts from a feed.
- `fb_get_comments`: Get comments on an object.
- `fb_reply_comment`: Post a reply to a comment.
## License
ISC