sjtu_cheap_task
Route low-risk jobs such as summarize, rewrite, classify, and extract.
Instructions
Route common low-risk jobs like summarize, rewrite, classify, and extract.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task | Yes | ||
| content | Yes | ||
| image_path | No | ||
| image_url | No | ||
| model | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/sjtu_mcp/server.py:112-148 (handler)The async function `sjtu_cheap_task` is the handler for the 'sjtu_cheap_task' MCP tool. It routes common low-risk jobs (summarize, rewrite, classify, extract, etc.) by building a routing prompt and calling the LLM API. Supports both text-only and image+text inputs, with model selection based on task type (reasoning models for 'reason'/'analyze'/'plan', text model otherwise).
async def sjtu_cheap_task( task: str, content: str, image_path: str | None = None, image_url: str | None = None, model: str | None = None, ) -> str: """Route common low-risk jobs like summarize, rewrite, classify, and extract.""" task_name = task.strip().lower() routing_prompt = ( "You are handling a low-risk utility task. Be concise, accurate, and structured.\n" f"Task: {task_name}\n" "Return the useful result directly." ) if image_path or image_url: response = await client.chat( model=model or settings.default_vision_model, messages=_build_vision_messages( f"{routing_prompt}\n\nInput:\n{content}", image_path=image_path, image_url=image_url, system_prompt=None, ), temperature=0.1, ) return _extract_text(response) selected_model = model or ( settings.default_reasoning_model if task_name in {"reason", "analyze", "plan"} else settings.default_text_model ) response = await client.chat( model=selected_model, messages=_build_text_messages(f"{routing_prompt}\n\nInput:\n{content}", None), temperature=0.1, ) return _extract_text(response) - src/sjtu_mcp/server.py:111-111 (registration)The `@mcp.tool()` decorator on line 111 registers `sjtu_cheap_task` as an MCP tool with the FastMCP server instance `mcp`.
@mcp.tool() - src/sjtu_mcp/server.py:15-29 (helper)Helper function `_extract_text` used by the handler to extract text from the API response dictionary.
def _extract_text(response: dict[str, Any]) -> str: choices = response.get("choices", []) if not choices: return "No choices returned." message = choices[0].get("message", {}) content = message.get("content", "") if isinstance(content, str): return content if isinstance(content, list): chunks: list[str] = [] for item in content: if isinstance(item, dict) and item.get("type") == "text": chunks.append(str(item.get("text", ""))) return "\n".join(chunk for chunk in chunks if chunk) return str(content) - src/sjtu_mcp/server.py:40-60 (helper)Helper function `_build_vision_messages` used when the handler processes image inputs.
def _build_vision_messages( prompt: str, *, image_path: str | None, image_url: str | None, system_prompt: str | None, ) -> list[dict[str, Any]]: if not image_path and not image_url: raise ValueError("Provide either image_path or image_url.") image_source = image_url or image_path_to_data_url(image_path or "") user_content = [ {"type": "text", "text": prompt}, {"type": "image_url", "image_url": {"url": image_source}}, ] messages: list[dict[str, Any]] = [] if system_prompt: messages.append({"role": "system", "content": system_prompt}) messages.append({"role": "user", "content": user_content}) return messages - src/sjtu_mcp/server.py:32-37 (helper)Helper function `_build_text_messages` used by the handler for text-only inputs.
def _build_text_messages(prompt: str, system_prompt: str | None) -> list[dict[str, Any]]: messages: list[dict[str, Any]] = [] if system_prompt: messages.append({"role": "system", "content": system_prompt}) messages.append({"role": "user", "content": prompt}) return messages