from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
import httpx
# Pylar MCP server configuration
PYLAR_MCP_URL = "https://mcp.publish.pylar.ai/mcp"
PYLAR_BEARER_TOKEN = "YOUR_BEARER_TOKEN_HERE"
# Create HTTP client with authentication
async def create_pylar_client():
async with httpx.AsyncClient() as client:
headers = {
"Authorization": f"Bearer {PYLAR_BEARER_TOKEN}",
"Content-Type": "application/json"
}
# Connect to Pylar MCP server
response = await client.post(
f"{PYLAR_MCP_URL}/tools/list",
headers=headers
)
if response.status_code == 200:
tools = response.json()
return tools
else:
raise Exception(f"Failed to connect: {response.status_code}")
# Use in your LangGraph agent
async def call_pylar_tool(tool_name, arguments):
async with httpx.AsyncClient() as client:
headers = {
"Authorization": f"Bearer {PYLAR_BEARER_TOKEN}",
"Content-Type": "application/json"
}
response = await client.post(
f"{PYLAR_MCP_URL}/tools/call",
headers=headers,
json={
"name": tool_name,
"arguments": arguments
}
)
return response.json()