Search by

socialmcp / socialmcp-php

mshahbazm

Official PHP SDK for SocialMCP: post and schedule to X, LinkedIn and more from your code.

v0.1.0 2026-12-03 07:47 UTC

This package is auto-updated.

Last update: 2026-12-03 09:58:12 UTC


README

Packagist CI

Post and schedule to X (Twitter), LinkedIn and more from your PHP app. Write the post once; SocialMCP checks it fits every network, threads it where it can, and puts it on your calendar, where you can see and edit it before it goes out.

  • Typed, readonly response objects (PHPStan level max)
  • Works with any framework, with a short Laravel setup
  • Safe retries: a post is never sent twice
  • Large videos upload straight from disk

Install

composer require socialmcp/socialmcp-php

Requires PHP 8.1 or newer. HTTP goes through Guzzle 7.

Get an API key

Sign up at getsocialmcp.com (start free, no card needed), connect your accounts, then create a key under Settings → Developers.

export SOCIALMCP_API_KEY=smcp_...

Post now

$social = new SocialMCP\Client(); // reads SOCIALMCP_API_KEY

$post = $social->posts->create([
    'text' => 'Shipped dark mode today 🌙',
    'networks' => ['x', 'linkedin'],
]);

foreach ($post->targets as $target) {
    echo "{$target->network}: {$target->status}\n";
}

Examples

A thread

On X, Bluesky and Threads each part is its own post in a chain. On LinkedIn the parts are joined into one post (you can change that in Settings).

$social->posts->create([
    'parts' => [
        ['text' => 'We rebuilt our editor from scratch. Here is what we learned 🧵'],
        ['text' => '1. Start with the undo stack, not the toolbar.'],
        ['text' => '2. Measure typing latency on the slowest laptop you can find.'],
    ],
]);

Schedule it

$social->posts->create([
    'text' => 'Our Black Friday sale starts now',
    'scheduledAt' => new DateTimeImmutable('2026-11-27 09:00', new DateTimeZone('America/New_York')),
]);

Dates can be any DateTimeInterface (Carbon too) or an ISO 8601 string.

Put it in your next posting slot

Set the times you like to post once, and new posts fill the next free slot, like a queue.

$social->postingTimes->set([
    'times' => [['time' => '09:00', 'days' => ['mon', 'tue', 'wed', 'thu', 'fri']]],
]);

$post = $social->posts->create(['text' => 'Tip of the day: …', 'postingTime' => 'next']);
echo $post->scheduledAt;

Images and videos

$image = $social->media->upload('screenshot.png', ['alt' => 'The new dashboard in dark mode']);
$video = $social->media->upload('demo.mp4', ['alt' => 'A 30-second tour']); // up to 1 GB

$social->posts->create([
    'parts' => [['text' => 'Dark mode is here', 'mediaIds' => [$image->id]]],
]);

// Or from a link (Dropbox and Google Drive share links work too):
$fromLink = $social->media->create(['url' => 'https://example.com/launch.mp4']);

media->upload() takes a file path, an SplFileInfo, an open stream from fopen(), or a PSR-7 stream. For bytes already in memory, use GuzzleHttp\Psr7\Utils::streamFor($bytes) and pass a filename. Videos go up in parts, read from disk one part at a time.

A different version for each network

$social->posts->create([
    'text' => 'v2.0 is out: faster sync, offline mode and a new API.',
    'overrides' => [
        'linkedin' => [['text' => 'Today we released v2.0. Three things our customers asked for most: …']],
    ],
]);

List posts

// One page
$page = $social->posts->list(['status' => 'scheduled', 'limit' => 50]);
$page->posts;      // list<Post>
$page->nextCursor; // pass as 'cursor' for the next page

// Every page, fetched as you go
foreach ($social->posts->listAll(['status' => ['failed', 'missed']]) as $post) {
    $social->posts->retry($post->id);
}

// Catch every post that published or failed since you last checked
$lastChecked = new DateTimeImmutable('-1 hour');
foreach ($social->posts->listAll(['updatedSince' => $lastChecked, 'status' => ['published', 'partial', 'failed']]) as $post) {
    echo $post->status, ' ', $post->id, PHP_EOL;
    $lastChecked = $post->updatedAt; // oldest change first, so this is where to pick up next time
}

Edit, cancel, delete

$social->posts->update($post->id, ['text' => 'Fixed a typo', 'scheduledAt' => '2026-12-01T10:00:00Z']);
$social->posts->cancel($post->id);
$social->posts->delete($post->id, ['fromNetworks' => true]); // also removes it from X, LinkedIn…

Accounts, networks and settings

$accounts = $social->accounts->list();
$networks = $social->networks->list(); // character limits, threads, images per post
$me = $social->me(); // you, your plan and what you've used this month
$social->settings->update(['timezone' => 'Europe/Berlin']);

// A link that opens the dashboard to connect another account
$link = $social->accounts->connect('linkedin');
echo $link->url;

Response objects

Every response is a readonly object with typed properties ($post->id, $post->targets[0]->url). Fields newer than this SDK are never dropped: read them with array access, or get everything as an array.

$post['someNewField'];
$post->toArray();
json_encode($post);

Errors

Every exception is a SocialMCP\Exception\SocialMCPException. When the API says no, you get an ApiException with a stable errorCode to branch on:

use SocialMCP\Exception\ApiException;
use SocialMCP\Exception\RateLimitException;

try {
    $social->posts->create(['text' => $longText, 'networks' => ['x']]);
} catch (RateLimitException $e) {
    // A posting limit: the daily limit, or another post on that account too close in time
} catch (ApiException $e) {
    if ($e->errorCode !== 'too_long') {
        throw $e;
    }
    echo $e->getMessage(); // "Too long for X (312/280)."
    print_r($e->details);  // ['network' => 'x', …]
}

$e->status (also getCode()) is the HTTP status, and $e->headers the response headers.

Status Exception (in SocialMCP\Exception)
400 BadRequestException
401 AuthenticationException
403 PermissionDeniedException
404 NotFoundException
409 ConflictException
410 GoneException
413 PayloadTooLargeException
415 UnsupportedMediaTypeException
422 UnprocessableEntityException
429 RateLimitException
5xx InternalServerException
no answer ApiConnectionException, ApiTimeoutException

Retries

Network errors, timeouts and 5xx answers are retried twice with backoff, honouring Retry-After. posts->create() sends an idempotency key, so a retry never posts twice; pass your own idempotencyKey to make your own retries (a queued job, say) safe too. Posting limits (429) are not retried.

Configuration

$social = new SocialMCP\Client([
    'apiKey' => 'smcp_...', // default: SOCIALMCP_API_KEY
    'baseUrl' => 'https://getsocialmcp.com/api/v1', // default: SOCIALMCP_BASE_URL, then this
    'timeout' => 60, // seconds
    'maxRetries' => 2,
    'httpClient' => new GuzzleHttp\Client(['proxy' => 'http://proxy:8080']), // optional
]);

// Per request
$social->posts->list([], ['timeout' => 5, 'maxRetries' => 0]);

Laravel

No extra package needed. Add the key to .env:

SOCIALMCP_API_KEY=smcp_...

Add it to config/services.php, so it still works with php artisan config:cache:

'socialmcp' => [
    'key' => env('SOCIALMCP_API_KEY'),
],

Bind the client once in App\Providers\AppServiceProvider:

use SocialMCP\Client;

public function register(): void
{
    $this->app->singleton(Client::class, fn () => new Client([
        'apiKey' => config('services.socialmcp.key'),
    ]));
}

Then type-hint it anywhere: controllers, jobs, commands.

use SocialMCP\Client;

class AnnounceRelease implements ShouldQueue
{
    use Queueable;

    public function __construct(public Release $release) {}

    public function handle(Client $social): void
    {
        $social->posts->create([
            'text' => "{$this->release->name} is out: {$this->release->url}",
            'postingTime' => 'next',
            'idempotencyKey' => "release-{$this->release->id}", // a retried job never posts twice
        ]);
    }
}

Uploads from a form go straight through: $social->media->upload($request->file('video'), ['alt' => $request->input('alt')]) uses the file's own name, so a video is sent as a video.

Common questions

Do I need my own X or LinkedIn developer app? No. You connect your accounts in SocialMCP once, with each network's normal sign-in, and the SDK posts to all of them with one SocialMCP API key. No developer accounts, app reviews or tokens to refresh.

Which networks can I post to? X (Twitter), LinkedIn and Bluesky today, with more on the way. The API's networks list gives each one's character limit, thread support and images per post.

What if a post is too long for one network? SocialMCP checks every part against each network's limits before it accepts the post, and the error says which network and part, and by how much. A post written in parts goes out as a thread where the network has threads, and as one post where it doesn't.

Can I see or change a post before it goes out? Yes. Scheduled posts appear on your SocialMCP calendar, where you can edit, reschedule or cancel them, and the SDK can do the same from your code.

Is it free? You can start free, no card needed. Paid plans are on the pricing page.

Can an AI agent post for me instead? Yes. Claude, ChatGPT, Cursor and other agents connect to the same account through the SocialMCP MCP server, so posts from your agent and from your code land on one calendar.

Also available

Node.js · Python · Go · Ruby · Java · .NET · Rust · CLI · n8n · Make · MCP server for AI agents

Development

composer install
composer test      # unit tests against a local fake API server
composer analyse   # PHPStan, level max
composer lint      # PSR-12 via php-cs-fixer

# Live tests against a real API (they schedule posts 30 days out and delete them; nothing goes live)
SOCIALMCP_TEST_API_KEY=smcp_... SOCIALMCP_TEST_BASE_URL=http://localhost:8787/api/v1 composer test

Links

License

MIT