Public
Remixed
Facebook MCP server + token generator
facebookgraph-apimcpoauth
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

Facebook_mcb

Facebook Graph API integration built on Val Town.

What it does

Setup

1. Create a Meta App

Go to developers.facebook.com/apps and create a new app. Note the App ID and App Secret from App Settings → Basic.

2. Set environment variables

KeyDescription
FB_APP_IDYour Meta App ID
FB_APP_SECRETYour Meta App Secret
FB_PAGE_ACCESS_TOKENPage Access Token (from Graph API Explorer or Page settings)
FB_VERIFY_TOKENAny random string you choose (used for webhook verification)

👉 Add FB_APP_ID here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_APP_ID

👉 Add FB_APP_SECRET here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_APP_SECRET

👉 Add FB_PAGE_ACCESS_TOKEN here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_PAGE_ACCESS_TOKEN

👉 Add FB_VERIFY_TOKEN here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_VERIFY_TOKEN

3. Subscribe the webhook

In your Meta App dashboard, go to Webhooks, add the live endpoint URL above as the callback URL, and use the same FB_VERIFY_TOKEN you set as the env var.

API

lib/facebook.ts exports

FunctionDescription
graphGet(path, params)Generic Graph API GET request
graphPost(path, body)Generic Graph API POST request
postToPage(pageId, message)Post a text message to a Page's feed
postLinkToPage(pageId, link, message?)Post a link (with optional message) to a Page's feed
getPageInfo(pageId)Get Page info (name, fans, about, etc.)
getPagePosts(pageId, limit?)Get recent posts from a Page
getLongLivedToken(appId, appSecret, shortToken)Exchange a short-lived token for a long-lived one

Files

main.ts           — HTTP endpoint (webhook verification + event receiver)
lib/facebook.ts   — Graph API helper functions