Skip to content

Commit f7a1356

Browse files
committed
feat: add MCP proxy config processing with inputs and servers
1 parent a7cedae commit f7a1356

File tree

1 file changed

+56
-3
lines changed
  • src/datapilot/core/mcp_utils

1 file changed

+56
-3
lines changed

src/datapilot/core/mcp_utils/mcp.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,62 @@ def create_mcp_proxy():
2121
content = click.edit()
2222
if content is None:
2323
click.echo("No input provided.")
24-
25-
output = asyncio.run(list_tools())
26-
click.echo(json.dumps(output, indent=2))
24+
return
25+
26+
try:
27+
config_data = json.loads(content)
28+
mcp_config = config_data.get("mcp", {})
29+
30+
# Process inputs
31+
inputs = []
32+
for input_def in mcp_config.get("inputs", []):
33+
inputs.append(InputParameter(
34+
name=input_def.get("name", input_def["id"]),
35+
type=input_def["type"],
36+
required=input_def.get("required", False),
37+
key=input_def["id"].lower(),
38+
description=input_def["description"],
39+
encrypted=input_def.get("password", False)
40+
))
41+
42+
# Process servers
43+
tool_config = []
44+
for server_name, server_def in mcp_config.get("servers", {}).items():
45+
# Command config
46+
tool_config.append(IntegrationConfigItem(
47+
key="command",
48+
value=server_def["command"]
49+
))
50+
51+
# Arguments config
52+
tool_config.append(IntegrationConfigItem(
53+
key="arguments",
54+
value=server_def.get("args", [])
55+
))
56+
57+
# Environment variables
58+
env_items = []
59+
for var_name, var_value in server_def.get("env", {}).items():
60+
if var_value.startswith("${input:"):
61+
_, input_id = var_value[2:-1].split(":")
62+
var_value = f"${{{input_id}}}"
63+
64+
env_items.append({"key": var_name, "value": var_value})
65+
66+
tool_config.append(IntegrationConfigItem(
67+
key="env",
68+
value=env_items
69+
))
70+
71+
integration_model = CustomDatamateIntegrationModel(
72+
config=inputs,
73+
toolConfig=tool_config
74+
)
75+
76+
click.echo(json.dumps(integration_model, cls=EnhancedJSONEncoder, indent=2))
77+
78+
except Exception as e:
79+
click.echo(f"Error processing config: {str(e)}")
2780

2881
async def list_tools(command: str, args: list[str], env: dict[str, str]) -> str:
2982
command = shutil.which(command)

0 commit comments

Comments
 (0)