48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import sys
|
|
import json
|
|
import os
|
|
|
|
# Add project root to sys.path
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
try:
|
|
import mcp_client
|
|
except ImportError:
|
|
print(json.dumps({"error": "Failed to import mcp_client"}))
|
|
sys.exit(1)
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
print(json.dumps({"error": "No tool name provided"}))
|
|
sys.exit(1)
|
|
|
|
tool_name = sys.argv[1]
|
|
|
|
# Read arguments from stdin
|
|
try:
|
|
input_data = sys.stdin.read()
|
|
if input_data:
|
|
tool_input = json.loads(input_data)
|
|
else:
|
|
tool_input = {}
|
|
except json.JSONDecodeError:
|
|
print(json.dumps({"error": "Invalid JSON input"}))
|
|
sys.exit(1)
|
|
|
|
try:
|
|
# Note: mcp_client.configure() is usually called by the GUI before each session,
|
|
# but for direct CLI calls, we might need a basic configuration.
|
|
# However, mcp_client tools generally resolve paths relative to CWD if not configured.
|
|
result = mcp_client.dispatch(tool_name, tool_input)
|
|
|
|
# We wrap the result in a JSON object for consistency if needed,
|
|
# but the CLI often expects just the string result from stdout.
|
|
# Actually, let's just print the raw result string as that's what mcp_client returns.
|
|
print(result)
|
|
except Exception as e:
|
|
print(f"ERROR executing tool {tool_name}: {e}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|