为 AI 智能体提供工具的 5 个 MCP 轻量替代方案

作者:Nahla Davies,KDnuggets,2026年11月23日,人工智能
假设你的应用已经有一个名为 lookup_product(sku) 的函数。该函数从商品目录中读取一行并返回价格。现在你想让模型能够调用它。这一次查找需要 Model Context Protocol (MCP) 服务器吗?
通常不需要,而且值得公平地说明原因。MCP 是一种将工具连接到多个宿主的协议:服务器描述其工具,任何兼容的客户端都能发现并调用它们。当前 MCP 架构(2026 年 7 月 28 日的修订版)既可通过同一台机器上的 stdio 运行,也可通过 Streamable HTTP 运行,因此采用它并不会强加给你一个网络服务。KDnuggets 的本地 MCP 助手演练展示了一个完整系统;在这里,我们将比较如何连接单个操作。下面五种选项并非五个相互竞争的标准。它们是同一个函数可以驻留的五个位置,取决于你已有条件:几个 Python 函数、一个智能体框架、一个 REST API、一个命令行工具或一个工作流平台。轻量意味着在你当前环境中承担更少的新集成和部署责任,仅此而已,没有比这更普适的含义。
每个示例都使用同一个虚构的商品目录。SKU BK-17 是一本 A5 野外笔记本,价格为 1,299 美分(美元),每条记录都带有 fixture: true,以免有人把它误认为价目表。实时示例中的模型是 Ollama 0.40.13 上的 qwen3.5:4b,展示的每项输出都是代码实际打印的结果。
在五种选择中保持相同的工具契约
无论你选择哪种连接方式,都会按相同顺序发生三件事。模型提议一次调用:一个工具名称和参数。应用程序根据它拥有的契约来检查该提议:名称必须是它允许的,参数必须符合声明的结构,而操作必须是该用户被允许运行的。然后由执行器执行工作,并返回结构化数据或明确的错误,应用程序再将其传回给模型。
图 1。无论使用哪种连接方式,应用程序都控制执行。五种替代方案及其所比较的 MCP 通道的示意图;未描绘任何已部署的系统。原图由 Nahla Davies 绘制。
这五种替代方案改变的是执行器的身份以及函数运行的位置。它们不改变业务规则,也没有任何一种会移除应用程序的检查。OWASP 的过度代理(excessive-agency)指南区分了三种出错方式:功能过多、权限过多和自主性过强,而这三者都由应用程序决定,而不是由传输层决定。
当选择不再简单时
几个本地 Python 函数
原生工具调用加上允许列表调度器
消息处理、权限和错误
多个提供商或客户端需要可复用的契约
一个 Python 智能体框架
业务授权与依赖维护
框架耦合的代价超过了省下的胶水代码
一个带 HTTP 接口的服务
一个精心维护的 REST 适配器,以 OpenAPI 作为地图
凭证、允许的操作与响应处理
规格宽泛或不断变动时,需要一个持续维护的适配层
一条可信且范围明确的命令
参数策略、权限与进程故障
不可信代码或更广泛的访问权限需要真正的隔离
一个持续维护的工作流平台
一个经过身份验证的 Webhook
工作流所有权、凭证与完成语义
部署该平台的工作量超过了其节省的集成工作量
契约本身很小:
# catalog.py import re SKU_PATTERN = re.compile(r"^[A-Z]{2}-\d{2,4}$") CATALOG = { "BK-17": {"sku": "BK-17", "name": "Field notebook, A5", "price_cents": 1299, "currency": "USD", "fixture": True}, "BK-18": {"sku": "BK-18", "name": "Field notebook, A4", "price_cents": 1799, "currency": "USD", "fixture": True}, } def validate_sku(sku: object) -> str: if not isinstance(sku, str) or not SKU_PATTERN.match(sku): raise ValueError(f"sku must match {SKU_PATTERN.pattern}, got {sku!r}") return sku def lookup_product(sku: str) -> dict: """Return the catalog record for one SKU, or raise KeyError if it does not exist.""" sku = validate_sku(sku) if sku not in CATALOG: raise KeyError(sku) return dict(CATALOG[sku])
1. 使用原生工具调用和一个小型调度器
如果函数与你的模型调用运行在同一个 Python 进程中,最短路径就是使用服务提供商自带的工具调用接口加一个字典。Ollama 的原生工具调用交互分为三步。你在聊天请求中发送工具 schema,助手消息返回时带的是 tool_calls 而不是文本。你自己执行该调用,并追加一条包含结果的 tool 消息。然后再次请求,模型便带着结果作答。
# k1_native_tools.py(核心) TOOLS = [{"type": "function", "function": { "name": "lookup_product", "description": "根据 SKU 在目录中查找一个产品并返回其价格。", "parameters": {"type": "object", "required": ["sku"], "properties": {"sku": {"type": "string", "description": "目录 SKU,例如 BK-17"}}}}}] DISPATCH = {"lookup_product": lookup_product} # 不在此处的名称永远不会执行 MAX_TURNS = 3 def run_tool_call(call: dict) -> str: name = call["function"]["name"] args = call["function"].get("arguments") or {} if name not in DISPATCH: return json.dumps({"error": f"工具 {name!r} 不可用"}) try: return json.dumps(DISPATCH[name](**args)) except (TypeError, ValueError) as err: return json.dumps({"error": f"无效参数:{err}"}) except KeyError as err: return json.dumps({"error": f"未知 sku {err.args[0]!r}"}) def ask(model: str, question: str) -> str: messages = [{"role": "user", "content": question}] for turn in range(MAX_TURNS): reply = chat(model, messages)["message"] # 向 /api/chat 发送 POST 请求,tools=TOOLS,stream=False messages.append(reply) calls = reply.get("tool_calls") or [] if not calls: return reply.get("content", "").strip() for call in calls: result = run_tool_call(call) messages.append({"role": "tool", "tool_name": call["function"]["name"], "content": result}) return f"在 {MAX_TURNS} 轮后未完成"
$ python k1_native_tools.py --model qwen3.5:4b "How much is BK-17?" model proposed: lookup_product({"sku": "BK-17"}) application returned: {"sku": "BK-17", "name": "Field notebook, A5", "price_cents": 1299, "currency": "USD", "fixture": true} final answer: The price of the Field notebook (A5), SKU BK-17, is $12.99 USD. $ python k1_native_tools.py --model qwen3.5:4b "How much is BK-99?" model proposed: lookup_product({"sku": "BK-99"}) application returned: {"error": "unknown sku 'BK-99'"} final answer: I couldn't find the price for SKU BK-99 in our catalog. ...
调度器就是这条路由的整个安全模型,所以它必须是一张固定的字典,绝不能是对模块做 getattr,也不能是任何模型能凭空命名出来的东西。第二次运行说明了错误路径为何重要。模型请求了一个并不存在的 SKU,应用程序返回的是结构化错误,而不是抛出异常。基于这个错误,模型如实告知了用户,而不是编造一个价格。这条路线不能给你的,是可移植性。消息结构是 Ollama 的;换一家提供商,tool_calls 的布局就不一样,而循环、轮次上限以及每一个错误都得由你自己负责。对于一个只有几个函数的单一应用来说,这是笔划算的交易;而等到有第二个客户端想用同一批工具的那天,就不划算了。
在这道边界之后,工具函数可以想多厚就多厚。对于文档处理类工具来说,从 PDF 中提取表格数据可以留在一个由 SDK 支撑的函数内部;智能体收到的是返回的字段,而不必自己去管理 PDF 解析器。那个链接的指南是 Apryse 的商业 SDK 文档,有其自身的许可要求;而目录示例除标准库之外什么都不需要。
2. 把 Python 函数封装为带类型的框架工具
当你已经在框架中编写智能体时,框架会为你完成注册和参数校验,而上面的调度器会隐入一个装饰器。PydanticAI 的类型化函数工具会根据函数签名和 docstring 构建面向模型的 schema;@agent.tool_plain 是用于不需要 run context 的函数的变体。
原文较长,译文为节选;译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。
查看英文原文(5 Lightweight Alternatives to MCP for Giving AI Agents Tools)
By Nahla Davies, KDnuggets on November 23, 2026 in Artificial Intelligence

Suppose your application already has a function called lookup_product(sku). The function reads one row from a catalog and returns a price. Now you want a model to be able to call it. Does that one lookup need a Model Context Protocol (MCP) server?
Usually not, and it is worth being fair about why. MCP is a protocol for connecting tools to many hosts: a server describes its tools, and any compatible client can discover and call them. The current MCP architecture, the July 28, 2026 revision, runs over stdio on the same machine as well as over Streamable HTTP, so adopting it does not force a network service on you. KDnuggets' local MCP assistant walkthrough shows a complete system; here, we will compare how to connect one operation. The five options below are not five rival standards. They are five places the same function can live, chosen by what you already own: a few Python functions, an agent framework, a REST API, a command-line tool, or a workflow platform. Lightweight means fewer new integration and deployment responsibilities in the environment you have now, nothing more universal than that.
Every example uses the same invented catalog. SKU BK-17 is an A5 field notebook at 1,299 cents in USD, and every record carries fixture: true so nobody mistakes it for a price list. The model in the live examples is qwen3.5:4b on Ollama 0.40.13, and every output shown is what the code printed.
Keeping the Same Tool Contract Across the Five Choices
Whichever connection you pick, three things happen in the same order. The model proposes a call: a tool name and arguments. The application checks that proposal against a contract it owns: the name must be one it allows, the arguments must fit the declared shape, and the operation must be one this user is permitted to run. Then an executor performs the work and returns either structured data or an explicit error, which the application passes back to the model.
Figure 1. The application controls execution whichever connection it uses. Schematic of the five alternatives and the MCP lane they are compared with; no deployed system is depicted. Original diagram by Nahla Davies.
The five alternatives change who the executor is and where the function runs. They do not change the business rule, and none of them removes the application's checks. OWASP's excessive-agency guidance separates three ways this goes wrong, too much functionality, too many permissions and too much autonomy, and all three are decided by the application, not by the transport.
When the choice stops being simple
A few local Python functions
Native tool calling plus an allowlisted dispatcher
Message handling, permissions and errors
Several providers or clients need reusable contracts
A Python agent framework
Business authorization and dependency maintenance
Framework coupling outweighs the saved glue
A service with an HTTP interface
A curated REST adapter, with OpenAPI as the map
Credentials, allowed operations and response handling
Broad or changing specs need a maintained adapter layer
A trusted narrow command
Argument policy, privileges and process failures
Untrusted code or wider access needs real isolation
A maintained workflow platform
An authenticated webhook
Workflow ownership, credentials and completion semantics
Deploying the platform exceeds the saved integration work
The contract itself is small:
# catalog.py
import re
SKU_PATTERN = re.compile(r"^[A-Z]{2}-\d{2,4}$")
CATALOG = {
"BK-17": {"sku": "BK-17", "name": "Field notebook, A5", "price_cents": 1299, "currency": "USD", "fixture": True},
"BK-18": {"sku": "BK-18", "name": "Field notebook, A4", "price_cents": 1799, "currency": "USD", "fixture": True},
}
def validate_sku(sku: object) -> str:
if not isinstance(sku, str) or not SKU_PATTERN.match(sku):
raise ValueError(f"sku must match {SKU_PATTERN.pattern}, got {sku!r}")
return sku
def lookup_product(sku: str) -> dict:
"""Return the catalog record for one SKU, or raise KeyError if it does not exist."""
sku = validate_sku(sku)
if sku not in CATALOG:
raise KeyError(sku)
return dict(CATALOG[sku])
1. Use Native Tool Calling and a Small Dispatcher
If the function lives in the same Python process as your model calls, the shortest route is the provider's own tool-calling interface and a dictionary. Ollama's native tool-calling exchange has three steps. You send the tool schema with the chat request, and the assistant message comes back with tool_calls instead of text. You run the call yourself and append a tool message holding the result. Then you ask again, and the model answers with the result in hand.
# k1_native_tools.py (core)
TOOLS = [{"type": "function", "function": {
"name": "lookup_product",
"description": "Look up one product in the catalog by SKU and return its price.",
"parameters": {"type": "object", "required": ["sku"],
"properties": {"sku": {"type": "string", "description": "Catalog SKU such as BK-17"}}}}}]
DISPATCH = {"lookup_product": lookup_product} # a name not in here is never executed
MAX_TURNS = 3
def run_tool_call(call: dict) -> str:
name = call["function"]["name"]
args = call["function"].get("arguments") or {}
if name not in DISPATCH:
return json.dumps({"error": f"tool {name!r} is not available"})
try:
return json.dumps(DISPATCH[name](**args))
except (TypeError, ValueError) as err:
return json.dumps({"error": f"invalid arguments: {err}"})
except KeyError as err:
return json.dumps({"error": f"unknown sku {err.args[0]!r}"})
def ask(model: str, question: str) -> str:
messages = [{"role": "user", "content": question}]
for turn in range(MAX_TURNS):
reply = chat(model, messages)["message"] # POST /api/chat with tools=TOOLS, stream=False
messages.append(reply)
calls = reply.get("tool_calls") or []
if not calls:
return reply.get("content", "").strip()
for call in calls:
result = run_tool_call(call)
messages.append({"role": "tool", "tool_name": call["function"]["name"], "content": result})
return f"unfinished after {MAX_TURNS} turns"
$ python k1_native_tools.py --model qwen3.5:4b "How much is BK-17?"
model proposed: lookup_product({"sku": "BK-17"})
application returned: {"sku": "BK-17", "name": "Field notebook, A5", "price_cents": 1299, "currency": "USD", "fixture": true}
final answer: The price of the Field notebook (A5), SKU BK-17, is $12.99 USD.
$ python k1_native_tools.py --model qwen3.5:4b "How much is BK-99?"
model proposed: lookup_product({"sku": "BK-99"})
application returned: {"error": "unknown sku 'BK-99'"}
final answer: I couldn't find the price for SKU BK-99 in our catalog. ...
The dispatcher is the whole security model of this route, so it has to be a fixed dictionary, never getattr on a module or anything the model can name into existence. The second run shows why the error path matters. The model asked for a SKU that does not exist, and the application returned a structured error rather than raising. Given that error, the model told the user so instead of inventing a price. What this route does not give you is portability. The message shapes are Ollama's; a different provider has a different tool_calls layout, and you own the loop, the turn limit and every error. That is a fine trade for one application with a few functions and a poor one the day a second client wants the same tools.
A tool function can be as thick as it needs to be behind that boundary. For a document-processing tool, extracting table data from PDFs can stay inside an SDK-backed function; the agent receives the returned fields rather than managing the PDF parser. That linked guide is Apryse's commercial SDK documentation, with licensing requirements of its own; the catalog example needs nothing beyond the standard library.
2. Wrap Python Functions as Typed Framework Tools
When you already write agents in a framework, the framework will do the registration and argument validation for you, and the dispatcher above disappears into a decorator. PydanticAI's typed function tools build the model-facing schema from the function signature and the docstring; @agent.tool_plain is the variant for a function that needs no run context.
# k2_pydantic_ai.py (core)
from pydantic import BaseModel, Field, ValidationError
from pydantic_ai import Agent, ModelRetry
from pydantic_ai.models.ollama import OllamaModel
from pydantic_ai.providers.ollama import OllamaProvider
model = OllamaModel("qwen3.5:4b", provider=OllamaProvider(base_url="http://127.0.0.1:11434/v1"))
agent = Agent(model, instructions="Answer with the price from the catalog tool. Prices are in cents.")
@agent.tool_plain
def lookup_product_tool(sku: str) -> dict:
"""Look up one product in the catalog by SKU and return its price.
Args:
sku: Catalog SKU such as BK-17.
"""
try:
return lookup_product(sku)
except ValueError as err:
raise ModelRetry(str(err)) from err # tell the model the argument was wrong
except KeyError:
return {"error": f"unknown sku {sku!r}"}
class LookupArgs(BaseModel):
sku: str = Field(pattern=SKU_PATTERN.pattern)
try:
LookupArgs.model_validate({"sku": 17}, strict=True) # raises: an int is not a string
except ValidationError as err:
print(f"strict validation rejected sku=17: {err.errors()[0]['msg']}")
result = agent.run_sync("How much is BK-17?")
print(result.output)
$ python k2_pydantic_ai.py --model qwen3.5:4b "How much is BK-17?"
tool schema: {"additionalProperties": false, "properties": {"sku": {"description": "Catalog SKU such as BK-17.", "type": "string"}}, "required": ["sku"], "type": "object"}
strict validation rejected sku=17: Input should be a valid string
final answer: BK-17 costs 1299 cents (US dollars).
The first output line is the schema the framework generated from one type hint and one docstring line, with additionalProperties: false added without being asked. The second is Pydantic's strict mode refusing 17 where a string was declared; by default Pydantic coerces when it can, so if you want the model's arguments rejected rather than repaired, say so explicitly. Validation is the framework's job here, and ModelRetry is how the tool sends a bad argument back to the model for another attempt. Authorization is still yours: nothing in the decorator knows whether this user may read this catalog. The cost is the dependency (pydantic-ai 2.66.0 in the run above) and a coupling to one framework's conventions. PydanticAI can also run the same tool over native calling or over MCP underneath, which is why this is a choice at a different layer from the others. For context on where a framework fits, the LLMOps stack overview places PydanticAI alongside tools for other jobs.
3. Adapt an Existing REST API, Using OpenAPI as Its Map
Often the function is not a function at all. It is an operation on a service that already exists, with its own authentication and its own documentation. In that case the agent does not need a new tool server; it needs a small adapter that knows one operation and nothing else.
The service's OpenAPI document is the map. An OpenAPI operation description (version 3.2.1, September 2026) tells you the method, the path, the parameters and the security requirement for GET /items/{sku}. It executes nothing and grants nothing; the adapter does both, and it does them for the one operation you have reviewed rather than for the whole specification.
# k3_http_adapter.py (core)
BASE_URL = "http://127.0.0.1:8765" # fixed in configuration
OPERATION = {"method": "GET", "path": "/items/{sku}"} # the one reviewed operation
API_KEY = os.environ["CATALOG_API_KEY"] # never a model-supplied value
MAX_BODY = 64_000
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args, **kwargs):
raise urllib.error.HTTPError(args[0].full_url, 310, "redirect refused by adapter", {}, None)
_OPENER = urllib.request.build_opener(NoRedirect, urllib.request.ProxyHandler({}))
def lookup_product_http(sku: str) -> dict:
sku = validate_sku(sku)
request = urllib.request.Request(BASE_URL + OPERATION["path"].format(sku=sku),
method=OPERATION["method"], headers={"X-API-Key": API_KEY})
try:
with _OPENER.open(request, timeout=10) as response:
body = response.read(MAX_BODY + 1)
except urllib.error.HTTPError as err:
return {"error": f"HTTP {err.code}", "detail": err.read().decode("utf-8", "replace")[:200]}
except (urllib.error.URLError, TimeoutError, OSError) as err:
return {"error": f"request failed: {err}"}
if len(body) > MAX_BODY:
return {"error": "response too large"}
data = json.loads(body)
if not isinstance(data, dict) or "price_cents" not in data:
return {"error": "response did not have the expected shape"}
return data
$ python k3_http_adapter.py BK-17 BK-99
BK-17: {"sku": "BK-17", "name": "Field notebook, A5", "price_cents": 1299, "currency": "USD", "fixture": true}
BK-99: {"error": "HTTP 404", "detail": "{\"error\": \"no item BK-99\"}"}
The service behind port 8765 in this run is a forty-line stand-in that implements that one operation behind an API-key header, which is all the adapter needs to be tested against. Four things in the adapter do the real work. The base URL and the operation are configuration, so the model can never steer a request to a different host or path. The credential comes from the environment and never appears in a tool argument. The response is bounded in size and checked for the shape the operation promised. And redirects are refused, because a redirect is how a same-origin request quietly becomes a cross-origin one. What stays with you is everything the spec does not do: keeping the credential, following version changes and normalizing the response when the service changes its mind about field names.
4. Expose One Bounded Command-Line Operation
Some of the most useful tools are commands you already trust, and the temptation is to let the model write command lines. Resist that; expose one command with a fixed executable, a fixed script and structured input and output, through subprocess.run.
# k4_cli.py (core)
SCRIPT = Path(__file__).with_name("catalog_cli.py") # JSON on stdin, one JSON object on stdout
TIMEOUT_SECONDS = 5
MAX_OUTPUT = 64_000
def lookup_product_cli(sku: str) -> dict:
sku = validate_sku(sku)
try:
completed = subprocess.run(
[sys.executable, str(SCRIPT)], # a list, never a string; shell=False is the default
input=json.dumps({"sku": sku}), capture_output=True, text=True, encoding="utf-8",
check=True, timeout=TIMEOUT_SECONDS, cwd=SCRIPT.parent,
)
except subprocess.TimeoutExpired:
return {"error": f"catalog_cli.py exceeded {TIMEOUT_SECONDS}s"}
except subprocess.CalledProcessError as err:
return {"error": f"exit {err.returncode}", "detail": err.stdout.strip()[:200]}
if len(completed.stdout) > MAX_OUTPUT:
return {"error": "output too large"}
return json.loads(completed.stdout)
$ python k4_cli.py BK-17
BK-17: {"sku": "BK-17", "name": "Field notebook, A5", "price_cents": 1299, "currency": "USD", "fixture": true}
$ CATALOG_CLI_SLOW=1 python k4_cli.py BK-17
BK-17: {"error": "catalog_cli.py exceeded 5s"}
The process boundary gives you an exit status, separate output streams and a timeout. The second run shows the timeout at work: the child was told to stall, and the caller gave up at five seconds and returned a structured error instead of hanging the agent. Passing the command as a list with shell=False means nothing in the arguments is interpreted by a shell. That is all shell=False means. The child runs with your process's privileges and can still do anything catalog_cli.py can do, so the controls are the argument grammar (the SKU pattern, checked before the process starts) and the choice of script. A .bat or .cmd wrapper would hand interpretation straight back to a shell. If the command runs untrusted code or needs broader access, this route stops being lightweight and you want actual isolation.
5. Call a Workflow You Already Run Through a Webhook
The fifth option looks like the third, since both use HTTP, and the difference is who owns the logic on the other end. An adapter calls one operation of a service. A webhook hands a request to a workflow someone else maintains, with its own downstream steps, and reads back whatever that workflow decides to return. In n8n that pair is a Webhook node with header authentication at the start and a Respond to Webhook node after the step that produces the result. Placed there, the response carries the workflow's actual data rather than a bare acknowledgment.
# k5_webhook.py (core)
WORKFLOW_URL = os.environ["WORKFLOW_URL"] # the workflow's test or production URL, fixed
TOKEN = os.environ["WORKFLOW_TOKEN"] # from configuration, never from the model
def call_workflow(name: str, sku: str, qty: int = 1) -> dict:
sku = validate_sku(sku)
request = urllib.request.Request(f"{WORKFLOW_URL}/{name}", data=json.dumps({"sku": sku, "qty": qty}).encode(),
method="POST", headers={"Content-Type": "application/json", "X-Workflow-Token": TOKEN})
try:
with _OPENER.open(request, timeout=15) as response:
code, data = response.status, json.loads(response.read(64_000))
except urllib.error.HTTPError as err:
return {"state": "failed", "http": err.code, "detail": err.read().decode("utf-8", "replace")[:200]}
if code == 200 and data.get("status") == "completed":
return {"state": "completed", "data": data}
if code == 202 and data.get("status") == "accepted":
return {"state": "pending", "job_id": data.get("job_id")}
return {"state": "failed", "http": code, "detail": "unexpected response"}
$ python k5_webhook.py quote-preview BK-17 3
quote-preview BK-17: {"state": "completed", "data": {"status": "completed", "quote": {"sku": "BK-17", "qty": 3, "total_cents": 3897, "currency": "USD", "fixture": true}}}
$ python k5_webhook.py restock-check BK-17
restock-check BK-17: {"state": "pending", "job_id": "rc-2026-11-04-0001"}
$ WORKFLOW_TOKEN=wrong python k5_webhook.py quote-preview BK-17
quote-preview BK-17: {"state": "failed", "http": 401, "detail": "{\"error\": \"authorization required\"}"}
The endpoint in this run is a local stand-in that answers with the contract an n8n workflow would be configured to return, since the point is the client's behavior, not the platform. Three responses, three states. A 200 with status: completed carries the quote and the agent can use it. A 202 with a job_id means the workflow accepted the work and has not finished. The tool reports pending, and the application decides what to do with a pending job. It does not tell the user the restock check is done, and it does not retry a write because the first attempt was slow. A 401 is a failure with a reason. One honest caveat about the premise: if you do not already run a workflow platform, standing one up for a catalog lookup is the opposite of lightweight. The agentic developer container guide introduces n8n as infrastructure; this option is useful when that workflow service is already maintained.
Keeping the Function and Adding the Model Context Protocol When Other Clients Need It
Start from the component you already maintain and give the model one read-only operation through the matching boundary. For a Python function that is the dictionary; in a framework, the decorator; for a service, the adapter; for a command, the bounded subprocess; for a workflow, the webhook. Then check two things before adding a second tool. The success path should return the data you expected. The denial path, whether an unknown SKU, a bad argument or a wrong token, should come back as a structured error the model can repeat rather than an exception the agent swallows.
MCP enters when the question changes from "how does my application call this function" to "how do several hosts discover and call it under one contract." At that point the business function from alternative 1 is exactly what an MCP server would expose through tools/list and tools/call. It can do so over stdio for a local host or over Streamable HTTP for a remote one. Nothing about the five choices above is wasted when that day comes. The function, its argument grammar and its error shape move; the transport changes around them.
Nahla Davies is a software developer and tech writer. Before devoting her work full time to technical writing, she managed—among other intriguing things—to serve as a lead programmer at an Inc. 5,000 experiential branding organization whose clients include Samsung, Time Warner, Netflix, and Sony.
原文为英文,正文由自动抓取并保留原文。
原文发布于 KDnuggets(5 Lightweight Alternatives to MCP for Giving AI Agents Tools),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。