MCP Client
Guide to using the Lybic Python SDK's MCP Client.
MCP
is a client for Lybic's Model Context Protocol (MCP) and its associated RESTful API.
MCP Client Usage
You can use the MCP
to execute actions via lybic.lmcp
.
class MCP:
async def call_tool_async(self,
mcp_server_id: str,
tool_name: str = "computer-use",
tool_args: dict = None):
"""
Call a tool on mcp server
:param mcp_server_id:
:param tool_name:
:param tool_args:
:return tool_result:
"""
call_tool_async
Method
mcp_server_id
You can get the mcp_server_id
from the website or the SDK.
-
Website:
- Open the dashboard of the Lybic web app.
- Find
MCP Servers
on the left side. - You will see the MCP server ID.
-
SDK:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) list_result = await mcp.list() for mcp_server in list_result.root: print(mcp_server.id) if __name__ == '__main__': asyncio.run(main())
tool_name
The name of the MCP tool you want to run.
tool_args
A dictionary of tool arguments, for example:
args = {
"action": "click",
"coordinate": [{x}, {y}],
"text": ",".join(hold_keys) if hold_keys else None
}
Return Value
The tool_result.content
contains the result of the tool execution.
Supported Actions & Examples
The MCP supports various actions. Here are the details for each action, including parameters and examples.
screenShot
Take a screenshot of the screen.
- Parameters: None
- Example:
import asyncio import base64 from io import BytesIO from PIL import Image from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='server_id',tool_args={"action": "screenShot"}) img_b64 = result.content[0].data img_bytes = base64.b64decode(img_b64) i = Image.open(BytesIO(img_bytes)) i.show() print(result) if __name__ == '__main__': asyncio.run(main())
type
Type a string of text on the keyboard.
- Parameters:
text
(str): The string of text to type(The vast majority of Unicode char is supported).
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "type", "text": "This is an English text, 这是一个中文文本, 이것은 한국어 문자열이다, and هذه سلسلة من السلسلة العربية."}) print(result) if __name__ == '__main__': asyncio.run(main())
click
Click the left mouse button at a specified coordinate.
- Parameters:
coordinate
(list[int, int]): The[x, y]
pixel coordinate to click.
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "click", "coordinate": [100, 200]}) print(result) if __name__ == '__main__': asyncio.run(main())
rightClick
Click the right mouse button at a specified coordinate.
- Parameters:
coordinate
(list[int, int]): The[x, y]
pixel coordinate to click.
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "rightClick", "coordinate": [100, 200]}) print(result) if __name__ == '__main__': asyncio.run(main())
doubleClick
Double-click the left mouse button at a specified coordinate.
- Parameters:
coordinate
(list[int, int]): The[x, y]
pixel coordinate to double-click.
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "doubleClick", "coordinate": [100, 200]}) print(result) if __name__ == '__main__': asyncio.run(main())
middleClick
Click the middle mouse button at a specified coordinate.
- Parameters:
coordinate
(list[int, int]): The[x, y]
pixel coordinate to click.
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "middleClick", "coordinate": [100, 200]}) print(result) if __name__ == '__main__': asyncio.run(main())
move
Move the cursor to a specified coordinate.
- Parameters:
coordinate
(list[int, int]): The[x, y]
pixel coordinate to move the cursor to.
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "move", "coordinate": [100, 200]}) print(result) if __name__ == '__main__': asyncio.run(main())
leftClickDrag
Click and drag the cursor from a starting coordinate to an ending coordinate.
- Parameters:
startCoordinate
(list[int, int]): The[x, y]
coordinate to start the drag from.coordinate
(list[int, int]): The[x, y]
coordinate to end the drag.
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "leftClickDrag", "startCoordinate": [100, 200], "coordinate": [500, 600]}) print(result) if __name__ == '__main__': asyncio.run(main())
scroll
Scroll the screen at a specified coordinate.
- Parameters:
scrollDirection
(str): The direction to scroll. Can be"up"
,"down"
,"left"
, or"right"
.scrollAmount
(int): The number of "clicks" to scroll.coordinate
(list[int, int], optional): The[x, y]
coordinate where the scroll action should occur.
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) # Scroll down by 5 clicks result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "scroll", "scrollDirection": "down", "scrollAmount": 5}) print(result) if __name__ == '__main__': asyncio.run(main())
keyPress
Press a key or a combination of keys. Supports xdotool
key syntax.
- Parameters:
text
(str): The key or key combination to press (e.g.,"a"
,"Return"
,"alt+Tab"
,"ctrl+s"
).
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) # Press Ctrl+S to save result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "keyPress", "text": "ctrl+s"}) print(result) if __name__ == '__main__': asyncio.run(main())
cursorPosition
Get the current [x, y]
coordinate of the cursor.
- Parameters: None
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "cursorPosition"}) print(f"Cursor position: {result.content}") if __name__ == '__main__': asyncio.run(main())
wait
Wait for a specified duration.
- Parameters:
duration
(float): The duration to wait in seconds.
- Example:
import asyncio from lybic import LybicClient, MCP async def main(): async with LybicClient() as client: mcp = MCP(client) # Wait for 2.5 seconds result = await mcp.call_tool_async(mcp_server_id='YOUR_MCP_SERVER_ID', tool_args={"action": "wait", "duration": 2.5}) print(f"Cursor position: {result.content}") if __name__ == '__main__': asyncio.run(main())
MCP Server Management
List All MCP Servers
- Method:
list()
- Returns:
dto.ListMcpServerResponse
import asyncio
from lybic import LybicClient, MCP
async def main():
async with LybicClient() as client:
mcp = MCP(client)
list_result = await mcp.list()
for mcp_server in list_result.root:
print(mcp_server.id)
if __name__ == '__main__':
asyncio.run(main())
Create an MCP Server
- Method:
create(data: dto.CreateMcpServerDto)
- Arguments:
name
(str): Name of the MCP server.projectId
(str, optional): Project to which the server belongs.
- Returns:
dto.McpServerResponseDto
import asyncio
from lybic import LybicClient, dto, MCP
async def main():
async with LybicClient() as client:
mcp = MCP(client)
new_server = await mcp.create(dto.CreateMcpServerDto(name="my-mcp-server"))
# or
# new_server = = await mcp.create(name="my-mcp-server")
print(new_server)
if __name__ == '__main__':
asyncio.run(main())
Get the Default MCP Server
- Method:
get_default()
- Returns:
dto.McpServerResponseDto
import asyncio
from lybic import LybicClient, MCP
async def main():
async with LybicClient() as client:
mcp = MCP(client)
default_server = await mcp.get_default()
print(default_server)
if __name__ == '__main__':
asyncio.run(main())
Delete an MCP Server
- Method:
delete(mcp_server_id: str)
- Arguments:
mcp_server_id
(str): ID of the MCP server to delete.
- Returns:
None
import asyncio
from lybic import LybicClient, MCP
async def main():
async with LybicClient() as client:
mcp = MCP(client)
await mcp.delete(mcp_server_id="MCP-xxxx")
if __name__ == '__main__':
asyncio.run(main())
Set MCP Server to a Sandbox
- Method:
set_sandbox(mcp_server_id: str, sandbox_id: str)
- Arguments:
mcp_server_id
(str): ID of the MCP server.sandbox_id
(str): ID of the sandbox to connect the MCP server to.
- Returns:
None
import asyncio
from lybic import LybicClient, MCP
async def main():
async with LybicClient() as client:
mcp = MCP(client)
await mcp.set_sandbox(mcp_server_id="MCP-xxxx", sandbox_id="SBX-xxxx")
if __name__ == '__main__':
asyncio.run(main())