# 5 Lightweight Alternatives to MCP for Giving AI Agents Tools

> Source: <https://www.kdnuggets.com/5-lightweight-alternatives-to-mcp-for-giving-ai-agents-tools>
> Published: 2026-11-23 13:00:00+00:00

**Recommendation:** For a single operation like lookup_product(sku), skip an MCP server and use an allowlisted dispatcher or framework tool, keeping name, argument and permission checks in your own code.
More in the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

# 5 Lightweight Alternatives to MCP for Giving AI Agents Tools

Compare five lightweight ways to give AI agents tools without an MCP server, from a Python dispatcher to framework tools, REST adapters, subprocesses, and webhooks, and learn when MCP becomes worth adding.

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](https://modelcontextprotocol.io/specification/2026-07-28/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](https://www.kdnuggets.com/building-local-ai-systems-qwen3-6-mcps) 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.

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](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/)** 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.

| Existing component | Connection choice | Work that remains yours | 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 | Typed function tools | 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 | A bounded subprocess | 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:

``` python
# 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](https://docs.ollama.com/capabilities/tool-calling)** 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"
bash
$ 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](https://docs.apryse.com/core/guides/smart-data-extraction)** 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](https://pydantic.dev/docs/ai/tools-toolsets/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.

``` python
# 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)
bash
$ 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](https://www.kdnuggets.com/llmops-in-2026-the-10-tools-every-team-must-have) 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](https://spec.openapis.org/oas/v3.2.1.html)** (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
bash
$ 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`](https://docs.python.org/3.12/library/subprocess.html).

```
# 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)
bash
$ 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](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.webhook)** with header authentication at the start and a [Respond to Webhook](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.respondtowebhook) 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"}
bash
$ 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](https://www.kdnuggets.com/5-useful-docker-containers-for-agentic-developers) 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\](http://nahlawrites.com/)**](http://nahlawrites.com/) 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.
