46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import asyncio
|
|
import sys
|
|
import os
|
|
from mcp import ClientSession, StdioServerParameters
|
|
from mcp.client.stdio import stdio_client
|
|
|
|
async def main():
|
|
# Get absolute path to the project root
|
|
project_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# Define the server parameters
|
|
server_params = StdioServerParameters(
|
|
command="uv",
|
|
args=["run", "src/server.py"],
|
|
env=os.environ.copy() # Pass current environment including PATH and .env vars
|
|
)
|
|
|
|
print("Connecting to server...")
|
|
async with stdio_client(server_params) as (read, write):
|
|
async with ClientSession(read, write) as session:
|
|
# Initialize
|
|
await session.initialize()
|
|
print("Initialized!")
|
|
|
|
# List tools
|
|
print("\n--- Available Tools ---")
|
|
tools = await session.list_tools()
|
|
for tool in tools.tools:
|
|
print(f"- {tool.name}: {tool.description}")
|
|
|
|
# Call list_calendars
|
|
print("\n--- Calling list_calendars ---")
|
|
try:
|
|
result = await session.call_tool("list_calendars", {})
|
|
print("Result:")
|
|
for content in result.content:
|
|
print(content.text)
|
|
except Exception as e:
|
|
print(f"Error calling tool: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
asyncio.run(main())
|
|
except KeyboardInterrupt:
|
|
sys.exit(0)
|