add cwd to StdioServerParameters (#292)

This commit is contained in:
Samuel Colvin 2025-03-19 12:03:10 +00:00 • committed by GitHub
commit 805fb469f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
import os import os
import sys import sys
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from pathlib import Path
from typing import Literal from typing import Literal
import anyio import anyio
@ -66,6 +67,9 @@ class StdioServerParameters(BaseModel):
If not specified, the result of get_default_environment() will be used. If not specified, the result of get_default_environment() will be used.
""" """
cwd: str | Path | None = None
"""The working directory to use when spawning the process."""
encoding: str = "utf-8" encoding: str = "utf-8"
""" """
The text encoding used when sending/receiving messages to the server The text encoding used when sending/receiving messages to the server
@ -101,6 +105,7 @@ async def stdio_client(server: StdioServerParameters):
[server.command, *server.args], [server.command, *server.args],
env=server.env if server.env is not None else get_default_environment(), env=server.env if server.env is not None else get_default_environment(),
stderr=sys.stderr, stderr=sys.stderr,
cwd=server.cwd,
) )
async def stdout_reader(): async def stdout_reader():