added new gemini creations

This commit is contained in:
2026-01-03 14:06:04 -05:00
parent 1dee6556c3
commit bbaa0daa7b
18 changed files with 449 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
import asyncio
import os
import sys
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from google import genai
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
async def main():
print("Starting MCP Client...")
# Check for API Key
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key:
print("Warning: GOOGLE_API_KEY is not set in .env. Gemini calls will fail.")
else:
print("GOOGLE_API_KEY found.")
# Define the server parameters
# We run the simple_server.py we created earlier
server_script = os.path.join(os.path.dirname(__file__), "simple_server.py")
server_params = StdioServerParameters(
command=sys.executable, # Use the current python interpreter
args=[server_script],
env=None
)
print(f"Connecting to MCP server at: {server_script}")
try:
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# Initialize the session
await session.initialize()
# List available tools
result = await session.list_tools()
tools = result.tools
print(f"\nSuccessfully connected! Found {len(tools)} tools:")
for tool in tools:
print(f" - {tool.name}: {tool.description}")
print(f" Schema: {tool.inputSchema}")
print("\n--- Integration with Gemini (google-genai) ---")
print("To integrate these tools with Gemini using the new SDK, you would:")
print("1. Convert the MCP tool schemas to Gemini tool definitions.")
print("2. Initialize the Gemini client:")
print(" from google import genai")
print(" client = genai.Client(api_key=api_key)")
print("3. Pass the tools to the generate_content call.")
print("4. Handle the tool calls returned by the model.")
except Exception as e:
print(f"Error connecting to MCP server: {e}")
if __name__ == "__main__":
asyncio.run(main())