Skip to content

Commit 03d471b

Browse files
murichrusiaaman
authored andcommitted
feat(mcp-server): add customizable server instructions via environment variable
Add support for WCGW_SERVER_INSTRUCTIONS environment variable to allow customization of server instructions in MCP Initialize tool responses. - Add CUSTOM_INSTRUCTIONS global variable to store instructions - Read WCGW_SERVER_INSTRUCTIONS environment variable on server startup - Prepend custom instructions to existing hardcoded Initialize response - Maintain backward compatibility when no custom instructions provided - Preserve original hardcoded message content
1 parent a358815 commit 03d471b

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/wcgw/client/mcp_server/server.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,18 @@ async def handle_call_tool(
121121
for output_or_done in output_or_dones:
122122
if isinstance(output_or_done, str):
123123
if issubclass(tool_type, Initialize):
124-
output_or_done += """
124+
# Prepare the original hardcoded message
125+
original_message = """
125126
- Additional important note: as soon as you encounter "The user has chosen to disallow the tool call.", immediately stop doing everything and ask user for the reason.
126127
127128
Initialize call done.
128129
"""
130+
131+
# If custom instructions exist, prepend them to the original message
132+
if CUSTOM_INSTRUCTIONS:
133+
output_or_done += f"\n{CUSTOM_INSTRUCTIONS}\n{original_message}"
134+
else:
135+
output_or_done += original_message
129136

130137
content.append(types.TextContent(type="text", text=output_or_done))
131138
else:
@@ -141,12 +148,16 @@ async def handle_call_tool(
141148

142149

143150
BASH_STATE = None
151+
CUSTOM_INSTRUCTIONS = None
144152

145153

146154
async def main() -> None:
147-
global BASH_STATE
155+
global BASH_STATE, CUSTOM_INSTRUCTIONS
148156
CONFIG.update(3, 55, 5)
149157
version = str(importlib.metadata.version("wcgw"))
158+
159+
# Read custom instructions from environment variable
160+
CUSTOM_INSTRUCTIONS = os.getenv("WCGW_SERVER_INSTRUCTIONS")
150161

151162
# starting_dir is inside tmp dir
152163
tmp_dir = get_tmpdir()

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)