Skip to content

Commit 246af0a

Browse files
authored
Set PYCLI_MCP_TOOL_NAME environment variable (#14)
1 parent c76ba3c commit 246af0a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1212

1313
- Add support for Typer
1414
- Add support for Argparse
15+
- Always set the `PYCLI_MCP_TOOL_NAME` environment variable when running commands
1516

1617
## 0.2.0 - 2025-06-28
1718

src/pycli_mcp/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT
33
from __future__ import annotations
44

5+
import os
56
import subprocess
67
from contextlib import asynccontextmanager
78
from functools import cached_property
@@ -173,12 +174,16 @@ async def call_tool_handler(self, req: CallToolRequest) -> ServerResult:
173174
The default handler for the `CallToolRequest`.
174175
"""
175176
command = self.commands[req.params.name].metadata.construct(req.params.arguments)
177+
env_vars = dict(os.environ)
178+
env_vars["PYCLI_MCP_TOOL_NAME"] = req.params.name
179+
176180
try:
177181
process = subprocess.run( # noqa: PLW1510
178182
command,
179183
encoding="utf-8",
180184
stdout=subprocess.PIPE,
181185
stderr=subprocess.STDOUT,
186+
env=env_vars,
182187
)
183188
# This can happen if the command is not found
184189
except subprocess.CalledProcessError as e:

0 commit comments

Comments
 (0)