Skip to content

Commit 58bc32e

Browse files
committed
merge: Resolve conflicts from v1.1.x merge
2 parents e32bf07 + d06b393 commit 58bc32e

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ target-version = "py310"
8383
members = ["examples/servers/*"]
8484

8585
[tool.uv.sources]
86-
mcp = { workspace = true }
86+
mcp = { workspace = true }

Diff for: src/mcp/client/stdio.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
from contextlib import asynccontextmanager
4+
from typing import Literal
45

56
import anyio
67
import anyio.lowlevel
@@ -65,6 +66,21 @@ class StdioServerParameters(BaseModel):
6566
If not specified, the result of get_default_environment() will be used.
6667
"""
6768

69+
encoding: str = "utf-8"
70+
"""
71+
The text encoding used when sending/receiving messages to the server
72+
73+
defaults to utf-8
74+
"""
75+
76+
encoding_error_handler: Literal["strict", "ignore", "replace"] = "strict"
77+
"""
78+
The text encoding error handler.
79+
80+
See https://docs.python.org/3/library/codecs.html#codec-base-classes for
81+
explanations of possible values
82+
"""
83+
6884

6985
@asynccontextmanager
7086
async def stdio_client(server: StdioServerParameters):
@@ -93,7 +109,11 @@ async def stdout_reader():
93109
try:
94110
async with read_stream_writer:
95111
buffer = ""
96-
async for chunk in TextReceiveStream(process.stdout):
112+
async for chunk in TextReceiveStream(
113+
process.stdout,
114+
encoding=server.encoding,
115+
errors=server.encoding_error_handler,
116+
):
97117
lines = (buffer + chunk).split("\n")
98118
buffer = lines.pop()
99119

@@ -115,7 +135,12 @@ async def stdin_writer():
115135
async with write_stream_reader:
116136
async for message in write_stream_reader:
117137
json = message.model_dump_json(by_alias=True, exclude_none=True)
118-
await process.stdin.send((json + "\n").encode())
138+
await process.stdin.send(
139+
(json + "\n").encode(
140+
encoding=server.encoding,
141+
errors=server.encoding_error_handler,
142+
)
143+
)
119144
except anyio.ClosedResourceError:
120145
await anyio.lowlevel.checkpoint()
121146

Diff for: src/mcp/server/lowlevel/server.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ def __init__(
101101

102102

103103
class Server:
104-
def __init__(self, name: str):
104+
def __init__(self, name: str, version: str | None = None):
105105
self.name = name
106+
self.version = version
106107
self.request_handlers: dict[
107108
type, Callable[..., Awaitable[types.ServerResult]]
108109
] = {
@@ -133,7 +134,7 @@ def pkg_version(package: str) -> str:
133134

134135
return InitializationOptions(
135136
server_name=self.name,
136-
server_version=pkg_version("mcp"),
137+
server_version=self.version if self.version else pkg_version("mcp"),
137138
capabilities=self.get_capabilities(
138139
notification_options or NotificationOptions(),
139140
experimental_capabilities or {},

Diff for: src/mcp/shared/exceptions.py

+5
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ class McpError(Exception):
77
"""
88

99
error: ErrorData
10+
11+
def __init__(self, error: ErrorData):
12+
"""Initialize McpError."""
13+
super().__init__(error.message)
14+
self.error = error

0 commit comments

Comments
 (0)