Created
August 17, 2025 06:43
-
-
Save janakiramm/a42db90cc1ca1fd7fb72d86982ae965d to your computer and use it in GitHub Desktop.
Simple MCP Gemini Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import asyncio | |
| from google import genai | |
| from mcp import ClientSession | |
| from mcp.client.streamable_http import streamablehttp_client | |
| import warnings | |
| warnings.filterwarnings("ignore") | |
| MCP_SERVER_URL = "http://127.0.0.1:8080/mcp/" | |
| client = genai.Client() | |
| async def main(): | |
| async with streamablehttp_client(MCP_SERVER_URL) as (read, write, _): | |
| async with ClientSession(read, write) as session: | |
| await session.initialize() | |
| prompt = "Who is the Intern in the company?" | |
| response = await client.aio.models.generate_content( | |
| model="gemini-2.5-flash", | |
| contents=prompt, | |
| config=genai.types.GenerateContentConfig( | |
| temperature=0, | |
| tools=[session], # Pass the MCP session as a tool | |
| ), | |
| ) | |
| print(response.text) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment