Why use Google ADK with a Twitter API?
Google’s Agent Development Kit (ADK) manages Gemini calls, tools, sessions, and agent handoffs. Model Context Protocol, or MCP, defines interoperable tool schemas. Xquik exposes bothexplore and xquik as remote MCP tools.
This Google ADK guide assigns one responsibility to each boundary. The Agent
Development Kit MCP client loads Xquik route schemas during startup.
Choose ADK when Gemini already powers the surrounding workflow. Choose a
direct REST client for deterministic jobs without model decisions.
Google ADK Twitter API prerequisites
- Python 3.10 or later
- An Xquik API key beginning with
xq_ - A Google AI API key for Gemini
- A connected X account for private reads or X write actions
Install Google ADK Python and MCP support
Install the current Google ADK 2.6 line with its compatible MCP client.mcp extra excludes MCP 2.x.
Store secrets outside source control.
.env
.gitignore
Connect Google Agent Development Kit to an MCP server
This Google Agent Development Kit MCP server setup uses Xquik remotely. ADK is the MCP client, while Xquik hosts the remote server.McpToolset discovers explore and xquik through standard tool calling.
These Google ADK tools cover tweets, profiles, followers, monitors, and X
actions. The separation keeps agent workflows independent from route schemas.
Build a Google ADK Python tweet search agent
Define the final handoff before creating the agent. ADK validates the final Gemini response while still allowing MCP tool calls.from google.adk import Agent imports the current agent class. This Google ADK
Python example validates final responses with Pydantic. The Twitter API
get tweets workflow calls the documented search route.
McpToolset when its context exits. Reuse one runner across
related turns. Repeated setup adds avoidable MCP handshakes.
xquik.request() returns normalized snake_case fields from the MCP runtime.
It normalizes createdAt to the Unix-second field created. Align the Pydantic
schema with this response format.
Search tweets with useful X operators
Send the search route a focusedq. Keep the exact query in the handoff.
This Twitter API integration accepts standard X search operators. Use
queryType=Latest for chronological monitoring. Use Top for engagement
ranking. See the complete tweet search API contract.
The search query twitter api get tweets maps to this route.
Pass the returned next_cursor unchanged. Never reconstruct a cursor. Stop
when has_more is false, the requested limit is met, or a cursor repeats.
Separate tweet research from X actions
Xquik intentionally exposes onexquik execution tool. MCP tool-name filters
cannot distinguish GET, POST, and DELETE requests inside that tool.
This Google ADK multi agent pattern separates research from publishing. Use
separate credentials and confirmation rules across multi agent systems.
Use separate ADK agents. Let the research agent read tweets and profiles. Make
the publishing agent confirm every xquik execution.
FunctionResponse. Treat confirmation as a product
workflow, not a prompt sentence.
Confirm every xquik write call. A code-string inspection does not authorize
an action.
For public research, a guest paid_reads key allows eligible GET routes only.
Guest wallets document the exact scope.
Discovery-Only tool filtering
Expose onlyexplore when an agent should inspect endpoint schemas.
xquik enables key-authorized
reads and writes. Because xquik wraps methods, name filtering cannot enforce
read-only access.
Use explore before unfamiliar operations. It returns routes, methods,
parameters, and response fields without calling X.
Store tweet IDs and cursors in ADK state
Keep compact identifiers in session state. Exclude complete tweet pages from ADK prompts and stored session state. Plain state keys belong to one conversation.user: keys persist across a
user’s sessions. app: keys hold shared configuration. temp: keys expire
after one invocation.
Recommended state entries include:
queryandquery_typelast_tweet_idandselected_tweet_idsnext_cursorandpages_fetchedmonitor_idandlast_event_idextraction_id,status, andpollwrite_action_id,status, andcharged_credits
header_provider resolve credentials
from your secret manager.
Use tenant-specific Xquik API keys
header_provider runs when ADK opens the MCP session. Read a non-secret tenant
identifier from ReadonlyContext. Resolve the key outside the prompt.
secret_store represents an existing secret manager. Keep its returned keys
outside Gemini prompts and ADK events.
Handle tweet search errors and rate limits
Handle every documented status with its matching recovery step.
Do not restart pagination after
429. Retain next_cursor and completed
result identifiers. Deduplicate recovered results through the exact tweet_id.
POST and DELETE routes document different statuses. Read each route before
building retry logic. See error handling.
Handoff checklist
Tweet search rows
Store
tweet_id, text, author_username, created, url, has_more, next_cursor, and the original q.User profile rows
Store source
id as user_id, plus username, name, followers, verified, profile_picture, has_more, next_cursor, and the source lookup or search query.Trend rows
Store each trend
name, rank, query, and description. Keep response count, woeid, and the requested region with the run checkpoint.Monitor and webhook setup
Store the returned monitor
id as monitor_id, event_types, next_billing_at, the returned webhook id as webhook_id, url, and the one-time secret in a secret manager. On production deliveries, store delivery_id for receiver retry de-dupe and stream_event_id when one monitor event should process once across endpoint changes.Stored event replay
Store
event_id, type, monitor_id, monitor_type, occurred_at, has_more, next_cursor, and the cursor query for the next page.Extraction jobs
Store
extraction_id, status, poll, and export_after_complete; poll before loading CSV, JSON, or XLSX rows.Writes
Store
tweet_id or write_action_id, reply_to_tweet_id, status, charged_credits, and poll; do not resend pending writes.Media attachments
For tweets or replies, pass public URLs in
media and store tweet_id or write_action_id. For DMs, upload first, pass one media_id in media_ids, store message_id, and leave reply_to_message_id unset.Choose Google ADK MCP or the REST API
Use MCP when Gemini chooses among related Twitter API operations. Use REST for
fixed routes, scheduled exports, or latency-sensitive services.
Migrate Google ADK 1.x MCP code
Google ADK 2.x keeps compatibility aliases. New code should use current API symbols.MCPToolset now emits a deprecation warning. The current class uses the
McpToolset capitalization.
Verified Google ADK package versions
These versions were checked on August 2, 2026.
Pin a tested minor range. Review ADK 2.x release notes before widening it.
Google ADK Twitter API questions
Does Google ADK support MCP?
Yes. Python ADK connects to remote Streamable HTTP servers throughMcpToolset. Xquik publishes explore and xquik at
https://xquik.com/mcp.
How does Google Agent Development Kit differ from MCP?
ADK orchestrates Gemini agents. MCP standardizes external tool discovery and invocation. Xquik serves the tools, whileMcpToolset connects the agent.
Does Google ADK MCP require Google Cloud or Cloud Run?
No. The agent code can run wherever Python 3.10 runs. Google Cloud and Cloud Run are optional deployment targets. Xquik requires no local MCP server.How do I connect Google ADK to a Twitter API?
CreateStreamableHTTPConnectionParams with the Xquik MCP URL. Send the
Xquik API key in the x-api-key header. Pass McpToolset to Agent.tools.
How do I search tweets with a gemini agent?
Ask the agent to callGET /api/v1/x/tweets/search. Supply an exact q,
queryType, and limit. Preserve tweet_id, created, and next_cursor.
This Twitter API integration can get tweets without X Developer credentials.
Private routes still require a connected X account.
Can Google ADK post tweets and replies?
Yes. A connected X account is required. Route everyxquik execution through
ADK confirmation. Validate the selected account, text, reply ID, and media.
See create tweet for the exact contract.
How do I handle Twitter API rate limits in Python?
Treat429 separately from dependency errors. Save the current cursor and
completed tweet IDs. Resume after the reset guidance. Never retry in a tight
loop.
Can a Google ADK agent export Twitter followers?
Yes. The followers API paginates follower profiles through response cursors. Extraction jobs produce larger CSV, JSON, or XLSX exports. Load exported rows only after polling confirms completion.Can Google ADK monitor tweets without repeated searches?
Yes. Create an account or keyword monitor. Replay stored events by cursor. Connect a webhook when the receiver can verify signatures and deduplicate deliveries. Monitors use scheduled checks and do not promise real time delivery.Google ADK or LangChain for a Twitter agent?
Choose ADK for Gemini-centered sessions and native agent handoffs. LangGraph emphasizes a broader model ecosystem and graph orchestration. Xquik supports both frameworks.Why does a remote MCP connection close between calls?
Keep one runner active during related turns. Its context manager closes eachMcpToolset instance. Increase connection and SSE timeouts for long operations.
Do not create one McpToolset per prompt.
Does tool filtering make the Twitter API read-only?
Onlyexplore without xquik blocks execution. The xquik tool can run every
operation authorized by its key. Separate agents and approvals protect X
actions.