Skip to content

Conversation

@Amdev-5
Copy link
Owner

@Amdev-5 Amdev-5 commented Feb 6, 2026

Fixes adenhq#2598

Description

This PR finalizes the X (Twitter) tools integration, adding Direct Message capabilities and robust error handling. addressing previous review feedback regarding OAuth scopes and testing.

Changes

  • Feature: Added x_send_dm tool using the X API v2 POST /dm_conversations/with/:participant_id/messages endpoint.
  • Fix: Updated DM payload structure to resolve HTTP 400 validation errors (previously using the wrong group-chat endpoint).
  • Enhancement: Improved error reporting in x_tool.py to surface raw API error messages (crucial for debugging permission scopes).
  • Test: Added comprehensive unit tests in test_x_tool.py covering the new DM logic.
  • Docs: Clarified docstrings to indicate which tools require OAuth 1.0a User Context (Write/DM) vs Bearer Token (Read).

Addressing Review Feedback

Hi, it seems like the X_BEARER_TOKEN does not have the ability to post, reply, or delete tweets, those require Oauth2.0.

Response: Correct. The implementation strictly separates these concerns:

  1. Read-Only Tools (x_search_tweets, x_get_mentions) use X_BEARER_TOKEN.
  2. Write Tools (x_post_tweet, x_reply_tweet, x_delete_tweet, x_send_dm) use OAuth 1.0a User Context (X_API_KEY, X_API_SECRET, X_ACCESS_TOKEN, X_ACCESS_TOKEN_SECRET).
    • Note: We verified that OAuth 1.0a User Context is fully supported by X API v2 for these endpoints and is often simpler for server-side scripts than the 3-legged OAuth 2.0 flow.

Could you please clarify that with the tools with a label, such as oauth_required = True

Response: I have updated the docstrings for all Write tools to explicitly state: "Requires OAuth 1.0a authentication".

Additionally, could you create a test file with pytests for these tools and add a tool to dm a user?

Response:

  • Tests: tests/tools/test_x_tool.py has been updated and fully passes (55 passed).
  • DM Tool: x_send_dm is now implemented and verified.

Verification Logs

Verified against the live X API.

Tool Status Notes Logs
x_search_tweets ✅ Pass Search used Bearer Token
View Log
{
"data": [
{
"id": "2019711890176577918",
"text": "RT @Myles_ofs: Python (FREE)..."
}
]
}
x_get_mentions ✅ Pass Fetch used Bearer Token
View Log
{
"data": [
{
"id": "2019703796579127499",
"text": "Hi,\n\n@Support @X..."
}
]
}
x_post_tweet ✅ Pass Created tweet 2019713526731043169
View Log
{
"data": {
"id": "2019713526731043169",
"text": "Hive MCP integration test - 1770372203"
}
}
x_reply_tweet ✅ Pass Created reply 2019713536696697048
View Log
{
"data": {
"id": "2019713536696697048",
"text": "Automated reply from Hive MCP tools!"
}
}
x_delete_tweet ✅ Pass Deleted reply & original tweet
View Log
{
"data": {
"deleted": true
}
}
x_send_dm ✅ Pass 1:1 DM sent to 1299966336068591616
View Log
Resolving ID for @SubramanyaAryan...
Found ID: 1299966336068591616
Result: {
"data": {
"dm_conversation_id": "1299966336068591616...",
"dm_event_id": "2019713555147432396"
}
}

Unit Tests

All 55 tests passed.

tests/tools/test_x_tool.py ....................................................... [100%]
55 passed in 0.41s


output for test locally on different tools 
============================================================
  x_search_tweets — Search recent tweets
============================================================

Result: {
  "data": [
    {
      "edit_history_tweet_ids": [
        "2019711890176577918"
      ],
      "text": "RT @Myles_ofs: Python (FREE)\n\nPython is beginner-friendly and powerful.\nUsed in web development, data science, and automation.\nGreat first\u2026",
      "id": "2019711890176577918"
    },

  ... (truncated)

============================================================
  x_get_mentions — Fetch mentions for a user
============================================================

Result: {
  "data": [
    {
      "id": "2019703796579127499",
      "text": "Hi,\n\n@Support @X @XDevelopers @premium\n@grok\n\nOver the past few time, I have noticed a sudden and significant drop in the reach and impressions on my posts, despite following the X Rules and community guidelines.\nIt seems my
  ... (truncated)

============================================================
  x_post_tweet — Post a new tweet
============================================================

Result: {
  "data": {
    "id": "2019713526731043169",
    "edit_history_tweet_ids": [
      "2019713526731043169"
    ],
    "text": "Hive MCP integration test - 1770372203"
  }
}

  Created tweet ID: 2019713526731043169

============================================================
  x_reply_tweet — Reply to the tweet we just posted
============================================================

Result: {
  "data": {
    "id": "2019713536696697048",
    "text": "Automated reply from Hive MCP tools!",
    "edit_history_tweet_ids": [
      "2019713536696697048"
    ]
  }
}

============================================================
  x_delete_tweet — Delete the reply
============================================================

Result: {
  "data": {
    "deleted": true
  }
}

============================================================
  x_delete_tweet — Delete the original tweet
============================================================

Result: {
  "data": {
    "deleted": true
  }
}

============================================================
  x_send_dm — Send a direct message
============================================================

Resolving ID for @SubramanyaAryan...
  Found ID: 1299966336068591616
Result: {
  "data": {
    "dm_conversation_id": "1299966336068591616-1854107699534856219",
    "dm_event_id": "2019713555147432396"
  }
}

============================================================
  Input validation tests
============================================================

Empty text: {
  "error": "Tweet text cannot be empty"
}
Too long:   {
  "error": "Tweet text exceeds 280 characters (281 chars)"
}
Empty reply: {
  "error": "Reply text cannot be empty"
}
<img width="1072" height="523" alt="Screenshot 2026-02-06 at 4 07 03 PM" src="https://github.com/user-attachments/assets/a32d6dc8-4b51-487b-a24d-58fa7faf976c" />
<img width="1093" height="409" alt="Screenshot 2026-02-06 at 4 05 02 PM" src="https://github.com/user-attachments/assets/d86f86a3-5a6d-4dc8-b70f-1aa91c597a65" />
<img width="1342" height="874" alt="Screenshot 2026-02-06 at 3 56 31 PM" src="https://github.com/user-attachments/assets/ee14181e-5fbc-4223-a4d2-2f88f4258329" />

sashankthapa and others added 7 commits January 31, 2026 15:49
- Added `x_send_dm` tool using v2 endpoint (`POST /dm_conversations/with/:id/messages`) for reliable 1:1 messaging.
- Fixed 403 Forbidden payload validation errors by simplifying DM payload structure.
- Enhanced `_handle_response` to verify `x_tool.py` returns raw API error details for 403/400 responses, aiding in permission debugging.
- Updated `demo_x_tools.py` to support standard `.env` variable names (e.g., `X_API_KEY`) and added user lookup for DM testing.
- Added unit tests covering new DM functionality and payload verification in `test_x_tool.py`.
- Audited credential handling: Read-only tools (Search/Mentions) correctly use Bearer Token, while Write tools (Post/Reply/Delete/DM) enforce OAuth 1.0a User Context.

Verified with live API tests (see PR description for logs).
@Amdev-5 Amdev-5 self-assigned this Feb 6, 2026
@github-actions
Copy link

github-actions bot commented Feb 6, 2026

PR Closed - Requirements Not Met

This PR has been automatically closed because it doesn't meet the requirements.

PR Author: @Amdev-5
Found issues:
Problem: The PR author must be assigned to the linked issue.

To fix:

  1. Assign yourself (@Amdev-5) to one of the linked issues
  2. Re-open this PR

Exception: To bypass this requirement, you can:

  • Add the micro-fix label or include micro-fix in your PR title for trivial fixes
  • Add the documentation label or include doc/docs in your PR title for documentation changes

Micro-fix requirements (must meet ALL):

Qualifies Disqualifies
< 20 lines changed Any functional bug fix
Typos & Documentation & Linting Refactoring for "clean code"
No logic/API/DB changes New features (even tiny ones)

Why is this required? See adenhq#472 for details.

@Amdev-5
Copy link
Owner Author

Amdev-5 commented Feb 6, 2026

Screenshot 2026-02-06 at 4 05 02 PM 42e7f0" /> Screenshot 2026-02-06 at 4 07 03 PM Screenshot 2026-02-06 at 3 56 31 PM

@Amdev-5
Copy link
Owner Author

Amdev-5 commented Feb 6, 2026

@bryanadenhq

@Amdev-5 Amdev-5 reopened this Feb 6, 2026
@github-actions github-actions bot closed this Feb 6, 2026
@bryanadenhq
Copy link

Hi @Amdev-5, we just created a new branch in our repo since this one seems to be auto-closing. However, went porting from your branch, we lost your contributor status in the branch. Since we still value your contribution and want to make sure you get the credit you deserve, would you please take a look at the tools test and update that to get on the contributors list again? Thank you so much and sorry about the inconvenience.

Here is the pr: adenhq#3807

@bryanadenhq
Copy link

Hi @Amdev-5, just to add a quick note, it seems like its possible that your email may not be verified/linked with GIthub so if you do that through Github Settings > Emails and add your email, github should retroactively link you as a contributor. Thanks again!

@Amdev-5
Copy link
Owner Author

Amdev-5 commented Feb 6, 2026

Hi @Amdev-5, just to add a quick note, it seems like its possible that your email may not be verified/linked with GIthub so if you do that through Github Settings > Emails and add your email, github should retroactively link you as a contributor. Thanks again!

Screenshot 2026-02-06 at 10 11 51 PM

@Amdev-5
Copy link
Owner Author

Amdev-5 commented Feb 6, 2026

Hi @Amdev-5, we just created a new branch in our repo since this one seems to be auto-closing. However, went porting from your branch, we lost your contributor status in the branch. Since we still value your contribution and want to make sure you get the credit you deserve, would you please take a look at the tools test and update that to get on the contributors list again? Thank you so much and sorry about the inconvenience.

Here is the pr: adenhq#3807

adenhq#3814

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Integration]: Add Twitter (X) integration as an MCP tool

3 participants