1+ """Example of an MCP server
2+
3+ You need to install the mcp package:
4+ uv pip install "mcp[cli]"
5+
6+ and run the example in MCP debug UI:
7+ uv run mcp dev docs/examples/tutorial/mcp_example.py
8+ """
9+
110from mcp .server .fastmcp import FastMCP
211
312from mellea import MelleaSession
4- from mellea .backends import model_ids
13+ from mellea .backends import ModelOption , model_ids
514from mellea .backends .ollama import OllamaModelBackend
615from mellea .stdlib .base import ModelOutputThunk
716from mellea .stdlib .requirement import Requirement , simple_validate
817from mellea .stdlib .sampling import RejectionSamplingStrategy
918
1019# #################
11- # run MCP debug UI with: uv run mcp dev docs/examples/mcp /mcp_example.py
20+ # run MCP debug UI with: uv run mcp dev docs/examples/tutorial /mcp_example.py
1221# ##################
1322
1423
1928@mcp .tool ()
2029def write_a_poem (word_limit : int ) -> str :
2130 """Write a poem with a word limit."""
22- m = MelleaSession (OllamaModelBackend (model_ids .QWEN3_8B ))
31+ m = MelleaSession (
32+ OllamaModelBackend (
33+ model_ids .HF_SMOLLM2_2B ,
34+ model_options = {ModelOption .MAX_NEW_TOKENS : word_limit + 10 },
35+ )
36+ )
2337 wl_req = Requirement (
2438 f"Use only { word_limit } words." ,
2539 validation_fn = simple_validate (lambda x : len (x .split (" " )) < word_limit ),
@@ -28,7 +42,7 @@ def write_a_poem(word_limit: int) -> str:
2842 res = m .instruct (
2943 "Write a poem" ,
3044 requirements = [wl_req ],
31- strategy = RejectionSamplingStrategy (loop_budget = 4 ),
45+ strategy = RejectionSamplingStrategy (loop_budget = 2 ),
3246 )
3347 assert isinstance (res , ModelOutputThunk )
3448 return str (res .value )
0 commit comments