This project is a MCP server for automating and managing interactions on a Facebook Page using the Facebook Graph API. It provides tools to create posts, moderate comments, fetch post insights, and filter negative feedback that can be used with Claude or other LLM-based agents.
To use this Facebook MCP server, you'll need:
git clone https://github.com/your-org/facebook-mcp-server.git
cd facebook-mcp-server
Install dependencies using uv, a fast Python package manager:
# Install uv if you don't have it already
curl -Ls https://astral.sh/uv/install.sh | bash
# Install project dependencies
uv pip install -r requirements.txt
Create a .env
file in the root directory with your Facebook credentials:
FACEBOOK_ACCESS_TOKEN=your_facebook_page_access_token
FACEBOOK_PAGE_ID=your_page_id
You can obtain these credentials from the Facebook Developer platform at Facebook Graph API Explorer.
To integrate the Facebook MCP server with Claude Desktop:
"FacebookMCP": {
"command": "uv",
"args": [
"run",
"--with",
"mcp[cli]",
"--with",
"requests",
"mcp",
"run",
"/path/to/facebook-mcp-server/server.py"
]
}
Be sure to replace /path/to/facebook-mcp-server/
with the actual path where you cloned the repository.
The Facebook MCP server provides the following tools:
post_to_facebook
- Create a new Facebook post with a messagepost_image_to_facebook
- Post an image with a captionupdate_post
- Update an existing post's messageschedule_post
- Schedule a post for future publicationdelete_post
- Delete a specific post by IDreply_to_comment
- Reply to a specific comment on a postdelete_comment
/ delete_comment_from_post
- Delete a specific comment by IDhide_comment
- Hide a comment from public viewunhide_comment
- Unhide a previously hidden commentfilter_negative_comments
- Filter out comments with negative sentiment keywordsbulk_delete_comments
- Delete multiple comments by IDbulk_hide_comments
- Hide multiple comments by IDget_page_posts
- Retrieve recent posts from the Pageget_post_comments
- Fetch comments on a given postget_number_of_comments
- Count comments on a postget_number_of_likes
- Count likes on a postget_post_impressions
- Get total impressions on a postget_post_impressions_unique
- Get number of unique users who saw the postget_post_impressions_paid
- Get number of paid impressionsget_post_impressions_organic
- Get number of organic impressionsget_post_engaged_users
- Get number of users who engaged with the postget_post_clicks
- Get number of clicks on the postget_post_reactions_like_total
- Get total number of 'Like' reactionsget_post_reactions_breakdown
- Get all reaction counts in one callget_post_top_commenters
- Get the top commenters on a postget_page_fan_count
- Retrieve the total number of Page fansget_post_share_count
- Get the number of shares on a postsend_dm_to_user
- Send a direct message to a userTo create a new post on your Facebook Page:
response = post_to_facebook("Check out our latest product announcement!")
post_id = response["id"]
print(f"Created post with ID: {post_id}")
To fetch and hide negative comments:
# Get comments from a post
comments = get_post_comments(post_id)
# Filter negative comments
negative_comments = filter_negative_comments(comments)
# Hide negative comments
for comment in negative_comments:
hide_comment(comment["id"])
To get insights about a post's performance:
# Get post engagement metrics
impressions = get_post_impressions(post_id)
engaged_users = get_post_engaged_users(post_id)
likes = get_number_of_likes(post_id)
comments = get_number_of_comments(post_id)
shares = get_post_share_count(post_id)
print(f"Post performance: {impressions} impressions, {engaged_users} engaged users")
print(f"Engagement: {likes} likes, {comments} comments, {shares} shares")
To schedule a post for future publication:
# Schedule a post for tomorrow at 10 AM
import datetime
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
scheduled_time = tomorrow.replace(hour=10, minute=0, second=0).isoformat()
response = schedule_post("Our weekend special starts tomorrow!", scheduled_time)
scheduled_post_id = response["id"]
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "facebook-mcp-server" '{"command":"uv","args":["run","--with","mcp[cli]","--with","requests","mcp","run","/path/to/facebook-mcp-server/server.py"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"facebook-mcp-server": {
"command": "uv",
"args": [
"run",
"--with",
"mcp[cli]",
"--with",
"requests",
"mcp",
"run",
"/path/to/facebook-mcp-server/server.py"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"facebook-mcp-server": {
"command": "uv",
"args": [
"run",
"--with",
"mcp[cli]",
"--with",
"requests",
"mcp",
"run",
"/path/to/facebook-mcp-server/server.py"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect