Repository navigation
feat(mcp): add scrape_artist_socials, get_scraper_results, get_artist_posts tools - #1243
Conversation
…_posts tools Expose the existing socials scrape, Apify run results and artist posts REST capabilities as MCP tools so agents can pull an artist's recent social posts. - Extract startArtistSocialsScrape and getScraperRunResults so the REST handlers and the MCP tools share the same domain logic. - scrape_artist_socials: artist access check, credit gate for every linked profile, charges only runs that started (write, spends credits). - get_scraper_results: run status plus dataset once SUCCEEDED (read; credential required, not owner-scoped, matching chat#1840). - get_artist_posts: saved posts with the REST pagination defaults (read). - Classify all three in the full OAuth policy and tool inventory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
usage_events.model_id is documented as METHOD /route/pattern for API charges; use the REST route's label so MCP and REST scrapes group together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ith REST Address the CodeRabbit Solid & Clean Code finding on #1243: - runArtistSocialsScrape now owns the access check, socials lookup, credit gate and start; POST /api/artist/socials/scrape and scrape_artist_socials both call it and only map its result (403/402/200 vs tool result). One credit gate path (checkCreditsAvailable) for one rule. - getArtistPosts builds the { status, posts, pagination } envelope for both GET /api/artists/{id}/posts and get_artist_posts. - ARTIST_SOCIALS_SCRAPE_MODEL_ID replaces the hardcoded usage label. REST wire shapes are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preview verification (api-cl5c7asqh-recoup.vercel.app, a23eae9)Run from a Vercel Sandbox against the PR preview. API key minted on the preview itself via
Notes
Generated by Claude Code |
Every profile's start can fail (bad Apify token, unsupported platform). The tool used to report success:true with all-null runs, so an agent could not tell nothing happened. Return an error listing each failure instead; credits are charged only for started runs, so the message says none were charged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Real scrape on the preview (api-gq45fkp8y-recoup.vercel.app, 2b67e27)Run from a non-persistent Vercel Sandbox (network limited to the preview host) after the preview's APIFY_TOKEN fix. Fresh
Not verified in this run
The no-run fix in 2b67e27 (a tool error when every profile fails to start) is covered by unit tests; this run took the started path. Generated by Claude Code |
Folds the cost into the first sentence and adds a test that the description stays at three sentences or fewer and still states the cost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remaining preview checks (api-ojbhaxpom-recoup.vercel.app, 6c1a165)Run from a non-persistent Vercel Sandbox (network limited to the preview host), with fresh
Notes
Generated by Claude Code |
There was a problem hiding this comment.
11 issues found across 26 files
Confidence score: 3/5
- The API-key paths in
registerGetScraperResultsToolandregisterScrapeArtistSocialsToolhave no account-scoped request limit, so repeated polling or scrape launches can drive unbounded work. Add per-account limits to both handlers. fullOAuthToolPolicy.tsunderquotes multi-profile runs because the $0.01-per-post surcharge applies to each profile that actually starts. State the per-started-profile formula so callers can assess the cost.runArtistSocialsScrape.tsuses the default 100-social limit, so artists with more linked socials can have profiles silently skipped. Pass the higher limit used by the sibling call sites.startArtistSocialsScrape.tsclassifies platforms from the raw URL, so mixed-case URLs likeX.com/...can be stored asnoneeven when the run starts. Normalize the URL before classification.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/mcp/oauth/fullOAuthToolPolicy.ts">
<violation number="1" location="lib/mcp/oauth/fullOAuthToolPolicy.ts:26">
P2: Custom agent: **Enforce Clear Code Style and Maintainability Practices**
These policy entries add 11 lines to an already oversized module, bringing it to 141 lines against Rule 3’s under-100-line limit. Split the policy inventory into cohesive modules and keep this file under 100 lines.</violation>
<violation number="2" location="lib/mcp/oauth/fullOAuthToolPolicy.ts:97">
P2: This underquotes multi-profile runs: the `$0.01 × posts` surcharge applies per profile, and charges apply only to profiles that actually start. State the per-started-profile formula so OAuth callers can evaluate the cost before confirming.</violation>
</file>
<file name="lib/mcp/tools/artistSocials/registerScrapeArtistSocialsTool.ts">
<violation number="1" location="lib/mcp/tools/artistSocials/registerScrapeArtistSocialsTool.ts:33">
P2: Custom agent: **API Design Consistency and Maintainability**
API-key callers can launch scrapes through this tool without a request-velocity limit. Add an account-scoped limiter before `runArtistSocialsScrape` so repeated calls cannot bypass throttling.</violation>
<violation number="2" location="lib/mcp/tools/artistSocials/registerScrapeArtistSocialsTool.ts:68">
P2: This message is wrong when the artist has linked socials, but none are on a scrapable platform: `scrapeProfileUrl` returns null for them and they are dropped, so `runs` comes back empty. Report that unsupported profiles were skipped instead of saying no socials are linked. The tool description's "Returns one run per profile" also overstates this.</violation>
</file>
<file name="lib/mcp/tools/artistSocials/registerGetScraperResultsTool.ts">
<violation number="1" location="lib/mcp/tools/artistSocials/registerGetScraperResultsTool.ts:32">
P2: Custom agent: **API Design Consistency and Maintainability**
This polling tool invites repeated calls, but its API-key handler has no rate limit; enforce a per-account limit before fetching run results to prevent unbounded polling.</violation>
</file>
<file name="lib/mcp/tools/artistSocials/__tests__/registerGetArtistPostsTool.test.ts">
<violation number="1" location="lib/mcp/tools/artistSocials/__tests__/registerGetArtistPostsTool.test.ts:77">
P3: This test only checks `success === false`, so it would still pass if the error message changed or the envelope were wrong. Assert the full error envelope with the `Authentication required.` message, as the other error-path tests do.</violation>
</file>
<file name="lib/apify/__tests__/getScraperRunResults.test.ts">
<violation number="1" location="lib/apify/__tests__/getScraperRunResults.test.ts:31">
P3: The new tests don't cover the SUCCEEDED branch where the dataset returns no items or `defaultDatasetId` is missing, even though the JSDoc promises `data` is omitted in that case. Add a case that mocks a SUCCEEDED run with no `defaultDatasetId` (or `listItems` returning no `items`) and asserts `data` is absent.</violation>
</file>
<file name="docs/mcp-oauth-tool-qualification.md">
<violation number="1" location="docs/mcp-oauth-tool-qualification.md:59">
P3: The source link for this row points to `startArtistSocialsScrape.ts`, which does not contain the artist access check or the pre-scrape credit gate this row describes. Link to `runArtistSocialsScrape.ts` instead, since that is where both gates run.</violation>
</file>
<file name="lib/artist/runArtistSocialsScrape.ts">
<violation number="1" location="lib/artist/runArtistSocialsScrape.ts:45">
P2: This call uses the default `limit` of 100 in `selectAccountSocials`, so an artist with more linked socials gets only the first 100 scraped and gated without any signal. Pass `limit: 10000`, as the sibling call sites do.</violation>
</file>
<file name="lib/artist/startArtistSocialsScrape.ts">
<violation number="1" location="lib/artist/startArtistSocialsScrape.ts:65">
P2: The platform is classified from the raw URL, so a mixed-case profile URL such as `X.com/...` is stored as `none` for a run that started. Lowercase the URL before classifying it, as `registerRootApifyRun` does.</violation>
</file>
<file name="lib/mcp/tools/artistSocials/registerGetArtistPostsTool.ts">
<violation number="1" location="lib/mcp/tools/artistSocials/registerGetArtistPostsTool.ts:57">
P3: The MCP handler repeats the REST access gate inline but skips the artist-existence check, so the two surfaces diverge. An org admin querying a nonexistent artist ID gets an empty success here, while REST returns 404 "Artist not found". Move the artist lookup and access check into a shared validator that both `validateGetArtistPostsRequest` and this tool call, as `runArtistSocialsScrape` does for the scrape tool.
(Based on your team's feedback about centralizing handler validation.)</violation>
</file>
Architecture diagram
sequenceDiagram
participant Agent as AI Agent (MCP Client)
participant McpServer as MCP Server
participant ApiKey as API Key / OAuth Auth
participant ToolReg as Tool Registry
participant ShareLogic as Shared Domain Logic
participant Db as Supabase DB
participant Credits as Credit Service
participant Api as External APIs
Note over Agent,Api: MCP Tools for Artist Social Scraping - Current State Flow
%% Tool Registration Phase
Agent->>ApiKey: Connect with API key or OAuth token
ApiKey->>McpServer: Authenticate request
McpServer->>ToolReg: Initialize with grants (OAuth mcp:read/mcp:write/mcp:spend)
ToolReg->>McpServer: Register scrape_artist_socials, get_scraper_results, get_artist_posts
McpServer-->>Agent: Tool list available
%% scrape_artist_socials - Write tool with credit gating
Agent->>McpServer: call scrape_artist_socials(artist_account_id, posts?)
alt API Key caller
McpServer->>McpServer: Resolve accountId from API key
else Full OAuth caller
McpServer->>McpServer: Resolve accountId + check mcp:write/mcp:spend scope
end
McpServer->>ShareLogic: runArtistSocialsScrape(accountId, artistAccountId, posts)
ShareLogic->>ShareLogic: checkAccountArtistAccess(accountId, artistAccountId)
alt Access denied
ShareLogic-->>McpServer: { kind: "forbidden" }
McpServer-->>Agent: Error "Access denied"
else Access granted
ShareLogic->>Db: selectAccountSocials(artistAccountId)
Db-->>ShareLogic: Linked social profiles
alt No linked socials
ShareLogic-->>McpServer: { kind: "started", runs: [] }
McpServer-->>Agent: Success with no runs
else Credits gate
ShareLogic->>Credits: checkCreditsAvailable(accountId, cost × profiles)
alt Insufficient credits
Credits-->>ShareLogic: { kind: "insufficient_credits" }
ShareLogic-->>McpServer: Shortfall details
McpServer-->>Agent: Error "Insufficient credits"
else Credits available
ShareLogic->>ShareLogic: startArtistSocialsScrape()
ShareLogic->>Api: Launch Apify scrape per profile
loop Each social profile
Api-->>ShareLogic: Started | Failed result per profile
end
alt At least one run started
ShareLogic->>Credits: deduct per started run (only if actually started)
ShareLogic->>Db: upsertApifyScraperRuns(batch)
ShareLogic-->>McpServer: { kind: "started", runs }
McpServer-->>Agent: Success with per-profile run results
else All runs failed
ShareLogic->>Credits: No deduction (no runs started)
ShareLogic-->>McpServer: { kind: "started", runs (all errors) }
McpServer-->>Agent: Error "No runs started. No credits charged."
end
end
end
end
%% get_scraper_results - Read tool (not owner-scoped, credential only)
Agent->>McpServer: call get_scraper_results(runId)
McpServer->>McpServer: Resolve accountId from auth
McpServer->>ShareLogic: getScraperRunResults(runId)
ShareLogic->>Api: Fetch Apify run status
alt Run SUCCEEDED
Api-->>ShareLogic: Status + defaultDatasetId
ShareLogic->>Api: Fetch dataset items
Api-->>ShareLogic: Scraped data
ShareLogic-->>McpServer: { status, dataset_id, data }
else Run still RUNNING/READY
Api-->>ShareLogic: Status + datasetId
ShareLogic-->>McpServer: { status, dataset_id } (no data)
else Run FAILED/ABORTED/TIMED-OUT
Api-->>ShareLogic: Error status
ShareLogic-->>McpServer: { status, dataset_id }
end
McpServer-->>Agent: Run status + data (when SUCCEEDED)
%% get_artist_posts - Read tool with artist gate
Agent->>McpServer: call get_artist_posts(artist_account_id, page?, limit?)
McpServer->>McpServer: Resolve accountId from auth
McpServer->>ShareLogic: checkAccountArtistAccess(accountId, artistAccountId)
alt Access denied
ShareLogic-->>McpServer: Denied
McpServer-->>Agent: Error "Access denied"
else Access granted
McpServer->>ShareLogic: getArtistPosts(artistAccountId, page=1, limit=20)
ShareLogic->>Db: selectPosts(artistAccountId, page, limit)
Db-->>ShareLogic: Posts + totalCount
ShareLogic-->>McpServer: Posts envelope { status, posts, pagination }
McpServer-->>Agent: Paginated posts with total_pages
end
%% Error handling for all tools
opt Any tool throws
ShareLogic-->>McpServer: Exception caught
McpServer-->>Agent: Redacted error message
end
Note over ShareLogic,Api: Shared domain logic across REST + MCP routes
Note over ShareLogic: Usage label: POST /api/artist/socials/scrape
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| export_release_pack: { readOnly: true }, | ||
| list_artists: { readOnly: true }, | ||
| get_artist_socials: { readOnly: true }, | ||
| get_artist_posts: { readOnly: true }, |
There was a problem hiding this comment.
P2: Custom agent: Enforce Clear Code Style and Maintainability Practices
These policy entries add 11 lines to an already oversized module, bringing it to 141 lines against Rule 3’s under-100-line limit. Split the policy inventory into cohesive modules and keep this file under 100 lines.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/oauth/fullOAuthToolPolicy.ts, line 26:
<comment>These policy entries add 11 lines to an already oversized module, bringing it to 141 lines against Rule 3’s under-100-line limit. Split the policy inventory into cohesive modules and keep this file under 100 lines.</comment>
<file context>
@@ -23,6 +23,11 @@ export const fullOAuthToolPolicy: Record<string, ToolPolicy> = {
export_release_pack: { readOnly: true },
list_artists: { readOnly: true },
get_artist_socials: { readOnly: true },
+ get_artist_posts: { readOnly: true },
+ get_scraper_results: {
+ readOnly: true,
</file context>
| */ | ||
| export function registerScrapeArtistSocialsTool(server: McpServer): void { | ||
| server.registerTool( | ||
| "scrape_artist_socials", |
There was a problem hiding this comment.
P2: Custom agent: API Design Consistency and Maintainability
API-key callers can launch scrapes through this tool without a request-velocity limit. Add an account-scoped limiter before runArtistSocialsScrape so repeated calls cannot bypass throttling.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/artistSocials/registerScrapeArtistSocialsTool.ts, line 33:
<comment>API-key callers can launch scrapes through this tool without a request-velocity limit. Add an account-scoped limiter before `runArtistSocialsScrape` so repeated calls cannot bypass throttling.</comment>
<file context>
@@ -0,0 +1,83 @@
+ */
+export function registerScrapeArtistSocialsTool(server: McpServer): void {
+ server.registerTool(
+ "scrape_artist_socials",
+ {
+ description:
</file context>
| server.registerTool( | ||
| "get_scraper_results", | ||
| { | ||
| description: |
There was a problem hiding this comment.
P2: Custom agent: API Design Consistency and Maintainability
This polling tool invites repeated calls, but its API-key handler has no rate limit; enforce a per-account limit before fetching run results to prevent unbounded polling.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/artistSocials/registerGetScraperResultsTool.ts, line 32:
<comment>This polling tool invites repeated calls, but its API-key handler has no rate limit; enforce a per-account limit before fetching run results to prevent unbounded polling.</comment>
<file context>
@@ -0,0 +1,55 @@
+ server.registerTool(
+ "get_scraper_results",
+ {
+ description:
+ "Check a social scrape run started by scrape_artist_socials. Returns the run status (READY, RUNNING, SUCCEEDED, FAILED, ABORTED, TIMED-OUT) and, once SUCCEEDED, the scraped profile and post data. Call again later while the run is still RUNNING.",
+ inputSchema: getScraperResultsSchema,
</file context>
| return { kind: "forbidden" }; | ||
| } | ||
|
|
||
| const socials = await selectAccountSocials({ accountId: artistAccountId }); |
There was a problem hiding this comment.
P2: This call uses the default limit of 100 in selectAccountSocials, so an artist with more linked socials gets only the first 100 scraped and gated without any signal. Pass limit: 10000, as the sibling call sites do.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/artist/runArtistSocialsScrape.ts, line 45:
<comment>This call uses the default `limit` of 100 in `selectAccountSocials`, so an artist with more linked socials gets only the first 100 scraped and gated without any signal. Pass `limit: 10000`, as the sibling call sites do.</comment>
<file context>
@@ -0,0 +1,69 @@
+ return { kind: "forbidden" };
+ }
+
+ const socials = await selectAccountSocials({ accountId: artistAccountId });
+ if (!socials.length) return { kind: "started", runs: [] };
+
</file context>
| const socials = await selectAccountSocials({ accountId: artistAccountId }); | |
| const socials = await selectAccountSocials({ accountId: artistAccountId, limit: 10000 }); |
| return getToolResultSuccess({ | ||
| success: true, | ||
| runs: [], | ||
| message: "This artist has no linked social profiles to scrape.", |
There was a problem hiding this comment.
P2: This message is wrong when the artist has linked socials, but none are on a scrapable platform: scrapeProfileUrl returns null for them and they are dropped, so runs comes back empty. Report that unsupported profiles were skipped instead of saying no socials are linked. The tool description's "Returns one run per profile" also overstates this.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/artistSocials/registerScrapeArtistSocialsTool.ts, line 68:
<comment>This message is wrong when the artist has linked socials, but none are on a scrapable platform: `scrapeProfileUrl` returns null for them and they are dropped, so `runs` comes back empty. Report that unsupported profiles were skipped instead of saying no socials are linked. The tool description's "Returns one run per profile" also overstates this.</comment>
<file context>
@@ -0,0 +1,83 @@
+ return getToolResultSuccess({
+ success: true,
+ runs: [],
+ message: "This artist has no linked social profiles to scrape.",
+ });
+ }
</file context>
| message: "This artist has no linked social profiles to scrape.", | |
| message: "No scrapable social profiles were found. Linked profiles on unsupported platforms or without a profile URL were skipped.", |
| readOnly: false, | ||
| destructive: false, | ||
| notice: | ||
| "Spends account credits: $0.05 per linked profile plus $0.01 per requested post. Confirm before scraping.", |
There was a problem hiding this comment.
P2: This underquotes multi-profile runs: the $0.01 × posts surcharge applies per profile, and charges apply only to profiles that actually start. State the per-started-profile formula so OAuth callers can evaluate the cost before confirming.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/oauth/fullOAuthToolPolicy.ts, line 97:
<comment>This underquotes multi-profile runs: the `$0.01 × posts` surcharge applies per profile, and charges apply only to profiles that actually start. State the per-started-profile formula so OAuth callers can evaluate the cost before confirming.</comment>
<file context>
@@ -85,6 +90,12 @@ export const fullOAuthToolPolicy: Record<string, ToolPolicy> = {
+ readOnly: false,
+ destructive: false,
+ notice:
+ "Spends account credits: $0.05 per linked profile plus $0.01 per requested post. Confirm before scraping.",
+ },
update_pulse: { readOnly: false },
</file context>
| "Spends account credits: $0.05 per linked profile plus $0.01 per requested post. Confirm before scraping.", | |
| "Spends account credits: ($0.05 + $0.01 per requested post) per started profile. Confirm before scraping.", |
|
|
||
| it("requires authentication", async () => { | ||
| const result = await handler({ artist_account_id: ARTIST_ID }, extra()); | ||
| expect(text(result).success).toBe(false); |
There was a problem hiding this comment.
P3: This test only checks success === false, so it would still pass if the error message changed or the envelope were wrong. Assert the full error envelope with the Authentication required. message, as the other error-path tests do.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/artistSocials/__tests__/registerGetArtistPostsTool.test.ts, line 77:
<comment>This test only checks `success === false`, so it would still pass if the error message changed or the envelope were wrong. Assert the full error envelope with the `Authentication required.` message, as the other error-path tests do.</comment>
<file context>
@@ -0,0 +1,93 @@
+
+ it("requires authentication", async () => {
+ const result = await handler({ artist_account_id: ARTIST_ID }, extra());
+ expect(text(result).success).toBe(false);
+ expect(selectPosts).not.toHaveBeenCalled();
+ });
</file context>
|
|
||
| it("returns only the status for a run still in progress", async () => { | ||
| mockRun({ status: "RUNNING", defaultDatasetId: "d1" }); | ||
| expect(await getScraperRunResults("r1")).toEqual({ status: "RUNNING", dataset_id: "d1" }); |
There was a problem hiding this comment.
P3: The new tests don't cover the SUCCEEDED branch where the dataset returns no items or defaultDatasetId is missing, even though the JSDoc promises data is omitted in that case. Add a case that mocks a SUCCEEDED run with no defaultDatasetId (or listItems returning no items) and asserts data is absent.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/apify/__tests__/getScraperRunResults.test.ts, line 31:
<comment>The new tests don't cover the SUCCEEDED branch where the dataset returns no items or `defaultDatasetId` is missing, even though the JSDoc promises `data` is omitted in that case. Add a case that mocks a SUCCEEDED run with no `defaultDatasetId` (or `listItems` returning no `items`) and asserts `data` is absent.</comment>
<file context>
@@ -0,0 +1,39 @@
+
+ it("returns only the status for a run still in progress", async () => {
+ mockRun({ status: "RUNNING", defaultDatasetId: "d1" });
+ expect(await getScraperRunResults("r1")).toEqual({ status: "RUNNING", dataset_id: "d1" });
+ expect(apifyClient.dataset).not.toHaveBeenCalled();
+ });
</file context>
| | `create_new_artist` | W | Create artist; wrapper strips conversation-copy input; optional org gate | Unknown: no per-call quote/ceiling established at this boundary | No outbound recipient; authenticated response only | Unknown: no wrapper idempotency/accepted-work guarantee | [source](../lib/mcp/tools/artists/registerCreateNewArtistTool.ts) | | ||
| | `update_account_info` | W | Update artist profile; artist ID gate | Unknown: no per-call quote/ceiling established at this boundary | No outbound recipient; authenticated response only | Unknown: no wrapper idempotency/accepted-work guarantee | [source](../lib/mcp/tools/registerUpdateAccountInfoTool.ts) | | ||
| | `update_artist_socials` | W | Update artist social records; artist ID gate | Unknown: no per-call quote/ceiling established at this boundary | No outbound recipient; authenticated response only | Unknown: no wrapper idempotency/accepted-work guarantee | [source](../lib/mcp/tools/artistSocials/registerUpdateArtistSocialsTool.ts) | | ||
| | `scrape_artist_socials` | W | Start one Apify scrape per linked artist social; artist ID gate; register runs as one batch | Credit availability gate for all linked profiles ($0.05 each + $0.01 per requested post); charges only runs that started | Apify social scrapers; no message recipient | Unknown: each call starts new paid runs; no wrapper idempotency | [source](../lib/artist/startArtistSocialsScrape.ts) | |
There was a problem hiding this comment.
P3: The source link for this row points to startArtistSocialsScrape.ts, which does not contain the artist access check or the pre-scrape credit gate this row describes. Link to runArtistSocialsScrape.ts instead, since that is where both gates run.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/mcp-oauth-tool-qualification.md, line 59:
<comment>The source link for this row points to `startArtistSocialsScrape.ts`, which does not contain the artist access check or the pre-scrape credit gate this row describes. Link to `runArtistSocialsScrape.ts` instead, since that is where both gates run.</comment>
<file context>
@@ -56,6 +56,9 @@ Each source link identifies the registration callback or shared domain/executor
| `create_new_artist` | W | Create artist; wrapper strips conversation-copy input; optional org gate | Unknown: no per-call quote/ceiling established at this boundary | No outbound recipient; authenticated response only | Unknown: no wrapper idempotency/accepted-work guarantee | [source](../lib/mcp/tools/artists/registerCreateNewArtistTool.ts) |
| `update_account_info` | W | Update artist profile; artist ID gate | Unknown: no per-call quote/ceiling established at this boundary | No outbound recipient; authenticated response only | Unknown: no wrapper idempotency/accepted-work guarantee | [source](../lib/mcp/tools/registerUpdateAccountInfoTool.ts) |
| `update_artist_socials` | W | Update artist social records; artist ID gate | Unknown: no per-call quote/ceiling established at this boundary | No outbound recipient; authenticated response only | Unknown: no wrapper idempotency/accepted-work guarantee | [source](../lib/mcp/tools/artistSocials/registerUpdateArtistSocialsTool.ts) |
+| `scrape_artist_socials` | W | Start one Apify scrape per linked artist social; artist ID gate; register runs as one batch | Credit availability gate for all linked profiles ($0.05 each + $0.01 per requested post); charges only runs that started | Apify social scrapers; no message recipient | Unknown: each call starts new paid runs; no wrapper idempotency | [source](../lib/artist/startArtistSocialsScrape.ts) |
+| `get_scraper_results` | RO | Read an Apify run status and, once SUCCEEDED, its dataset; credential required, not owner-scoped (chat#1840) | No credit charge at this boundary | Apify API read; no message recipient | Repeat read; external billing/retry behavior remains unqualified | [source](../lib/apify/getScraperRunResults.ts) |
+| `get_artist_posts` | RO | Read saved posts across the artist's linked socials; artist ID gate | No credit charge at this boundary | No outbound recipient; authenticated response only | Repeat read | [source](../lib/mcp/tools/artistSocials/registerGetArtistPostsTool.ts) |
</file context>
| | `scrape_artist_socials` | W | Start one Apify scrape per linked artist social; artist ID gate; register runs as one batch | Credit availability gate for all linked profiles ($0.05 each + $0.01 per requested post); charges only runs that started | Apify social scrapers; no message recipient | Unknown: each call starts new paid runs; no wrapper idempotency | [source](../lib/artist/startArtistSocialsScrape.ts) | | |
| | `scrape_artist_socials` | W | Start one Apify scrape per linked artist social; artist ID gate; register runs as one batch | Credit availability gate for all linked profiles ($0.05 each + $0.01 per requested post); charges only runs that started | Apify social scrapers; no message recipient | Unknown: each call starts new paid runs; no wrapper idempotency | [source](../lib/artist/runArtistSocialsScrape.ts) | |
|
|
||
| try { | ||
| const params = getArtistPostsParamsSchema.parse(args); | ||
| if (!(await checkAccountArtistAccess(accountId, params.artist_account_id))) { |
There was a problem hiding this comment.
P3: The MCP handler repeats the REST access gate inline but skips the artist-existence check, so the two surfaces diverge. An org admin querying a nonexistent artist ID gets an empty success here, while REST returns 404 "Artist not found". Move the artist lookup and access check into a shared validator that both validateGetArtistPostsRequest and this tool call, as runArtistSocialsScrape does for the scrape tool.
(Based on your team's feedback about centralizing handler validation.)
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/mcp/tools/artistSocials/registerGetArtistPostsTool.ts, line 57:
<comment>The MCP handler repeats the REST access gate inline but skips the artist-existence check, so the two surfaces diverge. An org admin querying a nonexistent artist ID gets an empty success here, while REST returns 404 "Artist not found". Move the artist lookup and access check into a shared validator that both `validateGetArtistPostsRequest` and this tool call, as `runArtistSocialsScrape` does for the scrape tool.
(Based on your team's feedback about centralizing handler validation.) </comment>
<file context>
@@ -0,0 +1,74 @@
+
+ try {
+ const params = getArtistPostsParamsSchema.parse(args);
+ if (!(await checkAccountArtistAccess(accountId, params.artist_account_id))) {
+ return getToolResultError("Access denied to specified artist_account_id");
+ }
</file context>
Before: an agent connected to the Recoup MCP server could read an artist's social profiles but had no way to start a socials scrape, check a scrape run, or read the artist's posts. Those only existed as REST routes.
After: three MCP tools expose them:
scrape_artist_socials(write, spends credits): starts a scrape of every social linked to the artist. Checks artist access, gates credits for all linked profiles ($0.05 each + $0.01 per requested post), charges only the runs that started, and registers them as one batch, exactly likePOST /api/artist/socials/scrape.get_scraper_results(read): run status, plus the dataset once SUCCEEDED. Same asGET /api/apify/runs/{runId}: requires a credential but is not owner-scoped (chat#1840).get_artist_posts(read): saved posts across the artist's socials with the REST pagination defaults (page 1, limit 20, max 100). Same asGET /api/artists/{id}/posts.Tracking and merge order
How
lib/artist/runArtistSocialsScrape.ts(access check, socials lookup, credit gate, start viastartArtistSocialsScrape),lib/apify/getScraperRunResults.ts, andlib/posts/getArtistPosts.ts(posts envelope). The REST handlers and tools only map results to their own response shapes; REST responses are unchanged. The usage label isARTIST_SOCIALS_SCRAPE_MODEL_IDinlib/const.ts.lib/mcp/tools/artistSocials/and are registered viaregisterAllArtistSocialsTools, so they are available to API-key callers and to full OAuth (mcp:tools) grants. Full OAuth also runs the existingprepareFullOAuthToolartist gate onartist_account_id.fullOAuthToolPolicy(scrape isreadOnly: falsewith a credit notice),scripts/mcp-oauth/tool-policy.json(scrape:mcp:write+mcp:spend) anddocs/mcp-oauth-tool-qualification.md. Full catalog count 89 → 92.mcp:read/mcp:writegrant (registerOAuthTools), which keeps its existing five-tool contract.Tests
runArtistSocialsScrape,startArtistSocialsScrape,getScraperRunResults,getArtistPosts.pnpm test: 1485 files / 9462 tests pass.tsc -p tsconfig.build.jsonandpnpm typecheck:mcp-oauth: clean. eslint and prettier clean on changed files.Generated by Claude Code
Summary by cubic
Adds MCP tools for starting artist social scrapes, checking scrape runs, and listing saved posts—capabilities previously only available through REST.
scrape_artist_socialschecks artist access, gates the full credit cost, charges only runs that started, and returns an error listing every failure when no run started (nothing was charged); MCP charges use the REST route label so usage groups together.get_scraper_resultsreturns run status and the dataset after success; like the REST route, it requires a credential but is not owner-scoped.get_artist_postsuses the REST pagination defaults.runArtistSocialsScrape), run-result logic, and posts envelope; REST responses are unchanged.Written for commit 6c1a165. Summary will update on new commits.
Generated by Claude Code
Summary by CodeRabbit