fastmcp 4.17.1 → 4.18.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.
@@ -0,0 +1,171 @@
1
+ import { FastMCP, FastMCPSessionAuth } from '../FastMCP.cjs';
2
+ import '@modelcontextprotocol/sdk/server/index.js';
3
+ import '@modelcontextprotocol/sdk/server/streamableHttp.js';
4
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
5
+ import '@modelcontextprotocol/sdk/shared/transport.js';
6
+ import '@modelcontextprotocol/sdk/types.js';
7
+ import '@standard-schema/spec';
8
+ import 'events';
9
+ import 'hono';
10
+ import 'http';
11
+ import 'mcp-proxy';
12
+ import 'strict-event-emitter-types';
13
+ import 'zod';
14
+ import '../OAuthProvider-Dy1PbWAT.cjs';
15
+ import 'node:http';
16
+
17
+ /**
18
+ * A minimal, hand-typed slice of a bundled OpenAPI 3.x document — just the
19
+ * parts this module reads. Deliberately not the full `openapi-types` shape,
20
+ * to avoid taking on that dependency for typing alone.
21
+ */
22
+ interface BundledOpenApiDocument {
23
+ components?: {
24
+ schemas?: Record<string, OpenApiSchema>;
25
+ };
26
+ info?: {
27
+ title?: string;
28
+ };
29
+ openapi?: string;
30
+ paths?: Record<string, RawPathItem>;
31
+ servers?: OpenApiServer[];
32
+ swagger?: string;
33
+ }
34
+ interface FromOpenAPIOptions {
35
+ /**
36
+ * Overrides the resolved `servers[0].url`. Required when the spec has no
37
+ * `servers` entry, or has a relative `servers[0].url` and was not loaded
38
+ * from an http(s) URL.
39
+ */
40
+ baseUrl?: string;
41
+ /**
42
+ * Excludes operations for which this returns `true`. Applied after
43
+ * `include`.
44
+ */
45
+ exclude?: (operation: OperationSummary) => boolean;
46
+ /**
47
+ * HTTP client used to execute generated tool calls. Defaults to the global
48
+ * `fetch`.
49
+ */
50
+ fetch?: typeof fetch;
51
+ /**
52
+ * Static or dynamically-resolved headers (e.g. an auth token) sent with
53
+ * every generated tool call.
54
+ */
55
+ headers?: (() => Promise<Record<string, string>> | Record<string, string>) | Record<string, string>;
56
+ /**
57
+ * Only keeps operations for which this returns `true`.
58
+ */
59
+ include?: (operation: OperationSummary) => boolean;
60
+ /**
61
+ * Hard cap on the number of generated tools. `fromOpenAPI` throws rather
62
+ * than silently truncating if the operation count (after `include`/
63
+ * `exclude`) exceeds this — or a default threshold, if neither this nor
64
+ * `include`/`exclude` was provided.
65
+ */
66
+ maxTools?: number;
67
+ /**
68
+ * Overrides the generated tool name for a given `operationId`.
69
+ */
70
+ mcpNames?: Record<string, string>;
71
+ /**
72
+ * Name for a newly-created server. Ignored when `server` is provided.
73
+ * @default the spec's `info.title`, or "OpenAPI Server"
74
+ */
75
+ name?: string;
76
+ /**
77
+ * An existing `FastMCP` server to register the generated tools onto,
78
+ * instead of creating a new one.
79
+ */
80
+ server?: FastMCP<FastMCPSessionAuth>;
81
+ /**
82
+ * A URL, a file path, or an already-parsed OpenAPI document.
83
+ *
84
+ * Passing a URL or file path (rather than a parsed object) is what lets
85
+ * external `$ref`s and a relative `servers[0].url` resolve correctly — both
86
+ * are resolved relative to this value.
87
+ */
88
+ spec: Record<string, unknown> | string;
89
+ /**
90
+ * Version for a newly-created server. Ignored when `server` is provided.
91
+ * @default "1.0.0"
92
+ */
93
+ version?: `${number}.${number}.${number}`;
94
+ }
95
+ type HttpMethod = "delete" | "get" | "patch" | "post" | "put";
96
+ interface HttpRoute {
97
+ deprecated: boolean;
98
+ method: HttpMethod;
99
+ operationId?: string;
100
+ parameters: OpenApiParameter[];
101
+ path: string;
102
+ requestBody?: OpenApiRequestBody;
103
+ summary?: string;
104
+ tags: string[];
105
+ }
106
+ interface OpenApiParameter {
107
+ deprecated?: boolean;
108
+ description?: string;
109
+ in: ParameterLocation;
110
+ name: string;
111
+ required?: boolean;
112
+ schema?: OpenApiSchema;
113
+ }
114
+ interface OpenApiParameterRef {
115
+ $ref: string;
116
+ }
117
+ interface OpenApiRequestBody {
118
+ content?: Record<string, {
119
+ schema?: OpenApiSchema;
120
+ }>;
121
+ required?: boolean;
122
+ }
123
+ /**
124
+ * A raw OpenAPI/JSON Schema fragment as it appears inside the document
125
+ * (a parameter's `schema`, a `components.schemas` entry, etc.). Unlike
126
+ * `JsonSchemaObject` (jsonSchemaAdapter.ts), these are not required to carry
127
+ * a top-level `type` — a bare `$ref`, `allOf`, or `enum`-only node is valid
128
+ * JSON Schema and shows up constantly in real specs. Only the final,
129
+ * assembled per-tool schema needs to satisfy `JsonSchemaObject` (see
130
+ * `schemas.ts`).
131
+ */
132
+ type OpenApiSchema = Record<string, unknown>;
133
+ interface OpenApiServer {
134
+ url: string;
135
+ variables?: Record<string, OpenApiServerVariable>;
136
+ }
137
+ interface OpenApiServerVariable {
138
+ default: string;
139
+ }
140
+ /**
141
+ * The subset of a route's shape exposed to `include`/`exclude` predicates.
142
+ */
143
+ interface OperationSummary {
144
+ deprecated: boolean;
145
+ method: HttpMethod;
146
+ operationId?: string;
147
+ path: string;
148
+ tags: string[];
149
+ }
150
+ type ParameterLocation = "cookie" | "header" | "path" | "query";
151
+ interface RawOperation {
152
+ deprecated?: boolean;
153
+ operationId?: string;
154
+ parameters?: (OpenApiParameter | OpenApiParameterRef)[];
155
+ requestBody?: OpenApiParameterRef | OpenApiRequestBody;
156
+ summary?: string;
157
+ tags?: string[];
158
+ }
159
+ type RawPathItem = {
160
+ parameters?: (OpenApiParameter | OpenApiParameterRef)[];
161
+ } & Partial<Record<HttpMethod, RawOperation>>;
162
+
163
+ /**
164
+ * Converts an OpenAPI 3.x document into an MCP server, one tool per
165
+ * operation.
166
+ *
167
+ * See docs/openapi.md for the full option reference and known limitations.
168
+ */
169
+ declare function fromOpenAPI(options: FromOpenAPIOptions): Promise<FastMCP>;
170
+
171
+ export { type BundledOpenApiDocument, type FromOpenAPIOptions, type HttpMethod, type HttpRoute, type OperationSummary, fromOpenAPI };
@@ -0,0 +1,171 @@
1
+ import { FastMCP, FastMCPSessionAuth } from '../FastMCP.js';
2
+ import '@modelcontextprotocol/sdk/server/index.js';
3
+ import '@modelcontextprotocol/sdk/server/streamableHttp.js';
4
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
5
+ import '@modelcontextprotocol/sdk/shared/transport.js';
6
+ import '@modelcontextprotocol/sdk/types.js';
7
+ import '@standard-schema/spec';
8
+ import 'events';
9
+ import 'hono';
10
+ import 'http';
11
+ import 'mcp-proxy';
12
+ import 'strict-event-emitter-types';
13
+ import 'zod';
14
+ import '../OAuthProvider-Dy1PbWAT.js';
15
+ import 'node:http';
16
+
17
+ /**
18
+ * A minimal, hand-typed slice of a bundled OpenAPI 3.x document — just the
19
+ * parts this module reads. Deliberately not the full `openapi-types` shape,
20
+ * to avoid taking on that dependency for typing alone.
21
+ */
22
+ interface BundledOpenApiDocument {
23
+ components?: {
24
+ schemas?: Record<string, OpenApiSchema>;
25
+ };
26
+ info?: {
27
+ title?: string;
28
+ };
29
+ openapi?: string;
30
+ paths?: Record<string, RawPathItem>;
31
+ servers?: OpenApiServer[];
32
+ swagger?: string;
33
+ }
34
+ interface FromOpenAPIOptions {
35
+ /**
36
+ * Overrides the resolved `servers[0].url`. Required when the spec has no
37
+ * `servers` entry, or has a relative `servers[0].url` and was not loaded
38
+ * from an http(s) URL.
39
+ */
40
+ baseUrl?: string;
41
+ /**
42
+ * Excludes operations for which this returns `true`. Applied after
43
+ * `include`.
44
+ */
45
+ exclude?: (operation: OperationSummary) => boolean;
46
+ /**
47
+ * HTTP client used to execute generated tool calls. Defaults to the global
48
+ * `fetch`.
49
+ */
50
+ fetch?: typeof fetch;
51
+ /**
52
+ * Static or dynamically-resolved headers (e.g. an auth token) sent with
53
+ * every generated tool call.
54
+ */
55
+ headers?: (() => Promise<Record<string, string>> | Record<string, string>) | Record<string, string>;
56
+ /**
57
+ * Only keeps operations for which this returns `true`.
58
+ */
59
+ include?: (operation: OperationSummary) => boolean;
60
+ /**
61
+ * Hard cap on the number of generated tools. `fromOpenAPI` throws rather
62
+ * than silently truncating if the operation count (after `include`/
63
+ * `exclude`) exceeds this — or a default threshold, if neither this nor
64
+ * `include`/`exclude` was provided.
65
+ */
66
+ maxTools?: number;
67
+ /**
68
+ * Overrides the generated tool name for a given `operationId`.
69
+ */
70
+ mcpNames?: Record<string, string>;
71
+ /**
72
+ * Name for a newly-created server. Ignored when `server` is provided.
73
+ * @default the spec's `info.title`, or "OpenAPI Server"
74
+ */
75
+ name?: string;
76
+ /**
77
+ * An existing `FastMCP` server to register the generated tools onto,
78
+ * instead of creating a new one.
79
+ */
80
+ server?: FastMCP<FastMCPSessionAuth>;
81
+ /**
82
+ * A URL, a file path, or an already-parsed OpenAPI document.
83
+ *
84
+ * Passing a URL or file path (rather than a parsed object) is what lets
85
+ * external `$ref`s and a relative `servers[0].url` resolve correctly — both
86
+ * are resolved relative to this value.
87
+ */
88
+ spec: Record<string, unknown> | string;
89
+ /**
90
+ * Version for a newly-created server. Ignored when `server` is provided.
91
+ * @default "1.0.0"
92
+ */
93
+ version?: `${number}.${number}.${number}`;
94
+ }
95
+ type HttpMethod = "delete" | "get" | "patch" | "post" | "put";
96
+ interface HttpRoute {
97
+ deprecated: boolean;
98
+ method: HttpMethod;
99
+ operationId?: string;
100
+ parameters: OpenApiParameter[];
101
+ path: string;
102
+ requestBody?: OpenApiRequestBody;
103
+ summary?: string;
104
+ tags: string[];
105
+ }
106
+ interface OpenApiParameter {
107
+ deprecated?: boolean;
108
+ description?: string;
109
+ in: ParameterLocation;
110
+ name: string;
111
+ required?: boolean;
112
+ schema?: OpenApiSchema;
113
+ }
114
+ interface OpenApiParameterRef {
115
+ $ref: string;
116
+ }
117
+ interface OpenApiRequestBody {
118
+ content?: Record<string, {
119
+ schema?: OpenApiSchema;
120
+ }>;
121
+ required?: boolean;
122
+ }
123
+ /**
124
+ * A raw OpenAPI/JSON Schema fragment as it appears inside the document
125
+ * (a parameter's `schema`, a `components.schemas` entry, etc.). Unlike
126
+ * `JsonSchemaObject` (jsonSchemaAdapter.ts), these are not required to carry
127
+ * a top-level `type` — a bare `$ref`, `allOf`, or `enum`-only node is valid
128
+ * JSON Schema and shows up constantly in real specs. Only the final,
129
+ * assembled per-tool schema needs to satisfy `JsonSchemaObject` (see
130
+ * `schemas.ts`).
131
+ */
132
+ type OpenApiSchema = Record<string, unknown>;
133
+ interface OpenApiServer {
134
+ url: string;
135
+ variables?: Record<string, OpenApiServerVariable>;
136
+ }
137
+ interface OpenApiServerVariable {
138
+ default: string;
139
+ }
140
+ /**
141
+ * The subset of a route's shape exposed to `include`/`exclude` predicates.
142
+ */
143
+ interface OperationSummary {
144
+ deprecated: boolean;
145
+ method: HttpMethod;
146
+ operationId?: string;
147
+ path: string;
148
+ tags: string[];
149
+ }
150
+ type ParameterLocation = "cookie" | "header" | "path" | "query";
151
+ interface RawOperation {
152
+ deprecated?: boolean;
153
+ operationId?: string;
154
+ parameters?: (OpenApiParameter | OpenApiParameterRef)[];
155
+ requestBody?: OpenApiParameterRef | OpenApiRequestBody;
156
+ summary?: string;
157
+ tags?: string[];
158
+ }
159
+ type RawPathItem = {
160
+ parameters?: (OpenApiParameter | OpenApiParameterRef)[];
161
+ } & Partial<Record<HttpMethod, RawOperation>>;
162
+
163
+ /**
164
+ * Converts an OpenAPI 3.x document into an MCP server, one tool per
165
+ * operation.
166
+ *
167
+ * See docs/openapi.md for the full option reference and known limitations.
168
+ */
169
+ declare function fromOpenAPI(options: FromOpenAPIOptions): Promise<FastMCP>;
170
+
171
+ export { type BundledOpenApiDocument, type FromOpenAPIOptions, type HttpMethod, type HttpRoute, type OperationSummary, fromOpenAPI };