@20baht/elysia-openapi-mcp 0.0.0-stage → 0.1.0
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/CHANGELOG.md +142 -0
- package/README.md +628 -2
- package/dist/auth/access.d.ts +13 -0
- package/dist/auth/access.d.ts.map +1 -0
- package/dist/auth/authenticate.d.ts +24 -0
- package/dist/auth/authenticate.d.ts.map +1 -0
- package/dist/auth/bearer.d.ts +13 -0
- package/dist/auth/bearer.d.ts.map +1 -0
- package/dist/auth/prm.d.ts +4 -0
- package/dist/auth/prm.d.ts.map +1 -0
- package/dist/auth/resolve.d.ts +110 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resource.d.ts +10 -0
- package/dist/auth/resource.d.ts.map +1 -0
- package/dist/auth/verify.d.ts +62 -0
- package/dist/auth/verify.d.ts.map +1 -0
- package/dist/execute.d.ts +43 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1577 -0
- package/dist/index.js.map +24 -0
- package/dist/openapi/derive.d.ts +61 -0
- package/dist/openapi/derive.d.ts.map +1 -0
- package/dist/openapi/naming.d.ts +21 -0
- package/dist/openapi/naming.d.ts.map +1 -0
- package/dist/openapi/schema.d.ts +83 -0
- package/dist/openapi/schema.d.ts.map +1 -0
- package/dist/openapi/types.d.ts +79 -0
- package/dist/openapi/types.d.ts.map +1 -0
- package/dist/plugin.d.ts +143 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/transport.d.ts +32 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/warnings.d.ts +14 -0
- package/dist/warnings.d.ts.map +1 -0
- package/package.json +63 -4
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal OpenAPI 3.x / JSON Schema shapes — just what tool derivation reads.
|
|
3
|
+
* Deliberately loose: the document is produced by `@elysiajs/openapi` and we
|
|
4
|
+
* only need to walk it, not validate it.
|
|
5
|
+
*/
|
|
6
|
+
export interface JsonSchema {
|
|
7
|
+
type?: string | string[];
|
|
8
|
+
properties?: Record<string, JsonSchema>;
|
|
9
|
+
required?: string[];
|
|
10
|
+
items?: JsonSchema | JsonSchema[];
|
|
11
|
+
description?: string;
|
|
12
|
+
$ref?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface OpenAPIParameter {
|
|
16
|
+
name: string;
|
|
17
|
+
in: 'path' | 'query' | 'header' | 'cookie' | string;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
description?: string;
|
|
20
|
+
schema?: JsonSchema;
|
|
21
|
+
}
|
|
22
|
+
interface OpenAPIMediaType {
|
|
23
|
+
schema?: JsonSchema;
|
|
24
|
+
}
|
|
25
|
+
interface OpenAPIRequestBody {
|
|
26
|
+
required?: boolean;
|
|
27
|
+
description?: string;
|
|
28
|
+
content?: Record<string, OpenAPIMediaType>;
|
|
29
|
+
}
|
|
30
|
+
export interface OpenAPIResponse {
|
|
31
|
+
description?: string;
|
|
32
|
+
content?: Record<string, OpenAPIMediaType>;
|
|
33
|
+
}
|
|
34
|
+
/** The object form of `detail.mcp`; it opts the route in like `true`. */
|
|
35
|
+
export interface McpRouteOptions {
|
|
36
|
+
/** Scopes a token must hold to call this tool, on top of `auth.scopes` (403 `insufficient_scope` otherwise). */
|
|
37
|
+
scopes?: string[];
|
|
38
|
+
/** Callable without a token when `auth.allowAnonymous` is set. */
|
|
39
|
+
public?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* JSON Schema of the tool's result, advertised as its `outputSchema` in
|
|
42
|
+
* place of the one derived from the route's `response`. Unlike `response`,
|
|
43
|
+
* Elysia does not check answers against it: it documents the result for
|
|
44
|
+
* agents only. A non-object schema is wrapped as `{ result }` (see
|
|
45
|
+
* `wrapNonObjectOutput`). A TypeBox `t.Object(...)` works too.
|
|
46
|
+
*/
|
|
47
|
+
output?: JsonSchema;
|
|
48
|
+
}
|
|
49
|
+
export interface OpenAPIOperation {
|
|
50
|
+
operationId?: string;
|
|
51
|
+
summary?: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
tags?: string[];
|
|
54
|
+
deprecated?: boolean;
|
|
55
|
+
parameters?: OpenAPIParameter[];
|
|
56
|
+
requestBody?: OpenAPIRequestBody;
|
|
57
|
+
responses?: Record<string, OpenAPIResponse>;
|
|
58
|
+
/** `@elysiajs/openapi` passes `detail.*` through verbatim, so these land here. */
|
|
59
|
+
hide?: boolean;
|
|
60
|
+
mcp?: boolean | McpRouteOptions;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
export interface OpenAPIDocument {
|
|
64
|
+
openapi?: string;
|
|
65
|
+
info?: {
|
|
66
|
+
title?: string;
|
|
67
|
+
version?: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
};
|
|
70
|
+
/** Loose on purpose: accepts `toOpenAPISchema()` output and `openapi-types` documents alike. */
|
|
71
|
+
paths?: Record<string, unknown>;
|
|
72
|
+
components?: {
|
|
73
|
+
schemas?: Record<string, JsonSchema>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export declare const HTTP_METHODS: readonly ["get", "post", "put", "patch", "delete"];
|
|
77
|
+
export declare function isOperation(value: unknown): value is OpenAPIOperation;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/openapi/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,UAAU,GAAG,UAAU,EAAE,CAAC;IA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kB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,kFAAkF;IAClF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAClE,gGAAgG;IAChG,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,UAAU,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;KAAE,CAAC;CACvD;AAED,eAAO,MAAM,YAAY,oDAAqD,CAAC;AAE/E,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAErE"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { AnyElysia } from 'elysia';
|
|
2
|
+
import { type McpifyAuthOptions, type McpifyRequestAuthOptions } from './auth/resolve.js';
|
|
3
|
+
import { type HeaderPolicy, type OnToolCall } from './execute.js';
|
|
4
|
+
import type { McpRouteOptions, OpenAPIDocument } from './openapi/types.js';
|
|
5
|
+
import { type McpifyWarningKind } from './warnings.js';
|
|
6
|
+
declare module 'elysia' {
|
|
7
|
+
interface DocumentDecoration {
|
|
8
|
+
/**
|
|
9
|
+
* `false` hides the route from MCP; with `allRoutes: false`, `true` opts
|
|
10
|
+
* it in. The object form opts in too and sets per-tool access:
|
|
11
|
+
* `{ scopes: ['users:write'] }`, `{ public: true }`.
|
|
12
|
+
*/
|
|
13
|
+
mcp?: boolean | McpRouteOptions;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export interface McpifyBaseOptions {
|
|
17
|
+
/** Where the MCP endpoint lives. Default `/mcp`. */
|
|
18
|
+
path?: string;
|
|
19
|
+
/**
|
|
20
|
+
* MCP server name / version reported on `initialize`. Default: the
|
|
21
|
+
* OpenAPI document's `info.title` / `info.version` (as set with
|
|
22
|
+
* `openapi({ documentation: { info } })`), else `@20baht/elysia-openapi-mcp` / `1.0.0`.
|
|
23
|
+
*/
|
|
24
|
+
name?: string;
|
|
25
|
+
version?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Returned in the `initialize` result: how to use the tools as a whole
|
|
28
|
+
* (when to call which, what to ask the user first). Clients typically put
|
|
29
|
+
* it in the model's context for the session.
|
|
30
|
+
*/
|
|
31
|
+
instructions?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Expose every operation unless `detail.mcp === false` (default true);
|
|
34
|
+
* `false` requires `detail.mcp: true`. With the default, a tool that declares
|
|
35
|
+
* no `detail.mcp.scopes` is callable by any token valid for the resource; see
|
|
36
|
+
* `auth.requireToolScopes`.
|
|
37
|
+
*/
|
|
38
|
+
allRoutes?: boolean;
|
|
39
|
+
/** Only expose operations carrying one of these OpenAPI tags. */
|
|
40
|
+
tags?: string[];
|
|
41
|
+
/**
|
|
42
|
+
* OpenAPI paths that never become tools (exact string or RegExp). Added to
|
|
43
|
+
* `DEFAULT_EXCLUDED_PATHS` (OAuth + `.well-known` endpoints) unless
|
|
44
|
+
* `excludeDefaults` is false; the MCP endpoint and the PRM path are always
|
|
45
|
+
* excluded.
|
|
46
|
+
*/
|
|
47
|
+
exclude?: (string | RegExp)[];
|
|
48
|
+
/** Keep `DEFAULT_EXCLUDED_PATHS` in the exclusion list. Default true. */
|
|
49
|
+
excludeDefaults?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Expose OpenAPI `in: 'header'` parameters as tool arguments, sent as
|
|
52
|
+
* request headers (overriding forwarded ones). Default false: they stay
|
|
53
|
+
* unexposed and a warning is printed for required ones.
|
|
54
|
+
*/
|
|
55
|
+
headerParams?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Where `@elysiajs/openapi` serves the JSON document. It is fetched
|
|
58
|
+
* in-process through `app.handle()` on the first MCP request and re-read
|
|
59
|
+
* whenever routes are added. When that route exists but does not answer
|
|
60
|
+
* with a document (it is guarded, say), the document is built in-process
|
|
61
|
+
* with `toOpenAPISchema(app)` instead, without the `openapi()` plugin's own
|
|
62
|
+
* options (`documentation`, `exclude`, `references`, `mapJsonSchema`).
|
|
63
|
+
* Default `/openapi/json`.
|
|
64
|
+
*/
|
|
65
|
+
specPath?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Bypass `specPath`: a document, or a function producing one. The function
|
|
68
|
+
* receives the app the plugin is mounted on, so
|
|
69
|
+
* `({ app }) => toOpenAPISchema(app)` from `@elysiajs/openapi` builds the
|
|
70
|
+
* document in-process even when the OpenAPI routes are disabled.
|
|
71
|
+
*/
|
|
72
|
+
document?: OpenAPIDocument | ((ctx: {
|
|
73
|
+
origin: string;
|
|
74
|
+
app: AnyElysia;
|
|
75
|
+
}) => OpenAPIDocument | Promise<OpenAPIDocument>);
|
|
76
|
+
/** Wrap non-object responses as `{ result }` so they still get an `outputSchema`. Default true. */
|
|
77
|
+
wrapNonObjectOutput?: boolean;
|
|
78
|
+
/** Which incoming MCP request headers reach the synthetic request. Default: all but hop-by-hop and transport headers. */
|
|
79
|
+
headers?: HeaderPolicy;
|
|
80
|
+
/**
|
|
81
|
+
* CORS on the MCP + metadata endpoints. `true` reflects any `Origin` and
|
|
82
|
+
* answers preflight; `{ origins }` does so only for listed origins (exact
|
|
83
|
+
* strings, or a predicate) and sends no `Access-Control-Allow-Origin` for any
|
|
84
|
+
* other; `false` sends no CORS headers. Default `false` in request mode
|
|
85
|
+
* (`auth: { verify }`, which may trust cookies) and `true` otherwise (bearer
|
|
86
|
+
* tokens are not sent by browsers on their own).
|
|
87
|
+
*/
|
|
88
|
+
cors?: McpifyCorsOption;
|
|
89
|
+
/**
|
|
90
|
+
* Called after every `tools/call` that reached the app, with the tool, its
|
|
91
|
+
* arguments, the synthetic request, a copy of the response and the time the
|
|
92
|
+
* app took: an audit log, metrics. It is awaited before the client gets the
|
|
93
|
+
* result; a throw is reported as `on-tool-call-error` and does not fail the
|
|
94
|
+
* call. Calls refused before the app (unknown tool, bad arguments, auth)
|
|
95
|
+
* are not reported. See also `isToolCall(request)`.
|
|
96
|
+
*/
|
|
97
|
+
onToolCall?: OnToolCall;
|
|
98
|
+
/**
|
|
99
|
+
* Where warnings go, with their kind. Default `console.warn(message)`, each
|
|
100
|
+
* distinct message once per process (across every mounted instance); a
|
|
101
|
+
* custom `warn` gets each message once per instance.
|
|
102
|
+
*/
|
|
103
|
+
warn?: (message: string, kind: McpifyWarningKind) => void;
|
|
104
|
+
/**
|
|
105
|
+
* Per-kind switch for warnings: `{ 'path-param-description': false }`
|
|
106
|
+
* silences that kind only. Every kind is on by default; an unknown kind
|
|
107
|
+
* throws.
|
|
108
|
+
*/
|
|
109
|
+
warnings?: Partial<Record<McpifyWarningKind, boolean>>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Exactly one of the two is required, so an endpoint never ends up open by
|
|
113
|
+
* forgetting `auth`.
|
|
114
|
+
*/
|
|
115
|
+
export type McpifyAuthMode = {
|
|
116
|
+
/**
|
|
117
|
+
* `{ resource, authorizationServers, ... }`: OAuth 2.1 resource server,
|
|
118
|
+
* every MCP request needs a valid access token.
|
|
119
|
+
* `{ verify(request) }`: request mode, for API-key or cookie-guarded
|
|
120
|
+
* apps; `true` or an admission (`{ scopes, tools, readOnly }`, which
|
|
121
|
+
* filters the tools) lets a request reach the endpoint, a refusal
|
|
122
|
+
* (`{ status, message }`) answers with that error, anything else gets a
|
|
123
|
+
* bare `401` with no OAuth challenge.
|
|
124
|
+
*/
|
|
125
|
+
auth: McpifyAuthOptions | McpifyRequestAuthOptions;
|
|
126
|
+
unsafeNoAuth?: never;
|
|
127
|
+
} | {
|
|
128
|
+
auth?: never;
|
|
129
|
+
/**
|
|
130
|
+
* Mount the endpoint with no authorization at all: anyone who can reach
|
|
131
|
+
* it can call every exposed route. Local development only.
|
|
132
|
+
*/
|
|
133
|
+
unsafeNoAuth: true;
|
|
134
|
+
};
|
|
135
|
+
export type McpifyOptions = McpifyBaseOptions & McpifyAuthMode;
|
|
136
|
+
/** See `McpifyBaseOptions.cors`. */
|
|
137
|
+
export type McpifyCorsOption = boolean | {
|
|
138
|
+
/** Exact origins (`https://app.example`), or a predicate on the request's `Origin`. */
|
|
139
|
+
origins: string[] | ((origin: string) => boolean);
|
|
140
|
+
};
|
|
141
|
+
export declare const DEFAULT_SPEC_PATH = "/openapi/json";
|
|
142
|
+
export declare function mcpify(options: McpifyOptions): <App extends AnyElysia>(app: App) => App;
|
|
143
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAIhD,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAG9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAuB,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAqC,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,kBAAkB;QAC1B;;;;WAIG;QACH,GAAG,CAAC,EAAE,OAAO,GAAG,eAAe,CAAC;KACjC;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,C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AAY,CAAC,EAAE,KAAK,CAAC;CACtB,GACD;IACE,IAAI,CAAC,EAAE,KAAK,CAAC;IACb;;;OAGG;IACH,YAAY,EAAE,IAAI,CAAC;CACpB,CAAC;AAEN,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,cAAc,CAAC;AAE/D,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GACxB,OAAO,GACP;IACE,uFAAuF;IACvF,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;CACnD,CAAC;AAEN,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAoQjD,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,IA2CnC,GAAG,SAAS,SAAS,EAAE,KAAK,GAAG,KAAG,GAAG,CAoR9C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateless Streamable HTTP, both protocol eras. 2026-07-28 (per-request
|
|
3
|
+
* envelope) traffic goes to the SDK's `createMcpHandler`; 2025-era traffic to
|
|
4
|
+
* a session-less transport answering plain JSON (the handler's own legacy leg
|
|
5
|
+
* always streams SSE). Every request gets a fresh server, which is what makes
|
|
6
|
+
* `tools/call` see the calling request's headers.
|
|
7
|
+
*/
|
|
8
|
+
import { type AuthInfo, type Tool } from '@modelcontextprotocol/server';
|
|
9
|
+
import { type Handler, type HeaderPolicy, type OnToolCall } from './execute.js';
|
|
10
|
+
import type { ToolSpec } from './openapi/derive.js';
|
|
11
|
+
export interface ToolSet {
|
|
12
|
+
list: Tool[];
|
|
13
|
+
byName: Map<string, ToolSpec>;
|
|
14
|
+
}
|
|
15
|
+
export interface ServeOptions {
|
|
16
|
+
request: Request;
|
|
17
|
+
app: Handler;
|
|
18
|
+
tools: ToolSet;
|
|
19
|
+
serverInfo: {
|
|
20
|
+
name: string;
|
|
21
|
+
version: string;
|
|
22
|
+
};
|
|
23
|
+
instructions?: string | undefined;
|
|
24
|
+
headerPolicy?: HeaderPolicy;
|
|
25
|
+
authInfo?: AuthInfo;
|
|
26
|
+
/** The JSON body, when something upstream already consumed the request stream. */
|
|
27
|
+
parsedBody?: unknown;
|
|
28
|
+
/** Called after each tool call that reached the app. */
|
|
29
|
+
onToolCall?: OnToolCall | undefined;
|
|
30
|
+
}
|
|
31
|
+
export declare function serveMcp(o: ServeOptions): Promise<Response>;
|
|
32
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAML,KAAK,QAAQ,EACb,KAAK,IAAI,EAEV,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAY,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,IAAI,EAAE,CAAC;IACb,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9C,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,kFAAkF;IAClF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,wDAAwD;IACxD,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CACrC;AAiED,wBAAsB,QAAQ,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEjE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every message the plugin sends to `warn` carries one of these kinds, so a
|
|
3
|
+
* caller can silence one kind (`warnings: { kind: false }`) or route kinds
|
|
4
|
+
* differently in its own `warn` without matching on the text.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MCPIFY_WARNING_KINDS: readonly ["unauthenticated", "path-param-description", "argument-description", "argument-collision", "duplicate-name", "stray-path-param", "header-param", "non-json-body", "no-output-schema", "invalid-scopes", "scopes-not-enforced", "tool-hidden", "no-tools", "document", "verify-error", "on-tool-call-error", "cors-reflects-origin"];
|
|
7
|
+
export type McpifyWarningKind = (typeof MCPIFY_WARNING_KINDS)[number];
|
|
8
|
+
export interface McpifyWarning {
|
|
9
|
+
kind: McpifyWarningKind;
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
12
|
+
/** Validate `warnings` and return the set of silenced kinds. */
|
|
13
|
+
export declare function silencedKinds(option: Partial<Record<McpifyWarningKind, boolean>> | undefined): Set<McpifyWarningKind>;
|
|
14
|
+
//# sourceMappingURL=warnings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,+UAuCvB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,gEAAgE;AAChE,wBAAgB,aAAa,CAC3B,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,GAC9D,GAAG,CAAC,iBAAiB,CAAC,CAWxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@20baht/elysia-openapi-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Mount an MCP server on an Elysia app: tools derived from the @elysiajs/openapi document, OAuth 2.1 resource-server enforcement built in",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"CHANGELOG.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "bun run scripts/build.ts",
|
|
23
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
24
|
+
"test": "bun test",
|
|
25
|
+
"test:coverage": "bun test --coverage"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"elysia",
|
|
29
|
+
"mcp",
|
|
30
|
+
"model-context-protocol",
|
|
31
|
+
"openapi",
|
|
32
|
+
"oauth",
|
|
33
|
+
"resource-server",
|
|
34
|
+
"bun"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@elysiajs/openapi": "^1.4.0",
|
|
38
|
+
"elysia": "^1.4.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@elysiajs/openapi": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@modelcontextprotocol/server": "^2.3.0",
|
|
47
|
+
"jose": "^6.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@elysiajs/openapi": "^1.4.16",
|
|
51
|
+
"@modelcontextprotocol/client": "^2.3.0",
|
|
52
|
+
"@types/bun": "latest",
|
|
53
|
+
"elysia": "^1.4.30",
|
|
54
|
+
"@20baht/elysia-oauth-provider": "workspace:*",
|
|
55
|
+
"typescript": "^5.6.3"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "git+https://github.com/bank20baht/20baht.git",
|
|
63
|
+
"directory": "packages/elysia/openapi-mcp"
|
|
64
|
+
}
|
|
65
|
+
}
|