Skip to content

Commit 8981ac3

Browse files
committed
refactor: simplify code formatting and improve string formatting
1 parent a8bb136 commit 8981ac3

File tree

1 file changed

+20
-24
lines changed
  • src/datapilot/core/mcp_utils

1 file changed

+20
-24
lines changed

src/datapilot/core/mcp_utils/mcp.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212

1313
logging.basicConfig(level=logging.INFO)
1414

15+
1516
@dataclass
16-
class InputParameter():
17+
class InputParameter:
1718
name: str
1819
type: str
1920
required: bool
2021
key: str
2122
description: str
2223

24+
2325
def find_input_tokens(data):
2426
tokens = set()
2527
if isinstance(data, list):
@@ -66,11 +68,7 @@ def create_mcp_proxy():
6668
ctx.exit(1)
6769

6870
if len(server_names) > 1:
69-
server_name = click.prompt(
70-
"Choose a server",
71-
type=click.Choice(server_names),
72-
show_choices=True
73-
)
71+
server_name = click.prompt("Choose a server", type=click.Choice(server_names), show_choices=True)
7472
else:
7573
server_name = server_names[0]
7674

@@ -94,13 +92,15 @@ def create_mcp_proxy():
9492
hide_input=True,
9593
)
9694
# Create InputParameters config entry
97-
input_configs.append(InputParameter(
98-
name=input_def.get("name", input_id),
99-
type="password",
100-
required=True,
101-
key=input_id,
102-
description=input_def.get("description", "")
103-
).__dict__)
95+
input_configs.append(
96+
InputParameter(
97+
name=input_def.get("name", input_id),
98+
type="password",
99+
required=True,
100+
key=input_id,
101+
description=input_def.get("description", ""),
102+
).__dict__
103+
)
104104

105105
# Replace input tokens in args
106106
processed_args = [
@@ -115,29 +115,25 @@ def create_mcp_proxy():
115115
}
116116

117117
# Execute with processed parameters
118-
output = asyncio.run(list_tools(server_config=server_config, command=server_config["command"], args=processed_args, env=processed_env))
118+
output = asyncio.run(
119+
list_tools(server_config=server_config, command=server_config["command"], args=processed_args, env=processed_env)
120+
)
119121
# Add processed parameters to output
120122
output_with_name = {
121123
"name": server_name,
122124
"config": input_configs,
123125
"command": server_config["command"],
124-
"args": [
125-
arg.replace("${input:", "${") if isinstance(arg, str) else arg
126-
for arg in server_config.get("args", [])
127-
],
128-
"env": {
129-
k: v.replace("${input:", "${") if isinstance(v, str) else v
130-
for k, v in server_config.get("env", {}).items()
131-
},
132-
**output
126+
"args": [arg.replace("${input:", "${") if isinstance(arg, str) else arg for arg in server_config.get("args", [])],
127+
"env": {k: v.replace("${input:", "${") if isinstance(v, str) else v for k, v in server_config.get("env", {}).items()},
128+
**output,
133129
}
134130
output_json = json.dumps(output_with_name, indent=2)
135131
click.echo(output_json)
136132
try:
137133
pyperclip.copy(output_json)
138134
click.secho("\nOutput copied to clipboard!", fg="green")
139135
except pyperclip.PyperclipException as e:
140-
click.secho(f"\nFailed to copy to clipboard: {str(e)}", fg="yellow")
136+
click.secho(f"\nFailed to copy to clipboard: {e!s}", fg="yellow")
141137

142138

143139
async def list_tools(server_config: dict, command: str, args: list[str], env: dict[str, str]):

0 commit comments

Comments
 (0)