Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/mcp/local-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
scrapeTweets,
searchTweets,
scrapeThread,
scrapePost,
scrapeLikes,
scrapeMedia,
scrapeListMembers,
Expand Down Expand Up @@ -61,6 +62,17 @@ async function ensureBrowser() {
return { browser, page };
}

/**
* Create a new tab in the shared browser for isolated work.
* Shares cookies/auth with all other tabs. Caller must close the tab when done.
*/
async function newTab(timeout = 60000) {
const { browser: br } = await ensureBrowser();
const tab = await createPage(br);
tab.setDefaultTimeout(timeout);
return tab;
}

/**
* Close browser (called by server.js on SIGINT/SIGTERM)
*/
Expand Down Expand Up @@ -198,8 +210,15 @@ export async function x_search_tweets({ query, limit = 50 }) {
// ============================================================================

export async function x_get_thread({ url }) {
const { page: pg } = await ensureBrowser();
return scrapeThread(pg, url);
const tab = await newTab();
try { return await scrapeThread(tab, url); }
finally { await tab.close().catch(() => {}); }
}

export async function x_read_post({ url }) {
const tab = await newTab();
try { return await scrapePost(tab, url); }
finally { await tab.close().catch(() => {}); }
}

export async function x_best_time_to_post({ username, limit = 100 }) {
Expand Down Expand Up @@ -1346,6 +1365,7 @@ export const toolMap = {
x_get_tweets,
x_search_tweets,
x_get_thread,
x_read_post,
x_best_time_to_post,
// Core actions
x_follow,
Expand Down
11 changes: 11 additions & 0 deletions src/mcp/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,17 @@ const TOOLS = [
required: ['url'],
},
},
{
name: 'x_read_post',
description: 'Read a tweet/post with full rich data. Returns thread if the post is part of one (author self-replies only). Recursively resolves quoted tweets. Each tweet includes: text, media (images + video URLs), X Articles, cards (link previews), external URLs, and engagement stats.',
inputSchema: {
type: 'object',
properties: {
url: { type: 'string', description: 'URL of the tweet/post' },
},
required: ['url'],
},
},
// ====== Posting Analytics ======
{
name: 'x_best_time_to_post',
Expand Down
2 changes: 2 additions & 0 deletions src/scrapers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const {
scrapeTweets,
searchTweets,
scrapeThread,
scrapePost,
scrapeLikes,
scrapeHashtag,
scrapeMedia,
Expand Down Expand Up @@ -308,6 +309,7 @@ export default {
scrapeTweets,
searchTweets,
scrapeThread,
scrapePost,
scrapeLikes,
scrapeHashtag,
scrapeMedia,
Expand Down
Loading