fastmcp 4.9.2 → 4.10.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/README.md +42 -0
- package/dist/FastMCP.cjs +4 -2
- package/dist/FastMCP.cjs.map +1 -1
- package/dist/FastMCP.d.cts +66 -1
- package/dist/FastMCP.d.ts +66 -1
- package/dist/FastMCP.js +4 -2
- package/dist/{chunk-ENLYR3QM.cjs → chunk-GF4ORBWZ.cjs} +113 -45
- package/dist/chunk-GF4ORBWZ.cjs.map +1 -0
- package/dist/{chunk-JIPRWP6F.js → chunk-MGP2FVUH.js} +69 -1
- package/dist/chunk-MGP2FVUH.js.map +1 -0
- package/dist/examples/custom-routes.cjs +2 -2
- package/dist/examples/custom-routes.js +1 -1
- package/package.json +11 -1
- package/dist/chunk-ENLYR3QM.cjs.map +0 -1
- package/dist/chunk-JIPRWP6F.js.map +0 -1
package/README.md
CHANGED
|
@@ -594,6 +594,48 @@ server.addTool({
|
|
|
594
594
|
});
|
|
595
595
|
```
|
|
596
596
|
|
|
597
|
+
**Plain JSON Schema Example:**
|
|
598
|
+
|
|
599
|
+
If you already have a JSON Schema — from an OpenAPI document, a config file, or
|
|
600
|
+
another server — `jsonSchemaAdapter` wraps it so it can be used directly, with
|
|
601
|
+
no schema library in between.
|
|
602
|
+
|
|
603
|
+
It requires the peer dependency `ajv`, which does the validation, plus
|
|
604
|
+
`ajv-formats` if your schema uses `format` keywords such as `email` or `uri`.
|
|
605
|
+
Both are imported the first time a tool is called, so servers that don't use
|
|
606
|
+
this pay nothing for it.
|
|
607
|
+
|
|
608
|
+
```bash
|
|
609
|
+
npm install ajv ajv-formats
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
import { jsonSchemaAdapter } from "fastmcp";
|
|
614
|
+
|
|
615
|
+
server.addTool({
|
|
616
|
+
name: "fetch-json-schema",
|
|
617
|
+
description: "Fetch the content of a url (using plain JSON Schema)",
|
|
618
|
+
parameters: jsonSchemaAdapter({
|
|
619
|
+
type: "object",
|
|
620
|
+
properties: {
|
|
621
|
+
url: { type: "string", format: "uri" },
|
|
622
|
+
},
|
|
623
|
+
required: ["url"],
|
|
624
|
+
}),
|
|
625
|
+
execute: async (args) => {
|
|
626
|
+
const { url } = args as { url: string };
|
|
627
|
+
return await fetchWebpageContent(url);
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
Works for `outputSchema` too. Note that FastMCP advertises every tool schema
|
|
633
|
+
with `additionalProperties: false`, whatever your schema said — the same
|
|
634
|
+
treatment Zod and Valibot schemas get.
|
|
635
|
+
|
|
636
|
+
Unlike the schema libraries above, a plain JSON Schema carries no TypeScript
|
|
637
|
+
types, so `execute` receives `unknown` arguments. Cast or narrow them yourself.
|
|
638
|
+
|
|
597
639
|
#### Tools Without Parameters
|
|
598
640
|
|
|
599
641
|
When creating tools that don't require parameters, you have two options:
|
package/dist/FastMCP.cjs
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
var _chunkGF4ORBWZcjs = require('./chunk-GF4ORBWZ.cjs');
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
@@ -41,5 +42,6 @@ var _chunkDZYT6QAHcjs = require('./chunk-DZYT6QAH.cjs');
|
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
|
|
46
|
+
exports.AuthProvider = _chunkDZYT6QAHcjs.AuthProvider; exports.AzureProvider = _chunkDZYT6QAHcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkGF4ORBWZcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkGF4ORBWZcjs.FastMCP; exports.FastMCPSession = _chunkGF4ORBWZcjs.FastMCPSession; exports.GitHubProvider = _chunkDZYT6QAHcjs.GitHubProvider; exports.GoogleProvider = _chunkDZYT6QAHcjs.GoogleProvider; exports.OAuthProvider = _chunkDZYT6QAHcjs.OAuthProvider; exports.ServerState = _chunkGF4ORBWZcjs.ServerState; exports.UnexpectedStateError = _chunkGF4ORBWZcjs.UnexpectedStateError; exports.UserError = _chunkGF4ORBWZcjs.UserError; exports.audioContent = _chunkGF4ORBWZcjs.audioContent; exports.getAuthSession = _chunkDZYT6QAHcjs.getAuthSession; exports.imageContent = _chunkGF4ORBWZcjs.imageContent; exports.jsonSchemaAdapter = _chunkGF4ORBWZcjs.jsonSchemaAdapter; exports.requireAll = _chunkDZYT6QAHcjs.requireAll; exports.requireAny = _chunkDZYT6QAHcjs.requireAny; exports.requireAuth = _chunkDZYT6QAHcjs.requireAuth; exports.requireRole = _chunkDZYT6QAHcjs.requireRole; exports.requireScopes = _chunkDZYT6QAHcjs.requireScopes;
|
|
45
47
|
//# sourceMappingURL=FastMCP.cjs.map
|
package/dist/FastMCP.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,inCAAC","file":"/home/runner/work/fastmcp/fastmcp/dist/FastMCP.cjs"}
|
package/dist/FastMCP.d.cts
CHANGED
|
@@ -47,6 +47,71 @@ declare class DiscoveryDocumentCache {
|
|
|
47
47
|
has(url: string): boolean;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* A plain JSON Schema object descriptor.
|
|
52
|
+
*/
|
|
53
|
+
type JsonSchemaObject = {
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
$schema?: string;
|
|
56
|
+
additionalProperties?: boolean;
|
|
57
|
+
properties?: Record<string, unknown>;
|
|
58
|
+
required?: string[];
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A Standard Schema that also carries the JSON Schema it was built from.
|
|
63
|
+
*
|
|
64
|
+
* `~standard.jsonSchema` is the Standard JSON Schema extension. Anything that
|
|
65
|
+
* knows about it — including the `xsschema` conversion FastMCP uses to build
|
|
66
|
+
* `tools/list` — reads the schema straight off the object instead of trying to
|
|
67
|
+
* derive one from a validation library it does not recognise.
|
|
68
|
+
*/
|
|
69
|
+
interface JsonSchemaStandardSchema extends StandardSchemaV1 {
|
|
70
|
+
readonly "~standard": {
|
|
71
|
+
readonly jsonSchema: {
|
|
72
|
+
readonly input: () => JsonSchemaObject;
|
|
73
|
+
readonly output: () => JsonSchemaObject;
|
|
74
|
+
};
|
|
75
|
+
} & StandardSchemaV1.Props;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Wraps a plain JSON Schema object so it can be used as a tool's `parameters`
|
|
79
|
+
* or `outputSchema`, without pulling in Zod, Valibot, or another validation
|
|
80
|
+
* library.
|
|
81
|
+
*
|
|
82
|
+
* Validation uses AJV, which is an optional peer dependency — install `ajv`
|
|
83
|
+
* (and `ajv-formats` if you use `format` keywords) to use this. It is imported
|
|
84
|
+
* on first validation, so servers that never call this pay nothing for it.
|
|
85
|
+
*
|
|
86
|
+
* Note that FastMCP applies the same strictness to every tool schema: objects
|
|
87
|
+
* are advertised with `additionalProperties: false`, whatever the input schema
|
|
88
|
+
* said.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { FastMCP, jsonSchemaAdapter } from "fastmcp";
|
|
93
|
+
*
|
|
94
|
+
* const server = new FastMCP({ name: "Example", version: "1.0.0" });
|
|
95
|
+
*
|
|
96
|
+
* server.addTool({
|
|
97
|
+
* name: "greet",
|
|
98
|
+
* description: "Greet a user",
|
|
99
|
+
* parameters: jsonSchemaAdapter({
|
|
100
|
+
* type: "object",
|
|
101
|
+
* properties: {
|
|
102
|
+
* name: { type: "string" },
|
|
103
|
+
* },
|
|
104
|
+
* required: ["name"],
|
|
105
|
+
* }),
|
|
106
|
+
* execute: async ({ name }) => `Hello, ${name}!`,
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param schema - A plain JSON Schema object
|
|
111
|
+
* @returns A Standard Schema that validates against `schema`
|
|
112
|
+
*/
|
|
113
|
+
declare function jsonSchemaAdapter(schema: JsonSchemaObject): JsonSchemaStandardSchema;
|
|
114
|
+
|
|
50
115
|
interface Logger {
|
|
51
116
|
debug(...args: unknown[]): void;
|
|
52
117
|
error(...args: unknown[]): void;
|
|
@@ -920,4 +985,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
920
985
|
stop(): Promise<void>;
|
|
921
986
|
}
|
|
922
987
|
|
|
923
|
-
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent };
|
|
988
|
+
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent, jsonSchemaAdapter };
|
package/dist/FastMCP.d.ts
CHANGED
|
@@ -47,6 +47,71 @@ declare class DiscoveryDocumentCache {
|
|
|
47
47
|
has(url: string): boolean;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* A plain JSON Schema object descriptor.
|
|
52
|
+
*/
|
|
53
|
+
type JsonSchemaObject = {
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
$schema?: string;
|
|
56
|
+
additionalProperties?: boolean;
|
|
57
|
+
properties?: Record<string, unknown>;
|
|
58
|
+
required?: string[];
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A Standard Schema that also carries the JSON Schema it was built from.
|
|
63
|
+
*
|
|
64
|
+
* `~standard.jsonSchema` is the Standard JSON Schema extension. Anything that
|
|
65
|
+
* knows about it — including the `xsschema` conversion FastMCP uses to build
|
|
66
|
+
* `tools/list` — reads the schema straight off the object instead of trying to
|
|
67
|
+
* derive one from a validation library it does not recognise.
|
|
68
|
+
*/
|
|
69
|
+
interface JsonSchemaStandardSchema extends StandardSchemaV1 {
|
|
70
|
+
readonly "~standard": {
|
|
71
|
+
readonly jsonSchema: {
|
|
72
|
+
readonly input: () => JsonSchemaObject;
|
|
73
|
+
readonly output: () => JsonSchemaObject;
|
|
74
|
+
};
|
|
75
|
+
} & StandardSchemaV1.Props;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Wraps a plain JSON Schema object so it can be used as a tool's `parameters`
|
|
79
|
+
* or `outputSchema`, without pulling in Zod, Valibot, or another validation
|
|
80
|
+
* library.
|
|
81
|
+
*
|
|
82
|
+
* Validation uses AJV, which is an optional peer dependency — install `ajv`
|
|
83
|
+
* (and `ajv-formats` if you use `format` keywords) to use this. It is imported
|
|
84
|
+
* on first validation, so servers that never call this pay nothing for it.
|
|
85
|
+
*
|
|
86
|
+
* Note that FastMCP applies the same strictness to every tool schema: objects
|
|
87
|
+
* are advertised with `additionalProperties: false`, whatever the input schema
|
|
88
|
+
* said.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { FastMCP, jsonSchemaAdapter } from "fastmcp";
|
|
93
|
+
*
|
|
94
|
+
* const server = new FastMCP({ name: "Example", version: "1.0.0" });
|
|
95
|
+
*
|
|
96
|
+
* server.addTool({
|
|
97
|
+
* name: "greet",
|
|
98
|
+
* description: "Greet a user",
|
|
99
|
+
* parameters: jsonSchemaAdapter({
|
|
100
|
+
* type: "object",
|
|
101
|
+
* properties: {
|
|
102
|
+
* name: { type: "string" },
|
|
103
|
+
* },
|
|
104
|
+
* required: ["name"],
|
|
105
|
+
* }),
|
|
106
|
+
* execute: async ({ name }) => `Hello, ${name}!`,
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param schema - A plain JSON Schema object
|
|
111
|
+
* @returns A Standard Schema that validates against `schema`
|
|
112
|
+
*/
|
|
113
|
+
declare function jsonSchemaAdapter(schema: JsonSchemaObject): JsonSchemaStandardSchema;
|
|
114
|
+
|
|
50
115
|
interface Logger {
|
|
51
116
|
debug(...args: unknown[]): void;
|
|
52
117
|
error(...args: unknown[]): void;
|
|
@@ -920,4 +985,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
920
985
|
stop(): Promise<void>;
|
|
921
986
|
}
|
|
922
987
|
|
|
923
|
-
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent };
|
|
988
|
+
export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type JsonSchemaObject, type JsonSchemaStandardSchema, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent, jsonSchemaAdapter };
|
package/dist/FastMCP.js
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
UnexpectedStateError,
|
|
7
7
|
UserError,
|
|
8
8
|
audioContent,
|
|
9
|
-
imageContent
|
|
10
|
-
|
|
9
|
+
imageContent,
|
|
10
|
+
jsonSchemaAdapter
|
|
11
|
+
} from "./chunk-MGP2FVUH.js";
|
|
11
12
|
import {
|
|
12
13
|
AuthProvider,
|
|
13
14
|
AzureProvider,
|
|
@@ -36,6 +37,7 @@ export {
|
|
|
36
37
|
audioContent,
|
|
37
38
|
getAuthSession,
|
|
38
39
|
imageContent,
|
|
40
|
+
jsonSchemaAdapter,
|
|
39
41
|
requireAll,
|
|
40
42
|
requireAny,
|
|
41
43
|
requireAuth,
|
|
@@ -114,6 +114,73 @@ var DiscoveryDocumentCache = class {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
+
// src/jsonSchemaAdapter.ts
|
|
118
|
+
function jsonSchemaAdapter(schema) {
|
|
119
|
+
let compiled;
|
|
120
|
+
const getValidator = () => {
|
|
121
|
+
compiled ??= compileSchema(schema).catch((error) => {
|
|
122
|
+
compiled = void 0;
|
|
123
|
+
throw error;
|
|
124
|
+
});
|
|
125
|
+
return compiled;
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
"~standard": {
|
|
129
|
+
jsonSchema: {
|
|
130
|
+
input: () => schema,
|
|
131
|
+
output: () => schema
|
|
132
|
+
},
|
|
133
|
+
validate: async (data) => {
|
|
134
|
+
const validate = await getValidator();
|
|
135
|
+
if (validate(data)) {
|
|
136
|
+
return { value: data };
|
|
137
|
+
}
|
|
138
|
+
return { issues: (_nullishCoalesce(validate.errors, () => ( []))).map(toIssue) };
|
|
139
|
+
},
|
|
140
|
+
vendor: "json-schema",
|
|
141
|
+
version: 1
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async function compileSchema(schema) {
|
|
146
|
+
let ajvModule;
|
|
147
|
+
try {
|
|
148
|
+
ajvModule = await Promise.resolve().then(() => _interopRequireWildcard(require("ajv")));
|
|
149
|
+
} catch (e2) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
'The "ajv" package is required to validate JSON Schema tool parameters. Install it with: npm install ajv'
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
const Ajv = unwrapDefault(unwrapDefault(ajvModule));
|
|
155
|
+
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
156
|
+
try {
|
|
157
|
+
const formatsModule = await Promise.resolve().then(() => _interopRequireWildcard(require("ajv-formats")));
|
|
158
|
+
const addFormats = unwrapDefault(
|
|
159
|
+
unwrapDefault(formatsModule)
|
|
160
|
+
);
|
|
161
|
+
addFormats(ajv);
|
|
162
|
+
} catch (e3) {
|
|
163
|
+
}
|
|
164
|
+
return ajv.compile(schema);
|
|
165
|
+
}
|
|
166
|
+
function toIssue(error) {
|
|
167
|
+
const path = error.instancePath.split("/").filter(Boolean).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")).map((segment) => {
|
|
168
|
+
const index = Number(segment);
|
|
169
|
+
return Number.isInteger(index) && segment !== "" ? index : segment;
|
|
170
|
+
});
|
|
171
|
+
const missingProperty = _optionalChain([error, 'access', _2 => _2.params, 'optionalAccess', _3 => _3.missingProperty]);
|
|
172
|
+
if (error.keyword === "required" && typeof missingProperty === "string") {
|
|
173
|
+
path.push(missingProperty);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
message: error.message || "Validation error",
|
|
177
|
+
path
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function unwrapDefault(value) {
|
|
181
|
+
return typeof value === "object" && value !== null && "default" in value ? value.default : value;
|
|
182
|
+
}
|
|
183
|
+
|
|
117
184
|
// src/FastMCP.ts
|
|
118
185
|
var imageContent = async (input) => {
|
|
119
186
|
let rawData;
|
|
@@ -151,13 +218,13 @@ var imageContent = async (input) => {
|
|
|
151
218
|
const mimeType = await fileTypeFromBuffer(rawData);
|
|
152
219
|
if (!mimeType || !mimeType.mime.startsWith("image/")) {
|
|
153
220
|
console.warn(
|
|
154
|
-
`Warning: Content may not be a valid image. Detected MIME: ${_optionalChain([mimeType, 'optionalAccess',
|
|
221
|
+
`Warning: Content may not be a valid image. Detected MIME: ${_optionalChain([mimeType, 'optionalAccess', _4 => _4.mime]) || "unknown"}`
|
|
155
222
|
);
|
|
156
223
|
}
|
|
157
224
|
const base64Data = rawData.toString("base64");
|
|
158
225
|
return {
|
|
159
226
|
data: base64Data,
|
|
160
|
-
mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess',
|
|
227
|
+
mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess', _5 => _5.mime]), () => ( "image/png")),
|
|
161
228
|
type: "image"
|
|
162
229
|
};
|
|
163
230
|
} catch (error) {
|
|
@@ -204,13 +271,13 @@ var audioContent = async (input) => {
|
|
|
204
271
|
const mimeType = await fileTypeFromBuffer(rawData);
|
|
205
272
|
if (!mimeType || !mimeType.mime.startsWith("audio/")) {
|
|
206
273
|
console.warn(
|
|
207
|
-
`Warning: Content may not be a valid audio file. Detected MIME: ${_optionalChain([mimeType, 'optionalAccess',
|
|
274
|
+
`Warning: Content may not be a valid audio file. Detected MIME: ${_optionalChain([mimeType, 'optionalAccess', _6 => _6.mime]) || "unknown"}`
|
|
208
275
|
);
|
|
209
276
|
}
|
|
210
277
|
const base64Data = rawData.toString("base64");
|
|
211
278
|
return {
|
|
212
279
|
data: base64Data,
|
|
213
|
-
mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess',
|
|
280
|
+
mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess', _7 => _7.mime]), () => ( "audio/mpeg")),
|
|
214
281
|
type: "audio"
|
|
215
282
|
};
|
|
216
283
|
} catch (error) {
|
|
@@ -484,10 +551,10 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
484
551
|
);
|
|
485
552
|
}
|
|
486
553
|
}
|
|
487
|
-
if (_optionalChain([this, 'access',
|
|
554
|
+
if (_optionalChain([this, 'access', _8 => _8.#rootsConfig, 'optionalAccess', _9 => _9.enabled]) !== false && _optionalChain([this, 'access', _10 => _10.#clientCapabilities, 'optionalAccess', _11 => _11.roots, 'optionalAccess', _12 => _12.listChanged]) && typeof this.#server.listRoots === "function") {
|
|
488
555
|
try {
|
|
489
556
|
const roots = await this.#server.listRoots();
|
|
490
|
-
this.#roots = _optionalChain([roots, 'optionalAccess',
|
|
557
|
+
this.#roots = _optionalChain([roots, 'optionalAccess', _13 => _13.roots]) || [];
|
|
491
558
|
} catch (e) {
|
|
492
559
|
if (e instanceof _typesjs.McpError && e.code === _typesjs.ErrorCode.MethodNotFound) {
|
|
493
560
|
this.#logger.debug(
|
|
@@ -508,7 +575,7 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
|
|
|
508
575
|
this.#pingInterval = setInterval(async () => {
|
|
509
576
|
try {
|
|
510
577
|
await this.#server.ping();
|
|
511
|
-
} catch (
|
|
578
|
+
} catch (e4) {
|
|
512
579
|
const logLevel = pingConfig.logLevel;
|
|
513
580
|
if (logLevel === "debug") {
|
|
514
581
|
this.#logger.debug("[FastMCP debug] server ping failed");
|
|
@@ -660,7 +727,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
660
727
|
},
|
|
661
728
|
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
662
729
|
log: this.#createLog(),
|
|
663
|
-
requestId: typeof _optionalChain([meta, 'optionalAccess',
|
|
730
|
+
requestId: typeof _optionalChain([meta, 'optionalAccess', _14 => _14.requestId]) === "string" ? meta.requestId : void 0,
|
|
664
731
|
session: this.#auth,
|
|
665
732
|
sessionId: this.#sessionId
|
|
666
733
|
};
|
|
@@ -706,8 +773,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
706
773
|
};
|
|
707
774
|
}
|
|
708
775
|
#formatSchemaIssues(issues) {
|
|
709
|
-
return _optionalChain([this, 'access',
|
|
710
|
-
const path = _optionalChain([issue, 'access',
|
|
776
|
+
return _optionalChain([this, 'access', _15 => _15.#utils, 'optionalAccess', _16 => _16.formatInvalidParamsErrorMessage]) ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
|
|
777
|
+
const path = _optionalChain([issue, 'access', _17 => _17.path, 'optionalAccess', _18 => _18.join, 'call', _19 => _19(".")]) || "root";
|
|
711
778
|
return `${path}: ${issue.message}`;
|
|
712
779
|
}).join(", ");
|
|
713
780
|
}
|
|
@@ -919,7 +986,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
919
986
|
result = await prompt.load(
|
|
920
987
|
args,
|
|
921
988
|
this.#auth,
|
|
922
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
989
|
+
this.#createLoadContext(_optionalChain([request, 'access', _20 => _20.params, 'optionalAccess', _21 => _21._meta]))
|
|
923
990
|
);
|
|
924
991
|
} catch (error) {
|
|
925
992
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -984,7 +1051,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
984
1051
|
const result = await resourceTemplate.load(
|
|
985
1052
|
match,
|
|
986
1053
|
this.#auth,
|
|
987
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
1054
|
+
this.#createLoadContext(_optionalChain([request, 'access', _22 => _22.params, 'optionalAccess', _23 => _23._meta]))
|
|
988
1055
|
);
|
|
989
1056
|
const resources = Array.isArray(result) ? result : [result];
|
|
990
1057
|
return {
|
|
@@ -1009,7 +1076,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1009
1076
|
try {
|
|
1010
1077
|
maybeArrayResult = await resource.load(
|
|
1011
1078
|
this.#auth,
|
|
1012
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
1079
|
+
this.#createLoadContext(_optionalChain([request, 'access', _24 => _24.params, 'optionalAccess', _25 => _25._meta]))
|
|
1013
1080
|
);
|
|
1014
1081
|
} catch (error) {
|
|
1015
1082
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1072,7 +1139,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1072
1139
|
);
|
|
1073
1140
|
}
|
|
1074
1141
|
setupRootsHandlers() {
|
|
1075
|
-
if (_optionalChain([this, 'access',
|
|
1142
|
+
if (_optionalChain([this, 'access', _26 => _26.#rootsConfig, 'optionalAccess', _27 => _27.enabled]) === false) {
|
|
1076
1143
|
this.#logger.debug(
|
|
1077
1144
|
"[FastMCP debug] roots capability explicitly disabled via config"
|
|
1078
1145
|
);
|
|
@@ -1164,7 +1231,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1164
1231
|
}
|
|
1165
1232
|
args = parsed.value;
|
|
1166
1233
|
}
|
|
1167
|
-
const progressToken = _optionalChain([request, 'access',
|
|
1234
|
+
const progressToken = _optionalChain([request, 'access', _28 => _28.params, 'optionalAccess', _29 => _29._meta, 'optionalAccess', _30 => _30.progressToken]);
|
|
1168
1235
|
let result;
|
|
1169
1236
|
try {
|
|
1170
1237
|
const reportProgress = async (progress) => {
|
|
@@ -1223,7 +1290,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1223
1290
|
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
1224
1291
|
log,
|
|
1225
1292
|
reportProgress,
|
|
1226
|
-
requestId: typeof _optionalChain([request, 'access',
|
|
1293
|
+
requestId: typeof _optionalChain([request, 'access', _31 => _31.params, 'optionalAccess', _32 => _32._meta, 'optionalAccess', _33 => _33.requestId]) === "string" ? request.params._meta.requestId : void 0,
|
|
1227
1294
|
session: this.#auth,
|
|
1228
1295
|
sessionId: this.#sessionId,
|
|
1229
1296
|
streamContent
|
|
@@ -1333,14 +1400,14 @@ function normalizePath(path) {
|
|
|
1333
1400
|
return path.startsWith("/") ? path : `/${path}`;
|
|
1334
1401
|
}
|
|
1335
1402
|
function parseBasicAuthHeader(authHeader) {
|
|
1336
|
-
const basicMatch = _optionalChain([authHeader, 'optionalAccess',
|
|
1403
|
+
const basicMatch = _optionalChain([authHeader, 'optionalAccess', _34 => _34.match, 'call', _35 => _35(/^Basic\s+(.+)$/)]);
|
|
1337
1404
|
if (!basicMatch) return null;
|
|
1338
1405
|
try {
|
|
1339
1406
|
const credentials = Buffer.from(basicMatch[1], "base64").toString("utf-8");
|
|
1340
1407
|
const credMatch = credentials.match(/^([^:]+):(.*)$/);
|
|
1341
1408
|
if (!credMatch) return null;
|
|
1342
1409
|
return { clientId: credMatch[1], clientSecret: credMatch[2] };
|
|
1343
|
-
} catch (
|
|
1410
|
+
} catch (e5) {
|
|
1344
1411
|
return null;
|
|
1345
1412
|
}
|
|
1346
1413
|
}
|
|
@@ -1767,7 +1834,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1767
1834
|
enableJsonResponse: httpConfig.enableJsonResponse,
|
|
1768
1835
|
eventStore: httpConfig.eventStore,
|
|
1769
1836
|
host: httpConfig.host,
|
|
1770
|
-
..._optionalChain([this, 'access',
|
|
1837
|
+
..._optionalChain([this, 'access', _36 => _36.#options, 'access', _37 => _37.oauth, 'optionalAccess', _38 => _38.enabled]) && _optionalChain([this, 'access', _39 => _39.#options, 'access', _40 => _40.oauth, 'access', _41 => _41.protectedResource, 'optionalAccess', _42 => _42.resource]) ? {
|
|
1771
1838
|
oauth: {
|
|
1772
1839
|
protectedResource: {
|
|
1773
1840
|
resource: this.#options.oauth.protectedResource.resource
|
|
@@ -1814,7 +1881,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1814
1881
|
enableJsonResponse: httpConfig.enableJsonResponse,
|
|
1815
1882
|
eventStore: httpConfig.eventStore,
|
|
1816
1883
|
host: httpConfig.host,
|
|
1817
|
-
..._optionalChain([this, 'access',
|
|
1884
|
+
..._optionalChain([this, 'access', _43 => _43.#options, 'access', _44 => _44.oauth, 'optionalAccess', _45 => _45.enabled]) && _optionalChain([this, 'access', _46 => _46.#options, 'access', _47 => _47.oauth, 'access', _48 => _48.protectedResource, 'optionalAccess', _49 => _49.resource]) ? {
|
|
1818
1885
|
oauth: {
|
|
1819
1886
|
protectedResource: {
|
|
1820
1887
|
resource: this.#options.oauth.protectedResource.resource
|
|
@@ -1916,7 +1983,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1916
1983
|
*/
|
|
1917
1984
|
#createUnauthorizedResponse(message) {
|
|
1918
1985
|
const oauth = this.#options.oauth;
|
|
1919
|
-
const resource = _optionalChain([oauth, 'optionalAccess',
|
|
1986
|
+
const resource = _optionalChain([oauth, 'optionalAccess', _50 => _50.enabled]) ? _optionalChain([oauth, 'access', _51 => _51.protectedResource, 'optionalAccess', _52 => _52.resource]) : void 0;
|
|
1920
1987
|
const wwwAuthenticateParts = [
|
|
1921
1988
|
'error="invalid_token"',
|
|
1922
1989
|
`error_description="${message.replace(/"/g, '\\"')}"`
|
|
@@ -2028,7 +2095,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2028
2095
|
}
|
|
2029
2096
|
}
|
|
2030
2097
|
const oauthConfig = this.#options.oauth;
|
|
2031
|
-
if (_optionalChain([oauthConfig, 'optionalAccess',
|
|
2098
|
+
if (_optionalChain([oauthConfig, 'optionalAccess', _53 => _53.enabled]) && req.method === "GET") {
|
|
2032
2099
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2033
2100
|
const authorizationServerMetadataPath = joinPaths(
|
|
2034
2101
|
"",
|
|
@@ -2062,8 +2129,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2062
2129
|
}
|
|
2063
2130
|
}
|
|
2064
2131
|
}
|
|
2065
|
-
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess',
|
|
2066
|
-
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess',
|
|
2132
|
+
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _54 => _54.proxy]);
|
|
2133
|
+
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _55 => _55.enabled])) {
|
|
2067
2134
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2068
2135
|
const oauthPath = basePathRelativePath;
|
|
2069
2136
|
try {
|
|
@@ -2080,7 +2147,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2080
2147
|
const statusCode = error.statusCode || 400;
|
|
2081
2148
|
res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
|
|
2082
2149
|
JSON.stringify(
|
|
2083
|
-
_optionalChain([error, 'access',
|
|
2150
|
+
_optionalChain([error, 'access', _56 => _56.toJSON, 'optionalCall', _57 => _57()]) || {
|
|
2084
2151
|
error: "invalid_request"
|
|
2085
2152
|
}
|
|
2086
2153
|
)
|
|
@@ -2107,7 +2174,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2107
2174
|
} catch (error) {
|
|
2108
2175
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2109
2176
|
JSON.stringify(
|
|
2110
|
-
_optionalChain([error, 'access',
|
|
2177
|
+
_optionalChain([error, 'access', _58 => _58.toJSON, 'optionalCall', _59 => _59()]) || {
|
|
2111
2178
|
error: "invalid_request"
|
|
2112
2179
|
}
|
|
2113
2180
|
)
|
|
@@ -2129,7 +2196,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2129
2196
|
} catch (error) {
|
|
2130
2197
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2131
2198
|
JSON.stringify(
|
|
2132
|
-
_optionalChain([error, 'access',
|
|
2199
|
+
_optionalChain([error, 'access', _60 => _60.toJSON, 'optionalCall', _61 => _61()]) || {
|
|
2133
2200
|
error: "server_error"
|
|
2134
2201
|
}
|
|
2135
2202
|
)
|
|
@@ -2164,7 +2231,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2164
2231
|
} catch (error) {
|
|
2165
2232
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2166
2233
|
JSON.stringify(
|
|
2167
|
-
_optionalChain([error, 'access',
|
|
2234
|
+
_optionalChain([error, 'access', _62 => _62.toJSON, 'optionalCall', _63 => _63()]) || {
|
|
2168
2235
|
error: "server_error"
|
|
2169
2236
|
}
|
|
2170
2237
|
)
|
|
@@ -2186,8 +2253,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2186
2253
|
const basicAuth = parseBasicAuthHeader(
|
|
2187
2254
|
req.headers.authorization
|
|
2188
2255
|
);
|
|
2189
|
-
const clientId = _optionalChain([basicAuth, 'optionalAccess',
|
|
2190
|
-
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess',
|
|
2256
|
+
const clientId = _optionalChain([basicAuth, 'optionalAccess', _64 => _64.clientId]) || params.get("client_id") || "";
|
|
2257
|
+
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _65 => _65.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
|
|
2191
2258
|
let response;
|
|
2192
2259
|
if (grantType === "authorization_code") {
|
|
2193
2260
|
response = await oauthProxy.exchangeAuthorizationCode({
|
|
@@ -2217,7 +2284,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2217
2284
|
const statusCode = error.statusCode || 400;
|
|
2218
2285
|
res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
|
|
2219
2286
|
JSON.stringify(
|
|
2220
|
-
_optionalChain([error, 'access',
|
|
2287
|
+
_optionalChain([error, 'access', _66 => _66.toJSON, 'optionalCall', _67 => _67()]) || {
|
|
2221
2288
|
error: "invalid_request"
|
|
2222
2289
|
}
|
|
2223
2290
|
)
|
|
@@ -2288,23 +2355,23 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2288
2355
|
const envBasePath = process.env.FASTMCP_BASE_PATH;
|
|
2289
2356
|
const envStateless = process.env.FASTMCP_STATELESS;
|
|
2290
2357
|
const envHost = process.env.FASTMCP_HOST;
|
|
2291
|
-
const transportType = _optionalChain([overrides, 'optionalAccess',
|
|
2358
|
+
const transportType = _optionalChain([overrides, 'optionalAccess', _68 => _68.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
|
|
2292
2359
|
if (transportType === "httpStream") {
|
|
2293
2360
|
const port = parseInt(
|
|
2294
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
2361
|
+
_optionalChain([overrides, 'optionalAccess', _69 => _69.httpStream, 'optionalAccess', _70 => _70.port, 'optionalAccess', _71 => _71.toString, 'call', _72 => _72()]) || portArg || envPort || "8080"
|
|
2295
2362
|
);
|
|
2296
|
-
const host = _optionalChain([overrides, 'optionalAccess',
|
|
2297
|
-
const endpoint = _optionalChain([overrides, 'optionalAccess',
|
|
2363
|
+
const host = _optionalChain([overrides, 'optionalAccess', _73 => _73.httpStream, 'optionalAccess', _74 => _74.host]) || hostArg || envHost || "localhost";
|
|
2364
|
+
const endpoint = _optionalChain([overrides, 'optionalAccess', _75 => _75.httpStream, 'optionalAccess', _76 => _76.endpoint]) || endpointArg || envEndpoint || "/mcp";
|
|
2298
2365
|
const basePath = normalizeBasePath(
|
|
2299
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
2366
|
+
_optionalChain([overrides, 'optionalAccess', _77 => _77.httpStream, 'optionalAccess', _78 => _78.basePath]) || basePathArg || envBasePath
|
|
2300
2367
|
);
|
|
2301
|
-
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess',
|
|
2302
|
-
const stateless = _optionalChain([overrides, 'optionalAccess',
|
|
2303
|
-
const cors = _optionalChain([overrides, 'optionalAccess',
|
|
2304
|
-
const eventStore = _optionalChain([overrides, 'optionalAccess',
|
|
2305
|
-
const sslCa = _optionalChain([overrides, 'optionalAccess',
|
|
2306
|
-
const sslCert = _optionalChain([overrides, 'optionalAccess',
|
|
2307
|
-
const sslKey = _optionalChain([overrides, 'optionalAccess',
|
|
2368
|
+
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _79 => _79.httpStream, 'optionalAccess', _80 => _80.enableJsonResponse]) || false;
|
|
2369
|
+
const stateless = _optionalChain([overrides, 'optionalAccess', _81 => _81.httpStream, 'optionalAccess', _82 => _82.stateless]) || statelessArg === "true" || envStateless === "true" || false;
|
|
2370
|
+
const cors = _optionalChain([overrides, 'optionalAccess', _83 => _83.httpStream, 'optionalAccess', _84 => _84.cors]);
|
|
2371
|
+
const eventStore = _optionalChain([overrides, 'optionalAccess', _85 => _85.httpStream, 'optionalAccess', _86 => _86.eventStore]);
|
|
2372
|
+
const sslCa = _optionalChain([overrides, 'optionalAccess', _87 => _87.httpStream, 'optionalAccess', _88 => _88.sslCa]);
|
|
2373
|
+
const sslCert = _optionalChain([overrides, 'optionalAccess', _89 => _89.httpStream, 'optionalAccess', _90 => _90.sslCert]);
|
|
2374
|
+
const sslKey = _optionalChain([overrides, 'optionalAccess', _91 => _91.httpStream, 'optionalAccess', _92 => _92.sslKey]);
|
|
2308
2375
|
return {
|
|
2309
2376
|
httpStream: {
|
|
2310
2377
|
basePath,
|
|
@@ -2376,5 +2443,6 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2376
2443
|
|
|
2377
2444
|
|
|
2378
2445
|
|
|
2379
|
-
|
|
2380
|
-
|
|
2446
|
+
|
|
2447
|
+
exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ServerState = ServerState; exports.FastMCPSession = FastMCPSession; exports.FastMCP = FastMCP;
|
|
2448
|
+
//# sourceMappingURL=chunk-GF4ORBWZ.cjs.map
|