Facebook MCP server
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.
- Go to Meta for Developers.
- Create a new App (choose "Other" -> "Consumer" or "Business" depending on your needs).
- Add the Facebook Login product to your app.
- 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. - Get your App ID and App Secret from the App Dashboard -> Settings -> Basic.
Installation
Local Setup
- Clone or copy the project files to your desired directory.
- Install dependencies:
npm install - Copy
.env.exampleto.envand fill in your credentials:
Editcp .env.example .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
- Build the project:
npm run build - Start the server:
npm start
Option 2: Docker
- Make sure your
.envfile is filled out. - Run with Docker Compose:
This will build the image and start the server, exposing the port specified in yourdocker-compose up --build.envfile (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:
{
"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:
- Ask Claude to "Authenticate with Facebook" or use the
fb_authenticatetool. - Claude will provide a login URL.
- Open the URL in your browser, log in to Facebook, and authorize the application.
- You will be redirected to a page that says "Authentication Successful!".
- The server automatically saves the access token in a local
.fb_token.jsonfile. - 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 acceptuserIdandfields.
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