@vitemcp/server 1.7.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/dist/ViteMCP.cjs +4 -1328
- package/dist/ViteMCP.cjs.map +1 -1
- package/dist/ViteMCP.js +13 -1337
- package/dist/ViteMCP.js.map +1 -1
- package/dist/chunk-2624N2BP.cjs +1351 -0
- package/dist/chunk-2624N2BP.cjs.map +1 -0
- package/dist/chunk-3CGG26M4.js +1351 -0
- package/dist/chunk-3CGG26M4.js.map +1 -0
- package/dist/openapi/index.cjs +1023 -0
- package/dist/openapi/index.cjs.map +1 -0
- package/dist/openapi/index.d.cts +142 -0
- package/dist/openapi/index.d.ts +142 -0
- package/dist/openapi/index.js +1023 -0
- package/dist/openapi/index.js.map +1 -0
- package/package.json +18 -2
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ A TypeScript framework for building stateless [MCP](https://glama.ai/mcp) server
|
|
|
30
30
|
- [Multi round-trip requests](#multi-round-trip-requests)
|
|
31
31
|
- [Cacheable results](#cacheable-results)
|
|
32
32
|
- [Client ID Metadata Documents](#client-id-metadata-documents)
|
|
33
|
+
- [Generating a server from OpenAPI](#generating-a-server-from-openapi)
|
|
33
34
|
- [Migrating from the session-based API](#migrating-from-the-session-based-api)
|
|
34
35
|
- [Server Features](#server-features)
|
|
35
36
|
- [Logging](#logging)
|
|
@@ -52,6 +53,7 @@ A TypeScript framework for building stateless [MCP](https://glama.ai/mcp) server
|
|
|
52
53
|
- [Acknowledgements](#acknowledgements)
|
|
53
54
|
|
|
54
55
|
Authentication has a dedicated reference — see the [OAuth guide](docs/oauth.md).
|
|
56
|
+
So does OpenAPI conversion — see the [OpenAPI guide](docs/openapi.md).
|
|
55
57
|
|
|
56
58
|
## Features
|
|
57
59
|
|
|
@@ -73,6 +75,7 @@ Authentication has a dedicated reference — see the [OAuth guide](docs/oauth.md
|
|
|
73
75
|
- [Prompt argument auto-completion](#prompt-argument-auto-completion)
|
|
74
76
|
- [Cacheable list results](#cacheable-results) (`ttlMs` / `cacheScope`)
|
|
75
77
|
- [Health-check endpoint](#health-check-endpoint)
|
|
78
|
+
- [Generate a whole server from an OpenAPI document](#generating-a-server-from-openapi)
|
|
76
79
|
- [In-memory transport](#unit-testing-with-an-in-memory-transport) for unit testing without binding a port
|
|
77
80
|
- CLI for [testing](#test-with-mcp-cli) and [debugging](#inspect-with-mcp-inspector)
|
|
78
81
|
|
|
@@ -1408,6 +1411,55 @@ const authProxy = new OAuthProxy({
|
|
|
1408
1411
|
});
|
|
1409
1412
|
```
|
|
1410
1413
|
|
|
1414
|
+
### Generating a server from OpenAPI
|
|
1415
|
+
|
|
1416
|
+
`fromOpenAPI()` turns an OpenAPI 3.x document into a server, one tool per
|
|
1417
|
+
operation. Parameters and the request body are flattened into a single argument
|
|
1418
|
+
list, `$ref`s are resolved, and each tool calls the real API when invoked.
|
|
1419
|
+
|
|
1420
|
+
```ts
|
|
1421
|
+
import { fromOpenAPI } from "@vitemcp/server/openapi";
|
|
1422
|
+
|
|
1423
|
+
const server = await fromOpenAPI({
|
|
1424
|
+
headers: { authorization: `Bearer ${process.env.API_TOKEN}` },
|
|
1425
|
+
include: (operation) => operation.tags.includes("pet"),
|
|
1426
|
+
spec: "https://petstore3.swagger.io/api/v3/openapi.json",
|
|
1427
|
+
});
|
|
1428
|
+
|
|
1429
|
+
await server.start({ transportType: "stdio" });
|
|
1430
|
+
```
|
|
1431
|
+
|
|
1432
|
+
`spec` takes a URL, a file path, inline JSON, or a parsed object. The result is
|
|
1433
|
+
an ordinary `ViteMCP` instance — add your own tools to it, or pass `server` to
|
|
1434
|
+
register the generated ones onto a server you already have.
|
|
1435
|
+
|
|
1436
|
+
Because ViteMCP is stateless, `headers` can be a function instead of an object,
|
|
1437
|
+
and it runs per request:
|
|
1438
|
+
|
|
1439
|
+
```ts
|
|
1440
|
+
await fromOpenAPI<Session>({
|
|
1441
|
+
headers: (context) => ({
|
|
1442
|
+
authorization: `Bearer ${context.auth!.upstreamToken}`,
|
|
1443
|
+
}),
|
|
1444
|
+
server,
|
|
1445
|
+
spec: "./openapi.json",
|
|
1446
|
+
});
|
|
1447
|
+
```
|
|
1448
|
+
|
|
1449
|
+
Credentials given this way are applied after the operation's own parameters, so
|
|
1450
|
+
a model that supplies its own `authorization` argument cannot displace them.
|
|
1451
|
+
|
|
1452
|
+
Selecting operations is required rather than optional. A document with two
|
|
1453
|
+
hundred operations makes a tool list no client can present, so with no
|
|
1454
|
+
`include`, `exclude` or `maxTools`, more than 40 operations is an error rather
|
|
1455
|
+
than a large server.
|
|
1456
|
+
|
|
1457
|
+
YAML documents and documents whose `$ref`s point at other files need the
|
|
1458
|
+
optional `@apidevtools/swagger-parser` peer dependency; a single-file JSON
|
|
1459
|
+
document needs nothing extra.
|
|
1460
|
+
|
|
1461
|
+
Full reference: the [OpenAPI guide](docs/openapi.md).
|
|
1462
|
+
|
|
1411
1463
|
### Migrating from the session-based API
|
|
1412
1464
|
|
|
1413
1465
|
Revision 2026-07-28 removed protocol sessions, the `initialize` handshake,
|