oterm/tests/tools/mcp_servers.py
Yiorgis Gozadinos b4d1c67530
Update dependencies and migrate the test MCP server to mcp 2.x
pydantic-ai-slim 2.17.0 -> 2.37.0, pydantic-ai-harness 0.10.0 -> 0.28.0,
pydantic 2.13.4 -> 2.13.5, packaging 26.2 -> 26.3, python-dotenv 1.2.2 -> 1.2.3,
typer 0.26.8 -> 0.27.2. Dev group: ruff 0.15.12 -> 0.16.5, ty 0.0.32 -> 0.0.77,
pytest 9.0.3 -> 9.1.1, pytest-asyncio 1.3.0 -> 1.4.0, pre-commit 4.6.0 -> 4.6.2.

This pulls mcp 1.29.1 -> 2.1.1 and fastmcp-slim 3.4.7 -> 4.0.0 transitively.
oterm's source only uses the fastmcp client, but tests/tools/mcp_servers.py
builds a server, so it moves from mcp.server.fastmcp.FastMCP to
mcp.server.mcpserver.MCPServer. The port kwarg is gone from the constructor
and the fixture only ever runs over stdio, so it is dropped.

textual-image is held at 0.12.0 and pytest-textual-snapshot at 1.0.0; both
newer releases are incompatible with oterm's supported Python and pytest.
2026-09-01 13:00:29 +03:00

43 lines
1.3 KiB
Python

from mcp import SamplingMessage
from mcp.server.mcpserver import Context, MCPServer
from mcp.types import ModelHint, ModelPreferences, TextContent
mcp = MCPServer("TestServer")
@mcp.resource("config://app")
def get_config() -> str:
return "Oracle MCP server"
@mcp.tool(name="oracle", description="Ask the oracle a question.")
async def oracle(query: str, ctx: Context) -> str:
return "Oracle says: oterm"
@mcp.tool(name="puzzle_solver", description="Solves a puzzle by asking an advanced AI.")
async def puzzle_solver(puzzle_description: str, ctx: Context) -> str:
"""
This tool is included to make a sampling request to the server.
It takes a puzzle description and returns the answer.
"""
session = ctx.session
sampling_response = await session.create_message(
messages=[
SamplingMessage(
role="user",
content=TextContent(
text=f"Please solve this puzzle: {puzzle_description}", type="text"
),
)
],
model_preferences=ModelPreferences(
hints=[ModelHint(name="mistral")],
),
max_tokens=100,
)
return sampling_response.content.text
if __name__ == "__main__":
mcp.run(transport="stdio")