mirror of
https://github.com/mcp-use/mcp-use.git
synced 2026-09-14 18:06:01 +08:00
be9942a4d4
* feat: server first implementation * docs: docs for server and images * chore: locked langchain dependencies in pyproject.toml (#321) * python/release/1.3.13 * catch uvicorn logs && log session id * fix debug logic * docs: logging update * fix: icon of elicitation * fix installation paths for local clones * docs: minor restructuring * docs: reorganization, killed non existing pages * docs: beta tag on server * chore: example servers * feat: inspector autopopulated and client only * feat: enhance MCP logging system with customizable formats and improved middleware * feat: implement weather alert and forecast tools in FastMCP example server * mcp path configurable * fix inspector * export as FastMCP too * chore: update fastmcp migration example * lock inspector version * type runner * unhide docs and remove dangers * migration diff * docs and context example * export context * logging improvement * pretty JSON RPC * autoConnect url param in inspecotr * move logging * type check * Server Router * show response logs * fallback tool name to function name in router registration * compatibility export * Introduced ty and prek as type checker and precommit engine respectively - moved ruff config in pyproject toml * add ty check * ty runs only on staged files * ty configuration fix * move startup info in logging * remove bug from action * update claude rules * fix resource serialization * comments on inspector errors * abstracted runner transports * remove redunant call for network * fix ip getter * add inspector mcp path * response limit logging * disable ty check in action * moved transport type to types * support sse * show transport type in logs * change default transport * refactored tests to use mcp server * removed fastmcp * file restructuring * test table * sampling, elicitation, tool disabling enabling * deprecte sse server side * simplified report * fix action * remove sse deprecated test * move tests files to allow for server integration tests * docs * reorg integration test files * api-reference-doxs * fix broken links * telemetry * remove feature useage from scarf
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
import asyncio
|
|
import logging
|
|
|
|
import pytest
|
|
from mcp.client.session import ClientSession
|
|
from mcp.types import CreateMessageRequestParams, CreateMessageResult, ErrorData, TextContent
|
|
|
|
from mcp_use.client import MCPClient
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def sampling_callback(
|
|
context: ClientSession, params: CreateMessageRequestParams
|
|
) -> CreateMessageResult | ErrorData:
|
|
return CreateMessageResult(
|
|
content=TextContent(text="Hello, world!", type="text"), model="gpt-4o-mini", role="assistant"
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_sampling(primitive_server):
|
|
config = {"mcpServers": {"PrimitiveServer": {"url": f"{primitive_server}/mcp"}}}
|
|
client = MCPClient(config, sampling_callback=sampling_callback) # type: ignore[invalid-argument-type]
|
|
try:
|
|
await client.create_all_sessions()
|
|
session = client.get_session("PrimitiveServer")
|
|
result = await session.call_tool(name="analyze_sentiment", arguments={"text": "Hello, world!"})
|
|
content = result.content[0]
|
|
logger.info(f"Result: {content}")
|
|
assert content.text == "Hello, world!"
|
|
finally:
|
|
await client.close_all_sessions()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_sampling_with_no_callback(primitive_server):
|
|
try:
|
|
config = {"mcpServers": {"PrimitiveServer": {"url": f"{primitive_server}/mcp"}}}
|
|
client = MCPClient(config)
|
|
await client.create_all_sessions()
|
|
session = client.get_session("PrimitiveServer")
|
|
result = await session.call_tool(name="analyze_sentiment", arguments={"text": "Hello, world!"})
|
|
logger.info(f"Result: {result}")
|
|
print(f"Result: {result}")
|
|
assert result.isError
|
|
finally:
|
|
await client.close_all_sessions()
|