Skip to content

Add MCP tools to list published posts and read their LinkedIn stats #2399

Open

Description

@sweetmantech

Tracking issue for exposing two existing REST capabilities, GET /api/posts and GET /api/posts/{id}/stats, as MCP tools on the Recoup MCP server (https://api.recoupable.dev/mcp). Status: in progress, docs#40 and api#1246 open as drafts. Context, out of scope: guest recaps need LinkedIn impressions for posts Recoup published (Sean's recap had them via app#2351), and today an MCP agent has no way to read them.

Goal

Agents connected with an API key or a full mcp:tools OAuth grant can:

  • list the account's published posts (GET /api/posts -> get_published_posts), with optional artist_account_id, platform, status, limit (1-50, default 20) and offset, returning each post's id, platform, post_url, status and publish time;
  • read one published post's platform analytics (GET /api/posts/{id}/stats -> get_published_post_stats), taking a post id and returning the same stats object as REST: impressions, unique impressions, clicks, likes, comments, shares, engagement, and video views, viewers and watch time for video posts. LinkedIn company-page posts only; $0.001 per successful read.

REST and MCP share one domain implementation each, extracted from the current handlers: getPosts from lib/publishing/getPostsHandler.ts and getPostStats from lib/publishing/stats/getPostStatsHandler.ts. REST response shapes and status codes stay unchanged. Tools live in a new lib/mcp/tools/posts/ and are classified in lib/mcp/oauth/fullOAuthToolPolicy.ts, scripts/mcp-oauth/tool-policy.json and docs/mcp-oauth-tool-qualification.md. The limited mcp:read / mcp:write grant keeps its current tools.

PRs (updated 2026-11-18)

PR Item State
docs#40 mcp-server.mdx "Published posts and stats" contract for the two tools (pending note), manifest.json + llms-full.txt rebuilt open (draft) -- preview shows the section (check); main merged in Nov 18 to clear a generated-manifest conflict; CI green
api#1246 shared getPosts / getPostStats, get_published_posts + get_published_post_stats tools, OAuth policy entries, tests open (draft) -- preview: tool list, auth and every error case pass, no charge (results); main merged in Nov 18 (OAuth policy now carries destructive/openWorld; catalog 96 tools); CI green; Tom post happy path waits for production after merge
docs#TBD after api merges: drop the pending note, pin operation-inventory.json to the merged api commit (two new static MCP registrations) not started

Merge sequencing: docs (contract) -> api -> docs (inventory pin). The first docs PR is the contract the api PR implements, so it leads. The inventory refresh reads the merged api source, so it follows. No database migration.

Open -- next up (in merge order)

  • Docs contract for the two tools. (docs#40)
    • Why: documentation-driven development; docs#38 is the precedent for MCP tool contracts.
    • Fix: add a "Published posts and stats" section to content/docs/source/mcp-server.mdx after "Social scrapes and posts", marked pending api#1246; state inputs, the returned envelopes, the $0.001 charge, the LinkedIn company-page limit, and how REST errors map to tool errors. Run pnpm docs:build and commit the regenerated manifest.json and llms-full.txt.
    • Done when: pnpm docs:check, pnpm test, pnpm type-check and pnpm lint pass, and the preview page shows the section.
  • Extract getPosts and getPostStats. (api#1246)
    • Why: MCP tools must not call HTTP routes or copy handler logic (CLAUDE.md DRY rule; app#2396 pattern with runArtistSocialsScrape).
    • Fix: getPosts({ accountId, artistAccountId?, status?, platform?, limit, offset }) returns mapped posts. getPostStats({ accountId, postId }) keeps today's order (lookup, access, published, LinkedIn company page, URN, connection, credit gate, LinkedIn read, charge) and returns a discriminated result (ok, insufficient_credits, or rejected with today's REST status and message) that each caller maps to its own shape. Handlers keep id/query validation and auth.
    • Done when: the existing getPostsHandler* and getPostStatsHandler* tests pass (the stats handler tests now mock checkCreditsAvailable, which getPostStats calls, instead of ensureCreditsOrShortCircuit), plus unit tests for each result kind.
  • get_published_posts and get_published_post_stats MCP tools. (api#1246)
    • Why: the MCP has no posts or stats tool; get_artist_posts reads scraped posts from a different table, and scraped LinkedIn URLs carry no scheduled_posts id, so they cannot feed stats.
    • Fix: register both in lib/mcp/tools/posts/, reusing getPostsQuerySchema limits for the list tool and a uuid id for the stats tool; account comes from resolveAccountId, never from input. Add both to fullOAuthToolPolicy.ts, scripts/mcp-oauth/tool-policy.json and docs/mcp-oauth-tool-qualification.md, and update the fullOAuthCatalog tool count. Register-tool tests mirror registerScrapeArtistSocialsTool.test.ts.
    • Done when: on the api preview, tools/list includes both; get_published_posts with platform: "linkedin" lists one of Tom Sarig's LinkedIn clip posts; get_published_post_stats on that post returns numbers matching GET /api/posts/{id}/stats for the same post and charges once; a non-uuid id, an unknown id, a non-LinkedIn post and an unauthenticated call each return the expected tool error, with no charge.
  • Docs follow-up after the api release.
    • Fix: drop the pending note and run scripts/refresh-contract-inventory.py --api against the merged api commit, as docs#39 did.
    • Done when: --check passes and the inventory lists the two new static registrations.

Architecture decisions

  • "published" in both names. get_artist_posts already exists and returns scraped posts (lib/posts/getArtistPosts.ts); these tools read scheduled_posts, which Recoup itself published.
  • Stats is a paid read. It changes nothing, so it is readOnly: true, destructive: false and openWorld: true (it calls LinkedIn) with a policy notice stating the $0.001 charge, and mcp:read + mcp:spend in tool-policy.json, like search_web and web_deep_research. That differs from scrape_artist_socials (app#2396), which is a write because it starts runs. get_published_posts is free: readOnly: true, destructive: false, openWorld: false, mcp:read.
  • No account_id input. CLAUDE.md forbids account ids in tool schemas, and the full OAuth wrapper strips them anyway. The list tool scopes to the authenticated account; artist_account_id stays as a filter, checked by the OAuth artist gate.
  • Credit gate before LinkedIn, charge after success, unchanged from REST: a failed read costs nothing.

Source references

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions