Skip to content

Commit b8fa1b5

Browse files
Generated best practices file (#182)
Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
1 parent e959ecf commit b8fa1b5

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

best_practices.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
<b>Pattern 1: When implementing command-line interfaces with Click, use consistent help option patterns and provide clear, structured help text with examples. Include both short (-h) and long (--help) options, and format examples using backslash-escaped blocks for proper display.
3+
</b>
4+
5+
Example code before:
6+
```
7+
@click.command()
8+
def my_command():
9+
"""Command description."""
10+
pass
11+
```
12+
13+
Example code after:
14+
```
15+
@click.command()
16+
@click.help_option("-h", "--help")
17+
def my_command():
18+
"""Command description.
19+
20+
Example:
21+
22+
\b
23+
mcpm command example
24+
"""
25+
pass
26+
```
27+
28+
<details><summary>Examples for relevant past discussions:</summary>
29+
30+
- https://github.com/pathintegral-institute/mcpm.sh/pull/46#discussion_r2038909708
31+
- https://github.com/pathintegral-institute/mcpm.sh/pull/119#discussion_r2059566646
32+
</details>
33+
34+
35+
___
36+
37+
<b>Pattern 2: When handling subprocess output streams, prefer reading from stderr for application logs and status information rather than stdout, as many applications follow the convention of writing logs to stderr while reserving stdout for data output.
38+
</b>
39+
40+
Example code before:
41+
```
42+
# Process both stdout and stderr
43+
if process.stdout:
44+
line = process.stdout.readline()
45+
if process.stderr:
46+
line = process.stderr.readline()
47+
```
48+
49+
Example code after:
50+
```
51+
# Focus on stderr for logs and status
52+
if process.stderr:
53+
line = process.stderr.readline()
54+
if line:
55+
console.print(line.rstrip())
56+
```
57+
58+
<details><summary>Examples for relevant past discussions:</summary>
59+
60+
- https://github.com/pathintegral-institute/mcpm.sh/pull/167#discussion_r2128177278
61+
</details>
62+
63+
64+
___
65+
66+
<b>Pattern 3: When implementing async handlers for web frameworks like Starlette, ensure handlers return proper Response objects and handle exceptions appropriately with try-catch blocks and proper cleanup in finally blocks.
67+
</b>
68+
69+
Example code before:
70+
```
71+
async def handle_request(request: Request) -> None:
72+
async with some_context() as context:
73+
await process_request(context)
74+
```
75+
76+
Example code after:
77+
```
78+
async def handle_request(request: Request) -> Response:
79+
try:
80+
async with some_context() as context:
81+
await process_request(context)
82+
except Exception as e:
83+
logger.error(f"Error: {e}", exc_info=True)
84+
finally:
85+
return Response()
86+
```
87+
88+
<details><summary>Examples for relevant past discussions:</summary>
89+
90+
- https://github.com/pathintegral-institute/mcpm.sh/pull/156#discussion_r2111437707
91+
</details>
92+
93+
94+
___
95+
96+
<b>Pattern 4: When managing server configurations and capabilities across multiple servers, implement proper conflict resolution strategies for duplicate names by either using strict mode to raise errors or auto-resolving conflicts with server-specific prefixes.
97+
</b>
98+
99+
Example code before:
100+
```
101+
# Direct assignment without conflict checking
102+
self.tools_mapping[tool.name] = tool
103+
```
104+
105+
Example code after:
106+
```
107+
tool_name = tool.name
108+
if tool_name in self.capabilities_to_server_id["tools"]:
109+
if self.strict:
110+
raise ValueError(f"Tool {tool_name} already exists")
111+
else:
112+
tool_name = f"{server_id}{SEPARATOR}{tool_name}"
113+
self.tools_mapping[tool_name] = tool
114+
self.capabilities_to_server_id["tools"][tool_name] = server_id
115+
```
116+
117+
<details><summary>Examples for relevant past discussions:</summary>
118+
119+
- https://github.com/pathintegral-institute/mcpm.sh/pull/76#discussion_r2050413886
120+
- https://github.com/pathintegral-institute/mcpm.sh/pull/76#discussion_r2050414500
121+
</details>
122+
123+
124+
___

0 commit comments

Comments
 (0)