Repository navigation
Description
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 optionalartist_account_id,platform,status,limit(1-50, default 20) andoffset, returning each post'sid,platform,post_url,statusand publish time; - read one published post's platform analytics (
GET /api/posts/{id}/stats->get_published_post_stats), taking a postidand returning the samestatsobject 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.mdxafter "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. Runpnpm docs:buildand commit the regeneratedmanifest.jsonandllms-full.txt. - Done when:
pnpm docs:check,pnpm test,pnpm type-checkandpnpm lintpass, and the preview page shows the section.
- Extract
getPostsandgetPostStats. (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, orrejectedwith 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*andgetPostStatsHandler*tests pass (the stats handler tests now mockcheckCreditsAvailable, whichgetPostStatscalls, instead ofensureCreditsOrShortCircuit), plus unit tests for each result kind.
- Why: MCP tools must not call HTTP routes or copy handler logic (CLAUDE.md DRY rule; app#2396 pattern with
-
get_published_postsandget_published_post_statsMCP tools. (api#1246)- Why: the MCP has no posts or stats tool;
get_artist_postsreads scraped posts from a different table, and scraped LinkedIn URLs carry noscheduled_postsid, so they cannot feed stats. - Fix: register both in
lib/mcp/tools/posts/, reusinggetPostsQuerySchemalimits for the list tool and a uuididfor the stats tool; account comes fromresolveAccountId, never from input. Add both tofullOAuthToolPolicy.ts,scripts/mcp-oauth/tool-policy.jsonanddocs/mcp-oauth-tool-qualification.md, and update thefullOAuthCatalogtool count. Register-tool tests mirrorregisterScrapeArtistSocialsTool.test.ts. - Done when: on the api preview,
tools/listincludes both;get_published_postswithplatform: "linkedin"lists one of Tom Sarig's LinkedIn clip posts;get_published_post_statson that post returns numbers matchingGET /api/posts/{id}/statsfor 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.
- Why: the MCP has no posts or stats tool;
- Docs follow-up after the api release.
- Fix: drop the pending note and run
scripts/refresh-contract-inventory.py --apiagainst the merged api commit, as docs#39 did. - Done when:
--checkpasses and the inventory lists the two new static registrations.
- Fix: drop the pending note and run
Architecture decisions
- "published" in both names.
get_artist_postsalready exists and returns scraped posts (lib/posts/getArtistPosts.ts); these tools readscheduled_posts, which Recoup itself published. - Stats is a paid read. It changes nothing, so it is
readOnly: true,destructive: falseandopenWorld: true(it calls LinkedIn) with a policy notice stating the $0.001 charge, andmcp:read+mcp:spendintool-policy.json, likesearch_webandweb_deep_research. That differs fromscrape_artist_socials(app#2396), which is a write because it starts runs.get_published_postsis free:readOnly: true,destructive: false,openWorld: false,mcp:read. - No
account_idinput. 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_idstays 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
- REST:
app/api/posts/route.ts,app/api/posts/[id]/stats/route.ts - LinkedIn read through Composio:
lib/publishing/stats/getLinkedInPostAnalytics.ts,lib/publishing/proxyLinkedIn.ts - Sibling MCP tools and shared-function pattern:
lib/mcp/tools/artistSocials/, app#2396 - Full OAuth wrapper:
lib/mcp/oauth/registerFullOAuthTools.ts,lib/mcp/oauth/prepareFullOAuthTool.ts
Activity