Turning an OpenAPI spec into an MCP server with LiteLLM without writing code
Many organizations have an internal REST API that agents or developer tools should call, but no team wants to write and maintain a Model Context Protocol server for it. LiteLLM can register an MCP server from an OpenAPI spec given a url and a spec_path (JSON or YAML), and it loads every endpoint in the spec as a tool. The result is a gateway-hosted tool surface built from the API description you already maintain, with no MCP server code in your repository.
This approach fits APIs with accurate, current specs: every operation has a clear operationId, meaningful summaries and descriptions, typed parameters and request bodies, and documented responses. It also fits APIs where each endpoint maps to one well-defined action that a model can reasonably choose and call. It does not fit APIs with stale or incomplete specs, operations whose side effects are unclear (for example, a POST that both creates and charges), or workflows that need custom logic such as multi-step orchestration, response reshaping, or business rules the spec cannot express. In those cases, a hand-written MCP server gives you control that generated tools do not.
Before you register anything, confirm three things with the API owner: that the spec validates against the OpenAPI version your tooling expects, that every endpoint you expose is safe for a model to call unattended, and which endpoints should be left out entirely. Then decide the authentication type. LiteLLM supports none, api_key and bearer_token auth for generated servers, so the credential the gateway holds for the upstream API must be scoped narrowly, stored in a secret manager, and rotated on a schedule your security team sets. Confirm the base URL the gateway will call, especially if the spec lists a different server than the one you use in production.
Treat the generated server like any other MCP server once it is registered. Generated tools inherit the same key, team and organization permissions, guardrails and cost tracking as hand-built servers, so restrict which teams can discover and call them from the start. Review the tool list after each spec change, because a new endpoint added upstream becomes a new tool for every permitted caller. Check the exact fields and behavior in the LiteLLM MCP from OpenAPI documentation against your LiteLLM version before you rely on them.
Which inputs and auth type to configure for the generated server
This table compares the registration inputs and auth types LiteLLM accepts when it builds tools from an OpenAPI spec. Read each row against the API you are exposing, then check whether the upstream credential is shared by every caller or tied to an individual. The main takeaway is that the auth type decides who the upstream API sees as the caller, so pick it before you decide how tools are governed.
| Option | When it fits | Main trade-off |
|---|---|---|
| spec_path (local JSON or YAML file) | Spec is versioned in your repository or config store and the gateway can read it at startup | Spec changes need a redeploy or reload, so confirm how your team tracks spec versions |
| url (spec served at a URL) | Spec is published by the API team and should follow their releases without a manual copy | The gateway must reach that URL, and a changed spec changes the tool list without review unless you pin it |
| Base URL handling | Spec paths are relative and the API runs behind a different host or path prefix than the spec lists | Confirm the base URL the gateway calls matches the production route, not the documentation host |
| auth type none | Public read-only API with no sensitive data behind it | Anyone who can call a tool reaches the API, so limit the server to public or internal-only exposure |
| auth type api_key | Internal API that accepts one shared service key the gateway holds | One upstream credential serves every caller, so the upstream logs cannot separate users |
| auth type bearer_token | API accepts a bearer token issued to a service account | Token rotation and expiry are your job, and the token still does not identify the end user |
| Per-user identity upstream | Upstream must record which person made each call | Not covered by these two inputs, so plan it separately with per-user credentials or delegated tokens; confirm the API supports it |
Registering an OpenAPI spec as an MCP server in LiteLLM
This sequence takes an existing REST API from a spec file to a registered, tested MCP server in LiteLLM, with credentials held in a secret manager and access limited to a test key before wider use. Each step ends with a check you can record before moving on.
Obtain and validate the OpenAPI spec
The API owner or your platform team exports the OpenAPI document in JSON or YAML and confirms it describes the endpoints you intend to expose as tools. Run the spec through a validator your team already uses, and remove or document any operations that should not be callable by a model, such as bulk deletes or administrative routes. Confirm the base URL the gateway will reach from its own network, which may differ from the public address in the spec. The step is done when the file validates, the operation list is agreed, and the reachable base URL has been tested from the LiteLLM host with a plain HTTP request.
Store upstream credentials in a secret manager
Create the API key or bearer token for the upstream service with the minimum permissions the tools need, then place it in the secret manager your LiteLLM deployment already uses. Reference that secret from the server configuration instead of pasting the value into a config file, a Kubernetes manifest or a shared notebook. Record who owns the credential and how it rotates. The step is done when the configuration contains only a reference, and a test read of the secret from the gateway runtime succeeds without exposing the value in logs.
Register the server with URL, spec path and auth type
Add the MCP server entry in the LiteLLM configuration with the base URL, the spec path (JSON or YAML) and the auth type that matches the upstream API, such as api_key or bearer_token. Apply the change through your normal configuration path and restart or reload the proxy as your deployment requires. The step is done when the proxy starts without errors and the server appears in the admin view as registered with the expected auth type.
List generated tools and review names and descriptions
Query the gateway for the tool list exposed by the new server. LiteLLM loads each endpoint from the spec as a tool, so the names and descriptions come from operation IDs and spec text. Check that every tool name is unambiguous, that descriptions tell a model when to use the tool, and that no operation you excluded appears. Where descriptions are weak, fix them in the source spec and re-register rather than editing generated output by hand. The step is done when a reviewer has signed off the tool list in writing.
Test each critical endpoint through the gateway
For each critical tool, make a test call through the gateway using a non-production record or a read-only operation, and compare the response with a direct call to the upstream API. Check status codes, error handling for missing or invalid parameters, and that the credential is applied upstream. Log the request and response shape, and confirm no secret appears in the gateway logs. The step is done when each critical endpoint returns the expected result through the gateway and the test evidence is saved with the change record.
Restrict the server to a test key first
Before widening access, create or select a virtual key used only for testing and limit the new MCP server to that key, using the access controls LiteLLM provides for MCP servers. Confirm that other keys cannot discover or call the tools. Run a short series of calls with that key and confirm that the spend and request records attribute to it. The step is done when a non-test key is shown to be denied, and the test key is shown to reach only the intended tools.
Widen access only after review
Once the tool list, test results and key restriction are signed off, extend access to teams or keys in the order agreed with the API owner and security reviewer. Record the scope of each grant, the owner of the upstream credential and the date of the review in your change system. Set a recurring check to compare the spec with the live API after upstream releases, since generated tools reflect the spec at registration time. The step is done when access lists match the approved scope and the review record is complete.
Governing generated tools like any other MCP server
A server generated from an OpenAPI spec is still an MCP server inside LiteLLM, so it takes the same controls as a hand-built one. The cards below cover who can reach it, whether it is public, how calls are screened, what gets logged and what each call costs. Confirm the exact configuration keys in the LiteLLM docs before you write policy against them.
Key, team and organization access
Decide which virtual keys, teams and organizations can discover the generated server and call its tools. Access is set per server, so a broad API such as one with dozens of endpoints can be narrowed to the tools a given team actually needs. Check that tool lists are filtered by permission, so a key without access does not see write operations it cannot use. Test this with a key from each team before you roll out.
MCP from OpenAPI docsPublic or internal-only exposure
Mark the server public only when external clients such as desktop chat apps should reach it. A generated server that wraps an internal REST API usually belongs on internal networks only, so restrict it by internal IP ranges. Review the base URL and the spec's server entries before exposure, since the generated tools call whatever host the spec points to. Confirm the per-server public flag and IP range settings in the docs.
Guardrails on tool inputs and results
Guardrails can check tool arguments before a call and tool results before the model sees them. This matters for generated tools because the API response may contain personal data or text that tries to steer the model. Choose which mode screens inputs, which screens results and which masks personal data. Test with sample payloads from the real API, not only with clean test data.
Logging of tool calls
Gateway logs record which key and team called which generated tool, so an endpoint that changes records can be traced to a caller. Decide how long these logs are kept and where they are sent, and check whether request and response bodies are stored. Confirm which fields are logged for MCP calls and whether they are forwarded to your SIEM or storage.
Cost tracking per call
Each generated tool call can be charged to a team or key, either with a default cost per query for the server or with per-tool costs. Per-tool pricing suits endpoints that differ in cost, such as a search versus an export. Agree with finance which unit of charge applies and how tool spend is reported next to model spend. Confirm the cost settings and any post-call hooks in the documentation.
How a tool call travels from the MCP client to the upstream REST API
The call starts in an MCP client such as a developer tool or agent, which sends it to the LiteLLM gateway with a LiteLLM key. The gateway checks that key and its team permissions against the tool before doing anything else. It then builds the upstream HTTP request from the OpenAPI operation, adds the upstream credential it reads from its own configuration, and crosses the trust boundary to the REST API. Check that the credential is read only inside the gateway and that the client never sees it on the return path.
Tool call path from MCP client through the gateway to the upstream REST API.
Security risks of turning an API into agent-callable tools
Generating MCP tools from an OpenAPI spec turns every documented endpoint into something an agent can invoke. The risks below share one root cause: the spec describes what the API can do, not what each caller should be allowed to do, so the gateway and the tests must close that gap before launch.
Over-broad endpoints exposed as tools
A spec often documents every operation, including delete and bulk-write endpoints, administrative routes and internal helpers. Once loaded, each one becomes a tool an agent can call. Before registration, review the spec and remove or exclude operations that no agent workflow needs. Confirm in your LiteLLM version which operations are loaded and whether you can filter them. Test by listing the generated tools for a restricted key and confirming that write and delete operations are absent.
MCP from OpenAPI docsShared upstream credential with excess rights
A single api_key or bearer_token configured on the server is used for every caller, so any agent that reaches the tool inherits the rights of that credential, which is often an administrator account. Issue a dedicated, least-privilege service credential for the gateway, scoped to the operations you allowed in the spec. Test by calling a forbidden operation through the gateway and confirming the upstream API rejects it, then checking that the upstream audit log records the gateway identity.
Prompt injection through API responses
Data returned by the upstream API, such as ticket text, customer notes or document bodies, can contain instructions aimed at the model. The model may act on them with the tools it has been granted. Limit the tools each team can reach, keep write tools off agent keys that also read untrusted data, and screen tool results with guardrails where your LiteLLM edition supports them. Test by planting an instruction in a test record and checking whether the agent attempts a follow-up call.
Leaked credentials in configuration
Registering an OpenAPI server stores the upstream key in the gateway configuration, and that configuration is often committed to version control, pasted into tickets or printed in logs. Keep the upstream secret in a secret manager and reference it at runtime, and keep LITELLM_MASTER_KEY out of files. Test by searching the configuration repository, container images and proxy logs for the credential value, and by rotating the key and confirming the gateway still starts from the secret store.
Misleading descriptions causing wrong tool choice
Tools are named and described from the spec's operation IDs and summaries. Vague or copied descriptions can lead a model to call a similar-looking endpoint, such as a cancel operation when it meant to read status. Edit operation summaries and descriptions in the spec before loading, use clear verb-noun names, and document which operation is safe for read-only tasks. Test with a set of realistic prompts and record which tool the model chooses for each, then fix any description that produces a wrong choice.
Questions teams ask before generating an MCP server from an OpenAPI spec
Can our team generate an MCP server from an OpenAPI spec without help?
Often yes, for a single well-documented API with one authentication method, because LiteLLM can register an MCP server from an OpenAPI spec by reading a spec path (JSON or YAML) and a base URL, then loads every endpoint as a tool. The work that usually needs experience is everything around that step: confirming which endpoints should become tools, testing each generated tool against the real API, choosing how credentials are injected, and deciding who may call each tool. Teams without a LiteLLM operator on staff should confirm they can run the proxy in their own environment, control its keys and review the tool list before going to production. Check the LiteLLM docs for MCP from OpenAPI against your API before committing.
What do the API and spec owners need to provide?
The engineers who own the API carry most of the prerequisites. They should supply a current OpenAPI spec in JSON or YAML that matches production behavior, the base URL the gateway can reach from its network, a test account or key with the least privilege needed, and a list of endpoints that should or should not be exposed to models. They should also state which authentication pattern applies, such as no authentication, an API key or a bearer token, and how that token is issued and rotated. Specs that are stale, incomplete or missing response schemas tend to produce tools that need manual correction, so ask the owners how often the spec is regenerated.
How do cost and effort grow with endpoints and auth patterns?
Effort grows with the number of endpoints that need review, the number of distinct authentication patterns, and the number of consumers who will call the tools. A small spec with one API key can be registered and tested quickly, while a large API with mixed auth schemes, write operations and sensitive data needs a per-endpoint decision record, separate handling for each credential and permission rules for each tool group. Costs are mainly the time of the people who test and approve the tool list. Ask any partner for a quote that lists endpoints in scope, auth patterns, environments to test and the governance work, and separate one-time setup from recurring upkeep such as spec refreshes.
How long does validation take for a complex API?
Validation time depends on how much of the API the team must prove works through the gateway and how many edge cases the spec hides. A simple read-only API can be checked in a short cycle, while an API with pagination, file uploads, error codes that differ from the spec, or write operations needs test cases for each class of call. Plan for staged validation: first confirm the registration and authentication against a non-production instance, then call each tool with safe inputs, then review results and error handling, and finally confirm permissions. Ask for the validation plan and acceptance criteria in writing so the duration follows from the scope rather than from an estimate.
Will the generated tools need custom code later?
Usually not for the basic case, because the generated tools map directly to the endpoints in the spec. Custom code becomes relevant when the API needs behavior the spec cannot express, such as multi-step workflows, request signing, complex pagination, or responses that must be filtered before a model sees them. In those cases, teams often choose to keep the tool surface simple and add the logic in the upstream API rather than in the gateway. Any change to the spec, such as new endpoints or renamed parameters, requires re-registration and re-testing, so assign an owner for that lifecycle before go-live.
How should API credentials be stored for generated tools?
Store upstream API keys and bearer tokens in a secret manager and reference them from the gateway configuration, rather than pasting them into configuration files or the admin UI. Keep the master key that administers LiteLLM in a secret manager too, since LiteLLM recommends that its master key start with sk- and be stored that way. Give each upstream credential the narrowest scope the API allows, use a dedicated service identity for the gateway, and plan rotation with a documented procedure. Confirm with your security team which secret manager is approved, who can read the secret and how access is logged. LiteLLM Enterprise lists integrations with AWS, Azure, Google, HashiCorp Vault and CyberArk, so check the edition you run.
When should we bring in a partner instead?
Bring in a partner when the API is large, has mixed authentication, handles regulated data, or must be governed across many teams and keys, because those factors multiply the review and testing work. A partner is also useful when the team lacks time to maintain the gateway after go-live. DeployOpen plans, implements, tests and documents self-hosted LiteLLM deployments inside your own infrastructure, and most engagements are fixed-scope with scope, deliverables and timelines agreed in writing before work starts. Ask for a written scope and quote that covers the endpoints, credentials, environments, testing and handover, and confirm which items remain with your team.
Official LiteLLM sources for MCP from OpenAPI
Start with the LiteLLM documentation for MCP from OpenAPI before you register your first spec. That page describes how LiteLLM reads a spec from a url and spec_path in JSON or YAML, loads its endpoints as tools, and applies auth types such as none, api_key and bearer_token. Confirm the exact configuration keys and supported auth options against the version you plan to run, because the generated tool behavior depends on that release. Treat the page as the reference for the import itself, and check it again before each upgrade, since the fields and behavior can change between releases. Read the LiteLLM docs: MCP from OpenAPI page first, then plan the rest of the work around it.
The surrounding governance lives in two other places. The production best practices guide covers how to run the proxy itself, including the PostgreSQL database, the Redis requirement once more than one proxy instance runs, and where the master key belongs. The LiteLLM docs: production best practices page is the next read for that. Virtual keys govern who can call the generated tools, with per-key limits and model restrictions, and the LiteLLM docs: virtual keys page explains the settings that apply to them. Use both pages to design access for the tools as you would for any other MCP server.
Before you go live, confirm three things against these sources: which auth types your release supports for the upstream API, how the generated tool names are formed, and whether the spec version you plan to import is parsed as expected. Record the answers in your change ticket with the LiteLLM version you tested. Ask the vendor or your DeployOpen team to walk through any gap you find before you depend on the generated tools for production traffic.
How DeployOpen scopes and delivers OpenAPI to MCP work
DeployOpen starts with the REST API you want agents to call, then agrees in writing which endpoints become tools, how LiteLLM authenticates to the API, and how the generated server is governed. We then configure, test, document and hand over the registration inside the LiteLLM gateway you run in your own infrastructure.
How we scope
- Inventory the OpenAPI spec file, its format (JSON or YAML) and which endpoints should and should not become MCP tools
- Confirm the base URL for each environment and whether the spec is reachable from the gateway network
- Agree the upstream auth type (none, API key or bearer token) and where the secret will be stored
How we build
- Register the API in LiteLLM from its spec path and base URL, then check that each endpoint loads as the expected tool
- Configure API key or bearer token authentication with credentials held in your secret manager, not in config files
- Test tool calls from a virtual key, confirming that failed upstream responses and malformed inputs are handled cleanly
How we hand over
- Document the registration settings, tool list, auth configuration and the owner of each upstream credential
- Set up the access controls, cost settings and logging for the generated server so it is governed like any other MCP server
- Run a walkthrough with your platform and security teams covering rotation, adding endpoints and removing tools
How we support
- Review the generated tool list again when the upstream API changes its spec, endpoints or authentication
- Retest tool access after gateway upgrades, since registration behavior can change between LiteLLM releases
- Offer ongoing support, upgrades and continuous testing as a retainer after the fixed-scope work is complete

