chore: import upstream snapshot with attribution
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Waiting to run
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import base64
|
||||
|
||||
import pytest
|
||||
from mcp_types import (
|
||||
BlobResourceContents,
|
||||
ReadResourceRequestParams,
|
||||
ReadResourceResult,
|
||||
TextResourceContents,
|
||||
)
|
||||
|
||||
from mcp import Client
|
||||
from mcp.server import Server, ServerRequestContext
|
||||
|
||||
pytestmark = pytest.mark.anyio
|
||||
|
||||
|
||||
async def test_read_resource_text():
|
||||
async def handle_read_resource(ctx: ServerRequestContext, params: ReadResourceRequestParams) -> ReadResourceResult:
|
||||
return ReadResourceResult(
|
||||
contents=[TextResourceContents(uri=str(params.uri), text="Hello World", mime_type="text/plain")]
|
||||
)
|
||||
|
||||
server = Server("test", on_read_resource=handle_read_resource)
|
||||
|
||||
async with Client(server) as client:
|
||||
result = await client.read_resource("test://resource")
|
||||
assert len(result.contents) == 1
|
||||
|
||||
content = result.contents[0]
|
||||
assert isinstance(content, TextResourceContents)
|
||||
assert content.text == "Hello World"
|
||||
assert content.mime_type == "text/plain"
|
||||
|
||||
|
||||
async def test_read_resource_binary():
|
||||
binary_data = b"Hello World"
|
||||
|
||||
async def handle_read_resource(ctx: ServerRequestContext, params: ReadResourceRequestParams) -> ReadResourceResult:
|
||||
return ReadResourceResult(
|
||||
contents=[
|
||||
BlobResourceContents(
|
||||
uri=str(params.uri),
|
||||
blob=base64.b64encode(binary_data).decode("utf-8"),
|
||||
mime_type="application/octet-stream",
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
server = Server("test", on_read_resource=handle_read_resource)
|
||||
|
||||
async with Client(server) as client:
|
||||
result = await client.read_resource("test://resource")
|
||||
assert len(result.contents) == 1
|
||||
|
||||
content = result.contents[0]
|
||||
assert isinstance(content, BlobResourceContents)
|
||||
assert content.mime_type == "application/octet-stream"
|
||||
assert base64.b64decode(content.blob) == binary_data
|
||||
Reference in New Issue
Block a user