{{ json_config_mac or '{\n "mcpServers": {\n "' + (mcp_package or '@microsoft/playwright-mcp') + '": {\n "command": "npx",\n "args": [\n "-y",\n "@mcp/cli@latest",\n "run",\n "' + (mcp_package or '@microsoft/playwright-mcp') + '",\n "--url",\n "' + (base_url or 'https://your-mcp-server.com') + '"\n ]\n }\n }\n}' }}
{{ json_config_windows or '{\n "mcpServers": {\n "' + (mcp_package or '@microsoft/playwright-mcp') + '": {\n "command": "npx.cmd",\n "args": [\n "-y",\n "@mcp/cli@latest",\n "run",\n "' + (mcp_package or '@microsoft/playwright-mcp') + '",\n "--url",\n "' + (base_url or 'https://your-mcp-server.com') + '"\n ]\n }\n }\n}' }}
{{ json_config_wsl or '{\n "mcpServers": {\n "' + (mcp_package or '@microsoft/playwright-mcp') + '": {\n "command": "npx",\n "args": [\n "-y",\n "@mcp/cli@latest",\n "run",\n "' + (mcp_package or '@microsoft/playwright-mcp') + '",\n "--url",\n "' + (base_url or 'https://your-mcp-server.com') + '"\n ]\n }\n }\n}' }}
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
async function connectToMCPServer() {
const transport = new StdioClientTransport({
command: 'npx',
args: ['-y', '@mcp/cli@latest', 'run', '{{ mcp_package or '@microsoft/playwright-mcp' }}', '--url', '{{ base_url or 'https://your-mcp-server.com' }}']
});
const client = new Client({
name: 'my-mcp-client',
version: '1.0.0'
}, {
capabilities: {}
});
await client.connect(transport);
// List available tools
const tools = await client.listTools();
console.log('Available tools:', tools);
// Call a tool
const result = await client.callTool({
name: 'example_tool',
arguments: {}
});
console.log('Tool result:', result);
}
connectToMCPServer().catch(console.error);
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
# Construct server URL with authentication
from urllib.parse import urlencode
base_url = "{{ base_url or 'https://your-mcp-server.com' }}"
params = {"api_key": "{{ api_key or 'your-api-key' }}"}
url = f"{base_url}?{urlencode(params)}"
async def main():
# Connect to the server using HTTP client
async with streamablehttp_client(url) as (read, write, _):
async with ClientSession(read, write) as session:
# Initialize the connection
await session.initialize()
# List available tools
tools_result = await session.list_tools()
print(f"Available tools: {', '.join([t.name for t in tools_result.tools])}")
if __name__ == '__main__':
import asyncio
asyncio.run(main())