basforge

Search titles, text and the “If it doesn’t work” cases.

    RU
    OverviewAIAI agents

    MCP, CLI, or script: when an MCP server helps and when it gets in the way

    Use MCP (Model Context Protocol) when the agent has no terminal or when an external service needs shared OAuth login and a strict schema. When the agent runs in an editor with a terminal, a regular CLI (gh, docker, psql) or your own script uses less context and avoids running another server.

    What problem it solves

    When MCP took off, people started plugging everything into their agents at once: GitHub, databases, Docker, email, issue trackers, calendars. Five or six servers later, the agent suddenly responds slower, hits limits sooner, and makes mistakes on straightforward edits.

    The reason is plain: by default, every MCP server puts the name, description, and full JSON input schema of every tool it exposes into the model’s context. Five large servers add 15,000–50,000 tokens before you ask your first question (Tokens). Meanwhile git, gh, docker, psql, and kubectl are already installed on your machine — models know their flags from training and don’t need dozens of kilobytes of schemas on every turn.

    Everything through MCP

    • Dozens of tool schemas sent on every request even when unused.
    • The model mixes up similar functions across different servers.
    • Raw JSON payloads bloat conversation history.
    • Extra background processes and package versions to maintain.

    MCP where it fits

    • Local tools (git, gh, docker) and scripts run through the terminal.
    • Remote MCP handles cloud services with OAuth and clients without a terminal.
    • Only the servers needed for the current task stay enabled per project.
    • Large tool catalogs use deferred tool loading.

    How MCP works and where token spend comes from

    MCP exchanges JSON-RPC 2.0 messages between the agent program (client) and an MCP server (Agents and tools). Context cost builds up at two steps — loading the tool list and returning results:

    start agent with MCP

    1. HandshakeinitializeClient and server announce supported capabilities: tools, resources, and prompt templates.
    2. Tool catalogtools/listThe server returns names, descriptions, and parameter JSON schemas. Without deferred loading, this entire list enters context on every request.
    3. Deferred loadingtool searchSome clients give the model one search tool instead of all schemas up front and load only 3–5 matching schemas per task.
    4. Invocationtools/callThe model outputs the tool name and schema-matched JSON arguments. The client checks permissions and forwards the call to the MCP server.
    5. Resulttool_resultThe server’s response goes into chat history. If it returns an entire document or hundreds of JSON lines, they stay in context for all following turns.

    reply with tool result

    Deferred loading (tool search) cuts most schema overhead, but it doesn’t shrink the server’s responses. On top of that, searching by description can miss a tool if your prompt phrases the task differently.

    Two MCP transports: local and remote

    The current MCP specification defines two main transports. Streamable HTTP replaced the older HTTP+SSE transport.

    stdio

    Local server

    process on your PC

    The agent spawns a local process (for instance via Node or Python) and exchanges JSON-RPC over stdin and stdout. No network ports open and OAuth isn’t used — keys and settings arrive through environment variables. The server code runs with your user’s permissions.

    Streamable HTTP

    Remote server

    HTTPS + OAuth 2.1

    A single HTTPS endpoint returning plain JSON or a Server-Sent Events (SSE) stream. Supports OAuth 2.1 login, so you don’t store raw tokens in local files. Fits email, calendar, trackers, and web chats — though every call argument travels to the MCP provider’s server (Your data in AI).

    MCP, CLI, or your own script

    An agent with terminal access has three ways to talk to external systems, each suited to different work:

    Method Startup context cost Schema and validation Where it works
    Terminal CLI (gh, docker, psql) near zero: model knows commands or checks --help no strict schema; plain-text output only where the agent has a terminal
    Own script + skill zero until the skill is invoked (Instructions for an AI agent) you define it: the script filters and prints a short summary wherever terminal and project files exist
    MCP (standard) high: thousands of tokens for all tool schemas strict JSON parameter schemas and uniform errors any compatible client, including web chat
    MCP with deferred loading low: only tool search at startup strict JSON schemas after loading needed tools clients that support tool search

    GitHub makes the difference clear. In an editor with gh, the agent runs gh pr view 42 --json title,state,reviews and pipes through jq. It gets twenty lines of exact data without loading forty GitHub MCP tool schemas into context. In a web chat with no terminal, by contrast, remote MCP is the way to reach an issue tracker or mailbox.

    When to pick which

    If you need to… Pick
    connect email, calendar, tracker, or cloud apps to a web chat without a terminal remote MCP (Streamable HTTP + OAuth 2.1)
    work with git, GitHub, Docker, Kubernetes, or databases from an editor agent installed CLI (git, gh, docker, kubectl, psql)
    run a recurring multi-call workflow and return a compact summary a repo script paired with a skill (Instructions for an AI agent)
    give several different team agents unified access to an internal API a compact custom MCP server: 5–15 task-oriented tools instead of 80 raw endpoints
    connect a SaaS app that has no CLI but offers an official OAuth MCP server remote MCP, enabled only in projects that need it

    Security: what to check before connecting

    MCP widens an agent’s attack surface. Check three things before adding a server:

    • Where local server code comes from. A command like npx -y some-mcp-server downloads and runs third-party code on your computer. Without a pinned version, a package update can silently change behavior.
    • Hidden instructions in outputs and descriptions. Tool descriptions from tools/list and data from tool_result enter the model’s context directly. A third-party or compromised server can smuggle agent commands in there (Someone else’s text is data, not commands).
    • OAuth scope width and argument leakage. A remote server sees everything the agent passes in call parameters and acts with the permissions you granted it. The model vendor’s privacy policy does not cover a third-party MCP server (Your data in AI).

    What you get and what it costs

    What you get

    • One plug for many clients. Build or connect a server once and use it in web chat, your editor, and CLI agents.
    • OAuth 2.1 sign-in. Remote services don’t require minting long-lived tokens and leaving them in local files.
    • Typed arguments. JSON schemas catch parameter typos before a request hits the external service.

    What it costs

    • Context overhead. Without deferred loading, dozens of tool schemas weigh down every turn (Long conversations).
    • Raw payloads. Off-the-shelf servers often dump entire objects, whereas a CLI or script trims noise with jq or grep before the model sees it.
    • Another layer to maintain. Local processes crash and need Node/Python versions and updates; remote servers depend on third-party uptime.

    Where to start

    1. If the agent has a terminal, check first whether a standard CLI (gh, docker, psql) or a short script in the repository solves the job.
    2. Add MCP for services without a CLI, OAuth workflows, or clients without a terminal — one server per concrete need, not a full catalog at once.
    3. Turn on deferred tool loading if your client supports it, and disable servers in projects that don’t use them.
    4. When building an internal MCP server for a team, design 5–10 task-oriented tools that return short, pre-filtered output instead of wrapping dozens of raw REST endpoints.

    If it doesn’t work

    After connecting several MCP servers, answers got pricier and weaker

    Cause
    Each server exposes schemas for all of its tools via tools/list. Dozens of tools eat thousands of context tokens before your first question, and the model confuses similar functions.
    Fix
    Disable servers you don’t need in the current project, turn on deferred tool loading (tool search), and switch to CLIs for local work.

    With deferred tool loading on, the agent misses an MCP tool even though the server is connected

    Cause
    The model’s search query didn’t match the words in the tool’s name or description.
    Fix
    Name the service explicitly in your prompt or add a short hint in AGENTS.md (Instructions for an AI agent).

    A local MCP server (stdio) fails to connect or drops right at startup

    Cause
    The server process prints debug output or a startup banner to stdout, while the stdio transport expects only JSON-RPC 2.0 messages there.
    Fix
    Route server logs to stderr and test running the command manually in a terminal.

    A single MCP tool call filled a large chunk of the context window

    Cause
    The server returned full raw JSON — a long issue list, an entire page body, or an unfiltered log.
    Fix
    Pass strict filters and a limit, or move the job into a script that extracts the needed fields and prints a short summary.

    A remote MCP server asks for write access to your entire account

    Cause
    The server bundles one broad OAuth scope for all actions even when you only need read access.
    Fix
    Select minimal scopes at sign-in, use a dedicated service account, or skip connecting the server.