-
Notifications
You must be signed in to change notification settings - Fork 493
Open
Labels
Description
Hi,
Even though I run the script with the required environment variables set for the mcp_server, the MCP server doesn’t seem to pick them up.
Instead of running without waiting for user approval in the new tab, each time it runs it prompts for user's approval like in the screenshot.
I'm using vscode in win11. The code is below. Environment variable has been set as in the extension documentation :
import asyncio
import shutil
from copilot import CopilotClient
from copilot.generated.session_events import SessionEventType
async def main():
client = CopilotClient(
{
"cli_path": shutil.which("copilot"),
}
)
try:
await client.start()
mcp_servers = {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--extension"],
"env": {
"PLAYWRIGHT_MCP_EXTENSION_TOKEN": "put_your_token_here"
},
"tools": ["*"],
}
}
def on_permission_request(request, invocation):
return {"kind": "approved"}
session = await client.create_session(
{
"model": "claude-sonnet-4.5",
"mcp_servers": mcp_servers,
"on_permission_request": on_permission_request,
}
)
response_data = {"content": None}
def handle_message(event):
if event.type == SessionEventType.ASSISTANT_MESSAGE:
response_data["content"] = event.data.content
session.on(handle_message)
await session.send_and_wait({"prompt": "navigate to medium.com"}, timeout=30)
if response_data["content"]:
print(f"Copilot: {response_data['content']}")
await session.destroy()
except Exception as e:
print(f"Error: {e}")
finally:
await client.stop()
if __name__ == "__main__":
asyncio.run(main())