rasuvaeff / mcp-openapi
Serve allow-listed OpenAPI operations as MCP tools: PSR-18 or in-process PSR-15 execution, no framework required
Requires
- php: 8.3 - 8.6
- mcp/sdk: ~0.10.0
- psr/container: ^2.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/simple-cache: ^2.0 || ^3.0
- rasuvaeff/mcp: ^0.1
- rasuvaeff/openapi-contract: ^0.19
Requires (Dev)
- ergebnis/composer-normalize: ^2.51
- firebase/php-jwt: ^7.0
- friendsofphp/php-cs-fixer: ^3.95
- infection/infection: ^0.35
- maglnet/composer-require-checker: ^4.17
- nyholm/psr7: ^1.8
- rasuvaeff/property-testing-core: ^1.3
- rasuvaeff/property-testing-openapi: ^0.23
- rasuvaeff/property-testing-testo: ^1.0
- rasuvaeff/rector-named-literals: ^1.0
- rasuvaeff/understudy-testo: ^1.0
- rector/rector: ^2.4
- roave/backward-compatibility-check: ^8.0
- testo/bridge-infection: ^0.1.6
- testo/testo: ^0.10.25
- vimeo/psalm: ^7.0
- yiisoft/test-support: ^3.0
Suggests
- guzzlehttp/guzzle: PSR-18 HTTP client for the operation executor and the spec loader
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-25 13:14:11 UTC
README
Serve allow-listed operations of an OpenAPI 3.x document as MCP tools. Runs on
rasuvaeff/mcp and needs no framework: a spec,
a PSR-18 client (or a PSR-15 handler) and PSR-17 factories are enough. Using Yii3?
rasuvaeff/yii3-mcp wires it from params.
Using an AI coding assistant? llms.txt contains a compact API reference you can share with the model. Contributors: see AGENTS.md. Projects using the llm/skills Composer plugin also get this package's agent skill synced into
.agents/skills/automatically on install.
Requirements
| Requirement | Version |
|---|---|
| PHP | 8.3 – 8.6 |
rasuvaeff/mcp |
^0.1 |
rasuvaeff/openapi-contract |
^0.19 |
| PSR-17 implementation | any |
| PSR-18 client | for HTTP execution or a URL spec |
Installation
composer require rasuvaeff/mcp-openapi
Usage
use Rasuvaeff\Mcp\McpServerFactory; use Rasuvaeff\Mcp\OpenApi\OpenApiBridgeFactory; $bridge = OpenApiBridgeFactory::create( spec: __DIR__ . '/openapi.json', // JSON file, http(s) URL or decoded array baseUrl: 'https://api.example.com', httpClient: $httpClient, requestFactory: $psr17, streamFactory: $psr17, operations: ['getBlogTags'], headers: ['Authorization' => 'Bearer ' . getenv('API_TOKEN')], safeMethodsOnly: true, toolNames: ['getBlogTags' => 'blog_tags_list'], ); $server = (new McpServerFactory( container: $container, sessionStore: $sessionStore, name: 'my-api', version: '1.0.0', ))->create([], [$bridge]);
A tool is named after its operationId (or toolNames), described by
summary/description; parameters and the JSON request body become arguments,
the body as one body argument. Shared schemas are inlined; a recursive one stays
a reference with its definition in the tool schema's $defs. A response schema too
large to inline is not advertised as outputSchema.
In-process execution
Pass inProcessHandler (PSR-15) and serverRequestFactory to call the
application's own handler without network I/O; httpClient and requestFactory
may then be null unless the spec is a URL.
Limits
Checked when the server is built, for the allow-listed operations:
- path parameters are scalars, query parameters are scalars or arrays of scalars;
- header and cookie parameters, non-default
style/explode(except for query arrays) andallowReservedare refused; - the document is OpenAPI 3.0 or 3.1, compiled by
rasuvaeff/openapi-contract; references must be local; itsservers,securityandwebhooksare ignored; - only
application/jsonrequest bodies; the document is JSON up to 10 MiB.
Components
| Class | Role |
|---|---|
OpenApiBridgeFactory |
builds the bridge from a spec and PSR services |
OpenApiServerConfigurator |
registers the allow-listed operations on the SDK builder |
OpenApiConfiguratorResolver |
for framework packages: the openapi params → the bridge, or null while it is disabled |
SpecLoader |
fetches a URL spec, with an optional PSR-16 cache |
Operation, OperationModifierInterface |
customize a tool per operation |
DelegatedHeaderProviderInterface |
upstream headers for the current execution identity |
ExecutionRequestAttributesInterface |
identity as attributes of an in-process request |
InProcessScopeInterface |
resets request-scoped state around an in-process call |
Exception\InvalidSpecException |
the document or an operation cannot be bridged |
Exception\UnknownOperationException |
an allow-listed operationId is not in the document |
Exception\UnsafeOperationException |
a non-GET operation under safeMethodsOnly |
Exception\InvalidToolArgumentException |
an argument cannot be put into the request |
Exception\OperationFailedException |
the upstream call failed |
Security
- Only operations in
operationsare served; an empty list serves nothing. headersgo tobaseUrlonly,specHeadersto the spec URL only; a spec URL with embedded credentials is refused.- A path argument that is empty,
., or contains..,/or\is refused;multiSegmentPathParamsrelaxes only/, per parameter. - Response bodies are read incrementally up to
maxResponseBytes. opaqueErrors: truehides upstream error bodies.- The spec and
baseUrlare trusted configuration: there is no SSRF protection.
Examples
See examples/: the script runs offline.
Development
No PHP/Composer on the host, run in Docker via the composer:2 image:
docker run --rm -v "$PWD":/app -w /app composer:2 composer build
Or with Make: make build, make cs-fix, make psalm, make test.
License
BSD-3-Clause. See LICENSE.md.