| name | molclaw-file-transfer |
| description | Implement data transmission between the local computer and the MCP Server using Base64 encoding |
| license | MIT license |
| metadata | {"skill-author":"PJLab"} |
File Transfer
1. Transfer local file to MCP server
Example code:
import base64
client = DrugSDAClient("https://scp.intern-ai.org.cn/api/v1/mcp/2/DrugSDA-Tool")
if not await client.connect():
print("connection failed")
return
local_file = "/path/a.txt"
with open(local_file, "rb") as f:
file_content = f.read()
file_base64_string = base64.b64encode(file_content).decode('utf-8')
response = await client.session.call_tool(
"base64_to_server_file",
arguments={
"file_name": "a.txt",
"file_base64_string": file_base64_string
}
)
result = client.parse_result(response)
save_file = result["save_file"]
await client.disconnect()
2. Transfer MCP server file to local
Example code:
import base64
client = DrugSDAClient("https://scp.intern-ai.org.cn/api/v1/mcp/2/DrugSDA-Tool")
if not await client.connect():
print("connection failed")
return
response = await client.session.call_tool(
"server_file_to_base64",
arguments={
"file_path": "/path/a.txt"
}
)
result = client.parse_result(response)
base64_string = result["base64_string"]
file_name = result["file_name"]
file_data = base64.b64decode(base64_string)
local_file_path = "/path/" + file_name
with open(local_file_path, "wb") as f:
f.write(file_data)
await client.disconnect()