JT

jackandjac/token-saver-mcp-java

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

22 stars 0 forks 质量 61 趋势 18

MCP服务器通过langchain4j和langgraph4j将简单的Claude代码/Codex/Wibey任务委托给本地LLM。

概览

一个MCP服务器,允许Claude Code / Codex / Wifiy(或任何符合MCP的编码代理)将简单且范围明确的任务委托给本地LLM——代码片段、孤立重构、文档、代码审查、基础问答——这样你就能把高级代币花在协调和架构上,而不是本地模型已经能完成的工作。 这是在 langchain4j(本地 LLM 客户端)、langgraph4j(编排)和官方 MCP Java SDK(标准服务器)上用 Java 完全重写的版本。 最初的想法和 Python/FastMCP 原型的功劳归于 csabakecskemeti/cc_token_saver_mcp ——该项目基于该概念,采用基于图的分类/委派/升级流程、服务器端文件读取、超时和可操作错误。 服务器会暴露两个MCP工具——query_local_llm和query_local_llm_with_context——Claude Code被指示先尝试用于简单的子任务。

概述(AI 翻译)

一个MCP服务器,允许Claude Code / Codex / Wifiy(或任何符合MCP的编码代理)将简单且范围明确的任务委托给本地LLM——代码片段、孤立重构、文档、代码审查、基础问答——这样你就能把高级代币花在协调和架构上,而不是本地模型已经能完成的工作。

这是在 langchain4j(本地 LLM 客户端)、langgraph4j(编排)和官方 MCP Java SDK(标准服务器)上用 Java 完全重写的版本。

最初的想法和 Python/FastMCP 原型的功劳归于 csabakecskemeti/cc_token_saver_mcp ——该项目基于该概念,采用基于图的分类/委派/升级流程、服务器端文件读取、超时和可操作错误。

它是如何运作的

服务器会暴露两个MCP工具——query_local_llm和[query_local_llm_with_context——Claude Code被指示先尝试用于简单的子任务。每次调用都通过一个小型langgraph4j图,而不是直接转发到模型:

classify 会向局部模型发出廉价、低温的调用,以判断该任务是否足够简单。如果不够简单,escalate 返回结构化的“ESCALATE: …

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Token Saver MCP Java

An MCP server that lets Claude Code / Codex / Wibey (or any MCP-compliant coding agent) delegate simple, well-scoped tasks to your local LLM — code snippets, isolated refactors, documentation, code reviews, basic Q&A — so you spend premium tokens on coordination and architecture, not on work a local model can already do.

This is a complete rewrite in Java on langchain4j (local LLM client), langgraph4j (orchestration), and the official MCP Java SDK (stdio server).

Credit for the original idea and the Python/FastMCP prototype goes to csabakecskemeti/cc_token_saver_mcp — this project builds on that concept with a graph-based classify/delegate/escalate flow, server-side file reading, timeouts, and actionable errors.

How it works

The server exposes two MCP tools — query_local_llm and query_local_llm_with_context — that Claude Code is instructed to try first for simple subtasks. Every call runs through a small langgraph4j graph instead of just forwarding straight to the model:

START -> classify -> delegate -> END   (task judged within the local model's competence)
                  \-> escalate -> END  (task judged too complex; local LLM never called)

classify makes a cheap, low-temperature call to the local model to judge whether the task is actually simple enough for it. If not, escalate returns a structured ESCALATE: ... message telling Claude Code to handle the task itself — so a task that’s too complex for the local model comes back as a clear signal, not a low-quality answer.

Features

  • Server-side file reading. Both tools accept an optional file_paths array. The server reads the files itself and passes their content straight to the local LLM — Claude Code passes a path instead of Read()-ing the file into its own context first. This is where the real token savings on large files come from.
  • Bounded waits. Both tools accept an optional timeout_seconds (default from LOCAL_LLM_TIMEOUT_SECONDS), enforced with a hard timeout around the call so a stalled local backend can’t hang a tool call indefinitely.
  • Actionable errors. Backend failures (connection refused, unreachable host, timeout) come back as a clear message naming the configured URL and the next step — e.g. “Local LLM backend unreachable at http://127.0.0.1:8000/v1. Check that it’s running…” — with isError: true set correctly, instead of a raw exception string.
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

"mcpServers": { "token-saver": { "type": "stdio", "command": "java", "args": ["-jar", "<path>/token-saver-mcp-java/target/token-saver-mcp-java.jar"] } }