Link-in-Bio-with-MCP-Server
Health Gecti
- License — License: NOASSERTION
- Description — Repository has a description
- Active repo — Last push 0 days ago
- Community trust — 36 GitHub stars
Code Uyari
- process.env — Environment variable access in .legacy/tests/landing.audit.js
- process.env — Environment variable access in tests/landing.audit.js
Permissions Gecti
- Permissions — No dangerous permissions requested
Bu listing icin henuz AI raporu yok.
Personal link-in-bio page on plain PHP 8.5: one JSON tree renders EN/RU pages, SEO, JSON-LD and the sitemap. An MCP server edits links over HTTP - token auth, atomic writes, backups. nginx + PHP-FPM, no framework, no build step, 100% line coverage.
Self-Hosted Link-in-Bio with MCP Server
A production-ready, content-driven link-in-bio page built on PHP 8.1+ (tested on 8.5). One JSON file powers both languages, the meta tags, JSON-LD, the sitemap, and a 12-tool MCP server for AI-assisted content changes.
No framework. No runtime dependencies. No build step.
Why this exists
Most link-in-bio tools are hosted, locked down, and require a subscription for basic customization. This project takes the opposite approach:
- you own the server and the content;
- the page is plain HTML generated by PHP;
- metadata and structured data come from the same content tree;
- an MCP endpoint lets agents add, reorder, hide, and edit links safely;
- every write is validated, backed up, and revision-controlled.
The result is a small, fast, SEO-friendly page that can be edited by a human or an AI client without touching templates.
Highlights
| Area | What you get |
|---|---|
| Rendering | PHP 8.1+, escaped output, no template engine |
| Content | One JSON tree for EN/RU, links, metadata, SEO and analytics |
| Editing | 12 MCP tools, optimistic concurrency via rev |
| Performance | Rendered HTML cache with deploy-aware invalidation |
| SEO | Canonical URLs, hreflang, Open Graph, Twitter Card, JSON-LD, sitemap |
| Accessibility | WCAG 2.0–2.2 AA target, axe-core clean, modifier-key shortcuts, reduced motion |
| Security | Token auth, strict validation, atomic writes, CSP and hardening headers |
| Operations | No daemons, no queues, no database, no Composer, no NPM at runtime |
| Testing | 195 unit tests, 100% line coverage, 16 HTTP checks, 76 browser checks |
How it works
request ──► web server ──► public/index.php ──► App ──► Cache ──► Renderer ──► HTML
│ ▲
└──► Content (app/content/site.json)
- One content source.
app/content/site.jsonholds both languages, all links, all metadata, and settings. - Rendered once, then cached. The cache key includes the content revision, the seed, the template, every PHP source file, and the public CSS/JS, so a deploy or edit invalidates itself.
- Writes are safe. Every mutation validates the whole tree, copies a backup, writes atomically under
flock, and appends to an audit log. - MCP uses the same path. There is no second admin mode and no parallel write path.
Quick start
Requirements: PHP 8.1 or newer (tested on 8.5). Xdebug is required for the coverage-gated test runner (tests/run.php); production does not need it.
php -S 127.0.0.1:8123 -t public tests/router.php
Open http://127.0.0.1:8123/.
tests/router.php mirrors the production rewrite rules, including /mcp, pretty URLs, and dotfile denial.
The first request provisions an MCP token in app/bio.token if the application directory is writable. For production, pre-create the token as described in Deployment.
Project structure
public/ # the only web root
├── index.php # front controller (/, /ru.html, /robots.txt, /sitemap.xml)
├── mcp.php # MCP endpoint (POST /mcp.php)
├── .htaccess # Apache rewrite, directory listing, dotfiles
├── assets/ # images, logos, favicon, self-hosted Inter font
├── styles.css # design tokens, dark/light themes
└── script.js # theme, clipboard, shortcuts
app/ # private, never served by the web server
├── src/
│ ├── App.php # routing, headers, ETag, 304, environment
│ ├── Content.php # validation, atomic writes, backups, audit
│ ├── Renderer.php # PHP → HTML, escaped
│ ├── Seo.php # meta, JSON-LD, sitemap
│ ├── Cache.php # rendered HTML + deploy-aware key
│ ├── Mcp.php # JSON-RPC, 12 tools
│ ├── Token.php # token provisioning
│ ├── Theme.php # pre-paint theme bootstrap + CSP hash
│ ├── Icons.php # inline SVG registry
│ └── ...
├── templates/page.php # the only template
├── content/site.seed.json # initial content (deployed, never overwritten)
├── content/site.json # live content (created on first write, gitignored)
├── cache/ # rendered HTML (gitignored)
└── bio.token # MCP token (0600, gitignored, outside public/)
tests/ # 195 unit, 16 HTTP, 76 Playwright checks
docs/preview.png # README preview (not deployed)
SECURITY.md # vulnerability reporting
Content model
A link item is intentionally small:
{
"id": "telegram",
"type": "link",
"href": "https://t.me/example",
"icon": "telegram",
"order": 1,
"visible": true,
"title": { "en": "Telegram Channel", "ru": "Телеграм-канал" },
"subtitle": { "en": "@example", "ru": "@example" }
}
Supported item types: link, featured, project, social, email.
Supported section layouts:
cards— every visible item is rendered as a card;social— every visible item is rendered as a square social button;mixed— social items go to a grid, everything else to cards.
Icons come from a fixed inline-SVG registry. An item can use logo instead of icon, including social buttons.
Validation rejects invalid content before it reaches disk: bad schemes, unsafe asset paths, missing asset files, duplicate IDs, empty required translations, impossible dates, invalid GA4 IDs, inconsistent email items, oversized fields and content, meta titles over 70 characters, descriptions outside 50–160 characters, and OG images that are not 1200×630. An item must have exactly one of icon or logo; the site has at most one email item and its href must match settings.email.
MCP server
Endpoint:
POST https://your-domain.com/mcp.php
Authorization: Bearer <MCP_TOKEN>
Content-Type: application/json
JSON-RPC 2.0 over Streamable HTTP. JSON responses only, POST only, no SSE stream. Request bodies are capped at 1 MiB; the token is checked before the body is read.
curl -s https://your-domain.com/mcp.php \
-H "Authorization: Bearer $MCP_TOKEN" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}'
Tools
| Tool | Purpose |
|---|---|
get_content |
Whole content tree and current revision |
get_schema |
Complete JSON Schema for the content tree |
list_sections |
Sections, labels, layouts, item counts |
list_links |
Links filtered by section or visibility; lang localizes titles |
create_link |
Add a link at an optional position |
update_link |
Patch title, subtitle, href, type, icon/logo, visibility |
move_link |
Move between sections or positions |
set_visibility |
Hide without deleting |
delete_link |
Soft delete by default; hard: true removes it |
update_settings |
Email, theme, footer year and GA4 |
preview |
Render either language without touching the cache |
publish |
Drop the HTML cache |
Every mutation requires rev. A stale revision returns a conflict instead of silently overwriting a newer change. Read-only tools carry readOnlyHint, delete_link carries destructiveHint, and create_link requires exactly one of icon or logo.
Authentication
The token is read from the first available source:
| Source | Notes |
|---|---|
MCP_TOKEN in the PHP-FPM pool environment |
Nothing on disk |
BIO_TOKEN_FILE |
Explicit path outside public/ |
app/bio.token |
Generated on first use when app/ is writable |
There is no .env fallback. Empty or short tokens (less than 32 URL-safe characters) lock the endpoint. The generated token is 64 lowercase hex characters.
Recommended production setup:
/var/www/example/app/bio.token # 64 hex characters, mode 0600
Rotate by deleting the file and provisioning a new one. If app/ is not writable, the application will not create it automatically.
Client setup
All clients need the same two values:
URL: https://your-domain.com/mcp.php
Authorization: Bearer <64 hex characters from app/bio.token>
Keep the token in an environment variable. On Windows:
setx BIO_TOKEN "<token>"
OpenCode V2
Project or global opencode.jsonc. oauth: false is required because this endpoint is header-only.
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"servers": {
"bio": {
"type": "remote",
"url": "https://your-domain.com/mcp.php",
"oauth": false,
"headers": {
"Authorization": "Bearer {env:BIO_TOKEN}"
}
}
}
}
}
opencode mcp list
{env:BIO_TOKEN} is the name of the environment variable, not the token itself.
OpenClaw
~/.openclaw/openclaw.json. transport must be explicit, otherwise OpenClaw falls back to SSE.
{
"mcp": {
"servers": {
"bio": {
"url": "https://your-domain.com/mcp.php",
"transport": "streamable-http",
"headers": {
"Authorization": "Bearer ${BIO_TOKEN}"
}
}
}
}
}
Or through the registry:
openclaw mcp set bio '{"url":"https://your-domain.com/mcp.php","transport":"streamable-http","headers":{"Authorization":"Bearer ${BIO_TOKEN}"}}'
openclaw mcp doctor bio --probe
Claude Code
claude mcp add --transport http bio https://your-domain.com/mcp.php \
--header "Authorization: Bearer $BIO_TOKEN"
Or .mcp.json at the project root. The file can be committed; the secret stays in the environment:
{
"mcpServers": {
"bio": {
"type": "http",
"url": "https://your-domain.com/mcp.php",
"headers": {
"Authorization": "Bearer ${BIO_TOKEN}"
}
}
}
}
type is not optional: an entry with a url and no type is read as a stdio server.
Connection troubleshooting
| Symptom | Likely cause |
|---|---|
401 |
Wrong token, or the token was rotated |
401 with Bearer {env:...} in config |
The token was pasted inside the braces |
405 |
The client probed with GET; this endpoint is POST-only |
| Client starts OAuth | The Authorization header is missing; check the header and oauth: false |
| 12 tools listed but none visible | Client-side tool filters or permissions |
Deployment
PHP-FPM is the supported runtime. Apache 2.4 works through public/.htaccess; nginx needs the usual try_files.
Document root: public/. Never point the web server at the repository root or at app/.
Nginx
root /var/www/example/public;
index index.php;
client_max_body_size 1m;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options DENY always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
add_header Strict-Transport-Security "max-age=31536000" always;
location ^~ /.well-known/ {
try_files $uri =404;
}
location ~ /\. {
deny all;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/mcp/?$ {
rewrite ^ /mcp.php last;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_AUTHORIZATION $http_authorization;
}
Nginx does not read .htaccess; keep the dotfile-deny block above. Apache users can ignore it.
Apache
Point DocumentRoot at public/, enable AllowOverride All (or at least FileInfo, Options, AuthConfig) and mod_rewrite. public/.htaccess handles /mcp, pretty URLs, directory listing, dotfiles, and forwards Authorization to PHP. On hosts where the header is still stripped, add CGIPassAuth On (Apache 2.4.13+) at the virtual-host level. A server-level LimitRequestBody 1048576 is recommended as a second body-size guard.
Routes
| URL | Result |
|---|---|
/ |
EN |
/?lang=ru |
RU |
/index.php?lang=ru |
RU |
/ru.html |
RU (rewritten to index.php) |
/mcp.php |
MCP endpoint |
/mcp |
Alias (rewrite or Apache rule) |
/robots.txt |
Generated from settings.siteUrl |
/sitemap.xml |
Generated from content |
Verify after deploy:
curl -s -o /dev/null -w '%{http_code}\n' https://your-domain.com/ # 200
curl -s https://your-domain.com/index.php?lang=ru | grep -c 'lang="ru"' # 1
curl -s -o /dev/null -w '%{http_code}\n' https://your-domain.com/mcp.php # 405
Static assets are served by the web server, not PHP. The Nginx sample and public/.htaccess add the main hardening headers to them; keep equivalent rules if you use a different server.
Files and permissions
Deploy both public/ and app/:
rsync -a public/ user@host:/var/www/example/public/
rsync -a \
--exclude 'bio.token*' \
--exclude 'content/site.json*' \
--exclude 'content/backups/' \
--exclude 'content/.audit.jsonl' \
--exclude 'cache/' \
app/ user@host:/var/www/example/app/
The GitHub workflow stages app/ and public/ into one deploy/ directory and rsyncs that directory. DEPLOY_TARGET_OCAT must point to the site root that should contain both, for example /var/www/example/.
PHP-FPM needs write access only to app/content/ and app/cache/. The token is a file, not a directory. Do not give the web user write access to app/ or the repository root: with write access to the parent directory, a compromised PHP process could replace the application.
install -d -o www-data -g www-data -m 0775 /var/www/example/app/content /var/www/example/app/cache
php -r 'echo bin2hex(random_bytes(32)), "\n";' > /var/www/example/app/bio.token
chown www-data:www-data /var/www/example/app/bio.token
chmod 600 /var/www/example/app/bio.token
If the token cannot be created or read, MCP answers 401 and the public site keeps working.
The content file, backups and audit log contain the public contact address. On
shared hosting, keep them private to the web user:
chmod 600 /var/www/example/app/content/site.json \
/var/www/example/app/content/.audit.jsonl
chmod 600 /var/www/example/app/content/backups/*.json
Cache
The rendered HTML cache is invalidated automatically when any of these change:
- content revision;
content/site.json(content hash, including out-of-band edits);- content seed;
- page template;
public/styles.cssorpublic/script.js;- any file in
app/src/.
Keys use SHA-1 content hashes rather than mtimes. ETags are derived from the rendered HTML, so an out-of-band edit that is picked up by the cache key also produces a new validator. publish is still useful to force a clean slate, but is normally not needed after a file edit.
After deploying new PHP code, reload PHP-FPM (or keep opcache.validate_timestamps=1); the HTML cache cannot compensate for stale opcache bytecode.
Security model
- Bearer token read from
MCP_TOKEN,BIO_TOKEN_FILE, orapp/bio.token; must be at least 32 URL-safe characters; compared withhash_equals. /mcp.phpcaps the body at 1 MiB and validates the token before reading it.public/is the only document root. Source, templates, content, cache and token are outside it.- Whole-tree schema validation before every write; invalid content never reaches disk. Asset paths are checked against
public/assets/, email items must matchsettings.email, and text/count/size limits apply. - Atomic writes (
tmp+rename) under an exclusive lock; short writes are rejected. - Backup of the previous revision before every write, including the seed on the first write; the last 20 are kept as
site-revNNN.json. - Audit log at
app/content/.audit.jsonl, including the tool/action name. - CSP without
unsafe-inline: inline theme bootstrap is allow-listed by SHA-256 hash, and GA4 is loaded from the external script; HSTS,X-Frame-Options: DENY,Referrer-Policy,Permissions-PolicyandX-Content-Type-Optionsare also sent. - All user content is escaped; JSON-LD uses
JSON_HEX_TAG; onlyhttp(s)andmailtolinks are accepted. - CSS/JS URLs carry a content-version query so a deploy does not leave browsers on stale assets.
- Google Fonts is not loaded; Inter is self-hosted from
public/assets/fonts/. - The app removes
X-Powered-By; keepexpose_php=Off,display_errors=Offandlog_errors=Onin production as the first line of defence. - Serve the site over HTTPS. The app sends HSTS but does not redirect HTTP to HTTPS; configure that at the web server. HSTS deliberately omits
includeSubDomainsso the setting stays safe on shared domains.
Security reports: see SECURITY.md.
Recovery
cp app/content/backups/site-rev003.json app/content/site.json
rm -f app/cache/*.html app/cache/*.key app/cache/*.tmp
Analytics
GA4 is off by default. An empty ga4 string means no tag and no request to googletagmanager.com.
"settings": { "ga4": "G-XXXXXXXXXX" }
Switch it at runtime through MCP:
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"update_settings","arguments":{"ga4":"G-XXXXXXXXXX","rev":1}}}
rev is required on every mutation; read get_content first to get the current revision.
Disable with "ga4": "". UA- properties are rejected.
GA4 sets cookies, so where consent is required this switch alone is not enough. The page does not ship a consent banner.
Testing
php -d xdebug.mode=coverage tests/run.php # 195 unit tests, 100% line coverage gate
php tests/http.php # 16 end-to-end checks over real sockets (needs curl)
npm i --no-save --no-package-lock playwright axe-core # test-only
npx playwright install chromium
php -S 127.0.0.1:8123 -t public tests/router.php &
node tests/landing.audit.js # 76 browser checks (Playwright + axe-core)
tests/run.php fails if any executable line in app/src, public/index.php, public/mcp.php or app/templates/page.php is not covered. Coverage is measured by Xdebug; there is no PHPUnit and no Composer.
The Playwright suite checks the axe-core WCAG rules, contrast in both themes, 44px touch targets, no horizontal overflow from 320 to 2560px, CLS, JSON-LD, hreflang, the clipboard fallback, and Alt+Shift+T / Alt+Shift+L keyboard shortcuts. axe-core is automated coverage, not a full WCAG audit.
Unit: 195 passed, 100.00% (1116/1116 lines)
HTTP: 16 passed
Playwright: 76 passed
Project policy
- No framework, no Composer, no runtime NPM dependencies.
- No build step.
- No application logging; content mutations are recorded in the audit log.
- No domain baked into the code: set
settings.siteUrlin the content tree. - The README stays domain-agnostic; the live URL belongs in the repository description.
Legacy
.legacy/ contains a frozen static HTML version kept for reference. It is not deployed and not maintained.
License
MIT License. See LICENSE.
The self-hosted Inter font is licensed under the SIL Open Font License; see public/assets/fonts/LICENSE.txt. Icon licenses are listed in THIRD_PARTY_NOTICES.md.
Yorumlar (0)
Yorum birakmak icin giris yap.
Yorum birakSonuc bulunamadi