Build API Plugins for Claude Code, Codex and Gemini CLI

By Sheng Pang · Published · 11 min read · Fictional team story with a locally tested API and MCP example. Assistant dialogue is illustrative.

AI in practice mcp plugins claude code codex gemini cli

Nina was still looking for the API handbook when her colleague typed the question into Claude Code. They were in a project meeting, trying to find the monthly run limit for Orchid. She had opened the documentation and an old example request, but the service had signed her out. Her colleague asked the assistant for the current limit and showed a result from the project's API.

After the meeting, she asked what he had installed. It was a small project integration that gave the assistant a way to call an existing service. Users could ask a normal question without knowing the route or writing an HTTP request. Someone still had to build that connection, though, and Nina wanted to understand that part before giving it to the rest of the team.

This guide uses MCP, the Model Context Protocol, to build such a connection. We will write one API tool, then package it for Claude Code, Codex and Gemini CLI. Those products support MCP, but their plugin files are different. The Gemini package in this example is for the terminal application, Gemini CLI.

Nina's first guess was that the plugin somehow updated the model's training. Her colleague showed her the request instead. The application had called a tool, the tool had fetched a record and the model had received that record as context.

The answer needs a tool that can reach the API

She opened the project's old guide and found the limit mentioned in it. A model answering from that guide could repeat the old number quite faithfully. General training data would be even less useful for a private project's current settings. The connection let the assistant ask the service that held those settings.

The coding assistant is the host application, and its MCP client connects to a small MCP server. Our server offers a function called get_project_limits for quota questions. Python uses the project's API, then returns a small record that the model can use in its next reply.

If those roles are new, read our introduction to MCP for the background. Our Python tool-calling lesson shows how an application carries a tool result back to a model. Here we use the SDK to handle the protocol, while we write the function that understands the project API. The model does not have to invent the URL.

A skill serves a different purpose. It can tell the assistant when to use this tool and which fields to quote, while the MCP server performs the request. A plugin packages those pieces so another person can load them. Nina could give her team a repeatable way to ask a quota question without sending everyone a page of curl commands.

Build and test the shared server first

She began with one question about one project. She did not add a tool that could call any URL or change a subscription. The function would accept a project ID and read its monthly limit. The API would still decide whether the account had permission to see that project.

You can download the API plugin example to follow the same steps. It contains a synthetic API, the MCP server and a generator for the three client packages. The token and project records are invented for this demo. The protocol calls and results in the archive were run locally.

Open a terminal in the extracted folder and run these commands. They use Unix paths, as in our tested macOS setup. We used Python 3.14.8 with MCP Python SDK 2.3.0. The dependency file does not pin mcp to that version, so your installation may use a different release.

python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python check.py
.venv/bin/python prepare.py

The check script starts the local API, makes real MCP calls and stops its own API process. It writes the full results to a new JSON file. It does not send a question to Claude, Codex or Gemini, and it does not need a model subscription to test the tool. Keep the recorded results separate when comparing your run.

In project_api.py the server registers the function with a decorator. The function's argument and return types let the SDK describe its inputs and output fields. The docstring tells the assistant what the tool is for. The complete file is in the archive, and the excerpt below shows the request and error handling inside it.

    path = "/v1/projects/" + project_id + "/limits"
    request = Request(origin + path, headers={"Authorization": "Bearer " + token,
                                             "Accept": "application/json"})
    try:
        with build_opener(NoRedirect).open(request, timeout=3) as response:
            raw = response.read(65537)
    except HTTPError as error:
        raise ToolError("Project API returned HTTP " + str(error.code)) from None
    except (URLError, TimeoutError, OSError):
        raise ToolError("Project API is unavailable. No current limit was returned.") from None

The person running the server sets the API address in its configuration. The model supplies a project ID, which the function checks before building the path. The full implementation also checks the returned record, including the project ID and the number's type. A valid JSON response for the wrong project should not become a successful answer.

Raising an ordinary Python exception made this SDK return a generic tool failure, hiding the useful HTTP status. We changed expected failures to ToolError so the client could distinguish a forbidden project from an unavailable service. The SDK still hides the details of unexpected exceptions from the client.

The successful record includes the monthly limit, the API's revision and its update time. Our wrapper adds the time it fetched the response. Those fields give Nina something to compare with the service and with an earlier answer. We leave unrelated account data out of the result.

Package the connection for each assistant

When Nina packaged the function for the three clients, she found that each expected a different folder layout and manifest, the file that describes a plugin. The example's generator copies the same Python server into each package, then writes the manifest that client expects. It also uses the Python interpreter that ran the generator, so the server can find the installed SDK.

ClientPackage filesServer path variable
Claude Code.claude-plugin/plugin.json and .mcp.jsonCLAUDE_PLUGIN_ROOT
CodexRoot plugin.json and mcp.jsonPLUGIN_ROOT
Gemini CLIgemini-extension.json and GEMINI.mdextensionPath

The Claude package keeps its metadata inside .claude-plugin and its MCP configuration at the package root. A small skill tells Claude to call the tool for current quota questions and report a failed lookup. A root-level CLAUDE.md file is not loaded as plugin context. We removed one after the local validator pointed that out.

For Codex, the example follows the current portable Agent Plugins format. Its root manifest identifies the plugin. The mcp.json file tells Codex how to launch the server. The connection uses standard input and output, often called stdio, to exchange messages. The older .codex-plugin/plugin.json layout remains a supported compatibility format. Renaming a Claude manifest is not enough to create the portable package.

Gemini CLI reads its extension manifest and loads the named context file. Its server path uses a different variable from the other two clients. That path matters when someone moves the folder to another directory. If a real extension needs a user-supplied secret through an environment variable, declare that setting in its manifest rather than assume every exported shell variable will reach it.

After generation, open the files under generated and compare them with the table. Each package contains its own copy of the server, with no dependency on a sibling folder. The demo API origin and public dummy token are set in its server configuration. A real token belongs in the client's secret setup, not in a manifest passed around the office.

Where the corresponding CLIs are installed, these commands validate the Claude and Gemini packages. Our local checks used Claude Code 2.1.322 and Gemini CLI 0.68.0. We also validated the Codex package against the published portable schemas and checked a direct MCP configuration with Codex CLI 0.167.0. Those checks cover package structure and tool connections, not the quality of an authenticated assistant's final reply.

claude plugin validate generated/claude/project-api --strict
gemini extensions validate generated/gemini/project-api

For a local Claude Code session, point its --plugin-dir option at the generated Claude folder. Gemini CLI can link the extension folder during development. In Codex, a direct MCP configuration is useful for trying the server before installing a packaged plugin through a marketplace. Generating the folders does not install them or enable tools in an existing chat.

Nina kept the API running while trying the connection. The packages launch the MCP process, which is the bridge, rather than the synthetic API itself. In the demo, start demo_api.py with the virtual environment's Python and keep that terminal open. You can then run probe.py from another terminal to inspect a tool result without relying on a model to choose it.

Change the API and ask the same question again

The old guide was still open when Nina returned to the quota question. In our recorded test, the first MCP call returned a monthly limit of 1,200 runs for Orchid. We changed the synthetic API record to 1,800 and called the same tool again. The second result returned 1,800 with a different revision, using the same running MCP client connection.

We changed neither the tool's code nor the package instructions between those calls. The API route and its permissions still have to work. We have not tested a model's accuracy merely by testing that the tool returned the right record.

Nina wanted the answer to include the project ID and revision, not just the larger number. That would help her spot a result for the wrong account or environment. Our sample skill asks for the limit and source time as well. These instructions guide the model, but they do not force a successful call on every question.

The wrapper's fetched_at field records when it received the result. The service supplies the source update time, which can be older. An API can serve cached or delayed data, so a recent fetch time alone cannot establish that a value reflects the latest business change.

She could also ask an ambiguous question, such as whether the team could run a large batch tonight. A monthly limit does not say how much has already been used, and it does not establish whether an overnight job is allowed. The assistant would need more information for that decision. The plugin should describe the fields it actually provides instead of promising answers to every project question.

Make failure visible before sharing the plugin

Before sending the package to a colleague, Nina tried a project her account could not read. The demo API returned HTTP 403, and the tool returned an error carrying that status. A missing project produced HTTP 404. Neither error provides a quota. If the assistant supplies a number anyway, the failed lookup does not support it.

Then she stopped the API. In our recorded run, the next call returned an explicit unavailable-service error, with no successful limit record. The assistant should then say it could not check the current value. Reusing the previous number would hide the outage from the person making a decision.

The archive includes these six API cases. Two are successful reads before and after the change. The others check a forbidden project, a missing project, an invalid ID and the stopped API. They are local protocol tests, not a six-question model benchmark.

For a real service, try those failures with an account that has the permissions your users will have. Checking the project ID helps prevent requests to unintended API paths. The API must still check whether the account can access the project. We would begin with a read-only account and one useful route before adding actions that change records.

Nina also removed fields the quota answer did not need. An assistant does not need a customer's email address to report a run limit. Although the MCP process can run locally, the host may include its returned data in a request to a model provider. Check the team's approved account and data rules before connecting private project information.

Nina asked her colleague to review the request code before sharing the package. The tool made one fixed GET request, returned selected fields and refused redirects. The host must also treat text returned by the API as data, rather than follow instructions embedded in it.

At the next meeting, Nina opened the tool result and checked the project ID and revision before using the number. She had obtained it without writing the request herself.

You can use our JSON visualizer to inspect the public recorded results as a tree. It helps reveal the response fields without judging whether the model used them correctly. For the larger control loop, our multi-step agent lesson shows how to check actions across several model requests. Start by running the demo once, then change its API record and inspect the next tool result.

← More AI in practice articles  ·  All articles

↑ Top